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:eu.trentorise.smartcampus.permissionprovider.auth.internal.RegistrationController.java

/**
 * Register with the REST call//from   www  . j a  v  a2 s .c om
 * @param model
 * @param reg
 * @param result
 * @param req
 * @return
 */
@RequestMapping(value = "/register/rest", method = RequestMethod.POST)
public @ResponseBody void registerREST(@RequestBody RegistrationBean reg, HttpServletResponse res) {
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<RegistrationBean>> errors = validator.validate(reg);

    if (errors.size() > 0) {
        res.setStatus(HttpStatus.BAD_REQUEST.value());
        return;
    }
    try {
        manager.register(reg.getName(), reg.getSurname(), reg.getEmail(), reg.getPassword(), reg.getLang());
    } catch (AlreadyRegisteredException e) {
        res.setStatus(HttpStatus.CONFLICT.value());
    } catch (RegistrationException e) {
        e.printStackTrace();
        res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    } catch (Exception e) {
        e.printStackTrace();
        res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    }
}

From source file:edu.kit.scc.RestServiceController.java

/**
 * Unlinking endpoint.//w  w w  .  ja  v  a2 s .c  o m
 * 
 * @param basicAuthorization authorization header value
 * @param scimUsers a JSON serialized list of SCIM users for unlinking
 * @param response the HttpServletResponse
 * @return A JSON serialized list of SCIM users containing the local user information.
 */
@RequestMapping(path = "/unlink", method = RequestMethod.POST, consumes = "application/scim+json", produces = "application/scim+json")
public ResponseEntity<?> unlinkUsers(@RequestHeader("Authorization") String basicAuthorization,
        @RequestBody List<ScimUser> scimUsers, HttpServletResponse response) {

    if (!verifyAuthorization(basicAuthorization)) {
        return new ResponseEntity<String>("REST Service Unauthorized", HttpStatus.UNAUTHORIZED);
    }

    log.debug("Request body {}", scimUsers);

    List<ScimUser> modifiedUsers = identityHarmonizer.unlinkUsers(scimUsers);
    if (!modifiedUsers.isEmpty()) {
        return new ResponseEntity<List<ScimUser>>(modifiedUsers, HttpStatus.OK);
    }

    return new ResponseEntity<String>("Conflicting information", HttpStatus.CONFLICT);
}

From source file:br.com.s2it.snakes.controllers.CarController.java

@CrossOrigin("*")
@RequestMapping(value = "/reservation", method = RequestMethod.POST)
public ResponseEntity<CarReservation> createReservation(@RequestBody CarReservation reservation) {

    if (reservation == null || reservation.getLicensePlate() == null || reservation.getLicensePlate() == null
            || reservation.getCustomer() == null || reservation.getDestiny() == null
            || reservation.getPassengers() <= 0 || reservation.getInitialReservationDate() == null
            || reservation.getFinalReservationDate() == null) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
    }/*from w w w  .  java  2  s . co m*/

    try {
        boolean reservationIsPossible = service.reservationIsPossible(reservation.getLicensePlate(),
                reservation.getInitialReservationDate(), reservation.getFinalReservationDate());
        if (reservationIsPossible) {
            return ResponseEntity.status(HttpStatus.OK).body(service.createReservation(reservation));
        } else {
            return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
        }
    } catch (Exception e) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
    }

}

From source file:org.entitypedia.games.common.api.handlers.DefaultExceptionDetailsResolver.java

private Map<String, String> createDefaultExceptionMappingDefinitions() {
    Map<String, String> m = new LinkedHashMap<>();

    // 400/*from  w  w w.  j  a  v  a 2 s  .c om*/
    applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST);
    applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST);
    applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST);
    applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST);

    // 404
    applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND);
    applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND);

    // 405
    applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED);

    // 406
    applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE);

    // 409
    //can't use the class directly here as it may not be an available dependency:
    applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT);

    // 415
    applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE);

    return m;
}

From source file:org.fineract.module.stellar.controller.BridgeController.java

@RequestMapping(value = "/vault/{assetCode}", method = RequestMethod.PUT, consumes = {
        "application/json" }, produces = { "application/json" })
public ResponseEntity<BigDecimal> adjustVaultIssuedAssets(
        @RequestHeader(API_KEY_HEADER_LABEL) final String apiKey,
        @RequestHeader(TENANT_ID_HEADER_LABEL) final String mifosTenantId,
        @PathVariable("assetCode") final String assetCode,
        @RequestBody final AmountConfiguration amountConfiguration) {
    this.securityService.verifyApiKey(apiKey, mifosTenantId);
    //TODO: add security for currency issuing.
    final BigDecimal amount = amountConfiguration.getAmount();
    if (amount.compareTo(BigDecimal.ZERO) < 0) {
        return new ResponseEntity<>(amount, HttpStatus.BAD_REQUEST);
    }//from  w  w  w.ja  v  a  2 s.c o  m

    final BigDecimal amountAdjustedTo = bridgeService.adjustVaultIssuedAssets(mifosTenantId, assetCode, amount);

    if (amountAdjustedTo.compareTo(amount) != 0)
        return new ResponseEntity<>(amountAdjustedTo, HttpStatus.CONFLICT);
    else
        return new ResponseEntity<>(amountAdjustedTo, HttpStatus.OK);
}

