Search in sources :

Example 11 with ConflictException

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();
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) ConflictException(org.forgerock.json.resource.ConflictException) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ServiceConfig(com.sun.identity.sm.ServiceConfig) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Aggregations

SSOException (com.iplanet.sso.SSOException)11 SMSException (com.sun.identity.sm.SMSException)11 BadRequestException (org.forgerock.json.resource.BadRequestException)11 ConflictException (org.forgerock.json.resource.ConflictException)11 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)10 NotFoundException (org.forgerock.json.resource.NotFoundException)10 ForbiddenException (org.forgerock.json.resource.ForbiddenException)9 ResourceException (org.forgerock.json.resource.ResourceException)9 JsonValue (org.forgerock.json.JsonValue)8 PermanentException (org.forgerock.json.resource.PermanentException)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)6 RealmContext (org.forgerock.openam.rest.RealmContext)6 IdRepoException (com.sun.identity.idm.IdRepoException)5 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)5 Set (java.util.Set)5 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)5 HashSet (java.util.HashSet)4 JsonValueException (org.forgerock.json.JsonValueException)4 NotSupportedException (org.forgerock.json.resource.NotSupportedException)4 SSOToken (com.iplanet.sso.SSOToken)3