Search in sources :

Example 1 with Merging

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();
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Branching(com.b2international.snowowl.core.branch.Branching) Merge(com.b2international.snowowl.core.merge.Merge) Merging(com.b2international.snowowl.core.branch.Merging) CommitResult(com.b2international.snowowl.core.request.CommitResult) RevisionBranch(com.b2international.index.revision.RevisionBranch) Branch(com.b2international.snowowl.core.branch.Branch) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) Test(org.junit.Test)

Aggregations

BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 Branch (com.b2international.snowowl.core.branch.Branch)1 Branching (com.b2international.snowowl.core.branch.Branching)1 Merging (com.b2international.snowowl.core.branch.Merging)1 RemoteJobEntry (com.b2international.snowowl.core.jobs.RemoteJobEntry)1 Merge (com.b2international.snowowl.core.merge.Merge)1 CommitResult (com.b2international.snowowl.core.request.CommitResult)1 SnomedDescriptionCreateRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder)1 Test (org.junit.Test)1