use of org.activityinfo.legacy.shared.model.ActivityFormDTO 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.model.ActivityFormDTO 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.ActivityFormDTO 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.ActivityFormDTO in project activityinfo by bedatadriven.
the class SiteRendererTest method multipleGroupsRender.
@Test
public void multipleGroupsRender() {
IndicatorDTO indicator1 = new IndicatorDTO();
indicator1.setId(1);
indicator1.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator1.setName("First indicator");
indicator1.setCategory("First group");
IndicatorDTO indicator2 = new IndicatorDTO();
indicator2.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator2.setId(2);
indicator2.setName("Second indicator");
indicator2.setCategory("Second group");
IndicatorDTO indicator3 = new IndicatorDTO();
indicator3.setAggregation(IndicatorDTO.AGGREGATE_SUM);
indicator3.setType(FieldTypeClass.NARRATIVE);
indicator3.setId(3);
indicator3.setName("Third indicator");
indicator3.setCategory("Second group");
ActivityFormDTO activity = new ActivityFormDTO();
activity.setId(1);
activity.getIndicators().add(indicator1);
activity.getIndicators().add(indicator2);
activity.getIndicators().add(indicator3);
SiteDTO site = new SiteDTO();
site.setIndicatorValue(1, 1000d);
site.setIndicatorValue(2, 2000d);
site.setIndicatorValue(3, "Some help but not a huge amount.\nHowever there was " + "some other information that I'd like to present in " + "second paragraph.");
String html = siteRenderer.renderSite(site, activity, true);
System.out.println(html);
assertTrue(html.contains(indicator1.getName()));
assertTrue(html.contains(indicator2.getName()));
assertTrue(html.contains(indicator3.getName()));
}
use of org.activityinfo.legacy.shared.model.ActivityFormDTO in project activityinfo by bedatadriven.
the class AttributeGroupTest method testCreate.
@Test
public void testCreate() throws Exception {
// execute the command
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("name", "Type de Conflit");
properties.put("multipleAllowed", true);
properties.put("activityId", 1);
CreateEntity cmd = new CreateEntity("AttributeGroup", properties);
CreateResult result = execute(cmd);
// check if it has been added
ActivityFormDTO activity = execute(new GetActivityForm(1));
AttributeGroupDTO group = activity.getAttributeGroupById(result.getNewId());
Assert.assertNotNull("attribute group is created", group);
Assert.assertEquals("name is correct", group.getName(), "Type de Conflit");
Assert.assertTrue("multiple allowed is set to true", group.isMultipleAllowed());
}
Aggregations