use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.
the class DefaultColumnModelProvider method fetchColumnModels.
@Override
public void fetchColumnModels(final Filter filter, final GroupingModel grouping, final AsyncCallback<ColumnModel> callback) {
if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
final int activityId = filter.getRestrictedCategory(DimensionType.Activity);
dispatcher.execute(new GetActivityForm(activityId)).then(new AsyncCallback<ActivityFormDTO>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(ActivityFormDTO activity) {
dispatcher.execute(new GetSchema()).then(new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(SchemaDTO schema) {
callback.onSuccess(forSingleActivity(grouping, schema.getDatabaseById(activity.getDatabaseId()), activity));
}
});
}
});
} else {
dispatcher.execute(new GetSchema()).then(new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(SchemaDTO result) {
if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Database)) {
UserDatabaseDTO singleDatabase = result.getDatabaseById(filter.getRestrictedCategory(DimensionType.Database));
callback.onSuccess(forSingleDatabase(grouping, singleDatabase));
} else {
callback.onSuccess(forMultipleDatabases(grouping, result));
}
}
});
}
}
use of org.activityinfo.legacy.shared.model.SchemaDTO 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);
}
use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.
the class CreateDatabaseTest method testCreate.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testCreate() throws CommandException {
UserDatabaseDTO db = new UserDatabaseDTO();
db.setName("RIMS");
db.setFullName("Reintegration Management Information System");
CreateResult cr = execute(new CreateEntity(db));
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
assertNotNull(newdb);
assertEquals(db.getName(), newdb.getName());
assertEquals(db.getFullName(), newdb.getFullName());
assertNotNull(newdb.getCountry());
assertEquals("Alex", newdb.getOwnerName());
assertThat(newdb.getPartners(), hasSize(1));
}
use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.
the class DeleteTest method testDeleteLocationType.
@Test
public void testDeleteLocationType() throws CommandException {
int locationTypeId = 4;
SchemaDTO schema = execute(new GetSchema());
// assert location type exists
assertNotNull(schema.getLocationTypeById(locationTypeId));
execute(new Delete("LocationType", locationTypeId));
schema = execute(new GetSchema());
// assert "delete" flag is set
assertTrue(schema.getLocationTypeById(locationTypeId).isDeleted());
}
use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.
the class LocalGetSchemaHandlerIntTest method forUser.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void forUser() throws CommandException {
// only has view access to databse 1
setUser(4);
synchronize();
SchemaDTO schema = executeLocally(new GetSchema());
assertThat(schema.getDatabases().size(), equalTo(2));
UserDatabaseDTO pearDb = schema.getDatabaseById(1);
assertThat(pearDb.getAmOwner(), equalTo(false));
assertThat(pearDb.isViewAllAllowed(), equalTo(false));
assertThat(pearDb.isEditAllowed(), equalTo(false));
assertThat(pearDb.isEditAllAllowed(), equalTo(true));
ActivityFormDTO activity = executeLocally(new GetActivityForm(1));
assertThat(activity.getAttributeGroups().size(), equalTo(3));
AttributeGroupDTO group = activity.getAttributeGroupById(1);
assertThat(group.getName(), equalTo("cause"));
assertThat(group.getAttributes().size(), equalTo(2));
}
Aggregations