Search in sources :

Example 1 with CatalogEntry

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);
}
Also used : CatalogEntry(org.activityinfo.model.form.CatalogEntry)

Example 2 with CatalogEntry

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;
}
Also used : CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 3 with CatalogEntry

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;
}
Also used : CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 4 with CatalogEntry

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;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) FormField(org.activityinfo.model.form.FormField)

Example 5 with CatalogEntry

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;
}
Also used : CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Aggregations

CatalogEntry (org.activityinfo.model.form.CatalogEntry)7 ArrayList (java.util.ArrayList)5 ResultSet (java.sql.ResultSet)4 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)1 FormStorage (org.activityinfo.store.spi.FormStorage)1