use of com.b2international.snowowl.core.merge.Merge 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();
}
use of com.b2international.snowowl.core.merge.Merge 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());
}
use of com.b2international.snowowl.core.merge.Merge 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());
}
use of com.b2international.snowowl.core.merge.Merge 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());
}
use of com.b2international.snowowl.core.merge.Merge 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;
}
}
Aggregations