Example usage for org.springframework.http HttpStatus CREATED

List of usage examples for org.springframework.http HttpStatus CREATED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus CREATED.

Prototype

HttpStatus CREATED

To view the source code for org.springframework.http HttpStatus CREATED.

Click Source Link

Document

201 Created .

Usage

From source file:de.thm.arsnova.controller.AudienceQuestionController.java

@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void postInterposedQuestion(@RequestParam final String sessionkey,
        @RequestBody final de.thm.arsnova.entities.InterposedQuestion question) {
    if (questionService.saveQuestion(question)) {
        return;//from   w w  w .j a  v a  2s  .  c o m
    }

    throw new BadRequestException();
}

From source file:io.fourfinanceit.homework.controller.ClientController.java

@RequestMapping(value = "/client", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<LoanApplication> createClient(@RequestBody Client client, HttpServletRequest request) {

    LoanApplication loanApplication = null;

    while (client.getLoanApplications().iterator().hasNext()) {
        loanApplication = client.getLoanApplications().iterator().next();
        loanApplication.setIpAddress(ipAddressDefiner.getIpAddress(request));
    }/* w w w .j a v a  2  s .c  o  m*/

    Client savedClient = clientRepository.save(client);

    while (savedClient.getLoanApplications().iterator().hasNext()) {
        if (!savedClient.getLoanApplications().iterator().hasNext()) {
            loanApplication = savedClient.getLoanApplications().iterator().next();
        }
    }

    if (loanApplication.getStatus() == LoanApplicationStatusEnum.ACTIVE.getStatus()) {
        return new ResponseEntity<LoanApplication>(loanApplication, HttpStatus.CREATED);
    } else {
        return new ResponseEntity<LoanApplication>(loanApplication, HttpStatus.FORBIDDEN);
    }

}

From source file:com.parivero.swagger.demo.controller.PersonaController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ApiOperation(value = "Alta de Persona")
@ApiErrors(errors = { @ApiError(code = 400, reason = "request invalido") })
@ApiModel(type = Persona.class)
public @ResponseBody Persona alta(
        @ApiParam(value = "recurso a crear sin id", required = true) @RequestBody Persona persona) {
    if (persona.getId() != null) {
        throw new IllegalArgumentException();
    }/*from  w w w  .j  a va  2s .co  m*/
    persona.setId(Long.MAX_VALUE);
    persona.setNombre(persona.getNombre() + "- Modificado");
    return persona;
}

From source file:com.nebhale.buildmonitor.web.ProjectController.java

@Transactional
@RequestMapping(method = RequestMethod.POST, value = "", produces = MEDIA_TYPE)
ResponseEntity<?> create(@RequestBody Project project) {
    if (this.repository.exists(project.getKey())) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }/*from   w  w w  . j  a v a2 s  .co m*/

    this.repository.saveAndFlush(project);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(linkTo(ProjectController.class).slash(project.getKey()).toUri());

    this.projectsChangedNotifier.projectsChanged();
    return new ResponseEntity<>(headers, HttpStatus.CREATED);
}

From source file:com.tsg.addressbookmvc.RESTController.java

@RequestMapping(value = "/address", method = RequestMethod.POST)
// response back to javascript confirming request was created
@ResponseStatus(HttpStatus.CREATED)
// payload expected
@ResponseBody//w  w w  . j  av a 2s .  co  m
public Address createAddress(@Valid @RequestBody Address address) {
    // persist the incoming address
    // The addAddress call to the dao assigned an addressId to the incoming
    // Address and set that value on the object. Now we return the updated
    // object to the caller.
    return dao.addAddress(address);

}

From source file:org.openwms.tms.api.TransportationController.java

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void createTO(@RequestBody CreateTransportOrderVO vo, HttpServletRequest req, HttpServletResponse resp) {
    validatePriority(vo);//w w w.  j a  va  2  s .  c  o m
    TransportOrder to = service.create(vo.getBarcode(), vo.getTarget(),
            PriorityLevel.valueOf(vo.getPriority()));
    resp.addHeader(HttpHeaders.LOCATION, getCreatedResourceURI(req, to.getPersistentKey()));
}

From source file:com.sms.server.controller.AdminController.java

@RequestMapping(value = "/user", method = RequestMethod.POST, headers = { "Content-type=application/json" })
@ResponseBody//from  w  w  w .j av a2 s.c  o  m
public ResponseEntity<String> createUser(@RequestBody User user) {
    // Check mandatory fields.
    if (user.getUsername() == null || user.getPassword() == null) {
        return new ResponseEntity<>("Missing required parameter.", HttpStatus.BAD_REQUEST);
    }

    // Check unique fields
    if (userDao.getUserByUsername(user.getUsername()) != null) {
        return new ResponseEntity<>("Username already exists.", HttpStatus.NOT_ACCEPTABLE);
    }

    // Add user to the database.
    if (!userDao.createUser(user)) {
        LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME,
                "Error adding user '" + user.getUsername() + "' to database.", null);
        return new ResponseEntity<>("Error adding user to database.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME,
            "User '" + user.getUsername() + "' created successfully.", null);
    return new ResponseEntity<>("User created successfully.", HttpStatus.CREATED);
}

From source file:be.boyenvaesen.EmployeeControllerTest.java

@Test
public void testScenarioPostOneGetList() {

    //Check if list is the list from setup
    ResponseEntity<Employee[]> responseEntity = restTemplate.getForEntity("/employees", Employee[].class);
    Employee[] employees = responseEntity.getBody();
    assertEquals("Boyen", employees[0].getFirstName());
    assertEquals(4, employees.length);//  w  w w.j  av  a2 s  .c o m

    //Post a new employee
    ResponseEntity<Employee> postedEntity = restTemplate.postForEntity("/employees",
            new Employee("newFirst", "newLast", "newDescr"), Employee.class);
    Employee postedEmployee = postedEntity.getBody();
    assertEquals(HttpStatus.CREATED, postedEntity.getStatusCode());
    assertEquals("newFirst", postedEmployee.getFirstName());

    //Check if list is now changed with the new value
    responseEntity = restTemplate.getForEntity("/employees", Employee[].class);
    employees = responseEntity.getBody();
    assertEquals("Boyen", employees[0].getFirstName());
    assertEquals(postedEmployee.getFirstName(), employees[4].getFirstName());

    assertEquals(5, employees.length);

}

From source file:com.mycompany.springrest.controllers.UserController.java

@RequestMapping(value = "/user/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) {
    logger.info("Creating User " + user.getUserName());
    if (userService.isUserExist(user)) {
        logger.info("A User with name " + user.getUserName() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }/*from  www  . j  a  va2s.  com*/
    userService.addUser(user);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(user.getId()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:de.escalon.hypermedia.spring.sample.ReviewController.java

@Action("ReviewAction")
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST, params = { "review", "rating" })
public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestParam String review,
        @RequestParam int rating) {
    final HttpHeaders headers = new HttpHeaders();
    headers.setLocation(//from  w w  w. ja va2  s . c om
            AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri());
    return new ResponseEntity(headers, HttpStatus.CREATED);
}