use of org.activityinfo.server.report.NullStorageProvider 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.report.NullStorageProvider in project activityinfo by bedatadriven.
the class SiteExporterTest method sheetNameTest.
@Test
public void sheetNameTest() {
LocaleProxy.initialize();
CountryDTO somalia = new CountryDTO(1, "Somalia");
LocationTypeDTO locationType = new LocationTypeDTO(1, "Village");
locationType.setAdminLevels(somalia.getAdminLevels());
somalia.getLocationTypes().add(locationType);
UserDatabaseDTO syli = new UserDatabaseDTO();
syli.setId(444);
syli.setName("SYLI");
syli.setCountry(somalia);
ActivityFormDTO activity = new ActivityFormDTO();
activity.setId(1);
activity.setDatabase(syli);
activity.setName("Construction/Rehabilitation of Sec. Schools");
activity.setLocationType(locationType);
ActivityFormDTO activity2 = new ActivityFormDTO();
activity2.setId(2);
activity2.setDatabase(syli);
activity2.setName("Construction/Rehabilitation of Primary Schools");
activity2.setLocationType(locationType);
ActivityFormDTO activity3 = new ActivityFormDTO();
activity3.setId(3);
activity3.setDatabase(syli);
activity3.setName("Construction Rehabil (2)");
activity3.setLocationType(locationType);
DispatcherSync dispatcher = createMock(DispatcherSync.class);
expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(new ArrayList<SiteDTO>())).anyTimes();
replay(dispatcher);
Filter filter = new Filter();
SiteExporter exporter = new SiteExporter(new TaskContext(dispatcher, new NullStorageProvider(), "XYZ"));
exporter.export(activity, filter);
exporter.export(activity2, filter);
exporter.export(activity3, filter);
HSSFWorkbook book = exporter.getBook();
assertThat(book.getSheetAt(0).getSheetName(), equalTo("Construction Rehabilitation of "));
assertThat(book.getSheetAt(1).getSheetName(), equalTo("Construction Rehabilitation"));
assertThat(book.getSheetAt(2).getSheetName(), equalTo("Construction Rehabil 2"));
}
use of org.activityinfo.server.report.NullStorageProvider 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);
}
use of org.activityinfo.server.report.NullStorageProvider in project activityinfo by bedatadriven.
the class SiteExporterDbTest method numberOfSheets.
/**
* Exporter obey following rules:
* - only activities of selected DB
* - number of sheets must be the same as number of activities
*/
@Test
public void numberOfSheets() {
Filter filter = new Filter();
filter.addRestriction(DimensionType.Database, PEAR_DB);
SiteExporter exporter = new SiteExporter(new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XY"));
exporter.buildExcelWorkbook(filter);
assertEquals(exporter.getBook().getNumberOfSheets(), 2);
assertNotNull(exporter.getBook().getSheet("NFI"));
}
Aggregations