class UserRest {

    @POST
    @RolesAllowed("admin")
    @ApiOperation("Create a Mobi User account")
    @Produces(MediaType.TEXT_PLAIN)
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response createUser(@FormDataParam("username") String username,
                        @FormDataParam("password") String password,
                        @FormDataParam("roles") List<FormDataBodyPart> roles,
                        @FormDataParam("firstName") String firstName,
                        @FormDataParam("lastName") String lastName,
                        @FormDataParam("email") String email) {
        if (StringUtils.isEmpty(username)) {
            throw ErrorUtils.sendError("Username must be provided", Response.Status.BAD_REQUEST);
        }
        if (StringUtils.isEmpty(password)) {
            throw ErrorUtils.sendError("Password must be provided", Response.Status.BAD_REQUEST);
        }
        try {
            if (engineManager.userExists(username)) {
                throw ErrorUtils.sendError("User already exists", Response.Status.BAD_REQUEST);
            }

            Set<String> roleSet = new HashSet<>();
            if (roles != null && roles.size() > 0) {
                roleSet = roles.stream().map(FormDataBodyPart::getValue).collect(Collectors.toSet());
            }

            UserConfig.Builder builder = new UserConfig.Builder(username, password, roleSet);
            if (firstName != null) {
                builder.firstName(firstName);
            }
            if (lastName != null) {
                builder.lastName(lastName);
            }
            if (email != null) {
                builder.email(email);
            }

            User user = engineManager.createUser(rdfEngine.getEngineName(), builder.build());
            if (!user.getUsername().isPresent()) {
                throw ErrorUtils.sendError("User must have a username", Response.Status.INTERNAL_SERVER_ERROR);
            }
            engineManager.storeUser(rdfEngine.getEngineName(), user);
            logger.info("Created user " + user.getResource() + " with username " + username);
            return Response.status(201).entity(user.getUsername().get().stringValue()).build();
        } catch (IllegalArgumentException ex) {
            throw ErrorUtils.sendError(ex.getMessage(), Response.Status.BAD_REQUEST);
        }
    }

}