Search in sources :

Example 1 with XFormList

use of org.activityinfo.io.xform.formList.XFormList in project activityinfo by bedatadriven.

the class FormLister method formList.

public Response formList(UriInfo uri, Optional<Integer> dbIdFilter) throws Exception {
    AuthenticatedUser user = authProvider.get();
    LOGGER.finer("ODK form list requested by " + user.getEmail() + " (" + user.getId() + ")");
    SchemaDTO schema = dispatcher.execute(new GetSchema());
    XFormList formList = new XFormList();
    for (UserDatabaseDTO db : schema.getDatabases()) {
        if (dbIdFilter.isPresent() && db.getId() != dbIdFilter.get()) {
            // skip
            continue;
        }
        if (db.isEditAllowed()) {
            for (ActivityDTO activity : db.getActivities()) {
                if (hasAdminLevelLocation(activity)) {
                    // Admin Level Locations are invalid for ODK forms - do not show
                    continue;
                }
                XFormListItem form = new XFormListItem();
                form.setName(db.getName() + " / " + activity.getName());
                form.setFormId("activityinfo.org:" + activity.getId());
                form.setVersion(getVersion());
                form.setDownloadUrl(uri.getBaseUriBuilder().path(XFormResources.class).path(Integer.toString(activity.getId())).path("xform").build());
                formList.getItems().add(form);
            }
        }
    }
    return OpenRosaResponse.build(formList);
}
Also used : XFormList(org.activityinfo.io.xform.formList.XFormList) XFormListItem(org.activityinfo.io.xform.formList.XFormListItem) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Aggregations

XFormList (org.activityinfo.io.xform.formList.XFormList)1 XFormListItem (org.activityinfo.io.xform.formList.XFormListItem)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)1