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;
}
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();
}
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);
}
}
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($));
}
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;
}
Aggregations