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.cloudfoundry.identity.uaa.scim.endpoints.ScimGroupEndpoints.java

@RequestMapping(value = { "/Groups/External" }, method = RequestMethod.POST)
@ResponseBody/*w  ww . j a  va2  s  .  com*/
@ResponseStatus(HttpStatus.CREATED)
public ScimGroupExternalMember mapExternalGroup(@RequestBody ScimGroupExternalMember sgm) {
    try {
        String displayName = sgm.getDisplayName();
        String groupId = hasText(sgm.getGroupId()) ? sgm.getGroupId() : getGroupId(displayName);
        String externalGroup = hasText(sgm.getExternalGroup()) ? sgm.getExternalGroup().trim()
                : sgm.getExternalGroup();
        String origin = hasText(sgm.getOrigin()) ? sgm.getOrigin() : LDAP;
        return externalMembershipManager.mapExternalGroup(groupId, externalGroup, origin);
    } catch (IllegalArgumentException e) {
        throw new ScimException(e.getMessage(), HttpStatus.BAD_REQUEST);
    } catch (ScimResourceNotFoundException e) {
        throw new ScimException(e.getMessage(), HttpStatus.NOT_FOUND);
    } catch (MemberAlreadyExistsException e) {
        throw new ScimException(e.getMessage(), HttpStatus.CONFLICT);
    }
}

From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimGroupEndpoints.java

@RequestMapping(value = {
        "/Groups/External/groupId/{groupId}/externalGroup/{externalGroup}/origin/{origin}" }, method = RequestMethod.DELETE)
@ResponseBody/*  w  ww  .  j  a  v a 2  s . c  o m*/
@ResponseStatus(HttpStatus.OK)
public ScimGroupExternalMember unmapExternalGroup(@PathVariable String groupId,
        @PathVariable String externalGroup, @PathVariable String origin) {
    try {
        if (!hasText(origin)) {
            origin = LDAP;
        }
        return externalMembershipManager.unmapExternalGroup(groupId, externalGroup.trim(), origin);
    } catch (IllegalArgumentException e) {
        throw new ScimException(e.getMessage(), HttpStatus.BAD_REQUEST);
    } catch (ScimResourceNotFoundException e) {
        throw new ScimException(e.getMessage(), HttpStatus.NOT_FOUND);
    } catch (MemberAlreadyExistsException e) {
        throw new ScimException(e.getMessage(), HttpStatus.CONFLICT);
    }
}

From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimGroupEndpoints.java

@RequestMapping(value = {
        "/Groups/External/displayName/{displayName}/externalGroup/{externalGroup}/origin/{origin}" }, method = RequestMethod.DELETE)
@ResponseBody//from w ww  . j av a 2 s.  c om
@ResponseStatus(HttpStatus.OK)
public ScimGroupExternalMember unmapExternalGroupUsingName(@PathVariable String displayName,
        @PathVariable String externalGroup, @PathVariable String origin) {
    try {
        if (!hasText(origin)) {
            origin = LDAP;
        }

        return externalMembershipManager.unmapExternalGroup(getGroupId(displayName), externalGroup.trim(),
                origin);
    } catch (IllegalArgumentException e) {
        throw new ScimException(e.getMessage(), HttpStatus.BAD_REQUEST);
    } catch (ScimResourceNotFoundException e) {
        throw new ScimException(e.getMessage(), HttpStatus.NOT_FOUND);
    } catch (MemberAlreadyExistsException e) {
        throw new ScimException(e.getMessage(), HttpStatus.CONFLICT);
    }
}

From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimGroupEndpoints.java

@RequestMapping(value = { "/Groups/{groupId}" }, method = RequestMethod.PUT)
@ResponseBody//from  w w  w. j  a  v a 2  s  .  c  o  m
public ScimGroup updateGroup(@RequestBody ScimGroup group, @PathVariable String groupId,
        @RequestHeader(value = "If-Match", required = false) String etag,
        HttpServletResponse httpServletResponse) {
    if (etag == null) {
        throw new ScimException("Missing If-Match for PUT", HttpStatus.BAD_REQUEST);
    }
    logger.debug("updating group: " + groupId);
    int version = getVersion(groupId, etag);
    group.setVersion(version);
    ScimGroup existing = getGroup(groupId, httpServletResponse);
    try {
        group.setZoneId(IdentityZoneHolder.get().getId());
        ScimGroup updated = dao.update(groupId, group);
        if (group.getMembers() != null && group.getMembers().size() > 0) {
            membershipManager.updateOrAddMembers(updated.getId(), group.getMembers());
        } else {
            membershipManager.removeMembersByGroupId(updated.getId());
        }
        updated.setMembers(membershipManager.getMembers(updated.getId(), null, false));
        addETagHeader(httpServletResponse, updated);
        return updated;
    } catch (IncorrectResultSizeDataAccessException ex) {
        logger.error("Error updating group, restoring to previous state");
        // restore to correct state before reporting error
        existing.setVersion(getVersion(groupId, "*"));
        dao.update(groupId, existing);
        throw new ScimException(ex.getMessage(), ex, HttpStatus.CONFLICT);
    } catch (ScimResourceNotFoundException ex) {
        logger.error("Error updating group, restoring to previous state: " + existing);
        // restore to correct state before reporting error
        existing.setVersion(getVersion(groupId, "*"));
        dao.update(groupId, existing);
        throw new ScimException(ex.getMessage(), ex, HttpStatus.BAD_REQUEST);
    }
}

