Search in sources :

Example 6 with ComponentIdentifier

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

the class BranchCompareRequest method execute.

@Override
public BranchCompareResult execute(RepositoryContext context) {
    final RevisionIndex index = context.service(RevisionIndex.class);
    final Branch branchToCompare = RepositoryRequests.branching().prepareGet(compare).build().execute(context);
    final long compareHeadTimestamp = branchToCompare.headTimestamp();
    final RevisionCompare compareResult;
    final String baseBranchPath;
    if (base != null) {
        compareResult = index.compare(base, compare, limit, excludeComponentChanges);
        baseBranchPath = base;
    } else {
        compareResult = index.compare(compare, limit, excludeComponentChanges);
        baseBranchPath = branchToCompare.parentPath();
    }
    final BranchCompareResult.Builder result = BranchCompareResult.builder(baseBranchPath, compare, compareHeadTimestamp);
    final Set<ComponentIdentifier> changedContainers = Sets.newHashSet();
    for (RevisionCompareDetail detail : compareResult.getDetails()) {
        final ObjectId affectedId;
        if (detail.isComponentChange()) {
            affectedId = detail.getComponent();
            if (!detail.getObject().isRoot() && !excludeComponentChanges) {
                changedContainers.add(ComponentIdentifier.of(detail.getObject().type(), detail.getObject().id()));
            }
        } else {
            affectedId = detail.getObject();
        }
        final ComponentIdentifier identifier = ComponentIdentifier.of(affectedId.type(), affectedId.id());
        switch(detail.getOp()) {
            case ADD:
                result.putNewComponent(identifier);
                break;
            case CHANGE:
                result.putChangedComponent(identifier);
                break;
            case REMOVE:
                result.putDeletedComponent(identifier);
                break;
        }
    }
    return result.totalNew(compareResult.getTotalAdded()).totalChanged(compareResult.getTotalChanged()).totalDeleted(compareResult.getTotalRemoved()).build(changedContainers);
}
Also used : RevisionIndex(com.b2international.index.revision.RevisionIndex) ObjectId(com.b2international.index.revision.ObjectId) Branch(com.b2international.snowowl.core.branch.Branch) RevisionCompare(com.b2international.index.revision.RevisionCompare) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) RevisionCompareDetail(com.b2international.index.revision.RevisionCompareDetail)

Example 7 with ComponentIdentifier

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

the class ValidateRequest method fetchWhiteListEntries.

private Multimap<String, ComponentIdentifier> fetchWhiteListEntries(BranchContext context, final Set<String> ruleIds) {
    // fetch all white list entries to determine whether an issue is whitelisted already or not
    final Multimap<String, ComponentIdentifier> whiteListedEntries = HashMultimap.create();
    ValidationWhiteListSearchRequestBuilder whiteListReq = ValidationRequests.whiteList().prepareSearch();
    // fetch whitelist entries associated with the defined rules
    if (!CompareUtils.isEmpty(ruleIds)) {
        whiteListReq.filterByRuleIds(ruleIds);
    }
    whiteListReq.all().build().execute(context).stream().forEach(whitelist -> whiteListedEntries.put(whitelist.getRuleId(), whitelist.getComponentIdentifier()));
    return whiteListedEntries;
}
Also used : ValidationWhiteListSearchRequestBuilder(com.b2international.snowowl.core.validation.whitelist.ValidationWhiteListSearchRequestBuilder) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier)

Example 8 with ComponentIdentifier

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

the class BranchCompareRequestTest method compareBranchWithNewComponentOnExistingComponent.

@Test
public void compareBranchWithNewComponentOnExistingComponent() throws Exception {
    final Set<ComponentIdentifier> componentsOnParentBranch = prepareBranchWithNewChanges(branchPath);
    final String taskBranchPath = createBranch(branchPath, "taskBranch");
    final ComponentIdentifier concept = componentsOnParentBranch.stream().filter(ci -> ci.getComponentType() == SnomedConcept.TYPE).findFirst().get();
    final String newDescriptionId = SnomedRequests.prepareNewDescription().setIdFromNamespace(null).setConceptId(concept.getComponentId()).setTerm("New Description").setModuleId(Concepts.MODULE_SCT_CORE).setLanguageCode("en").setTypeId(Concepts.FULLY_SPECIFIED_NAME).build(taskBranchPath, RestExtensions.USER, "Create new Description on Concept: " + concept.getComponentId()).execute(bus).getSync(1, TimeUnit.MINUTES).getResultAs(String.class);
    final ComponentIdentifier newDescription = ComponentIdentifier.of(SnomedDescription.TYPE, newDescriptionId);
    final BranchCompareResult compareResult = compare(branchPath, taskBranchPath);
    assertThat(compareResult.getNewComponents()).containsOnly(newDescription);
    assertThat(compareResult.getChangedComponents()).containsOnly(concept);
    assertThat(compareResult.getDeletedComponents()).isEmpty();
}
Also used : BranchCompareResult(com.b2international.snowowl.core.branch.compare.BranchCompareResult) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) Test(org.junit.Test)

Example 9 with ComponentIdentifier

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

the class BranchCompareRequestTest method compareBranchWithNewComponents.

@Test
public void compareBranchWithNewComponents() throws Exception {
    final Set<ComponentIdentifier> newIds = prepareBranchWithNewChanges(branchPath);
    final BranchCompareResult compare = compare(null, branchPath);
    assertThat(compare.getNewComponents()).containsAll(newIds);
    assertThat(compare.getChangedComponents()).doesNotContainAnyElementsOf(newIds);
    assertThat(compare.getDeletedComponents()).isEmpty();
}
Also used : BranchCompareResult(com.b2international.snowowl.core.branch.compare.BranchCompareResult) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) Test(org.junit.Test)

Example 10 with ComponentIdentifier

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

the class BranchCompareRequestTest method remoteJobSupportCompareWithContent.

@Test
public void remoteJobSupportCompareWithContent() throws Exception {
    final Set<ComponentIdentifier> newIds = prepareBranchWithNewChanges(branchPath);
    final BranchCompareResult compare = compareOnJob(null, branchPath);
    assertThat(compare.getNewComponents()).containsAll(newIds);
    assertThat(compare.getChangedComponents()).doesNotContainAnyElementsOf(newIds);
    assertThat(compare.getDeletedComponents()).isEmpty();
}
Also used : BranchCompareResult(com.b2international.snowowl.core.branch.compare.BranchCompareResult) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) Test(org.junit.Test)

Aggregations

ComponentIdentifier (com.b2international.snowowl.core.ComponentIdentifier)13 BranchCompareResult (com.b2international.snowowl.core.branch.compare.BranchCompareResult)6 Test (org.junit.Test)6 ValidationIssue (com.b2international.snowowl.core.validation.issue.ValidationIssue)2 ValidationWhiteListSearchRequestBuilder (com.b2international.snowowl.core.validation.whitelist.ValidationWhiteListSearchRequestBuilder)2 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)2 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)2 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)2 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)2 CompareUtils (com.b2international.commons.CompareUtils)1 Writer (com.b2international.index.Writer)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 ObjectId (com.b2international.index.revision.ObjectId)1 RevisionCompare (com.b2international.index.revision.RevisionCompare)1 RevisionCompareDetail (com.b2international.index.revision.RevisionCompareDetail)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)1 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1