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();
}
}
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();
}
}
Aggregations