String name = item.getName();
String query = item.getQuery();
int steps = item.getSteps();
MetaGraphTx tx = metaGraphService.newTransaction();
BranchCommitSubsetJob branchCommitSubsetJob;
try {
UserMetadata userMetadata = tx.getOrCreateUser(principal);
if (userMetadata == null) {
throw new NotFound(UserMetadata.class, principal.getName());
}
ProjectMetadata srcProjectMetadata = tx.getProject(projectId);
if (srcProjectMetadata == null) {
throw new NotFound(ProjectMetadata.class, projectId);
}
BranchMetadata srcBranchMetadata = srcProjectMetadata.getCurrentBranch();
if (srcBranchMetadata == null) {
throw new NotFound(BranchMetadata.class);
}
GraphMetadata srcGraphMetadata = srcBranchMetadata.getGraph();
if (srcGraphMetadata == null) {
throw new NotFound(GraphMetadata.class);
}
ProjectMetadata dstProjectMetadata = tx.createProject(name, userMetadata);
BranchMetadata dstBranchMetadata = dstProjectMetadata.getCurrentBranch();
if (dstBranchMetadata == null) {
throw new NotFound(BranchMetadata.class);
}
GraphMetadata dstGraphMetadata = dstBranchMetadata.getGraph();
if (dstGraphMetadata == null) {
throw new NotFound(GraphMetadata.class);
}
JobMetadata jobMetadata = tx.createJob(srcProjectMetadata);
// We can't pass the values directly because they'll live in a separate thread.
branchCommitSubsetJob = new BranchCommitSubsetJob(
metaGraphService.getMetaGraph(),
jobMetadata.getId(),
dstProjectMetadata.getId(),
dstBranchMetadata.getId(),
srcGraphMetadata.getId(),
dstGraphMetadata.getId(),
query,
steps);
} catch (Exception e) {
tx.rollback();
throw e;
}
tx.commit();
//taskExecutor.execute(branchCommitSubsetJob);
branchCommitSubsetJob.run();
return new BranchJobResponse(branchCommitSubsetJob);