@Override public boolean isLeaf(Object value) { if (value instanceof CatalogEntry) { CatalogEntry entry = (CatalogEntry) value; if(entry.getType() == CatalogEntryType.FOLDER) { return false; } } return true; } }
@Override public boolean hasChildren(CatalogEntry parent) { if(parent.getType() == CatalogEntryType.FORM && !includeSubForms) { return false; } return !parent.isLeaf(); } }
private Set<CatalogEntry> getSelectedLeafNodes() { Set<CatalogEntry> set = Sets.newHashSet(); for (CatalogEntry node : selectionModel.getSelectedSet()) { if (node.getType() == CatalogEntryType.FORM) { set.add(node); } } return set; }
@Override public boolean apply(@Nullable CatalogEntry entry) { return !entry.getId().equals("geodb") && entry.getType() == CatalogEntryType.FOLDER && entry.getId().startsWith("d"); } });
private void selectionChanged(Observable<Optional<CatalogEntry>> selection) { boolean hasSelection = selection.isLoaded() && selection.get().isPresent(); CatalogEntry catalogEntry = null; if(hasSelection) { catalogEntry = selection.get().get(); } openTable.setEnabled(hasSelection && (catalogEntry.getType() == CatalogEntryType.FORM || catalogEntry.getType() == CatalogEntryType.ANALYSIS)); newReport.setEnabled(hasSelection && catalogEntry.getType() == CatalogEntryType.FOLDER); }
private String icon(CatalogEntry node) { if (node.getType() == CatalogEntryType.FORM) { return Icons.INSTANCE.form(); } else { return Icons.INSTANCE.folder(); } } }
public void selectForm(CatalogEntry form) { if(form.getType() == CatalogEntryType.FORM) { selectForm(Optional.of(ResourceId.valueOf(form.getId()))); } }
@Override public ImageResource getIcon(CatalogEntry model) { switch (model.getType()) { case FOLDER: return IconBundle.INSTANCE.databaseClosed(); case ANALYSIS: return IconBundle.INSTANCE.report(); default: case FORM: return IconBundle.INSTANCE.form(); } } });
private void matchEntries(List<CatalogEntry> fetched, List<String> expectedEntries, CatalogEntryType expectedType, boolean leaf) { assert fetched.size() == expectedEntries.size(); for (CatalogEntry entry : fetched) { assert expectedEntries.contains(entry.getId()); assert entry.getType().equals(expectedType); assert entry.isLeaf() == leaf; } }
@Override protected void onDoubleClick(Event event) { super.onDoubleClick(event); TreeNode<CatalogEntry> node = findNode(event.getEventTarget().<Element> cast()); if(node != null) { CatalogEntry entry = node.getModel(); if(entry.getType() == CatalogEntryType.FORM) { } } } };
private void openTable(SelectEvent event) { if(treeView.getSelectedEntry().isLoaded() && treeView.getSelectedEntry().get().isPresent()) { CatalogEntry catalogEntry = treeView.getSelectedEntry().get().get(); if(catalogEntry.getType() == CatalogEntryType.FORM) { String url = Window.Location.createUrlBuilder().setHash("table/" + catalogEntry.getId()).buildString(); Window.open(url, null, null); } else if(catalogEntry.getType() == CatalogEntryType.ANALYSIS) { String url = Window.Location.createUrlBuilder().setHash("analysis/" + catalogEntry.getId()).buildString(); Window.open(url, null, null); } } }
@Test public void countries() { // should have only one country on current data set : Rdc List<CatalogEntry> countries = catalog.getChildren(GeoDatabaseProvider.GEODB_ID.asString(), ALEX); assert countries.size() == 1; assert countries.get(0).getId().equals(RDC_CODE); assert countries.get(0).getLabel().equals(RDC_LABEL); assert countries.get(0).getType().equals(CatalogEntryType.FOLDER); assert !countries.get(0).isLeaf(); }
@Override public void load(CatalogEntry parent, final Callback<List<CatalogEntry>, Throwable> callback) { LOGGER.info("Loading children for " + parent); Observable<List<CatalogEntry>> entries; if(parent == null) { entries = formStore.getCatalogRoots(); } else { if(parent.getType() == CatalogEntryType.FORM && ! includeSubForms) { entries = Observable.just(Collections.emptyList()); } else { entries = formStore.getCatalogChildren(ResourceId.valueOf(parent.getId())); } } entries = entries.transform(new Function<List<CatalogEntry>, List<CatalogEntry>>() { @Override public List<CatalogEntry> apply(List<CatalogEntry> catalogEntries) { return Lists.newArrayList(Iterables.filter(catalogEntries, filter)); } }); Subscription subscription = entries.subscribe(observable -> { if (!observable.isLoading()) { callback.onSuccess(observable.get()); } }); subscriptions.add(subscription); } }
private void folderEntries(UserDatabaseMeta db) { // Each folder entry should have: // - an id equal to the resource id // - a label equal to the resource label // - an isLeaf boolean of FALSE, as the FORM should have a nested subform // - a type of FORM Map<ResourceId,Resource> folderResources = RESOURCES.folderResources().stream().collect(Collectors.toMap(Resource::getId,r -> r)); List<CatalogEntry> rootEntries = db.findCatalogEntries(RESOURCES.FOLDER_ID); assert rootEntries.size() == folderResources.size(); for (CatalogEntry rootEntry : rootEntries) { ResourceId rootEntryId = ResourceId.valueOf(rootEntry.getId()); assert folderResources.containsKey(rootEntryId); assert folderResources.get(rootEntryId).getLabel().equals(rootEntry.getLabel()); assert !rootEntry.isLeaf(); assert rootEntry.getType().equals(CatalogEntryType.FORM); } }
private void rootEntries(UserDatabaseMeta db) { // Each root entry should have: // - an id equal to the resource id // - a label equal to the resource label // - an isLeaf boolean of TRUE, EXCEPT for the folder resource which is FALSE // - a type of FORM, EXCEPT for the folder resource which has type FOLDER Map<ResourceId,Resource> rootResources = RESOURCES.rootResources().stream().collect(Collectors.toMap(Resource::getId,r -> r)); List<CatalogEntry> rootEntries = db.findCatalogEntries(RESOURCES.DB_ID); assert rootEntries.size() == rootResources.size(); for (CatalogEntry rootEntry : rootEntries) { ResourceId rootEntryId = ResourceId.valueOf(rootEntry.getId()); assert rootResources.containsKey(rootEntryId); assert rootResources.get(rootEntryId).getLabel().equals(rootEntry.getLabel()); if (!rootEntryId.equals(RESOURCES.FOLDER_ID)) { assert rootEntry.isLeaf(); assert rootEntry.getType().equals(CatalogEntryType.FORM); } else { assert !rootEntry.isLeaf(); assert rootEntry.getType().equals(CatalogEntryType.FOLDER); } } }
@Test public void databases_bavon() { // should have 1 database for bavon List<CatalogEntry> databases = catalog.getChildren(UserDatabaseProvider.ROOT_ID, BAVON); List<String> expectedEntries = Lists.newArrayList(CuidAdapter.databaseId(LEBANON_DB).asString()); matchEntries(databases, expectedEntries, CatalogEntryType.FOLDER, false); // LEBANON Database List<CatalogEntry> lebanonResources = catalog.getChildren(CuidAdapter.databaseId(LEBANON_DB).asString(), BAVON); List<CatalogEntry> folders = lebanonResources.stream().filter(entry -> entry.getType().equals(CatalogEntryType.FOLDER)).collect(Collectors.toList()); expectedEntries = Lists.newArrayList( CuidAdapter.folderId(7).asString(), CuidAdapter.folderId(8).asString()); matchEntries(folders, expectedEntries, CatalogEntryType.FOLDER, false); // Should have two forms, Intake Form and the Partner Form List<CatalogEntry> forms = lebanonResources.stream().filter(entry -> entry.getType().equals(CatalogEntryType.FORM)).collect(Collectors.toList()); assert forms.size() == 2; List<CatalogEntry> intakeForm = forms.stream().filter(entry -> entry.getId().equals(INTAKE_PARENT_FORM.asString())).collect(Collectors.toList()); List<CatalogEntry> partnerForm = forms.stream().filter(entry -> entry.getId().equals(CuidAdapter.partnerFormId(LEBANON_DB).asString())).collect(Collectors.toList()); expectedEntries = Lists.newArrayList(INTAKE_PARENT_FORM.asString()); matchEntries(intakeForm, expectedEntries, CatalogEntryType.FORM, false); expectedEntries = Lists.newArrayList(CuidAdapter.partnerFormId(LEBANON_DB).asString()); matchEntries(partnerForm, expectedEntries, CatalogEntryType.FORM, true); List<CatalogEntry> intakeFormResources = catalog.getChildren(INTAKE_PARENT_FORM.asString(), BAVON); expectedEntries = Lists.newArrayList(INTAKE_SUB_FORM.asString()); matchEntries(intakeFormResources, expectedEntries, CatalogEntryType.FORM, true); }
private void subFormEntries(UserDatabaseMeta db) { // Single sub form entry should have: // - an id equal to the resource id // - a label equal to the resource label // - an isLeaf boolean of TRUE // - a type of FORM List<CatalogEntry> rootEntries = db.findCatalogEntries(RESOURCES.FOLDER_FORM_ID); assert rootEntries.size() == 1; CatalogEntry subFormEntry = rootEntries.get(0); ResourceId subFormEntryId = ResourceId.valueOf(subFormEntry.getId()); assert subFormEntryId.equals(RESOURCES.SUB_FORM_ID); assert subFormEntry.getLabel().equals(RESOURCES.subFormResource().getLabel()); assert subFormEntry.isLeaf(); assert subFormEntry.getType().equals(CatalogEntryType.FORM); }
List<CatalogEntry> syriaFolders = syriaEntries.stream().filter(entry -> entry.getType().equals(CatalogEntryType.FOLDER)).collect(Collectors.toList()); List<CatalogEntry> syriaForms = syriaEntries.stream().filter(entry -> entry.getType().equals(CatalogEntryType.FORM)).collect(Collectors.toList()); List<CatalogEntry> lebanonForms = lebanonResources.stream().filter(entry -> entry.getType().equals(CatalogEntryType.FORM)).collect(Collectors.toList()); List<CatalogEntry> intakeForm = lebanonForms.stream().filter(entry -> entry.getId().equals(INTAKE_PARENT_FORM.asString())).collect(Collectors.toList()); List<CatalogEntry> partnerForm = lebanonForms.stream().filter(entry -> entry.getId().equals(CuidAdapter.partnerFormId(LEBANON_DB).asString())).collect(Collectors.toList()); List<CatalogEntry> lebanonFolders = lebanonResources.stream().filter(entry -> entry.getType().equals(CatalogEntryType.FOLDER)).collect(Collectors.toList()); expectedEntries = Lists.newArrayList(CuidAdapter.folderId(7).asString()); matchEntries(lebanonFolders, expectedEntries, CatalogEntryType.FOLDER, false);
@Test public void databases_alex() { // should have 2 databases for alex List<CatalogEntry> databases = catalog.getChildren(UserDatabaseProvider.ROOT_ID, ALEX); List<String> expectedEntries = Lists.newArrayList( CuidAdapter.databaseId(IRAQ_DB).asString(), CuidAdapter.databaseId(SYRIA_DB).asString()); matchEntries(databases, expectedEntries, CatalogEntryType.FOLDER, false); // IRAQ Database List<CatalogEntry> iraqEntries = catalog.getChildren(CuidAdapter.databaseId(IRAQ_DB).asString(), ALEX); List<CatalogEntry> iraqFolders = iraqEntries.stream().filter(entry -> entry.getType() == CatalogEntryType.FOLDER).collect(Collectors.toList()); List<CatalogEntry> iraqForms = iraqEntries.stream().filter(entry -> entry.getType() == CatalogEntryType.FORM).collect(Collectors.toList()); // For root folders expectedEntries = Lists.newArrayList( CuidAdapter.folderId(1).asString(), CuidAdapter.folderId(2).asString(), CuidAdapter.folderId(3).asString()); matchEntries(iraqFolders, expectedEntries, CatalogEntryType.FOLDER, false); // For root forms (should only be partner form) expectedEntries = Collections.singletonList(CuidAdapter.partnerFormId(IRAQ_DB).asString()); matchEntries(iraqForms, expectedEntries, CatalogEntryType.FORM, true); List<CatalogEntry> folderForms = catalog.getChildren(CuidAdapter.folderId(1).asString(), ALEX); expectedEntries = Lists.newArrayList( CuidAdapter.activityFormClass(1).asString(), CuidAdapter.activityFormClass(2).asString()); matchEntries(folderForms, expectedEntries, CatalogEntryType.FORM, true); }
entry -> entry.getType() != CatalogEntryType.ANALYSIS);