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