Search in sources :

Example 1 with RecordLockSet

use of org.activityinfo.model.database.RecordLockSet in project activityinfo by bedatadriven.

the class FormResource method getMetadataResponse.

@GET
@NoCache
@Produces(JSON_CONTENT_TYPE)
public FormMetadata getMetadataResponse(@InjectParam DatabaseProviderImpl databaseProvider, @InjectParam AuthenticatedUser user, @QueryParam("localVersion") Long localVersion) {
    Optional<FormStorage> storage = backend.getStorage().getForm(formId);
    if (!storage.isPresent()) {
        return FormMetadata.notFound(formId);
    }
    ResourceId databaseId = storage.get().getFormClass().getDatabaseId();
    UserDatabaseMeta databaseMetadata;
    try {
        databaseMetadata = databaseProvider.getDatabaseMetadata(databaseId, user.getUserId());
    } catch (Exception e) {
        // We are initially using this just for locks,
        // not actually permissions, so just log the warning for now.
        LOGGER.log(Level.SEVERE, "Failed to retrieve metadata for database " + databaseId + " for user " + user.getUserId(), e);
        databaseMetadata = new UserDatabaseMeta.Builder().setDatabaseId(databaseId).setLabel("").setOwner(false).build();
    }
    FormPermissions permissions = backend.getFormSupervisor().getFormPermissions(formId);
    if (!permissions.isVisible()) {
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    } else {
        // Workaround for sub form, which we don't yet have indexed to the
        // database in which they live.
        FormClass schema = storage.get().getFormClass();
        RecordLockSet locks;
        if (schema.isSubForm()) {
            locks = databaseMetadata.getEffectiveLocks(schema.getParentFormId().get());
        } else {
            locks = databaseMetadata.getEffectiveLocks(formId);
        }
        return new FormMetadata.Builder().setId(formId).setPermissions(permissions).setSchema(schema).setLocks(locks).setVersion(storage.get().cacheVersion()).build();
    }
}
Also used : VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder) XlsFormBuilder(org.activityinfo.io.xlsform.XlsFormBuilder) RecordLockSet(org.activityinfo.model.database.RecordLockSet) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) NotFoundException(com.sun.jersey.api.NotFoundException) SQLException(java.sql.SQLException) InvalidUpdateException(org.activityinfo.store.query.server.InvalidUpdateException) ParseException(com.vividsolutions.jts.io.ParseException)

Aggregations

NotFoundException (com.sun.jersey.api.NotFoundException)1 ParseException (com.vividsolutions.jts.io.ParseException)1 SQLException (java.sql.SQLException)1 XlsFormBuilder (org.activityinfo.io.xlsform.XlsFormBuilder)1 RecordLockSet (org.activityinfo.model.database.RecordLockSet)1 UserDatabaseMeta (org.activityinfo.model.database.UserDatabaseMeta)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 JsonFormTreeBuilder (org.activityinfo.model.formTree.JsonFormTreeBuilder)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 InvalidUpdateException (org.activityinfo.store.query.server.InvalidUpdateException)1 FormStorage (org.activityinfo.store.spi.FormStorage)1 VersionedFormStorage (org.activityinfo.store.spi.VersionedFormStorage)1