use of org.activityinfo.model.database.UserDatabaseMeta in project activityinfo by bedatadriven.
the class LockedPeriodTest method createForFolder.
@Test
public void createForFolder() {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("NFI ");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setFolderId(1);
execute(create);
// Now verify that they appear
SchemaDTO schema = execute(new GetSchema());
assertThat(schema.getDatabaseById(1).getFolderById(1).getLockedPeriods(), Matchers.hasSize(1));
LockedPeriodSet locks = new LockedPeriodSet(schema);
assertTrue(locks.isActivityLocked(1, new LocalDate(2011, 1, 1)));
// Verify that the new code works too...
DatabaseProviderImpl provider = new DatabaseProviderImpl(Providers.of(em));
UserDatabaseMeta metadata = provider.getDatabaseMetadata(CuidAdapter.databaseId(1), 1);
ArrayList<RecordLock> folderLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.folderId(1)));
ArrayList<RecordLock> formLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.activityFormClass(1)));
assertThat(folderLocks, Matchers.hasSize(2));
assertThat(formLocks, Matchers.hasSize(3));
}
use of org.activityinfo.model.database.UserDatabaseMeta 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();
}
}
use of org.activityinfo.model.database.UserDatabaseMeta in project activityinfo by bedatadriven.
the class GetSchemaTest method testDatabaseMetadata.
@Test
public void testDatabaseMetadata() {
DatabaseProviderImpl impl = injector.getInstance(DatabaseProviderImpl.class);
UserDatabaseMeta metadata = impl.getDatabaseMetadata(CuidAdapter.databaseId(1), 1);
System.out.println(Json.stringify(metadata.toJson(), 4));
}
Aggregations