Search in sources :

Example 1 with AttributeGroupDTO

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

Example 2 with AttributeGroupDTO

use of org.activityinfo.legacy.shared.model.AttributeGroupDTO in project activityinfo by bedatadriven.

the class LocalGetSchemaHandlerIntTest method forUser.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void forUser() throws CommandException {
    // only has view access to databse 1
    setUser(4);
    synchronize();
    SchemaDTO schema = executeLocally(new GetSchema());
    assertThat(schema.getDatabases().size(), equalTo(2));
    UserDatabaseDTO pearDb = schema.getDatabaseById(1);
    assertThat(pearDb.getAmOwner(), equalTo(false));
    assertThat(pearDb.isViewAllAllowed(), equalTo(false));
    assertThat(pearDb.isEditAllowed(), equalTo(false));
    assertThat(pearDb.isEditAllAllowed(), equalTo(true));
    ActivityFormDTO activity = executeLocally(new GetActivityForm(1));
    assertThat(activity.getAttributeGroups().size(), equalTo(3));
    AttributeGroupDTO group = activity.getAttributeGroupById(1);
    assertThat(group.getName(), equalTo("cause"));
    assertThat(group.getAttributes().size(), equalTo(2));
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 3 with AttributeGroupDTO

use of org.activityinfo.legacy.shared.model.AttributeGroupDTO 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 4 with AttributeGroupDTO

use of org.activityinfo.legacy.shared.model.AttributeGroupDTO 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)

Example 5 with AttributeGroupDTO

use of org.activityinfo.legacy.shared.model.AttributeGroupDTO in project activityinfo by bedatadriven.

the class AttributeGroupFilterWidgets method draw.

public void draw(final Filter filter) {
    final Filter value = new Filter(filter);
    value.clearRestrictions(DIMENSION_TYPE);
    // prevents executing the same command needlessly
    if (prevFilter == null || !prevFilter.equals(filter)) {
        prevFilter = filter;
        Log.debug("AttributeGroupFilterWidgets called for filter " + filter);
        service.execute(new GetActivityForms(filter), new AsyncCallback<ActivityFormResults>() {

            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Failed to load schema", caught);
            }

            @Override
            public void onSuccess(final ActivityFormResults forms) {
                // clean up old widgets
                for (AttributeGroupFilterWidget widget : widgets) {
                    panel.remove(widget);
                }
                // create new widgets, one for each attributegroup.
                // remember the old selection
                Set<Integer> selection = getSelectedIds();
                widgets = new ArrayList<AttributeGroupFilterWidget>();
                Set<String> attributesByName = Sets.newHashSet();
                for (ActivityFormDTO form : forms.getData()) {
                    for (AttributeGroupDTO group : form.getAttributeGroups()) {
                        String key = group.getName().toLowerCase();
                        if (!attributesByName.contains(key)) {
                            AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
                            widget.setSelection(selection);
                            if (valueChangeHandler != null) {
                                widget.addValueChangeHandler(valueChangeHandler);
                            }
                            panel.add(widget);
                            widgets.add(widget);
                            attributesByName.add(key);
                        }
                    }
                }
                if (drawCallback != null) {
                    drawCallback.onSuccess(null);
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) Filter(org.activityinfo.legacy.shared.command.Filter) GetActivityForms(org.activityinfo.legacy.shared.command.GetActivityForms) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults)

Aggregations

AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)6 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)5 Test (org.junit.Test)4 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 HashMap (java.util.HashMap)2 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)2 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetActivityForms (org.activityinfo.legacy.shared.command.GetActivityForms)1 UpdateEntity (org.activityinfo.legacy.shared.command.UpdateEntity)1 ActivityFormResults (org.activityinfo.legacy.shared.command.result.ActivityFormResults)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 OnDataSet (org.activityinfo.server.database.OnDataSet)1 SchemaCsvWriter (org.activityinfo.server.endpoint.rest.SchemaCsvWriter)1