Search in sources :

Example 1 with MergeConflict

use of com.b2international.snowowl.core.merge.MergeConflict in project snow-owl by b2ihealthcare.

the class SnomedMergeConflictTest method changedInSourceDetachedInTargetMergeConflict.

@Test
public void changedInSourceDetachedInTargetMergeConflict() {
    String memberId = createNewRefSetMember(branchPath);
    IBranchPath a = BranchPathUtils.createPath(branchPath, "a");
    branching.createBranch(a).statusCode(201);
    LocalDate nextEffectiveTime = getNextAvailableEffectiveDate(SnomedContentRule.SNOMEDCT_ID);
    String nextEffectiveTimeAsString = EffectiveTimes.format(nextEffectiveTime, DateFormats.SHORT);
    Map<?, ?> effectiveTimeUpdateRequest = ImmutableMap.builder().put("effectiveTime", nextEffectiveTimeAsString).put("commitComment", "Updated effective time on reference set member").build();
    updateRefSetComponent(branchPath, SnomedComponentType.MEMBER, memberId, effectiveTimeUpdateRequest, true).statusCode(204);
    deleteComponent(a, SnomedComponentType.MEMBER, memberId, false).statusCode(204);
    Collection<MergeConflict> conflicts = merge(branchPath, a, "Rebased reference set member deletion over effective time update").body("status", equalTo(Merge.Status.CONFLICTS.name())).extract().as(Merge.class).getConflicts();
    assertEquals(1, conflicts.size());
    MergeConflict conflict = Iterables.getOnlyElement(conflicts);
    assertEquals(memberId, conflict.getComponentId());
    assertEquals("member", conflict.getComponentType());
    assertEquals(ConflictType.DELETED_WHILE_CHANGED, conflict.getType());
    Map<String, ConflictingAttribute> expectedAttributes = newHashMap();
    expectedAttributes.put("effectiveTime", ConflictingAttribute.builder().property("effectiveTime").sourceValue(nextEffectiveTimeAsString).build());
    expectedAttributes.put("released", ConflictingAttribute.builder().property("released").oldValue("false").sourceValue("true").build());
    for (ConflictingAttribute attribute : conflict.getConflictingAttributes()) {
        ConflictingAttribute expected = expectedAttributes.remove(attribute.getProperty());
        assertNotNull(expected);
        assertEquals(expected.toDisplayName(), attribute.toDisplayName());
    }
    assertThat(expectedAttributes).isEmpty();
}
Also used : MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) ConflictingAttribute(com.b2international.snowowl.core.merge.ConflictingAttribute) Merge(com.b2international.snowowl.core.merge.Merge) LocalDate(java.time.LocalDate) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 2 with MergeConflict

use of com.b2international.snowowl.core.merge.MergeConflict in project snow-owl by b2ihealthcare.

the class SnomedMergeConflictTest method addedInTargetDetachedInSourceMergeConflict.

@Test
public void addedInTargetDetachedInSourceMergeConflict() {
    String conceptId = createNewConcept(branchPath);
    IBranchPath a = BranchPathUtils.createPath(branchPath, "a");
    branching.createBranch(a).statusCode(201);
    deleteComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, false).statusCode(204);
    String relationshipId = createNewRelationship(a, Concepts.ROOT_CONCEPT, Concepts.PART_OF, conceptId);
    Collection<MergeConflict> conflicts = merge(branchPath, a, "Rebased new relationship over deleted concept").body("status", equalTo(Merge.Status.CONFLICTS.name())).extract().as(Merge.class).getConflicts();
    assertEquals(1, conflicts.size());
    ConflictingAttribute attribute = ConflictingAttribute.builder().property("destinationId").sourceValue(conceptId).build();
    MergeConflict conflict = Iterables.getOnlyElement(conflicts);
    assertEquals(relationshipId, conflict.getComponentId());
    assertEquals("relationship", conflict.getComponentType());
    assertEquals(ConflictType.HAS_MISSING_REFERENCE, conflict.getType());
    assertEquals(attribute.toDisplayName(), Iterables.getOnlyElement(conflict.getConflictingAttributes()).toDisplayName());
}
Also used : MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) ConflictingAttribute(com.b2international.snowowl.core.merge.ConflictingAttribute) Merge(com.b2international.snowowl.core.merge.Merge) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 3 with MergeConflict

