Search in sources :

Example 46 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class ItemSetBuilder method build.

public StreamingOutput build(ResourceId formClassId) throws IOException {
    final Set<ResourceId> rangeClassIds = findRanges(formClassId);
    return new StreamingOutput() {

        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException {
            ItemSetWriter writer = new ItemSetWriter(output);
            // We need at least one item set or ODK will crash
            writer.writeItem("__dummy", "dummy", "dummy");
            // Write out real item sets
            for (ResourceId formClassId : rangeClassIds) {
                writeInstances(formClassId, writer);
            }
            writer.flush();
        }
    };
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput)

Example 47 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class ItemSetBuilder method findRanges.

private Set<ResourceId> findRanges(ResourceId formClassId) {
    FormClass formClass = locator.getFormClass(formClassId);
    Set<ResourceId> rangeClassIds = Sets.newHashSet();
    for (FormField field : formClass.getFields()) {
        if (field.getType() instanceof ReferenceType) {
            rangeClassIds.addAll(((ReferenceType) field.getType()).getRange());
        }
    }
    return rangeClassIds;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

Example 48 with ResourceId

use of org.activityinfo.model.resource.ResourceId 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 49 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class FormResource method getVersionRange.

@GET
@NoCache
@Path("records/versionRange")
@Operation(summary = "Get the records that have changed between two versions of this form")
public FormSyncSet getVersionRange(@QueryParam("localVersion") long localVersion, @QueryParam("version") long version) {
    FormStorage collection = assertVisible(formId);
    // Compute a predicate that will tell us whether a given
    // record should be visible to the user, based on their *current* permissions.
    java.util.function.Predicate<ResourceId> visibilityPredicate = computeVisibilityPredicate();
    FormSyncSet syncSet;
    if (collection instanceof VersionedFormStorage) {
        syncSet = ((VersionedFormStorage) collection).getVersionRange(localVersion, version, visibilityPredicate);
    } else {
        syncSet = FormSyncSet.emptySet(formId);
    }
    return syncSet;
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) Operation(io.swagger.v3.oas.annotations.Operation)

Example 50 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class SchemaCsvWriterV3 method writeForms.

public void writeForms(UserDatabaseDTO db) throws IOException {
    List<ResourceId> formIds = new ArrayList<>();
    for (ActivityDTO activity : db.getActivities()) {
        if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_ONCE) {
            formIds.add(CuidAdapter.activityFormClass(activity.getId()));
        }
    }
    writeForms(db, formIds);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ArrayList(java.util.ArrayList) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9