From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimGroupEndpoints.java

@RequestMapping(value = { "/Groups/{groupId}" }, method = RequestMethod.DELETE)
@ResponseBody//from ww  w . ja  v  a2 s  . c  om
public ScimGroup deleteGroup(@PathVariable String groupId,
        @RequestHeader(value = "If-Match", required = false, defaultValue = "*") String etag,
        HttpServletResponse httpServletResponse) {
    ScimGroup group = getGroup(groupId, httpServletResponse);
    logger.debug("deleting group: " + group);
    try {
        membershipManager.removeMembersByGroupId(groupId);
        membershipManager.removeMembersByMemberId(groupId);
        dao.delete(groupId, getVersion(groupId, etag));
    } catch (IncorrectResultSizeDataAccessException ex) {
        logger.debug("error deleting group", ex);
        throw new ScimException("error deleting group: " + groupId, ex, HttpStatus.CONFLICT);
    }
    return group;
}

From source file:org.cloudfoundry.identity.uaa.scim.ScimUserEndpoints.java

@RequestMapping(value = "/User/{userId}", method = RequestMethod.PUT)
@ResponseBody// w ww.  ja v  a2 s .  com
public ScimUser updateUser(@RequestBody ScimUser user, @PathVariable String userId,
        @RequestHeader(value = "If-Match", required = false, defaultValue = "NaN") String etag) {
    if (etag.equals("NaN")) {
        throw new ScimException("Missing If-Match for PUT", HttpStatus.BAD_REQUEST);
    }
    int version = getVersion(userId, etag);
    user.setVersion(version);
    try {
        return dao.updateUser(userId, user);
    } catch (OptimisticLockingFailureException e) {
        throw new ScimException(e.getMessage(), HttpStatus.CONFLICT);
    }
}

From source file:org.eclipse.hawkbit.mgmt.rest.resource.MgmtTargetResourceTest.java

@Test
@Description("Ensures that a post request for creating the same target again leads to a conflict response.")
public void createTargetsSingleEntryListDoubleReturnConflict() throws Exception {
    final String knownName = "someName";
    final String knownControllerId = "controllerId1";
    final String knownDescription = "someDescription";
    final String createTargetsJson = getCreateTargetsListJsonString(knownControllerId, knownName,
            knownDescription);/*from   w ww .  j  av a  2  s  .  c o  m*/

    // create a taret first to provoke a already exists error

    mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(createTargetsJson)
            .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
            .andExpect(status().is2xxSuccessful());
    // create another one to retrieve the entity already exists exception
    final MvcResult mvcResult = mvc
            .perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(createTargetsJson)
                    .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().is(HttpStatus.CONFLICT.value())).andReturn();

    // verify only one entry
    assertThat(targetManagement.count()).isEqualTo(1);

    // verify response json exception message
    final ExceptionInfo exceptionInfo = ResourceUtility
            .convertException(mvcResult.getResponse().getContentAsString());
    assertThat(exceptionInfo.getExceptionClass()).isEqualTo(EntityAlreadyExistsException.class.getName());
    assertThat(exceptionInfo.getErrorCode()).isEqualTo(SpServerError.SP_REPO_ENTITY_ALRREADY_EXISTS.getKey());
    assertThat(exceptionInfo.getMessage()).isEqualTo(SpServerError.SP_REPO_ENTITY_ALRREADY_EXISTS.getMessage());
}

From source file:org.finra.dm.service.helper.DmErrorInformationExceptionHandler.java

/**
 * Handle exceptions that result in a "conflict" status.
 *//* w  w w . j a v a  2s  .c  o m*/
@ExceptionHandler(value = { AlreadyExistsException.class, ObjectAlreadyExistsException.class })
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody
public ErrorInformation handleConflictException(Exception exception) {
    return getErrorInformation(HttpStatus.CONFLICT, exception);
}

From source file:org.finra.herd.service.helper.HerdErrorInformationExceptionHandler.java

/**
 * Handle exceptions that result in a "conflict" status.
 *///from ww  w  .  jav a2 s  .c  o  m
@ExceptionHandler(value = { AlreadyExistsException.class, ObjectAlreadyExistsException.class,
        OptimisticLockException.class })
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody
public ErrorInformation handleConflictException(Exception exception) {
    return getErrorInformation(HttpStatus.CONFLICT, exception);
}

From source file:org.geoserver.rest.security.AbstractAclController.java

protected void postMap(Map map) throws Exception {

    validateMap(map);/* w  w  w  .  j  a va  2 s .  co  m*/

    Set<Object> commonKeys = intersection(map);

    if (!commonKeys.isEmpty()) {
        String msg = "Already existing rules: " + StringUtils.join(commonKeys.iterator(), ",");
        throw new RestException(msg, HttpStatus.CONFLICT);
    }

    for (Object entry : map.entrySet()) {
        Comparable rule = convertEntryToRule((Entry<String, String>) entry);
        ruleDAO.addRule(rule);
    }
    ruleDAO.storeRules();

}