use of org.activityinfo.server.endpoint.export.SiteExporter 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());
TaskContext context = new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XYZ");
SiteExporter export = new SiteExporter(context);
for (UserDatabaseDTO db : schema.getDatabases()) {
for (ActivityDTO activity : db.getActivities()) {
export.export(execute(new GetActivityForm(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.server.endpoint.export.SiteExporter in project activityinfo by bedatadriven.
the class CustomerCalcIndicatorTest method pivot.
@Test
public void pivot() throws IOException {
formClass = createFormClass();
int activityId = getLegacyIdFromCuid(formClass.getId());
double[] alloc = new double[] { 20, 10, 50, 20, 10 };
int[] year = new int[] { 2011, 2012, 2013 };
AttributeGroupDTO group = getAttributeGroup(activityId);
List<Command> batch = Lists.newArrayList();
for (int i = 0; i != 50; ++i) {
SiteDTO newSite = newSite(activityId);
newSite.setDate1((new GregorianCalendar(year[i % year.length], 1, 1)).getTime());
newSite.setDate2((new GregorianCalendar(year[i % year.length], 1, 1)).getTime());
newSite.setIndicatorValue(fieldId("EXP"), (i % 10) * 1000);
newSite.setIndicatorValue(fieldId("WATER_ALLOC"), alloc[i % alloc.length]);
newSite.setIndicatorValue(fieldId("PCT_INITIAL"), 50);
newSite.setIndicatorValue(fieldId("PCT_INITIAL_HARD"), 20);
newSite.setIndicatorValue(fieldId("PCT_INITIAL_SOFT"), 30);
if (i % 2 == 0) {
newSite.setAttributeValue(group.getAttributes().get(0).getId(), true);
} else {
newSite.setAttributeValue(group.getAttributes().get(1).getId(), true);
}
batch.add(new CreateSite(newSite));
}
execute(new BatchCommand(batch));
// Export to excel
ActivityFormDTO activity = execute(new GetActivityForm(activityId));
SiteExporter exporter = new SiteExporter(new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XYZ"));
exporter.export(activity, Filter.filter().onActivity(activityId));
exporter.done();
try (FileOutputStream fos = TestOutput.open(getClass(), "calcs.xls")) {
exporter.getBook().write(fos);
}
// Get a full sum
fullPivot(activityId);
pivotByYear(activityId);
pivotByAttributeGroup(activityId);
}
Aggregations