use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.
the class ExportIntegrationTest method fullTest.
@Test
public void fullTest() throws Throwable {
User user = new User();
user.setId(1);
user.setName("Alex");
SchemaDTO schema = execute(new GetSchema());
SiteExporter export = new SiteExporter(getDispatcherSync());
for (UserDatabaseDTO db : schema.getDatabases()) {
for (ActivityDTO activity : db.getActivities()) {
export.export(activity, new Filter());
}
}
File outputDir = new File("target/report-test/");
outputDir.mkdirs();
FileOutputStream fos = new FileOutputStream("target/report-test/ExportTest.xls");
export.getBook().write(fos);
fos.close();
}
use of org.activityinfo.shared.dto.SchemaDTO 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.SchemaDTO in project activityinfo by bedatadriven.
the class AdminTreeProxy method load.
@Override
public void load(DataReader<List<AdminEntityDTO>> dataReader, final Object parent, final AsyncCallback<List<AdminEntityDTO>> callback) {
if (filter == null) {
callback.onSuccess(new ArrayList<AdminEntityDTO>());
return;
}
service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Failed to load admin entities", caught);
}
@Override
public void onSuccess(SchemaDTO schema) {
final Set<CountryDTO> countries = findCountries(schema);
if (CollectionUtil.isEmpty(countries)) {
callback.onSuccess(new ArrayList<AdminEntityDTO>());
return;
}
initLevelsWithChildren(countries);
GetAdminEntities request = new GetAdminEntities(toIdSet(countries), filter);
if (parent != null) {
assert parent instanceof AdminEntityDTO : "expecting AdminEntityDTO";
request.setParentId(((AdminEntityDTO) parent).getId());
}
service.execute(request, new AsyncCallback<AdminEntityResult>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(AdminEntityResult result) {
prepareData(countries, result.getData());
callback.onSuccess(result.getData());
}
});
}
});
}
use of org.activityinfo.shared.dto.SchemaDTO 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.SchemaDTO in project activityinfo by bedatadriven.
the class DataEntryPage method doImport.
protected void doImport() {
final int activityId = currentPlace.getFilter().getRestrictedCategory(DimensionType.Activity);
dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(SchemaDTO result) {
Wizard wizard = new ImporterWizard(dispatcher, result.getActivityById(activityId));
WizardDialog dialog = new WizardDialog(wizard);
dialog.show(new WizardCallback() {
});
}
});
}
Aggregations