@ResponseBody
public GetJobsResponse getJobs(Principal principal) {
// This needs to be a read/write transaction as we might make a user.
MetaGraphTx tx = metaGraphService.buildTransaction().start();
GetJobsResponse getJobsResponse;
try {
UserMetadata userMetadata = tx.getOrCreateUser(principal);
List<GetJobResponse> jobs = new ArrayList<>();
for (ProjectMetadata projectMetadata : userMetadata.getProjects()) {
for (JobMetadata jobMetadata : projectMetadata.getJobs()) {
jobs.add(new GetJobResponse(jobMetadata));
}
}
getJobsResponse = new GetJobsResponse(jobs);
} catch (Throwable t) {
tx.rollback();
throw t;
}