use of org.activityinfo.legacy.shared.command.GetActivityForm in project activityinfo by bedatadriven.
the class SiteDialogLauncher method addSite.
public void addSite(final Filter filter, final SiteDialogCallback callback) {
if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
final int activityId = filter.getRestrictedCategory(DimensionType.Activity);
dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(SchemaDTO schema) {
ActivityDTO activity = schema.getActivityById(activityId);
if (!activity.getClassicView()) {
promptUseNewEntry(activity);
return;
}
Log.trace("adding site for activity " + activity + ", locationType = " + activity.getLocationType());
if (activity.getDatabase().getPartners().isEmpty()) {
// Since we are creating a partner by default for every database,
// this shouldn't happen beyond the development environment
MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.noPartners(), null);
return;
}
LockedPeriodSet locks = new LockedPeriodSet(activity.getDatabase());
dispatcher.execute(new GetActivityForm(activityId)).then(new AsyncCallback<ActivityFormDTO>() {
@Override
public void onFailure(Throwable caught) {
showError(caught);
}
@Override
public void onSuccess(ActivityFormDTO activityForm) {
if (activityForm.getLocationType().isAdminLevel()) {
addNewSiteWithBoundLocation(locks, activityForm, callback);
} else if (activityForm.getLocationType().isNationwide()) {
addNewSiteWithNoLocation(locks, activityForm, callback);
} else {
chooseLocationThenAddSite(locks, activityForm, callback);
}
}
});
}
});
}
}
use of org.activityinfo.legacy.shared.command.GetActivityForm in project activityinfo by bedatadriven.
the class AttributeGroupTest method testUpdate.
@Test
public void testUpdate() throws Exception {
// change the name of an entity group
ActivityFormDTO activity = execute(new GetActivityForm(1));
AttributeGroupDTO group = activity.getAttributeGroups().get(0);
group.setName("Foobar");
Map<String, Object> changes = new HashMap<String, Object>();
changes.put("name", group.getName());
execute(new UpdateEntity(group, changes));
// reload data
activity = execute(new GetActivityForm(1));
// verify the property has been duly changed
assertThat(activity.getAttributeGroups().get(0).getName(), equalTo(group.getName()));
}
use of org.activityinfo.legacy.shared.command.GetActivityForm in project activityinfo by bedatadriven.
the class DeleteTest method testDeleteIndicator.
@Test
public void testDeleteIndicator() throws CommandException {
int activityId = 1;
int indicatorId = 1;
execute(new Delete("Indicator", indicatorId));
ActivityFormDTO form = execute(new GetActivityForm(activityId));
assertNull(form.getIndicatorById(indicatorId));
PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
assertNull(sites.getData().get(0).getIndicatorValue(1));
}
use of org.activityinfo.legacy.shared.command.GetActivityForm in project activityinfo by bedatadriven.
the class SchemaImporterV2Test method southSudan.
@Test
public void southSudan() throws IOException {
UserDatabaseDTO db = doImport("schema_1321.csv");
int activityId = db.getActivities().get(0).getId();
ActivityFormDTO h2 = execute(new GetActivityForm(activityId));
assertThat(h2.getName(), equalTo("H2"));
assertThat(h2.getCategory(), equalTo("Health"));
}
use of org.activityinfo.legacy.shared.command.GetActivityForm in project activityinfo by bedatadriven.
the class ExportIntegrationTest method fullTest.
@Test
public void fullTest() throws Throwable {
User user = new User();
user.setId(1);
user.setName("Alex");
SchemaDTO schema = execute(new GetSchema());
TaskContext context = new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XYZ");
SiteExporter export = new SiteExporter(context);
for (UserDatabaseDTO db : schema.getDatabases()) {
for (ActivityDTO activity : db.getActivities()) {
export.export(execute(new GetActivityForm(activity)), new Filter());
}
}
File outputDir = new File("target/report-test/");
outputDir.mkdirs();
FileOutputStream fos = new FileOutputStream("target/report-test/ExportTest.xls");
export.getBook().write(fos);
fos.close();
}
Aggregations