Search in sources :

Example 36 with Dimension

use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.

the class ProjectTest method deleteProject.

@Test
public void deleteProject() {
    setUser(1);
    long originalDatabaseVersion = lookupDbVersion(1);
    int projectId = 2;
    execute(RequestChange.delete("Project", projectId));
    SchemaDTO schema = execute(new GetSchema());
    assertThat(schema.getProjectById(projectId), nullValue());
    // make sure it's gone from sites
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Site, 3);
    SiteResult sites = execute(new GetSites(filter));
    assertThat(sites.getData().get(0).getProject(), is(nullValue()));
    // and doesn't show up in pivoting...
    PivotSites pivot = new PivotSites();
    Dimension projectDimension = new Dimension(DimensionType.Project);
    pivot.setDimensions(projectDimension);
    pivot.setFilter(filter);
    PivotResult buckets = execute(pivot);
    assertThat(buckets.getBuckets().size(), equalTo(1));
    assertThat(buckets.getBuckets().get(0).getCategory(projectDimension), is(nullValue()));
    // make sure the version number of the database is updated
    assertThat(lookupDbVersion(1), not(equalTo(originalDatabaseVersion)));
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) Filter(org.activityinfo.shared.command.Filter) SiteResult(org.activityinfo.shared.command.result.SiteResult) PivotResult(org.activityinfo.shared.command.PivotSites.PivotResult) GetSites(org.activityinfo.shared.command.GetSites) Dimension(org.activityinfo.shared.report.model.Dimension) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 37 with Dimension

use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.

the class EmptyChartsTest method generate.

@Test
public void generate() {
    PivotChartReportElement element = new PivotChartReportElement(Type.StackedBar);
    element.setIndicator(1);
    element.addCategoryDimension(new Dimension(DimensionType.Partner));
    element.addSeriesDimension(new Dimension(DimensionType.Database));
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(Collections.EMPTY_LIST));
    expect(dispatcher.execute(isA(GetDimensionLabels.class))).andReturn(new GetDimensionLabels.DimensionLabels(Collections.EMPTY_MAP));
    replay(dispatcher);
    IndicatorDAO indicatorDAO = createMock(IndicatorDAO.class);
    expect(indicatorDAO.findById(eq(1))).andReturn(new Indicator());
    replay(indicatorDAO);
    PivotChartGenerator generator = new PivotChartGenerator(dispatcher, indicatorDAO);
    generator.generate(new User(), element, new Filter(), new DateRange());
}
Also used : IndicatorDAO(org.activityinfo.server.database.hibernate.dao.IndicatorDAO) GetDimensionLabels(org.activityinfo.shared.command.GetDimensionLabels) User(org.activityinfo.server.database.hibernate.entity.User) Dimension(org.activityinfo.shared.report.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) PivotSites(org.activityinfo.shared.command.PivotSites) DateRange(org.activityinfo.shared.report.model.DateRange) Filter(org.activityinfo.shared.command.Filter) PivotChartGenerator(org.activityinfo.server.report.generator.PivotChartGenerator) PivotChartReportElement(org.activityinfo.shared.report.model.PivotChartReportElement) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 38 with Dimension

use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.

the class PivotTableGeneratorTest method testIndicatorSortOrder.

