Search in sources :

Example 1 with NullStorageProvider

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();
}
Also used : SiteExporter(org.activityinfo.server.endpoint.export.SiteExporter) User(org.activityinfo.server.database.hibernate.entity.User) TaskContext(org.activityinfo.server.endpoint.export.TaskContext) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) Filter(org.activityinfo.legacy.shared.command.Filter) FileOutputStream(java.io.FileOutputStream) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) File(java.io.File) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) Test(org.junit.Test)

Example 2 with NullStorageProvider

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"));
}
Also used : HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) Filter(org.activityinfo.legacy.shared.command.Filter) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 3 with NullStorageProvider

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);
}
Also used : TaskContext(org.activityinfo.server.endpoint.export.TaskContext) GregorianCalendar(java.util.GregorianCalendar) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) SiteExporter(org.activityinfo.server.endpoint.export.SiteExporter) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 4 with NullStorageProvider

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"));
}
Also used : Filter(org.activityinfo.legacy.shared.command.Filter) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) Test(org.junit.Test)

Aggregations

NullStorageProvider (org.activityinfo.server.report.NullStorageProvider)4 Test (org.junit.Test)4 Filter (org.activityinfo.legacy.shared.command.Filter)3 FileOutputStream (java.io.FileOutputStream)2 SiteExporter (org.activityinfo.server.endpoint.export.SiteExporter)2 TaskContext (org.activityinfo.server.endpoint.export.TaskContext)2 File (java.io.File)1 GregorianCalendar (java.util.GregorianCalendar)1 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)1 DispatcherSync (org.activityinfo.server.command.DispatcherSync)1 User (org.activityinfo.server.database.hibernate.entity.User)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1