use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.
the class DbListPresenterTest method setUp.
@Before
public void setUp() throws Exception {
ownedDb = new UserDatabaseDTO(OWNED_DB_ID, "My Database");
ownedDb.setAmOwner(true);
ownedDb.setDesignAllowed(true);
ownedDb.setManageUsersAllowed(true);
schema.getDatabases().add(ownedDb);
designableDb = new UserDatabaseDTO(DESIGNABLE_DB_ID, "My Database");
designableDb.setAmOwner(false);
designableDb.setDesignAllowed(true);
designableDb.setManageUsersAllowed(true);
schema.getDatabases().add(designableDb);
viewableDb = new UserDatabaseDTO(VIEWABLE_DB_ID, "My database");
viewableDb.setAmOwner(false);
viewableDb.setDesignAllowed(false);
viewableDb.setManageUsersAllowed(false);
schema.getDatabases().add(viewableDb);
}
use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.
the class SchemaImporterV2Test method doImport.
private UserDatabaseDTO doImport(String resourceName) throws IOException {
Map<String, Object> dbProps = Maps.newHashMap();
dbProps.put("name", "Syria");
dbProps.put("countryId", 1);
int databaseId = execute(new CreateEntity("UserDatabase", dbProps)).getNewId();
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO db = schema.getDatabaseById(databaseId);
if (db == null) {
throw new AssertionError("database not created");
}
SchemaImporterV2 importer = new SchemaImporterV2(getDispatcher(), db, warningTemplates());
importer.setProgressListener(new SchemaImporterV2.ProgressListener() {
@Override
public void submittingBatch(int batchNumber, int batchCount) {
System.out.println("Submitting batch " + batchNumber + " of " + batchCount);
}
});
boolean success = importer.parseColumns(source(resourceName));
if (success) {
importer.processRows();
}
for (SafeHtml warning : importer.getWarnings()) {
System.err.println(warning);
}
if (!success) {
throw new AssertionError("there were fatal errors");
}
importer.persist(new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
System.out.println("Success");
}
@Override
public void onFailure(Throwable caught) {
throw new AssertionError(caught);
}
});
return execute(new GetSchema()).getDatabaseById(databaseId);
}
use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.
the class SchemaImporterV2Test method syria.
@Test
public void syria() throws IOException {
UserDatabaseDTO syria = doImport("schema_1064.csv");
int activityId = syria.getActivities().get(0).getId();
ActivityFormDTO cash = execute(new GetActivityForm(activityId));
for (AttributeGroupDTO group : cash.getAttributeGroups()) {
System.out.println(group.getName());
}
assertThat(cash.getName(), equalTo("1.Provision of urgent cash assistance"));
assertThat(cash.getAttributeGroups().size(), equalTo(3));
SchemaCsvWriter writer = new SchemaCsvWriter(getDispatcherSync());
writer.write(syria.getId());
Files.write(writer.toString(), TestOutput.getFile(getClass(), "syria", ".csv"), Charsets.UTF_8);
}
use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.
the class CreateDatabaseTest method createWithSpecificCountry.
@Test
@OnDataSet("/dbunit/multicountry.db.xml")
public void createWithSpecificCountry() throws CommandException {
UserDatabaseDTO db = new UserDatabaseDTO();
db.setName("Warchild Haiti");
db.setFullName("Warchild Haiti");
setUser(1);
CreateEntity cmd = new CreateEntity(db);
cmd.getProperties().put("countryId", 2);
CreateResult cr = execute(cmd);
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
assertNotNull(newdb);
assertThat(newdb.getCountry(), is(notNullValue()));
assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
}
use of org.activityinfo.legacy.shared.model.UserDatabaseDTO in project activityinfo by bedatadriven.
the class LocationTypeProxy method load.
@Override
public void load(DataReader<ListLoadResult<LocationTypeEntry>> reader, Object loadConfig, AsyncCallback<ListLoadResult<LocationTypeEntry>> callback) {
dispatcher.execute(new GetSchema()).then(new Function<SchemaDTO, ListLoadResult<LocationTypeEntry>>() {
@Override
public ListLoadResult<LocationTypeEntry> apply(SchemaDTO schema) {
// Build a dictionary of databases that have been shared with the user
Map<Integer, String> databaseNames = new HashMap<>();
for (UserDatabaseDTO db : schema.getDatabases()) {
databaseNames.put(db.getId(), db.getName());
}
List<LocationTypeEntry> list = new ArrayList<>();
for (LocationTypeDTO locationType : schema.getCountryById(countryId).getLocationTypes()) {
if (!locationType.isDeleted()) {
if (locationType.getDatabaseId() == null) {
list.add(new LocationTypeEntry(locationType));
} else {
list.add(new LocationTypeEntry(locationType, databaseNames.get(locationType.getDatabaseId())));
}
}
}
Collections.sort(list);
return new BaseListLoadResult<>(list);
}
}).then(callback);
}
Aggregations