@Test
public void testIndicatorSortOrder() {
    // test input data: user
    User user = new User();
    user.setLocale("fr");
    // test input data: PivotTableElement
    PivotTableReportElement element = new PivotTableReportElement();
    Dimension indicatorDim = new Dimension(DimensionType.Indicator);
    element.addRowDimension(indicatorDim);
    // test input data: aggregated results
    List<Bucket> buckets = new ArrayList<Bucket>();
    buckets.add(newBucket(300, category(indicatorDim, 1, "Nb. menages", 3)));
    buckets.add(newBucket(400, category(indicatorDim, 2, "Nb. personnes", 1)));
    buckets.add(newBucket(600, category(indicatorDim, 3, "Nb. deplaces", 2)));
    // collaborator : PivotDAO
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(buckets));
    replay(dispatcher);
    // CLASS UNDER TEST!!
    PivotTableGenerator generator = new PivotTableGenerator(dispatcher);
    generator.generate(user, element, null, null);
    Assert.assertNotNull("element content", element.getContent());
    List<PivotTableData.Axis> rows = element.getContent().getData().getRootRow().getChildren();
    Assert.assertEquals(2, ((EntityCategory) rows.get(0).getCategory()).getId());
    Assert.assertEquals(3, ((EntityCategory) rows.get(1).getCategory()).getId());
    Assert.assertEquals(1, ((EntityCategory) rows.get(2).getCategory()).getId());
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 39 with Dimension

use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.

the class PieMapMarkerTest method testPies.

@Test
public void testPies() {
    Dimension dimension = new Dimension(DimensionType.Indicator);
    dimension.setCategoryColor(101, 255);
    dimension.setCategoryColor(102, 0x00FF00);
    dimension.setCategoryColor(103, 0x0000FF);
    SiteDTO site1 = new SiteDTO();
    site1.setId(1);
    site1.setX(0d);
    site1.setY(0d);
    site1.setIndicatorValue(101, 50d);
    site1.setIndicatorValue(102, 40d);
    site1.setIndicatorValue(103, 10d);
    List<SiteDTO> sites = new ArrayList<SiteDTO>();
    sites.add(site1);
    PiechartMapLayer layer = new PiechartMapLayer();
    layer.addIndicatorId(101);
    layer.addIndicatorId(102);
    layer.addIndicatorId(103);
    // layer.getColorDimensions().add(dimension);
    MapReportElement mapElement = new MapReportElement();
    mapElement.addLayer(layer);
    MapContent content = new MapContent();
    TiledMap map = new TiledMap(640, 480, new AiLatLng(0, 0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(101, new Indicator());
    indicators.put(102, new Indicator());
    indicators.put(103, new Indicator());
    PiechartLayerGenerator generator = new PiechartLayerGenerator(layer, indicators);
    generator.setSites(sites);
    generator.generate(map, content);
    Assert.assertEquals(1, content.getMarkers().size());
    PieMapMarker marker = (PieMapMarker) content.getMarkers().get(0);
    Assert.assertEquals(3, marker.getSlices().size());
}
Also used : MapContent(org.activityinfo.shared.report.content.MapContent) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) Test(org.junit.Test)

Example 40 with Dimension

use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.

the class PivotSitesHandlerTest method testLinkedAttributegroupFilterData.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testLinkedAttributegroupFilterData() {
    withAttributeGroupDim();
    forFilterData();
    execute();
    assertThat().thereAre(2).buckets();
    Dimension dim = new Dimension(DimensionType.AttributeGroup);
    Bucket causeBucket = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", causeBucket.getCategory(dim).getLabel());
    assertEquals(0, (int) causeBucket.doubleValue());
    Bucket contenuBucket = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", contenuBucket.getCategory(dim).getLabel());
    assertEquals(0, (int) contenuBucket.doubleValue());
}
Also used : Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

Dimension (org.activityinfo.shared.report.model.Dimension)46 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)31 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)29 DateDimension (org.activityinfo.shared.report.model.DateDimension)28 Test (org.junit.Test)23 Bucket (org.activityinfo.shared.command.result.Bucket)11 OnDataSet (org.activityinfo.server.database.OnDataSet)10 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)10 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)9 ArrayList (java.util.ArrayList)6 PivotSites (org.activityinfo.shared.command.PivotSites)6 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)4 Comparator (java.util.Comparator)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)3 DimensionCategory (org.activityinfo.shared.report.content.DimensionCategory)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 ReportChangeEvent (org.activityinfo.client.page.report.ReportChangeEvent)2