use of com.b2international.snowowl.core.branch.Merging in project snow-owl by b2ihealthcare.
the class SnomedBranchRequestTest method createBranchAndCommitToParent.
@Test
public void createBranchAndCommitToParent() throws Exception {
final Branching branches = RepositoryRequests.branching();
final Merging merges = RepositoryRequests.merging();
final String branchA = UUID.randomUUID().toString();
final String branchB = UUID.randomUUID().toString();
final String first = branches.prepareCreate().setParent(branchPath).setName(branchA).build(REPOSITORY_ID).execute(bus).getSync();
final SnomedDescriptionCreateRequestBuilder fsnBuilder = SnomedRequests.prepareNewDescription().setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).setModuleId(Concepts.MODULE_ROOT).setTerm("FSN " + branchA).setTypeId(Concepts.FULLY_SPECIFIED_NAME).setAcceptability(ImmutableMap.of(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
final SnomedDescriptionCreateRequestBuilder ptBuilder = SnomedRequests.prepareNewDescription().setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).setModuleId(Concepts.MODULE_ROOT).setTerm("PT " + branchA).setTypeId(Concepts.SYNONYM).setAcceptability(ImmutableMap.of(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
final AsyncRequest<CommitResult> conceptRequest = SnomedRequests.prepareNewConcept().setModuleId(Concepts.MODULE_ROOT).setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).addParent(Concepts.ROOT_CONCEPT).addDescription(fsnBuilder).addDescription(ptBuilder).build(first, RestExtensions.USER, "Created new concept");
final CommitResult info = conceptRequest.execute(bus).getSync();
final String conceptId = info.getResultAs(String.class);
final String firstParentPath = BranchPathUtils.createPath(first).getParentPath();
final Request<ServiceProvider, Merge> mergeRequest = merges.prepareCreate().setSource(first).setTarget(firstParentPath).setUserId(User.SYSTEM.getUsername()).setCommitComment("Merging changes").build(REPOSITORY_ID).getRequest();
final String mergeJobId = JobRequests.prepareSchedule().setDescription("Merging changes").setRequest(mergeRequest).setUser(User.SYSTEM.getUsername()).buildAsync().execute(bus).getSync();
final RemoteJobEntry mergeJobResult = JobRequests.waitForJob(bus, mergeJobId);
final Merge merge = mergeJobResult.getResultAs(JsonSupport.getDefaultObjectMapper(), Merge.class);
assertEquals(true, merge.getConflicts().isEmpty());
String second = branches.prepareCreate().setParent(firstParentPath).setName(branchB).build(REPOSITORY_ID).execute(bus).getSync();
final Branch sourceBranch = branches.prepareGet(merge.getSource()).build(REPOSITORY_ID).execute(bus).getSync();
final Branch secondBranch = branches.prepareGet(second).build(REPOSITORY_ID).execute(bus).getSync();
assertBranchesCreated(branchA, branchB, sourceBranch, secondBranch);
assertBranchSegmentsValid(merge.getTarget(), sourceBranch.path(), secondBranch.path());
// Check that the concept is visible on parent
SnomedRequests.prepareGetConcept(conceptId).build(firstParentPath).execute(bus).getSync();
}
Aggregations