class ResourceTypesResource extends RealmAwareResource {

    @Override
    public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {

        if (METHOD_PUT.equalsIgnoreCase(context.asContext(HttpContext.class).getMethod())) {
            return getException(METHOD_NOT_ALLOWED).asPromise();
        }

        String principalName = "unknown";
        try {
            final Subject subject = getSubject(context);
            principalName = PrincipalRestUtils.getPrincipalNameFromSubject(subject);
            final JsonResourceType jsonWrapper = createJsonResourceType(request.getContent());

            if (StringUtils.isEmpty(jsonWrapper.getName())) {
                throw new EntitlementException(MISSING_RESOURCE_TYPE_NAME);
            }

            // Here we save the resource type and use that returned, since the resource type service
            // adds all manner of good stuff - creation dates, updated dates, etc. etc.  It is the resource type filled
            // out with this extra stuff that we put into the resource and the user gets to see.
            //
            final ResourceType savedResourceType = resourceTypeService.saveResourceType(subject, getRealm(context),
                    jsonWrapper.getResourceType(true));

            if (logger.messageEnabled()) {
                logger.message("ResourceTypeResource :: CREATE by "
                        + principalName
                        + ": for Resource Type: "
                        + savedResourceType.getName());
            }
            return newResultPromise(newResourceResponse(savedResourceType.getUUID(), null,
                    new JsonResourceType(savedResourceType).toJsonValue()));
        } catch (EntitlementException e) {
            if (logger.errorEnabled()) {
                logger.error("ResourceTypeResource :: CREATE by "
                             + principalName
                             + ": Resource Type creation failed. ",
                             e);
            }
            return exceptionMappingHandler.handleError(context, request, e).asPromise();
        }
    }

    @Inject public  ResourceTypesResource(
            @Named("frRest") Debug logger,
            ExceptionMappingHandler<EntitlementException, ResourceException> exceptionMappingHandler,
            ResourceTypeService resourceTypeService);

}