Search in sources :

Example 6 with ActivityFormDTO

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"));
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 7 with ActivityFormDTO

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);
                }
            });
        }
    });
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Promise(org.activityinfo.promise.Promise) Function(com.google.common.base.Function) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) Nullable(javax.annotation.Nullable)

Example 8 with ActivityFormDTO

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);
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) SchemaCsvWriter(org.activityinfo.server.endpoint.rest.SchemaCsvWriter) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 9 with ActivityFormDTO

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()));
}
Also used : IndicatorDTO(org.activityinfo.legacy.shared.model.IndicatorDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Test(org.junit.Test)

Example 10 with ActivityFormDTO

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());
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) HashMap(java.util.HashMap) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Aggregations

ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)14 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)10 Test (org.junit.Test)9 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)5 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)4 Delete (org.activityinfo.legacy.shared.command.Delete)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 HashMap (java.util.HashMap)2 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)2 ActivityFormResults (org.activityinfo.legacy.shared.command.result.ActivityFormResults)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 Function (com.google.common.base.Function)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 StreamResult (javax.xml.transform.stream.StreamResult)1