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