Search in sources :

Example 1 with ConflictingAttribute

use of com.b2international.snowowl.core.merge.ConflictingAttribute 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 ConflictingAttribute

use of com.b2international.snowowl.core.merge.ConflictingAttribute 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 ConflictingAttribute

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

the class AbstractBranchChangeRequest method toMergeConflict.

private MergeConflict toMergeConflict(ObjectId objectId, Collection<Conflict> conflicts) {
    final MergeConflict.Builder conflict = MergeConflict.builder().componentId(objectId.id()).componentType(objectId.type()).type(ConflictType.CONFLICTING_CHANGE);
    final List<ConflictingAttribute> conflictingAttributes = conflicts.stream().filter(ChangedInSourceAndTargetConflict.class::isInstance).map(ChangedInSourceAndTargetConflict.class::cast).map(c -> ConflictingAttribute.builder().property(c.getSourceChange().getProperty()).oldValue(c.getSourceChange().getOldValue()).sourceValue(c.getSourceChange().getNewValue()).targetValue(c.getTargetChange().getNewValue()).build()).collect(Collectors.toList());
    if (!conflictingAttributes.isEmpty()) {
        return conflict.conflictingAttributes(conflictingAttributes).build();
    } else {
        // XXX multiple conflicts are not expected here for a single object
        Conflict c = Iterables.getFirst(conflicts, null);
        if (c instanceof AddedInSourceAndTargetConflict) {
            return conflict.message(c.getMessage()).conflictingAttribute(ConflictingAttribute.builder().property(Revision.Fields.ID).build()).build();
        } else if (c instanceof ChangedInSourceAndDetachedInTargetConflict) {
            return conflict.message(c.getMessage()).type(ConflictType.DELETED_WHILE_CHANGED).conflictingAttributes(((ChangedInSourceAndDetachedInTargetConflict) c).getChanges().stream().map(attributeChange -> ConflictingAttribute.builder().property(attributeChange.getProperty()).oldValue(attributeChange.getOldValue()).sourceValue(attributeChange.getNewValue()).build()).collect(Collectors.toList())).build();
        } else if (c instanceof AddedInSourceAndDetachedInTargetConflict) {
            return conflict.message(c.getMessage()).type(ConflictType.CAUSES_MISSING_REFERENCE).componentId(((AddedInSourceAndDetachedInTargetConflict) c).getDetachedOnTarget().id()).componentType(((AddedInSourceAndDetachedInTargetConflict) c).getDetachedOnTarget().type()).build();
        } else if (c instanceof AddedInTargetAndDetachedInSourceConflict) {
            return conflict.message(c.getMessage()).type(ConflictType.HAS_MISSING_REFERENCE).componentId(((AddedInTargetAndDetachedInSourceConflict) c).getAddedOnTarget().id()).componentType(((AddedInTargetAndDetachedInSourceConflict) c).getAddedOnTarget().type()).conflictingAttribute(ConflictingAttribute.builder().property(((AddedInTargetAndDetachedInSourceConflict) c).getFeatureName()).targetValue(((AddedInTargetAndDetachedInSourceConflict) c).getDetachedOnSource().id()).build()).build();
        } else {
            return conflict.message("Not implemented conflict mapping").build();
        }
    }
}
Also used : MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Iterables(com.google.common.collect.Iterables) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) MergeConflict(com.b2international.snowowl.core.merge.MergeConflict) com.b2international.index.revision(com.b2international.index.revision) Collection(java.util.Collection) Request(com.b2international.snowowl.core.events.Request) ConflictingAttribute(com.b2international.snowowl.core.merge.ConflictingAttribute) ConflictType(com.b2international.snowowl.core.merge.MergeConflict.ConflictType) Merge(com.b2international.snowowl.core.merge.Merge) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) Multimaps(com.google.common.collect.Multimaps) Strings(com.google.common.base.Strings) List(java.util.List) RepositoryCommitNotificationSender(com.b2international.snowowl.core.repository.RepositoryCommitNotificationSender) NotEmpty(org.hibernate.validator.constraints.NotEmpty) AccessControl(com.b2international.snowowl.core.authorization.AccessControl) ApiError(com.b2international.commons.exceptions.ApiError) Permission(com.b2international.snowowl.core.identity.Permission) User(com.b2international.snowowl.core.identity.User) ApiException(com.b2international.commons.exceptions.ApiException) NotFoundException(com.b2international.commons.exceptions.NotFoundException) ConflictingAttribute(com.b2international.snowowl.core.merge.ConflictingAttribute) MergeConflict(com.b2international.snowowl.core.merge.MergeConflict)

