Example usage for org.springframework.http HttpStatus CONFLICT

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

Introduction

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

Prototype

HttpStatus CONFLICT

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

Click Source Link

Document

409 Conflict .

Usage

From source file:org.trustedanalytics.user.invite.RestErrorHandler.java

@ResponseBody
@ResponseStatus(HttpStatus.CONFLICT)
@ExceptionHandler(OrgExistsException.class)
public UserConflictResponse orgExists(OrgExistsException e) throws IOException {
    return UserConflictResponse.of(UserConflictResponse.ConflictedField.ORG, e.getMessage());
}

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

@RequestMapping(value = "/role/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> createRole(@RequestBody Role role, UriComponentsBuilder ucBuilder) {
    logger.info("Creating Role " + role.getName());
    if (roleService.isRoleExist(role)) {
        logger.info("A Role with name " + role.getName() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }// www .java 2 s.  com
    roleService.addRole(role);

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

From source file:org.lecture.controller.UserController.java

/**
 * Creates a new User//ww w .j av  a 2  s  .c o m
 * @param entity the user from the post-request. This user is deserialized by
 *              jackson.
 * @return A respoonse containing a link to the new resource.
 */
@RequestMapping(method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
public ResponseEntity<?> create(@RequestBody User entity) {
    User user = this.userRepository.findByUsername(entity.getUsername());
    if (user == null) {
        this.userRepository.save(entity);
        nats.publish("authentication-service.user-created", entity.getId());
        return ResponseEntity.noContent().build();
    }
    return ResponseEntity.status(HttpStatus.CONFLICT).build();
}

From source file:ch.wisv.areafiftylan.extras.rfid.controller.RFIDController.java

@ExceptionHandler(RFIDTakenException.class)
public ResponseEntity<?> handleRFIDTakenException(RFIDTakenException e) {
    return createResponseEntity(HttpStatus.CONFLICT, e.getMessage());
}

From source file:com.agroservices.restcontrollers.DespachoRest.java

/**
 * Mtodo encargado de confirmar que el producto comprado por el minorista le fue entregado
 * @param id// www.j  a  va2s .  c  o  m
 * @return
 * @throws OperationFailedException 
 */

@RequestMapping(value = "/confirmat/{id}", method = RequestMethod.POST)
public ResponseEntity<?> confirmarDetalleDespacho(@PathVariable int id) throws OperationFailedException {

    if (df.setDetalleDespacho(id)) {
        return new ResponseEntity<>(HttpStatus.OK);
    } else {
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

}

From source file:ch.wisv.areafiftylan.teams.controller.TeamRestController.java

/**
 * The method to handle POST requests on the /teams endpoint. This creates a new team. Users can only create new
 * Teams with themselves as Captain. Admins can also create Teams with other Users as Captain.
 *
 * @param teamDTO Object containing the Team name and Captain username. When coming from a user, username should
 *                equal their own username.
 * @param auth    Authentication object from Spring Security
 *
 * @return Return status message of the operation
 *///from www.jav  a 2  s  .  co m
@PreAuthorize("isAuthenticated() and @currentUserServiceImpl.hasAnyTicket(principal)")
@JsonView(View.Public.class)
@RequestMapping(method = RequestMethod.POST)
ResponseEntity<?> add(@Validated @RequestBody TeamDTO teamDTO, Authentication auth) {
    if (teamService.teamnameUsed(teamDTO.getTeamName())) {
        return createResponseEntity(HttpStatus.CONFLICT,
                "Team with name \"" + teamDTO.getTeamName() + "\" already exists.");
    }

    Team team;
    // Users can only create teams with themselves as Captain
    if (auth.getAuthorities().contains(Role.ROLE_ADMIN)) {
        team = teamService.create(teamDTO.getCaptainUsername(), teamDTO.getTeamName());
    } else {
        // If the DTO contains another username as the the current user, return an error.
        if (!auth.getName().equalsIgnoreCase(teamDTO.getCaptainUsername())) {
            return createResponseEntity(HttpStatus.BAD_REQUEST,
                    "Can not create team with another user as Captain");
        }
        team = teamService.create(auth.getName(), teamDTO.getTeamName());
    }

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}")
            .buildAndExpand(team.getId()).toUri());

    return createResponseEntity(HttpStatus.CREATED, httpHeaders,
            "Team successfully created at " + httpHeaders.getLocation(), team);
}

From source file:com.itn.webservices.AdminControllerWebservice.java

@RequestMapping(value = "/food", method = RequestMethod.POST)
public ResponseEntity<Void> createFood(@RequestBody FoodInventory food, UriComponentsBuilder ucBuilder) {
    logger.info("Creating Food " + food.getFoodName());

    if (foodInventoryService.isFoodExist(food)) {
        logger.info("A Food already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }/*w w w.j a  v a  2s  .  c o m*/

    foodInventoryService.save(food);

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

From source file:com.example.session.app.order.OrderController.java

@ExceptionHandler({ EmptyCartOrderException.class, InvalidCartOrderException.class })
@ResponseStatus(HttpStatus.CONFLICT)
ModelAndView handleOrderException(BusinessException e) {
    return new ModelAndView("common/error/businessError").addObject(e.getResultMessages());
}

From source file:com.agroservices.restcontrollers.ComprasRest.java

@RequestMapping(value = "/{idMinorista}/{idProductoEnVenta}/{cantidadComprada}", method = RequestMethod.POST)
public ResponseEntity<?> agregarCompra(@PathVariable int idMinorista, @PathVariable int idProductoEnVenta,
        @PathVariable float cantidadComprada, @RequestBody Factura factura) {

    boolean resultado = cf.agregarFactura(factura, idMinorista, idProductoEnVenta, cantidadComprada);

    if (resultado) {
        return new ResponseEntity<>(HttpStatus.OK);
    } else {/*from www. j ava  2 s.c  o m*/
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

}

From source file:su90.mybatisdemo.web.endpoints.EmployeesEndpoints.java

@RequestMapping(value = "/set/", method = RequestMethod.POST, consumes = {
        MediaType.APPLICATION_JSON_UTF8_VALUE }, produces = { MediaType.TEXT_PLAIN_VALUE })
@ApiOperation(value = "create one employee if possible")
public ResponseEntity<Void> createEmployee(@RequestBody EmployeeIn employeeIn) {
    if (employeeIn.email == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }/*from   ww  w  .  jav a2  s .c om*/
    if (employeesService.hasEntityWithEmail(employeeIn.email)) {
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }

    if (employeeIn.job_id != null && jobsService.getEntryById(employeeIn.job_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    if (employeeIn.manager_id != null && employeesService.getEntryById(employeeIn.manager_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    if (employeeIn.department_id != null && departmentsService.getEntryById(employeeIn.department_id) == null) {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

    Long thekey = employeesService.saveEntry(employeeIn.getDomain());

    if (thekey != null) {
        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(
                UriUtils.generateUri(MvcUriComponentsBuilder.on(EmployeesEndpoints.class).getOne(thekey)));
        return new ResponseEntity<>(headers, HttpStatus.CREATED);
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
    }

}