class CatalogRest {

    @POST
    @Path("{catalogId}/records")
    @Produces(MediaType.TEXT_PLAIN)
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @RolesAllowed("user")
    @ApiOperation("Creates a new Record in the Catalog.")
    @ActionAttributes(
            @AttributeValue(id = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", value = "type",
                    type = ValueType.BODY))
    @ResourceId(value = "catalogId", type = ValueType.PATH)
    public Response createRecord(@Context ContainerRequestContext context,
                          @PathParam("catalogId") String catalogId,
                          @FormDataParam("type") String typeIRI,
                          @FormDataParam("title") String title,
                          @FormDataParam("identifier") String identifier,
                          @FormDataParam("description") String description,
                          @FormDataParam("markdown") String markdown,
                          @FormDataParam("keywords") List<FormDataBodyPart> keywords) {
        checkStringParam(title, "Record title is required");
        Map<String, OrmFactory<? extends Record>> recordFactories = getRecordFactories();
        if (typeIRI == null || !recordFactories.keySet().contains(typeIRI)) {
            throw ErrorUtils.sendError("Invalid Record type", Response.Status.BAD_REQUEST);
        }
        User activeUser = getActiveUser(context, engineManager);
        CreateActivity createActivity = null;
        try {
            createActivity = provUtils.startCreateActivity(activeUser);
            RecordConfig.Builder builder = new RecordConfig.Builder(title, Collections.singleton(activeUser));
            if (StringUtils.isNotEmpty(identifier)) {
                builder.identifier(identifier);
            }
            if (StringUtils.isNotEmpty(description)) {
                builder.description(description);
            }
            if (StringUtils.isNotEmpty(markdown)) {
                builder.markdown(markdown);
            }
            if (keywords != null && keywords.size() > 0) {
                builder.keywords(keywords.stream().map(FormDataBodyPart::getValue).collect(Collectors.toSet()));
            }

            Record newRecord = catalogManager.createRecord(builder.build(), recordFactories.get(typeIRI));
            catalogManager.addRecord(vf.createIRI(catalogId), newRecord);
            provUtils.endCreateActivity(createActivity, newRecord.getResource());
            return Response.status(201).entity(newRecord.getResource().stringValue()).build();
        } catch (IllegalArgumentException ex) {
            provUtils.removeActivity(createActivity);
            throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST);
        } catch (MobiException ex) {
            provUtils.removeActivity(createActivity);
            throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
        } catch (Exception ex) {
            provUtils.removeActivity(createActivity);
            throw ex;
        }
    }

}