Search in sources :

Example 6 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class DimensionPrunerTest method setupData.

@Before
public void setupData() {
    ActivityDTO dist = new ActivityDTO(1, "Distribution");
    IndicatorDTO nbMenages = new IndicatorDTO();
    nbMenages.setId(NB_MENAGES_INDICATOR_ID);
    nbMenages.setName("Nb Menages");
    dist.getIndicators().add(nbMenages);
    AttributeGroupDTO distFunding = new AttributeGroupDTO(NFI_FUNDING_GROUP_ID);
    distFunding.setName("Funding Source");
    dist.getAttributeGroups().add(distFunding);
    ActivityDTO fairs = new ActivityDTO(2, "Faire");
    AttributeGroupDTO fairFunding = new AttributeGroupDTO(FAIR_FUNDING_GROUP_ID);
    fairFunding.setName("Funding Source");
    fairs.getAttributeGroups().add(fairFunding);
    IndicatorDTO voucherValue = new IndicatorDTO();
    voucherValue.setId(VOUCHER_INDICATOR_ID);
    voucherValue.setName("Voucher Value");
    fairs.getIndicators().add(voucherValue);
    UserDatabaseDTO nfi = new UserDatabaseDTO(1, "NFI");
    nfi.getActivities().add(dist);
    nfi.getActivities().add(fairs);
    this.schema = new SchemaDTO();
    schema.getDatabases().add(nfi);
    dispatcher.setResult(GetSchema.class, schema);
}
Also used : IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Before(org.junit.Before)

Example 7 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class AttributeGroupTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    // initial data load
    SchemaDTO schema = execute(new GetSchema());
    // change the name of an entity group
    ActivityDTO activity = schema.getActivityById(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
    schema = execute(new GetSchema());
    // verify the property has been duly changed
    Assert.assertEquals(group.getName(), schema.getActivityById(1).getAttributeGroups().get(0).getName());
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) HashMap(java.util.HashMap) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 8 with AttributeGroupDTO

use of org.activityinfo.shared.dto.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);
    synchronizeFirstTime();
    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));
    ActivityDTO activity = schema.getActivityById(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.shared.dto.AttributeGroupDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 9 with AttributeGroupDTO

use of org.activityinfo.shared.dto.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);
        // retrieve all attributegroups for the current filter
        service.execute(new GetAttributeGroupsDimension(value), new AsyncCallback<AttributeGroupResult>() {

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

            @Override
            public void onSuccess(final AttributeGroupResult attributeGroupResult) {
                // if the result is indeed different from the last time, (re)draw the widgets
                if (prevResult == null || !prevResult.equals(attributeGroupResult)) {
                    prevResult = attributeGroupResult;
                    Log.debug("AttributeGroupFilterWidgets drawing widgets for result: " + attributeGroupResult);
                    service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

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

                        @Override
                        public void onSuccess(final SchemaDTO schema) {
                            // clean up old widgets
                            for (AttributeGroupFilterWidget widget : widgets) {
                                panel.remove(widget);
                            }
                            duplicates.clear();
                            // decorate resultlist from schema
                            List<AttributeGroupDTO> pivotData = attributeGroupResult.getData();
                            groups = new ArrayList<AttributeGroupDTO>();
                            if (CollectionUtil.isNotEmpty(pivotData)) {
                                for (AttributeGroupDTO pivotGroup : pivotData) {
                                    AttributeGroupDTO schemaGroup = schema.getAttributeGroupById(pivotGroup.getId());
                                    if (schemaGroup != null) {
                                        groups.add(schemaGroup);
                                    }
                                }
                            }
                            // create new widgets, one for each attributegroup.
                            // remember the old selection
                            List<Integer> selection = getSelectedIds();
                            widgets = new ArrayList<AttributeGroupFilterWidget>();
                            for (AttributeGroupDTO group : groups) {
                                // create
                                AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
                                // set old selection
                                widget.setSelection(selection);
                                // what to do when value changes
                                if (valueChangeHandler != null) {
                                    widget.addValueChangeHandler(valueChangeHandler);
                                }
                                // already been added
                                if (isNoDuplicate(widget)) {
                                    widgets.add(widget);
                                    panel.add(widget);
                                } else {
                                    // otherwise add to collection of duplicates
                                    duplicates.put(group.getName().toLowerCase(), widget);
                                }
                            }
                            if (drawCallback != null) {
                                drawCallback.onSuccess(null);
                            }
                        }
                    });
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) AttributeGroupResult(org.activityinfo.shared.command.result.AttributeGroupResult) Filter(org.activityinfo.shared.command.Filter) GetAttributeGroupsDimension(org.activityinfo.shared.command.GetAttributeGroupsDimension) GetSchema(org.activityinfo.shared.command.GetSchema)

Example 10 with AttributeGroupDTO

use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.

the class DesignPresenter method fillStore.

private void fillStore(UIConstants messages) {
    for (ActivityDTO activity : db.getActivities()) {
        ActivityDTO activityNode = new ActivityDTO(activity);
        treeStore.add(activityNode, false);
        AttributeGroupFolder attributeFolder = new AttributeGroupFolder(messages.attributes());
        treeStore.add(activityNode, attributeFolder, false);
        for (AttributeGroupDTO group : activity.getAttributeGroups()) {
            if (group != null) {
                AttributeGroupDTO groupNode = new AttributeGroupDTO(group);
                treeStore.add(attributeFolder, groupNode, false);
                for (AttributeDTO attribute : group.getAttributes()) {
                    AttributeDTO attributeNode = new AttributeDTO(attribute);
                    treeStore.add(groupNode, attributeNode, false);
                }
            }
        }
        IndicatorFolder indicatorFolder = new IndicatorFolder(messages.indicators());
        treeStore.add(activityNode, indicatorFolder, false);
        for (IndicatorDTO indicator : activity.getIndicators()) {
            IndicatorDTO indicatorNode = new IndicatorDTO(indicator);
            treeStore.add(indicatorFolder, indicatorNode, false);
        }
    }
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Aggregations

AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)16 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)9 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)7 AttributeDTO (org.activityinfo.shared.dto.AttributeDTO)6 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)5 ModelData (com.extjs.gxt.ui.client.data.ModelData)3 GetSchema (org.activityinfo.shared.command.GetSchema)3 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 GetAttributeGroupsDimension (org.activityinfo.shared.command.GetAttributeGroupsDimension)2 AttributeGroupResult (org.activityinfo.shared.command.result.AttributeGroupResult)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)2 FieldBinding (com.extjs.gxt.ui.client.binding.FieldBinding)1 TreeGridDragSource (com.extjs.gxt.ui.client.dnd.TreeGridDragSource)1 TreeGridDropTarget (com.extjs.gxt.ui.client.dnd.TreeGridDropTarget)1 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 DNDEvent (com.extjs.gxt.ui.client.event.DNDEvent)1 DNDListener (com.extjs.gxt.ui.client.event.DNDListener)1