use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.
the class PartnerTest method testAddPartner.
@Test
public void testAddPartner() {
PartnerDTO newPartner = new PartnerDTO();
newPartner.setName("Solidarites");
CreateResult cr = execute(new UpdatePartner(PEAR_PLUS_DB_ID, newPartner));
assertThat(cr.getNewId(), not(equalTo(SOL_ID)));
SchemaDTO schema = execute(new GetSchema());
PartnerDTO partner = schema.getDatabaseById(PEAR_PLUS_DB_ID).getPartnerById(cr.getNewId());
Assert.assertNotNull(partner);
Assert.assertEquals(newPartner.getName(), partner.getName());
}
use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.
the class GetActivityFormsHandler method execute.
@Override
public void execute(GetActivityForms command, final ExecutionContext context, final AsyncCallback<ActivityFormResults> callback) {
composeQuery(command.getFilter()).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, final SqlResultSet results) {
context.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(SchemaDTO schema) {
LOGGER.log(Level.INFO, "Forms matching filter: " + results.getRows().size());
final List<Promise<ActivityFormDTO>> pending = new ArrayList<>();
for (SqlResultSetRow row : results.getRows()) {
int activityId = row.getInt("activityId");
boolean visible = (schema.getActivityById(activityId) != null);
if (visible) {
pending.add(fetchForm(context, activityId));
}
}
LOGGER.log(Level.INFO, "Forms pending: " + pending.size());
Promise.waitAll(pending).then(new Function<Void, ActivityFormResults>() {
@Nullable
@Override
public ActivityFormResults apply(@Nullable Void aVoid) {
LOGGER.log(Level.INFO, "Form loading completed.");
List<ActivityFormDTO> forms = new ArrayList<>();
for (Promise<ActivityFormDTO> pendingForm : pending) {
forms.add(pendingForm.get());
}
return new ActivityFormResults(forms);
}
}).then(callback);
}
});
}
});
}
use of org.activityinfo.legacy.shared.model.SchemaDTO 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.SchemaDTO 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.SchemaDTO in project activityinfo by bedatadriven.
the class DeleteTest method testDeleteActivity.
@Test
public void testDeleteActivity() throws CommandException {
ActivityFormDTO form = execute(new GetActivityForm(1));
execute(new Delete(form));
execute(new Delete("Activity", 4));
SchemaDTO schema = execute(new GetSchema());
assertNull("delete by entity reference", schema.getActivityById(1));
assertNull("delete by id", schema.getActivityById(4));
}
Aggregations