use of com.b2international.snowowl.core.merge.MergeConflict in project snow-owl by b2ihealthcare.

the class SnomedMergeConflictTest method addedInSourceDetachedInTargetMergeConflict.

@Test
public void addedInSourceDetachedInTargetMergeConflict() {
    String conceptId = createNewConcept(branchPath);
    IBranchPath a = BranchPathUtils.createPath(branchPath, "a");
    branching.createBranch(a).statusCode(201);
    createNewRelationship(branchPath, Concepts.ROOT_CONCEPT, Concepts.PART_OF, conceptId);
    deleteComponent(a, SnomedComponentType.CONCEPT, conceptId, false).statusCode(204);
    Collection<MergeConflict> conflicts = merge(branchPath, a, "Rebased deleted concept over new relationship").body("status", equalTo(Merge.Status.CONFLICTS.name())).extract().as(Merge.class).getConflicts();
    assertEquals(1, conflicts.size());
    MergeConflict conflict = Iterables.getOnlyElement(conflicts);
    assertEquals(conceptId, conflict.getComponentId());
    assertEquals("concept", conflict.getComponentType());
    assertEquals(ConflictType.CAUSES_MISSING_REFERENCE, conflict.getType());
}
Also used : MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) Merge(com.b2international.snowowl.core.merge.Merge) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 4 with MergeConflict

use of com.b2international.snowowl.core.merge.MergeConflict in project snow-owl by b2ihealthcare.

the class SnomedMergeConflictTest method noMergeNewRelationshipToUnrelatedBranch.

@Test
public void noMergeNewRelationshipToUnrelatedBranch() {
    String conceptId = createNewConcept(branchPath);
    IBranchPath a = BranchPathUtils.createPath(branchPath, "a");
    branching.createBranch(a).statusCode(201);
    createNewRelationship(a, Concepts.ROOT_CONCEPT, Concepts.PART_OF, conceptId);
    IBranchPath b = BranchPathUtils.createPath(branchPath, "b");
    branching.createBranch(b).statusCode(201);
    deleteComponent(b, SnomedComponentType.CONCEPT, conceptId, false).statusCode(204);
    Collection<MergeConflict> conflicts = merge(a, b, "Merged new relationship to unrelated branch").body("status", equalTo(Merge.Status.CONFLICTS.name())).extract().as(Merge.class).getConflicts();
    assertEquals(1, conflicts.size());
    MergeConflict conflict = Iterables.getOnlyElement(conflicts);
    assertEquals(conceptId, conflict.getComponentId());
    assertEquals("concept", conflict.getComponentType());
    assertEquals(ConflictType.CAUSES_MISSING_REFERENCE, conflict.getType());
    assertEquals(0, conflict.getConflictingAttributes().size());
}
Also used : MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) Merge(com.b2international.snowowl.core.merge.Merge) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 5 with MergeConflict

use of com.b2international.snowowl.core.merge.MergeConflict in project snow-owl by b2ihealthcare.

the class CodeSystemUpgradeSynchronizationRequest method execute.

