Search in sources :

Example 21 with CrossOrigin

use of org.springframework.web.bind.annotation.CrossOrigin in project LaRocheChemAssessment by clubberstake.

the class ClassController method saveSyllabus.

@CrossOrigin(origins = "http://localhost:4200")
@PostMapping("/saveSyllabus")
public ResponseEntity<Void> saveSyllabus(@RequestBody String[] syllabus) throws FileNotFoundException {
    System.out.println(syllabus[1]);
    String[] filepath = syllabus[0].split("/");
    String PATH = "src/main/java/laroche/chem/assessment/syllabus";
    for (int i = 0; i < filepath.length - 1; i++) {
        PATH = PATH + "/" + filepath[i];
        File directory = new File(String.valueOf(PATH));
        if (!directory.exists()) {
            directory.mkdir();
        }
    }
    System.out.println(PATH);
    writer = new PrintWriter(PATH + "/" + filepath[filepath.length - 1]);
    writer.println(syllabus[1]);
    writer.close();
    return ResponseEntity.status(HttpStatus.CONFLICT).build();
}
Also used : File(java.io.File) PrintWriter(java.io.PrintWriter) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 22 with CrossOrigin

use of org.springframework.web.bind.annotation.CrossOrigin in project Info-Evaluation by TechnionYP5777.

the class InfoevalServiceImp method checkAmbiguities.

@Override
@CrossOrigin
@RequestMapping(path = "Queries/checkAmbiguities", method = RequestMethod.GET)
public synchronized ArrayList<String> checkAmbiguities(String name) throws IOException {
    String UpdatedName = updteName(name);
    try {
        logger.log(Level.INFO, "Checking ambiguities in URL: " + "https://en.wikipedia.org/wiki/" + UpdatedName);
        WikiParsing wiki = (new WikiParsing("https://en.wikipedia.org/wiki/" + UpdatedName));
        // System.out.print("Trying to fetch from ,
        // https://en.wikipedia.org/wiki/" + UpdatedName);
        wiki.CheckAmbiguities();
        return !wiki.isConflictedName() ? null : wiki.getNames();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Problem in checking ambiguities");
        throw e;
    }
}
Also used : WikiParsing(infoeval.main.WikiData.WikiParsing) IOException(java.io.IOException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with CrossOrigin

use of org.springframework.web.bind.annotation.CrossOrigin in project Info-Evaluation by TechnionYP5777.

the class InfoevalServiceImp method getArrested.

@Override
@CrossOrigin
@RequestMapping(path = "Queries/Arrests", method = RequestMethod.GET)
public synchronized LinkedList<String> getArrested(String name) throws Exception {
    // Parse user's input:
    String UpdatedName = updteName(name);
    try {
        logger.log(Level.INFO, "Analyzing Arrests query from url: " + "https://en.wikipedia.org/wiki/" + UpdatedName);
        WikiParsing wiki = (new WikiParsing("https://en.wikipedia.org/wiki/" + UpdatedName));
        wiki.Parse("arrested");
        new ArrayList<>();
        analyze.setParagraphsArrests(wiki.getParagraphs());
        analyze.clearArrestsInformation();
        analyze.ArrestsQuery();
        return analyze.getArrestsInformation();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Problem in arrests query");
        throw e;
    }
}
Also used : WikiParsing(infoeval.main.WikiData.WikiParsing) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with CrossOrigin

use of org.springframework.web.bind.annotation.CrossOrigin in project c4sg-services by Code4SocialGood.

the class OrganizationController method createUserOrganization.

@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}", method = RequestMethod.POST)
@ApiOperation(value = "Create a relation between user and organization")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of organization or user invalid") })
public // TODO: Replace explicit user{id} with AuthN user id.
ResponseEntity<?> createUserOrganization(@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId, @ApiParam(value = "ID of organization", required = true) @PathVariable("id") Integer organizationId) {
    System.out.println("************** OrganizationController.createUserOrganization()" + ": userId=" + userId + "; organizationId=" + organizationId + " **************");
    try {
        organizationService.saveUserOrganization(userId, organizationId);
        URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}/users/{userId}").buildAndExpand(organizationId, userId).toUri();
        return ResponseEntity.created(location).build();
    } catch (NullPointerException | UserOrganizationException e) {
        throw new NotFoundException("ID of organization or user invalid, or relationship already exist");
    }
}
Also used : UserOrganizationException(org.c4sg.exception.UserOrganizationException) NotFoundException(org.c4sg.exception.NotFoundException) URI(java.net.URI) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with CrossOrigin

use of org.springframework.web.bind.annotation.CrossOrigin in project spring-framework by spring-projects.

the class RequestMappingHandlerMapping method initCorsConfiguration.

@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
    HandlerMethod handlerMethod = createHandlerMethod(handler, method);
    Class<?> beanType = handlerMethod.getBeanType();
    CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
    CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);
    if (typeAnnotation == null && methodAnnotation == null) {
        return null;
    }
    CorsConfiguration config = new CorsConfiguration();
    updateCorsConfig(config, typeAnnotation);
    updateCorsConfig(config, methodAnnotation);
    if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
        for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
            config.addAllowedMethod(allowedMethod.name());
        }
    }
    return config.applyPermitDefaultValues();
}
Also used : CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) HandlerMethod(org.springframework.web.method.HandlerMethod)

Aggregations

CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 Task (com.viadee.sonarQuest.entities.Task)8 SpecialTask (com.viadee.sonarQuest.entities.SpecialTask)7 Quest (com.viadee.sonarQuest.entities.Quest)6 ApiOperation (io.swagger.annotations.ApiOperation)5 IOException (java.io.IOException)5 NotFoundException (org.c4sg.exception.NotFoundException)4 UserOrganizationException (org.c4sg.exception.UserOrganizationException)4 SpecialTaskDto (com.viadee.sonarQuest.dtos.SpecialTaskDto)3 TaskDto (com.viadee.sonarQuest.dtos.TaskDto)3 TaskDto.toTaskDto (com.viadee.sonarQuest.dtos.TaskDto.toTaskDto)3 World (com.viadee.sonarQuest.entities.World)3 WikiParsing (infoeval.main.WikiData.WikiParsing)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ArrayList (java.util.ArrayList)3 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)3 OrganizationDTO (org.c4sg.dto.OrganizationDTO)3 BadRequestException (org.c4sg.exception.BadRequestException)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3