@POST
public Response createProfile(ProfileDTO profileDTO) throws URISyntaxException {
Objects.notNull(profileDTO, "profileDTO");
FabricService fabricService = getFabricService();
Objects.notNull(fabricService, "fabricService");
ProfileService profileService = getProfileService();
Objects.notNull(profileService, "profileService");
String id = profileDTO.getId();
if (Strings.isNullOrBlank(id)) {
return Response.status(Response.Status.BAD_REQUEST).entity("No id specified for the profile to be created").build();
}
URI location = new URI(getBaseUri() + "profile/" + id);
// lets check it doesn't already exist
String versionId = version.getId();
if (profileService.hasProfile(versionId, id)) {
return Response.seeOther(location).entity("Profile already exists for id: " + id).build();
}
// lets override whatever the version is set to
profileDTO.setVersion(versionId);
// create the profile
ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, id);
profileDTO.populateBuilder(fabricService, profileService, builder);
Profile profile = builder.getProfile();
profileService.createProfile(profile);
return Response.created(location).build();
}