Example 4 with ConflictingAttribute

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

the class SnomedMergeConflictTest method addedInSourceAndTargetMergeConflict.

@Test
public void addedInSourceAndTargetMergeConflict() {
    IBranchPath a = BranchPathUtils.createPath(branchPath, "a");
    branching.createBranch(a).statusCode(201);
    String descriptionId = createNewDescription(branchPath);
    Map<?, ?> requestBody = ImmutableMap.builder().put("id", descriptionId).put("conceptId", Concepts.ROOT_CONCEPT).put("moduleId", Concepts.MODULE_SCT_CORE).put("typeId", Concepts.SYNONYM).put("term", "Synonym of root concept").put("languageCode", "en").put("acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP).put("caseSignificanceId", Concepts.ENTIRE_TERM_CASE_INSENSITIVE).put("commitComment", "Created new synonym with duplicate SCTID").build();
    createComponent(a, SnomedComponentType.DESCRIPTION, requestBody).statusCode(201);
    Collection<MergeConflict> conflicts = merge(branchPath, a, "Rebased new description over new description with same SCTID").body("status", equalTo(Merge.Status.CONFLICTS.name())).extract().as(Merge.class).getConflicts();
    assertEquals(1, conflicts.size());
    ConflictingAttribute attribute = ConflictingAttribute.builder().property("id").build();
    MergeConflict conflict = Iterables.getOnlyElement(conflicts);
    assertEquals(descriptionId, conflict.getComponentId());
    assertEquals("description", conflict.getComponentType());
    assertEquals(ConflictType.CONFLICTING_CHANGE, 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 5 with ConflictingAttribute

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

the class SnomedMergeConflictTest method deleteReferencedComponentOnSourceMergeConflict.

@Test
public void deleteReferencedComponentOnSourceMergeConflict() {
    String conceptId = createNewConcept(branchPath);
    IBranchPath a = BranchPathUtils.createPath(branchPath, "a");
    branching.createBranch(a).statusCode(201);
    deleteComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, false).statusCode(204);
    String memberId = createNewRefSetMember(a, conceptId);
    Collection<MergeConflict> conflicts = merge(branchPath, a, "Rebased new reference set member over deleted referenced component").body("status", equalTo(Merge.Status.CONFLICTS.name())).extract().as(Merge.class).getConflicts();
    assertEquals(1, conflicts.size());
    ConflictingAttribute attribute = ConflictingAttribute.builder().property("container").sourceValue(conceptId).build();
    MergeConflict conflict = Iterables.getOnlyElement(conflicts);
    assertEquals(memberId, conflict.getComponentId());
    assertEquals("member", 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)

Aggregations

ConflictingAttribute (com.b2international.snowowl.core.merge.ConflictingAttribute)7 Merge (com.b2international.snowowl.core.merge.Merge)7 MergeConflict (com.b2international.snowowl.core.merge.MergeConflict)7 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)6 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)6 Test (org.junit.Test)6 ApiError (com.b2international.commons.exceptions.ApiError)1 ApiException (com.b2international.commons.exceptions.ApiException)1 NotFoundException (com.b2international.commons.exceptions.NotFoundException)1 com.b2international.index.revision (com.b2international.index.revision)1 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)1 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)1 Request (com.b2international.snowowl.core.events.Request)1 Permission (com.b2international.snowowl.core.identity.Permission)1 User (com.b2international.snowowl.core.identity.User)1 ConflictType (com.b2international.snowowl.core.merge.MergeConflict.ConflictType)1 RepositoryCommitNotificationSender (com.b2international.snowowl.core.repository.RepositoryCommitNotificationSender)1 RepositoryRequests (com.b2international.snowowl.core.repository.RepositoryRequests)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Strings (com.google.common.base.Strings)1