@Override
public Boolean execute(RepositoryContext context) {
    final String message = String.format("Merge %s into %s", source, codeSystemId);
    CodeSystem codeSystem = CodeSystemRequests.prepareGetCodeSystem(codeSystemId.getResourceId()).build().execute(context);
    if (codeSystem.getUpgradeOf() == null) {
        throw new BadRequestException("Code System '%s' is not an Upgrade Code System. It cannot be synchronized with '%s'.", codeSystemId, source);
    }
    final String sourceBranchPath = context.service(ResourceURIPathResolver.class).resolve(context, List.of(source)).stream().findFirst().get();
    // merge all changes from the source to the current upgrade of branch
    final Merge merge = RepositoryRequests.merging().prepareCreate().setSource(sourceBranchPath).setTarget(codeSystem.getBranchPath()).setUserId(context.service(User.class).getUsername()).setCommitComment(message).setSquash(false).build(codeSystem.getToolingId()).getRequest().execute(context);
    if (merge.getStatus() != Merge.Status.COMPLETED) {
        // report conflicts
        ApiError apiError = merge.getApiError();
        Collection<MergeConflict> conflicts = merge.getConflicts();
        context.log().error("Failed to sync source CodeSystem content to upgrade CodeSystem. Error: {}. Conflicts: {}", apiError.getMessage(), conflicts);
        throw new ConflictException("Upgrade code system synchronization can not be performed due to conflicting content errors.").withAdditionalInfo(Map.of("conflicts", conflicts, "mergeError", apiError.getMessage()));
    }
    if (!codeSystem.getUpgradeOf().equals(source)) {
        return new BranchRequest<>(Branch.MAIN_PATH, new ResourceRepositoryCommitRequestBuilder().setBody((tx) -> {
            ResourceDocument entry = tx.lookup(codeSystemId.getResourceId(), ResourceDocument.class);
            tx.add(ResourceDocument.builder(entry).upgradeOf(source).build());
            tx.commit(String.format("Update upgradeOf from '%s' to '%s'", codeSystem.getUpgradeOf(), source));
            return Boolean.TRUE;
        }).setCommitComment(String.format("Complete upgrade of %s to %s", codeSystem.getUpgradeOf().getResourceId(), codeSystem.getExtensionOf())).build()).execute(context).getResultAs(Boolean.class);
    } else {
        return Boolean.TRUE;
    }
}
Also used : MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) BadRequestException(com.b2international.commons.exceptions.BadRequestException) BranchRequest(com.b2international.snowowl.core.request.BranchRequest) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ConflictException(com.b2international.commons.exceptions.ConflictException) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) Collection(java.util.Collection) Request(com.b2international.snowowl.core.events.Request) ResourceURIPathResolver(com.b2international.snowowl.core.uri.ResourceURIPathResolver) Merge(com.b2international.snowowl.core.merge.Merge) NotNull(javax.validation.constraints.NotNull) Branch(com.b2international.snowowl.core.branch.Branch) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) List(java.util.List) Map(java.util.Map) ApiError(com.b2international.commons.exceptions.ApiError) ResourceRepositoryCommitRequestBuilder(com.b2international.snowowl.core.context.ResourceRepositoryCommitRequestBuilder) User(com.b2international.snowowl.core.identity.User) ResourceURI(com.b2international.snowowl.core.ResourceURI) User(com.b2international.snowowl.core.identity.User) ConflictException(com.b2international.commons.exceptions.ConflictException) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) Merge(com.b2international.snowowl.core.merge.Merge) BadRequestException(com.b2international.commons.exceptions.BadRequestException) ApiError(com.b2international.commons.exceptions.ApiError) ResourceRepositoryCommitRequestBuilder(com.b2international.snowowl.core.context.ResourceRepositoryCommitRequestBuilder) BranchRequest(com.b2international.snowowl.core.request.BranchRequest)

Aggregations

Merge (com.b2international.snowowl.core.merge.Merge)13 MergeConflict (com.b2international.snowowl.core.merge.MergeConflict)13 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)10 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)10 Test (org.junit.Test)10 ConflictingAttribute (com.b2international.snowowl.core.merge.ConflictingAttribute)7 ApiError (com.b2international.commons.exceptions.ApiError)3 BadRequestException (com.b2international.commons.exceptions.BadRequestException)2 ConflictException (com.b2international.commons.exceptions.ConflictException)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)2 Request (com.b2international.snowowl.core.events.Request)2 User (com.b2international.snowowl.core.identity.User)2 RepositoryRequests (com.b2international.snowowl.core.repository.RepositoryRequests)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 Collection (java.util.Collection)2 List (java.util.List)2 ApiException (com.b2international.commons.exceptions.ApiException)1 NotFoundException (com.b2international.commons.exceptions.NotFoundException)1 com.b2international.index.revision (com.b2international.index.revision)1