use of org.activityinfo.model.form.CatalogEntry in project activityinfo by bedatadriven.
the class CatalogView method selectionChanged.
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);
}
use of org.activityinfo.model.form.CatalogEntry in project activityinfo by bedatadriven.
the class DatabasesFolder method queryLocationTypes.
private List<CatalogEntry> queryLocationTypes(ResourceId databaseId) throws SQLException {
List<CatalogEntry> entries = new ArrayList<>();
try (ResultSet rs = executor.query("SELECT locationTypeId, name FROM locationtype " + "WHERE databaseId = ? ", CuidAdapter.getLegacyIdFromCuid(databaseId))) {
while (rs.next()) {
String formId = CuidAdapter.locationFormClass(rs.getInt(1)).asString();
String label = rs.getString(2);
entries.add(new CatalogEntry(formId, label, CatalogEntryType.FORM));
}
}
return entries;
}
use of org.activityinfo.model.form.CatalogEntry in project activityinfo by bedatadriven.
the class DatabasesFolder method queryDatabases.
private List<CatalogEntry> queryDatabases(int userId) throws SQLException {
List<CatalogEntry> entries = new ArrayList<>();
try (ResultSet rs = executor.query("select d.name, d.databaseId " + "FROM userdatabase d " + "WHERE d.dateDeleted is NULL AND (d.ownerUserId = ? OR d.databaseId IN " + " (select databaseid from userpermission where userpermission.userId = ? and allowview=1))" + "ORDER BY d.name", userId, userId)) {
while (rs.next()) {
String label = rs.getString(1);
String formId = CuidAdapter.databaseId(rs.getInt(2)).asString();
entries.add(new CatalogEntry(formId, label, CatalogEntryType.FOLDER));
}
}
return entries;
}
use of org.activityinfo.model.form.CatalogEntry in project activityinfo by bedatadriven.
the class FormFolder method getChildren.
public List<CatalogEntry> getChildren(ResourceId formId) {
Optional<FormStorage> storage = catalog.getForm(formId);
if (!storage.isPresent()) {
return Collections.emptyList();
}
List<CatalogEntry> entries = new ArrayList<>();
FormClass formClass = storage.get().getFormClass();
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
ResourceId subFormId = subFormType.getClassId();
CatalogEntry catalogEntry = new CatalogEntry(subFormId.asString(), formField.getLabel(), CatalogEntryType.FORM);
catalogEntry.setLeaf(true);
entries.add(catalogEntry);
}
}
return entries;
}
use of org.activityinfo.model.form.CatalogEntry in project activityinfo by bedatadriven.
the class DatabasesFolder method queryForms.
private List<CatalogEntry> queryForms(ResourceId databaseId) throws SQLException {
List<CatalogEntry> entries = new ArrayList<>();
try (ResultSet rs = executor.query("SELECT " + "ActivityId, " + "name, " + "(ActivityId IN (SELECT ActivityId FROM indicator WHERE indicator.type='subform')) subforms " + "FROM activity " + "WHERE dateDeleted IS NULL AND databaseId = ? ", CuidAdapter.getLegacyIdFromCuid(databaseId))) {
while (rs.next()) {
String formId = CuidAdapter.activityFormClass(rs.getInt(1)).asString();
String label = rs.getString(2);
boolean hasSubForms = rs.getBoolean(3);
CatalogEntry entry = new CatalogEntry(formId, label, CatalogEntryType.FORM);
entry.setLeaf(!hasSubForms);
entries.add(entry);
}
}
return entries;
}
Aggregations