Search in sources :

Example 81 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class UmaLabelResource method createInstance.

@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context serverContext, CreateRequest createRequest) {
    final JsonValue umaLabel = createRequest.getContent();
    try {
        validate(umaLabel);
    } catch (BadRequestException e) {
        return e.asPromise();
    }
    final String realm = getRealm(serverContext);
    final String userName = getUserName(serverContext);
    final String labelName = umaLabel.get(NAME_LABEL).asString();
    final String labelType = umaLabel.get(TYPE_LABEL).asString();
    final ResourceSetLabel label;
    try {
        label = labelStore.create(realm, userName, new ResourceSetLabel(null, labelName, LabelType.valueOf(labelType), Collections.EMPTY_SET));
        return newResultPromise(newResourceResponse(label.getId(), String.valueOf(label.hashCode()), label.asJson()));
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)

Example 82 with BadRequestException

use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.

the class UmaLabelResource method deleteInstance.

@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String labelId, DeleteRequest deleteRequest) {
    try {
        ResourceSetLabel resourceSetLabel = labelStore.read(getRealm(serverContext), getUserName(serverContext), labelId);
        if (!isSameRevision(deleteRequest, resourceSetLabel)) {
            throw new BadRequestException("Revision number doesn't match latest revision.");
        }
        labelStore.delete(getRealm(serverContext), getUserName(serverContext), labelId);
        return newResultPromise(newResourceResponse(labelId, null, resourceSetLabel.asJson()));
    } catch (ResourceException e) {
        return new BadRequestException("Error deleting label.").asPromise();
    }
}
Also used : BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)

Aggregations

BadRequestException (org.forgerock.json.resource.BadRequestException)82 JsonValue (org.forgerock.json.JsonValue)44 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)40 ResourceException (org.forgerock.json.resource.ResourceException)39 SSOException (com.iplanet.sso.SSOException)37 NotFoundException (org.forgerock.json.resource.NotFoundException)37 SMSException (com.sun.identity.sm.SMSException)31 ForbiddenException (org.forgerock.json.resource.ForbiddenException)26 ResourceResponse (org.forgerock.json.resource.ResourceResponse)25 IdRepoException (com.sun.identity.idm.IdRepoException)23 PermanentException (org.forgerock.json.resource.PermanentException)22 ConflictException (org.forgerock.json.resource.ConflictException)21 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)20 SSOToken (com.iplanet.sso.SSOToken)19 NotSupportedException (org.forgerock.json.resource.NotSupportedException)17 RealmContext (org.forgerock.openam.rest.RealmContext)17 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)16 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)16 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)14 MessagingException (javax.mail.MessagingException)13