}
String name = item.getName();
boolean createGraph = item.createGraph();
MetaGraphTx tx = metaGraphService.newTransaction();
GetProjectResponse getProjectResponse;
HttpHeaders headers = new HttpHeaders();
try {
UserMetadata userMetadata = tx.getOrCreateUser(principal);
if (userMetadata == null) {
throw new NotFound(UserMetadata.class, principal.getName());
}
ProjectMetadata projectMetadata = tx.createProject(name, userMetadata, createGraph);
headers.setLocation(builder.path("/projects/{projectId}").buildAndExpand(projectMetadata.getId()).toUri());
getProjectResponse = new GetProjectResponse(projectMetadata);
} catch (Throwable t) {
tx.rollback();
throw t;
}
// Commit must come after all graph access.
tx.commit();
return new ResponseEntity<>(getProjectResponse, headers, HttpStatus.CREATED);
}