Search in sources :

Example 1 with TaskContext

use of org.activityinfo.server.endpoint.export.TaskContext 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 TaskContext

use of org.activityinfo.server.endpoint.export.TaskContext 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)

Aggregations

FileOutputStream (java.io.FileOutputStream)2 SiteExporter (org.activityinfo.server.endpoint.export.SiteExporter)2 TaskContext (org.activityinfo.server.endpoint.export.TaskContext)2 NullStorageProvider (org.activityinfo.server.report.NullStorageProvider)2 Test (org.junit.Test)2 File (java.io.File)1 GregorianCalendar (java.util.GregorianCalendar)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)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 User (org.activityinfo.server.database.hibernate.entity.User)1