use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class StartEndDateFieldBinding method extractFieldData.
@Override
public BaseModelData[] extractFieldData(BaseModelData[] dataArray, ColumnSet columnSet) {
ColumnView startDate = columnSet.getColumnView(START_DATE_COLUMN);
ColumnView endDate = columnSet.getColumnView(END_DATE_COLUMN);
for (int i = 0; i < columnSet.getNumRows(); i++) {
if (!startDate.isMissing(i)) {
dataArray[i].set(START_DATE_COLUMN, LocalDate.parse(startDate.getString(i)));
}
if (!endDate.isMissing(i)) {
dataArray[i].set(END_DATE_COLUMN, LocalDate.parse(endDate.getString(i)));
}
}
return dataArray;
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class ResourceLocatorSyncImpl method getReferenceChoices.
@Override
public List<ReferenceChoice> getReferenceChoices(Collection<ResourceId> range) {
ResourceId formId = Iterables.getOnlyElement(range);
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("id");
queryModel.selectExpr("label").as("label");
ColumnSetBuilder builder = new ColumnSetBuilder(catalog.get(), new NullFormSupervisor());
ColumnSet columnSet = builder.build(queryModel);
ColumnView id = columnSet.getColumnView("id");
ColumnView label = columnSet.getColumnView("label");
List<ReferenceChoice> choices = Lists.newArrayList();
for (int i = 0; i < columnSet.getNumRows(); i++) {
ResourceId choiceId = ResourceId.valueOf(id.getString(i));
String choiceLabel = label.getString(i);
choices.add(new ReferenceChoice(new RecordRef(formId, choiceId), choiceLabel));
}
return choices;
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class FormResource method computeVisibilityPredicate.
/**
* Computes a record-level visibility predicate.
*/
private java.util.function.Predicate<ResourceId> computeVisibilityPredicate() {
FormPermissions formPermissions = backend.getFormSupervisor().getFormPermissions(formId);
if (!formPermissions.hasVisibilityFilter()) {
return resourceId -> true;
}
QueryModel queryModel = new QueryModel(formId);
queryModel.selectResourceId().as("id");
ColumnSet columnSet = executeQuery(queryModel);
ColumnView id = columnSet.getColumnView("id");
final Set<String> idSet = new HashSet<>();
for (int i = 0; i < id.numRows(); i++) {
idSet.add(id.getString(i));
}
return resourceId -> idSet.contains(resourceId.asString());
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class ResourceLocatorAdaptorTest method deleteLocation.
@Test
public void deleteLocation() {
ResourceId instanceToDelete = CuidAdapter.locationInstanceId(1);
assertResolves(locator.remove(CuidAdapter.locationFormClass(1), instanceToDelete));
QueryModel queryModel = new QueryModel(CuidAdapter.locationFormClass(1));
queryModel.selectResourceId().as("id");
ColumnSet columnSet = assertResolves(locator.queryTable(queryModel));
ColumnView idColumn = columnSet.getColumnView("id");
for (int i = 0; i < idColumn.numRows(); i++) {
if (idColumn.getString(i).equals(instanceToDelete.asString())) {
throw new AssertionError();
}
}
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class FormScanBatch method computeParentFilter.
private Slot<TableFilter> computeParentFilter(FilterLevel filterLevel, ResourceId formId) {
if (parentFilterMap.containsKey(formId)) {
return parentFilterMap.get(formId);
}
FormClass formClass = formClassProvider.getFormClass(formId);
if (!formClass.isSubForm()) {
return new PendingSlot<>(TableFilter.ALL_SELECTED);
}
Slot<PrimaryKeyMap> parentPrimaryKeySlot = addPrimaryKey(filterLevel, formClass.getParentFormId().get());
Slot<ColumnView> parentId = addParentColumn(FilterLevel.NONE, formId);
ParentMask filter = new ParentMask(parentPrimaryKeySlot, parentId);
parentFilterMap.put(formId, filter);
return filter;
}
Aggregations