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();
}
};
}
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;
}
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());
}
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;
}
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);
}
Aggregations