use of org.forgerock.json.resource.ConflictException in project OpenAM by OpenRock.
the class SmsCollectionProvider method createInstance.
/**
* Creates a new child instance of config. The parent config referenced by the request path is found, and
* new config is created using the provided name property.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
JsonValue content = request.getContent();
final String realm = realmFor(context);
try {
Map<String, Set<String>> attrs = converter.fromJson(realm, content);
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
String name = content.get("_id").asString();
if (name == null) {
name = request.getNewResourceId();
} else if (request.getNewResourceId() != null && !name.equals(request.getNewResourceId())) {
return new BadRequestException("name and URI's resource ID do not match").asPromise();
}
if (name == null) {
return new BadRequestException("Invalid name").asPromise();
}
config.addSubConfig(name, lastSchemaNodeName(), 0, attrs);
final ServiceConfig created = checkedInstanceSubConfig(context, name, config);
return awaitCreation(context, name).then(new Function<Void, ResourceResponse, ResourceException>() {
@Override
public ResourceResponse apply(Void aVoid) {
JsonValue result = getJsonValue(realm, created);
return newResourceResponse(created.getName(), String.valueOf(result.hashCode()), result);
}
});
} catch (ServiceAlreadyExistsException e) {
debug.warning("::SmsCollectionProvider:: ServiceAlreadyExistsException on create", e);
return new ConflictException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (ResourceException e) {
return e.asPromise();
}
}
Aggregations