use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class MySqlCatalogTest method singlePartner.
@Test
public void singlePartner() {
FormStorage form = catalog.getForm(CuidAdapter.partnerFormId(1)).get();
Optional<FormRecord> partnerRecord = form.get(CuidAdapter.partnerRecordId(1));
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class MySqlCatalogTest method singleSiteWithBoundLocation.
@Test
public void singleSiteWithBoundLocation() {
FormStorage siteStorage = catalog.getForm(CuidAdapter.activityFormClass(4)).get();
FormRecord siteRecord = siteStorage.get(CuidAdapter.cuid(CuidAdapter.SITE_DOMAIN, 6)).get();
FormInstance site = FormInstance.toFormInstance(siteStorage.getFormClass(), siteRecord);
FieldValue location = site.get(CuidAdapter.locationField(4));
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class TargetFormProvider method openForms.
@Override
public Map<ResourceId, FormStorage> openForms(QueryExecutor executor, Set<ResourceId> formIds) throws SQLException {
Set<Integer> targetIds = Sets.newHashSet();
for (ResourceId resourceId : formIds) {
if (accept(resourceId)) {
targetIds.add(CuidAdapter.getLegacyIdFromCuid(resourceId));
}
}
Map<ResourceId, FormStorage> collectionMap = Maps.newHashMap();
if (!targetIds.isEmpty()) {
Map<Integer, DatabaseTargetForm> targetMap = Maps.newHashMap();
try (ResultSet rs = executor.query("SELECT " + "D.DatabaseId, " + "D.Name, " + "I.IndicatorId, " + "I.Name, " + "I.Units, " + "A.schemaVersion " + " FROM userdatabase D " + " LEFT JOIN activity A ON (D.DatabaseId = A.DatabaseId and A.dateDeleted IS NULL) " + " LEFT JOIN indicator I ON (A.ActivityId=I.ActivityId and I.dateDeleted IS NULL and I.type = 'QUANTITY') " + " WHERE D.databaseID IN (" + Joiner.on(',').join(targetIds) + ")")) {
while (rs.next()) {
int databaseId = rs.getInt(1);
DatabaseTargetForm target = targetMap.get(databaseId);
if (target == null) {
target = new DatabaseTargetForm(databaseId, rs.getString(2), rs.getLong(6));
targetMap.put(databaseId, target);
}
int indicatorId = rs.getInt(3);
if (!rs.wasNull()) {
target.addIndicator(indicatorId, rs.getString(4), rs.getString(5));
}
}
}
for (DatabaseTargetForm target : targetMap.values()) {
collectionMap.put(target.getFormClassId(), new TargetFormStorage(executor, target));
}
}
return collectionMap;
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class TargetFormProvider method openForm.
@Override
public FormStorage openForm(QueryExecutor executor, ResourceId formId) throws SQLException {
Map<ResourceId, FormStorage> result = openForms(executor, Collections.singleton(formId));
FormStorage collection = result.get(formId);
if (collection == null) {
throw new IllegalArgumentException("no such target collection: " + formId);
}
return collection;
}
use of org.activityinfo.store.spi.FormStorage in project activityinfo by bedatadriven.
the class FormSourceSyncImpl method getFormMetadata.
public FormMetadata getFormMetadata(ResourceId formId) {
Optional<FormStorage> storage = formCatalog.getForm(formId);
if (!storage.isPresent()) {
return FormMetadata.notFound(formId);
}
FormPermissions permissions = storage.get().getPermissions(userId);
if (!permissions.isVisible()) {
return FormMetadata.forbidden(formId);
}
return FormMetadata.of(storage.get().cacheVersion(), storage.get().getFormClass(), permissions);
}
Aggregations