From source file:jp.classmethod.aws.brian.web.TriggerController.java

/**
 * Create trigger./*from  w ww .  j  ava 2 s .co m*/
 * 
 * @param triggerGroupName groupName
 * @return trigger names
 * @throws SchedulerException
 */
@ResponseBody
@RequestMapping(value = "/triggers/{triggerGroupName}", method = RequestMethod.POST)
public ResponseEntity<?> createTrigger(@PathVariable("triggerGroupName") String triggerGroupName,
        @RequestBody BrianTriggerRequest triggerRequest) throws SchedulerException {
    logger.info("createTrigger {}.{}", triggerGroupName, triggerRequest.getTriggerName());
    logger.info("{}", triggerRequest);

    String triggerName = triggerRequest.getTriggerName();
    if (Strings.isNullOrEmpty(triggerName)) {
        return new ResponseEntity<>(new BrianResponse<>(false, "triggerName is not found"),
                HttpStatus.BAD_REQUEST);
    }

    try {
        TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);
        if (scheduler.checkExists(triggerKey)) {
            String message = String.format("trigger %s.%s already exists.", triggerGroupName, triggerName);
            return new ResponseEntity<>(new BrianResponse<>(false, message), HttpStatus.CONFLICT);
        }

        Trigger trigger = getTrigger(triggerRequest, triggerKey);

        Date nextFireTime = scheduler.scheduleJob(trigger);
        logger.info("scheduled {}", triggerKey);

        SimpleDateFormat df = CalendarUtil.newSimpleDateFormat(TimePoint.ISO8601_FORMAT_UNIVERSAL, Locale.US,
                TimeZones.UNIVERSAL);
        Map<String, Object> map = new HashMap<>();
        map.put("nextFireTime", df.format(nextFireTime));
        return new ResponseEntity<>(new BrianResponse<>(true, "created", map), HttpStatus.CREATED); // TODO return URI
    } catch (ParseException e) {
        logger.warn("parse cron expression failed", e);
        String message = "parse cron expression failed - " + e.getMessage();
        return ResponseEntity.badRequest().body(new BrianResponse<>(false, message));
    }
}

From source file:com.sothawo.taboo2.Taboo2Service.java

/**
 * ExceptionHandler for AlreadyExistsException. returns the exception's error message in the body with the 409
 * status code.//  w  ww  . j a v  a  2s  .  co m
 *
 * @param e
 *         the exception to handle
 * @return HTTP CONFLICT Response Status and error message
 */
@ExceptionHandler(AlreadyExistsException.class)
@ResponseStatus(HttpStatus.CONFLICT)
public final String exceptionHandlerAlreadyExistsException(final AlreadyExistsException e) {
    return '"' + e.getMessage() + '"';
}

From source file:resources.RedSocialColaborativaRESTFUL.java

/**
 *
 * @param _newPasswordDTO/*from  w w  w  . java 2s .  c  o m*/
 * @return
 * @throws NoSuchAlgorithmException
 */
@RequestMapping(value = "/perfil/password", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
public ResponseEntity<String> cambioPasswordUsuario(@RequestBody NewPasswordDTO _newPasswordDTO)
        throws NoSuchAlgorithmException {
    String usernameConectado = null;
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    if (principal instanceof UserDetails) {
        usernameConectado = ((UserDetails) principal).getUsername();

        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

        if (_newPasswordDTO.getPasswordActual() == null) {
            return new ResponseEntity<>(HttpStatus.CONFLICT);
        }

        if (!encoder.matches(_newPasswordDTO.getPasswordActual(), ((UserDetails) principal).getPassword())) {
            return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
        }
    }

    if (!_newPasswordDTO.getNewPassword().equals(_newPasswordDTO.getConfPassword())) {
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    red.setUsername(usernameConectado);

    red.cambiarPassword(_newPasswordDTO.getNewPassword());

    return new ResponseEntity<>(HttpStatus.OK);
}

From source file:ch.wisv.areafiftylan.users.controller.UserRestController.java

@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<?> handleDataIntegrityViolationException(DataIntegrityViolationException ex) {
    return createResponseEntity(HttpStatus.CONFLICT, "Username or Email already taken!");
}

From source file:com.aquest.emailmarketing.web.controllers.RestfulController.java

@RequestMapping(value = "/api/campaign", method = RequestMethod.POST)
public ResponseEntity<Void> createCampaignFromRest(@RequestBody Campaigns campaigns,
        UriComponentsBuilder ucBuilder) {
    if (campaignsService.isCampaignExist(campaigns.getCampaign_id())) {
        System.out.println("A Campaign with id " + campaigns.getCampaign_id() + " already exist");
        return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    }// w  w  w . j  a v  a2 s. co  m
    Timestamp curTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime());
    campaigns.setCreation_dttm(curTimestamp);
    campaigns.setCampaign_status("DEFINED");
    campaignsService.SaveOrUpdate(campaigns);
    return new ResponseEntity<Void>(HttpStatus.CREATED);
}