use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.
the class ConfigNavigator method loadDbList.
private void loadDbList(final AsyncCallback<List<Link>> callback, SchemaDTO result) {
List<Link> list = Lists.newArrayList();
for (UserDatabaseDTO db : result.getDatabases()) {
Link link = Link.to(new DbPageState(DbConfigPresenter.PAGE_ID, db.getId())).labeled(db.getName()).withIcon(icons.database()).build();
link.set("db", db);
list.add(link);
}
callback.onSuccess(list);
}
use of org.activityinfo.legacy.shared.model.UserDatabaseDTO 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.UserDatabaseDTO 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.UserDatabaseDTO in project activityinfo by bedatadriven.
the class ExportAuditLogExecutor method execute.
@Override
public ExportResult execute(ExportAuditLog descriptor) throws IOException {
UserDatabaseDTO db = dispatcher.execute(new GetSchema()).getDatabaseById(descriptor.getDatabaseId());
GeneratedResource export = storageProvider.create("text/csv;charset=UTF-8", String.format("AuditLog_%d_%s.csv", db.getId(), Filenames.timestamp()));
try (CsvWriter writer = new CsvWriter(new OutputStreamWriter(export.openOutputStream(), Charsets.UTF_8))) {
AuditLogWriter logWriter = new AuditLogWriter(entityManager.get(), db, writer);
for (ActivityDTO activityDTO : db.getActivities()) {
logWriter.writeForm(catalog, activityDTO.getFormId());
}
}
return new ExportResult(export.getDownloadUri());
}
use of org.activityinfo.legacy.shared.model.UserDatabaseDTO 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));
}
Aggregations