throw new BindingException(result);
}
String graphId = item.getGraphId();
MetaGraphTx tx = metaGraphService.newTransaction();
BranchCommitJob branchCommitJob;
GetBranchResponse getBranchResponse;
try {
ProjectMetadata projectMetadata = tx.getProject(projectId);
if (projectMetadata == null) {
throw new NotFound(ProjectMetadata.class, projectId);
}
BranchMetadata branchMetadata;
if (graphId == null) {
branchMetadata = tx.createBranch(branchName, projectMetadata);
} else {
GraphMetadata graphMetadata = tx.getGraph(graphId);
if (graphMetadata == null) {
throw new NotFound(GraphMetadata.class, graphId);
}
branchMetadata = tx.createBranch(branchName, graphMetadata);
}
GraphMetadata srcGraphMetadata = branchMetadata.getGraph();
if (srcGraphMetadata == null) {
throw new NotFound(GraphMetadata.class);
}
GraphMetadata dstGraphMetadata = tx.createGraph(srcGraphMetadata);
JobMetadata jobMetadata = tx.createJob(projectMetadata);
Git git = historyService.projectGitRepository(projectMetadata);
try {
git.branchCreate()
.setName(branchName)
.call();
} finally {
git.close();
}
// We can't pass the values directly because they'll live in a separate thread.
branchCommitJob = new BranchCommitJob(
metaGraphService.getMetaGraph(),
jobMetadata.getId(),
projectMetadata.getId(),
branchMetadata.getId(),
srcGraphMetadata.getId(),
dstGraphMetadata.getId());
getBranchResponse = new GetBranchResponse(branchMetadata, jobMetadata);
} catch (Throwable t) {
tx.rollback();
throw t;
}
// Commit must come after all branch access.
tx.commit();
//taskExecutor.execute(branchCommitJob);
branchCommitJob.run();
return getBranchResponse;