Search in sources :

Example 36 with IBranchPath

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

the class BranchCompareRequestTest method prepareBranchWithNewChanges.

private Set<ComponentIdentifier> prepareBranchWithNewChanges(String branchPath) {
    final IBranchPath branch = BranchPathUtils.createPath(branchPath);
    final String newConceptId = createNewConcept(branch);
    final SnomedConcept concept = getComponent(branch, SnomedComponentType.CONCEPT, newConceptId, "descriptions(expand(members())),relationships()").extract().as(SnomedConcept.class);
    final Set<ComponentIdentifier> newIds = newHashSet();
    newIds.add(ComponentIdentifier.of(SnomedConcept.TYPE, concept.getId()));
    for (SnomedDescription description : concept.getDescriptions()) {
        newIds.add(ComponentIdentifier.of(SnomedDescription.TYPE, description.getId()));
        for (SnomedReferenceSetMember member : description.getMembers()) {
            newIds.add(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, member.getId()));
        }
    }
    for (SnomedRelationship relationship : concept.getRelationships()) {
        newIds.add(ComponentIdentifier.of(SnomedRelationship.TYPE, relationship.getId()));
    }
    return newIds;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) IBranchPath(com.b2international.snowowl.core.api.IBranchPath)

Example 37 with IBranchPath

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

the class BranchCompareRequestTest method compareBranchWithChangedComponents.

@Test
public void compareBranchWithChangedComponents() throws Exception {
    final IBranchPath branch = BranchPathUtils.createPath(branchPath);
    final String newConceptId = createNewConcept(branch);
    final SnomedConcept concept = getComponent(branch, SnomedComponentType.CONCEPT, newConceptId).extract().as(SnomedConcept.class);
    final String taskBranchPath = createBranch(branchPath, "taskBranch");
    SnomedRequests.prepareUpdateConcept(concept.getId()).setModuleId(Concepts.MODULE_SCT_MODEL_COMPONENT).build(taskBranchPath, RestExtensions.USER, "Change module ID").execute(bus).getSync();
    // compare task branch and its parent
    final BranchCompareResult compare = compare(branchPath, taskBranchPath);
    assertThat(compare.getNewComponents()).isEmpty();
    assertThat(compare.getChangedComponents()).contains(ComponentIdentifier.of(SnomedConcept.TYPE, newConceptId));
    assertThat(compare.getDeletedComponents()).isEmpty();
}
Also used : BranchCompareResult(com.b2international.snowowl.core.branch.compare.BranchCompareResult) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Test(org.junit.Test)

Example 38 with IBranchPath

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

the class RepositoryBranchRestRequests method createBranchRecursively.

public void createBranchRecursively(IBranchPath branchPath, Map<?, ?> metadata) {
    IBranchPath currentPath = branchPath;
    ValidatableResponse response = getBranch(currentPath);
    List<String> segmentsToCreate = newArrayList();
    // Step upwards until we find an existing branch
    while (response.extract().statusCode() == 404 || response.extract().<Boolean>path("deleted")) {
        segmentsToCreate.add(segmentsToCreate.size(), currentPath.lastSegment());
        currentPath = currentPath.getParent();
        response = getBranch(currentPath);
    }
    // No response should return with a status outside of 404, then 200
    response.assertThat().statusCode(200);
    // Step downwards and create all non-existing segments
    while (!segmentsToCreate.isEmpty()) {
        currentPath = BranchPathUtils.createPath(currentPath, segmentsToCreate.remove(segmentsToCreate.size() - 1));
        Map<?, ?> currentMetadata = segmentsToCreate.isEmpty() ? metadata : ImmutableMap.of();
        createBranch(currentPath, currentMetadata).assertThat().statusCode(201);
    }
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) IBranchPath(com.b2international.snowowl.core.api.IBranchPath)

Example 39 with IBranchPath

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

the class BranchPathUtils method topToBottomIterator.

/**
 * Returns with a iterator of branch path for the given branch path argument.
 * <br>The iterator traverse the branch path parentage from top to down, hence the first item of the iterator is always the
 * {@link IBranchPath#MAIN_BRANCH MAIN branch} then its descendants.
 * @param branchPath the branch path.
 * @return an iterator for traversing the branch hierarchy from top to down.
 */
public static Iterator<IBranchPath> topToBottomIterator(final IBranchPath branchPath) {
    if (isMain(checkNotNull(branchPath, "Branch path argument cannot be null."))) {
        return singletonList(branchPath).iterator();
    }
    checkArgument(!NullBranchPath.INSTANCE.equals(branchPath), "Null branch path is not allowed.");
    boolean hasParent = true;
    IBranchPath currentPath = branchPath;
    // list for storing branch path top most first, descendants then
    final List<IBranchPath> $ = newArrayList(currentPath);
    while (hasParent) {
        final IBranchPath currentParent = currentPath.getParent();
        $.add(currentParent);
        if (isMain(currentParent)) {
            hasParent = false;
        } else {
            currentPath = currentParent;
        }
    }
    return new BackwardListIterator<IBranchPath>(unmodifiableList($));
}
Also used : BackwardListIterator(com.b2international.commons.collections.BackwardListIterator) IBranchPath(com.b2international.snowowl.core.api.IBranchPath)

Example 40 with IBranchPath

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

the class BranchPathUtils method getAllPaths.

public static List<String> getAllPaths(String branchPath) {
    final List<String> allPaths = new ArrayList<>(3);
    IBranchPath path = createPath(branchPath);
    Iterator<IBranchPath> it = bottomToTopIterator(path);
    while (it.hasNext()) {
        allPaths.add(it.next().getPath());
    }
    return allPaths;
}
Also used : ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) IBranchPath(com.b2international.snowowl.core.api.IBranchPath)

Aggregations

IBranchPath (com.b2international.snowowl.core.api.IBranchPath)79 Test (org.junit.Test)73 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)70 Merge (com.b2international.snowowl.core.merge.Merge)10 MergeConflict (com.b2international.snowowl.core.merge.MergeConflict)10 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)8 ConflictingAttribute (com.b2international.snowowl.core.merge.ConflictingAttribute)6 LocalDate (java.time.LocalDate)5 Pair (com.b2international.commons.Pair)4 File (java.io.File)4 Ignore (org.junit.Ignore)2 BackwardListIterator (com.b2international.commons.collections.BackwardListIterator)1 Json (com.b2international.commons.json.Json)1 BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)1 RevisionBranch (com.b2international.index.revision.RevisionBranch)1 ComponentIdentifier (com.b2international.snowowl.core.ComponentIdentifier)1 Repository (com.b2international.snowowl.core.Repository)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 BranchCompareResult (com.b2international.snowowl.core.branch.compare.BranchCompareResult)1