Search in sources :

Example 16 with ColumnView

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

Example 17 with ColumnView

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;
}
Also used : ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) ColumnView(org.activityinfo.model.query.ColumnView) RecordRef(org.activityinfo.model.type.RecordRef) ColumnSet(org.activityinfo.model.query.ColumnSet) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) QueryModel(org.activityinfo.model.query.QueryModel)

Example 18 with ColumnView

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());
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) ColumnJsonWriter(org.activityinfo.store.query.output.ColumnJsonWriter) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder) GeoAreaType(org.activityinfo.model.type.geo.GeoAreaType) ResourceId.valueOf(org.activityinfo.model.resource.ResourceId.valueOf) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) WKBReader(com.vividsolutions.jts.io.WKBReader) PermissionsEnforcer(org.activityinfo.store.query.server.PermissionsEnforcer) org.activityinfo.model.form(org.activityinfo.model.form) NotFoundException(com.sun.jersey.api.NotFoundException) Level(java.util.logging.Level) HashSet(java.util.HashSet) Operation(io.swagger.v3.oas.annotations.Operation) SQLException(java.sql.SQLException) ResourceId(org.activityinfo.model.resource.ResourceId) Optional(com.google.common.base.Optional) Geometry(com.vividsolutions.jts.geom.Geometry) RecordRef(org.activityinfo.model.type.RecordRef) JsonValue(org.activityinfo.json.JsonValue) FormTreePrettyPrinter(org.activityinfo.model.formTree.FormTreePrettyPrinter) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) RecordLockSet(org.activityinfo.model.database.RecordLockSet) InvalidUpdateException(org.activityinfo.store.query.server.InvalidUpdateException) PrintWriter(java.io.PrintWriter) Charsets(com.google.common.base.Charsets) ParseException(com.vividsolutions.jts.io.ParseException) StringWriter(java.io.StringWriter) Set(java.util.Set) javax.ws.rs.core(javax.ws.rs.core) Logger(java.util.logging.Logger) String.format(java.lang.String.format) FormStorage(org.activityinfo.store.spi.FormStorage) RecordLock(org.activityinfo.model.database.RecordLock) List(java.util.List) javax.ws.rs(javax.ws.rs) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Tag(io.swagger.v3.oas.annotations.tags.Tag) XlsFormBuilder(org.activityinfo.io.xlsform.XlsFormBuilder) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) InjectParam(com.sun.jersey.api.core.InjectParam) FormTree(org.activityinfo.model.formTree.FormTree) RowBasedJsonWriter(org.activityinfo.store.query.output.RowBasedJsonWriter) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) HashSet(java.util.HashSet)

Example 19 with ColumnView

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();
        }
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 20 with ColumnView

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

Aggregations

ColumnView (org.activityinfo.model.query.ColumnView)67 ColumnSet (org.activityinfo.model.query.ColumnSet)22 Test (org.junit.Test)22 QueryModel (org.activityinfo.model.query.QueryModel)21 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)8 ResourceId (org.activityinfo.model.resource.ResourceId)7 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)7 DoubleArrayColumnView (org.activityinfo.model.query.DoubleArrayColumnView)6 NullFormScanCache (org.activityinfo.store.query.shared.NullFormScanCache)6 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)5 FormClass (org.activityinfo.model.form.FormClass)5 FormTree (org.activityinfo.model.formTree.FormTree)5 FormulaNode (org.activityinfo.model.formula.FormulaNode)4 Nullable (javax.annotation.Nullable)3 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)3 ColumnModel (org.activityinfo.model.query.ColumnModel)3 RecordRef (org.activityinfo.model.type.RecordRef)3 PrintWriter (java.io.PrintWriter)2 HashSet (java.util.HashSet)2 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)2