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);
}
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());
}
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));
}
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);
}
}
});
}
}
});
}
}
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);
}
}
}
Aggregations