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.