use of com.b2international.snowowl.core.Resources in project snow-owl by b2ihealthcare.
the class BundleApiTest method updateBundleId_ReparentToRoot.
@Test
public void updateBundleId_ReparentToRoot() {
final String parentBundleId = createBundle("p5", IComponent.ROOT_ID, "Parent bundle");
final String middleBundleId = createBundle("m4", parentBundleId, "Middle bundle");
final String childBundleId = createBundle("c4", middleBundleId, "Child bundle");
final String grandchildBundleId = createBundle("g1", childBundleId, "Grandchild bundle");
ResourceRequests.bundles().prepareUpdate(middleBundleId).setBundleId(IComponent.ROOT_ID).build(USER, String.format("Update bundle: %s", middleBundleId)).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
final Resources descendantsOfParent = ResourceRequests.prepareSearch().setLimit(0).filterByBundleAncestorId(parentBundleId).buildAsync().execute(Services.bus()).getSync(1L, TimeUnit.MINUTES);
assertEquals(0, descendantsOfParent.getTotal());
final Resources descendantsOfMiddle = ResourceRequests.prepareSearch().setLimit(2).filterByBundleAncestorId(middleBundleId).buildAsync().execute(Services.bus()).getSync(1L, TimeUnit.MINUTES);
assertEquals(2, descendantsOfMiddle.getTotal());
assertThat(descendantsOfMiddle).extracting(Resource::getId).containsOnly(childBundleId, grandchildBundleId);
// Check that bundle paths are incremental
assertThat(getBundle(parentBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID);
assertThat(getBundle(middleBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID);
assertThat(getBundle(childBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID, middleBundleId);
assertThat(getBundle(grandchildBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID, middleBundleId, childBundleId);
}
use of com.b2international.snowowl.core.Resources in project snow-owl by b2ihealthcare.
the class BundleApiTest method updateBundleId_Hierarchy.
@Test
public void updateBundleId_Hierarchy() {
final String parentBundleId = createBundle("p3", IComponent.ROOT_ID, "Parent bundle");
final String middleBundleId = createBundle("m3", parentBundleId, "Middle bundle");
final String childBundleId = createBundle("c3", middleBundleId, "Child bundle");
final String otherParentBundleId = createBundle("p4", IComponent.ROOT_ID, "Other parent bundle");
ResourceRequests.bundles().prepareUpdate(parentBundleId).setBundleId(otherParentBundleId).build(USER, String.format("Update bundle: %s", parentBundleId)).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
final Resources descendants = ResourceRequests.prepareSearch().setLimit(3).filterByBundleAncestorId(otherParentBundleId).buildAsync().execute(Services.bus()).getSync(1L, TimeUnit.MINUTES);
assertEquals(3, descendants.getTotal());
assertThat(descendants).extracting(Resource::getId).containsOnly(parentBundleId, middleBundleId, childBundleId);
// Check that bundle paths are incremental
assertThat(getBundle(parentBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID, otherParentBundleId);
assertThat(getBundle(middleBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID, otherParentBundleId, parentBundleId);
assertThat(getBundle(childBundleId).getResourcePathSegments()).containsOnly(IComponent.ROOT_ID, otherParentBundleId, parentBundleId, middleBundleId);
}
use of com.b2international.snowowl.core.Resources in project snow-owl by b2ihealthcare.
the class BundleConverter method expandContents.
private void expandContents(final List<Bundle> results) {
if (!expand().containsKey(Bundle.Expand.RESOURCES)) {
return;
}
results.forEach(result -> {
final Resources resources = ResourceRequests.prepareSearch().setLimit(getLimit(expand().getOptions(Bundle.Expand.RESOURCES))).filterByBundleId(result.getId()).buildAsync().getRequest().execute(context());
result.setResources(resources);
});
}
use of com.b2international.snowowl.core.Resources in project snow-owl by b2ihealthcare.
the class BundleResourceTypeConverter method expand.
@Override
public void expand(RepositoryContext context, Options expand, List<ExtendedLocale> locales, Collection<Resource> results) {
if (expand.containsKey("content")) {
// allow expanding content via content expansion, for now hit count only
results.forEach(bundle -> {
final Resources resources = ResourceRequests.prepareSearch().filterByBundleAncestorId(bundle.getId()).setLimit(0).build().execute(context);
bundle.setProperties("content", resources);
});
}
}