dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31567
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16105: Chart centralization. Added enum AnalyticsType.
------------------------------------------------------------
revno: 16105
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-07-12 16:18:34 +0200
message:
Chart centralization. Added enum AnalyticsType.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticsType.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java 2014-07-12 13:08:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/BaseChart.java 2014-07-12 14:18:34 +0000
@@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.hisp.dhis.common.AnalyticsType;
import org.hisp.dhis.common.BaseAnalyticalObject;
import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.DxfNamespaces;
@@ -45,6 +46,7 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.user.User;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
@@ -127,6 +129,16 @@
protected transient List<OrganisationUnit> organisationUnitsInGroups = new ArrayList<OrganisationUnit>();
// -------------------------------------------------------------------------
+ // Abstract methods
+ // -------------------------------------------------------------------------
+
+ public abstract List<NameableObject> series();
+
+ public abstract List<NameableObject> category();
+
+ public abstract AnalyticsType getAnalyticsType();
+
+ // -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
@@ -167,6 +179,39 @@
{
return IdentifiableObjectUtils.join( getFilterItems() );
}
+
+ public boolean isAnalyticsType( AnalyticsType type )
+ {
+ return getAnalyticsType().equals( type );
+ }
+
+ // -------------------------------------------------------------------------
+ // Getters and setters for transient properties
+ // -------------------------------------------------------------------------
+
+ @JsonIgnore
+ public I18nFormat getFormat()
+ {
+ return format;
+ }
+
+ @JsonIgnore
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ @JsonIgnore
+ public List<Period> getRelativePeriods()
+ {
+ return relativePeriods;
+ }
+
+ @JsonIgnore
+ public void setRelativePeriods( List<Period> relativePeriods )
+ {
+ this.relativePeriods = relativePeriods;
+ }
// -------------------------------------------------------------------------
// Getters and setters
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java 2014-07-12 13:08:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java 2014-07-12 14:18:34 +0000
@@ -32,6 +32,7 @@
import java.util.Date;
import java.util.List;
+import org.hisp.dhis.common.AnalyticsType;
import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
@@ -44,7 +45,6 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.user.User;
-import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
@@ -177,6 +177,11 @@
this.filterDimensions.add( filter );
}
+ public AnalyticsType getAnalyticsType()
+ {
+ return AnalyticsType.AGGREGATE;
+ }
+
public int getWidth()
{
return 700;
@@ -231,34 +236,6 @@
}
// -------------------------------------------------------------------------
- // Getters and setters for transient properties
- // -------------------------------------------------------------------------
-
- @JsonIgnore
- public I18nFormat getFormat()
- {
- return format;
- }
-
- @JsonIgnore
- public void setFormat( I18nFormat format )
- {
- this.format = format;
- }
-
- @JsonIgnore
- public List<Period> getRelativePeriods()
- {
- return relativePeriods;
- }
-
- @JsonIgnore
- public void setRelativePeriods( List<Period> relativePeriods )
- {
- this.relativePeriods = relativePeriods;
- }
-
- // -------------------------------------------------------------------------
// Merge with
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2014-04-28 11:24:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2014-07-12 14:18:34 +0000
@@ -58,7 +58,7 @@
JFreeChart getJFreeChart( int id, I18nFormat format );
- JFreeChart getJFreeChart( Chart chart, I18nFormat format );
+ JFreeChart getJFreeChart( BaseChart chart, I18nFormat format );
/**
* Generates a JFreeChart.
@@ -70,7 +70,7 @@
* @param format the i18n format.
* @return a JFreeChart object.
*/
- JFreeChart getJFreeChart( Chart chart, Date date, OrganisationUnit organisationUnit, I18nFormat format );
+ JFreeChart getJFreeChart( BaseChart chart, Date date, OrganisationUnit organisationUnit, I18nFormat format );
JFreeChart getJFreePeriodChart( Indicator indicator, OrganisationUnit organisationUnit, boolean title, I18nFormat format );
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticsType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticsType.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AnalyticsType.java 2014-07-12 14:18:34 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.common;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+* @author Lars Helge Overland
+*/
+public enum AnalyticsType
+{
+ AGGREGATE, EVENT;
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java 2014-06-06 07:44:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseAnalyticalObject.java 2014-07-12 14:18:34 +0000
@@ -409,7 +409,7 @@
// Tracked entity data element
Map<String, TrackedEntityDataElementDimension> dataElements = new HashMap<String, TrackedEntityDataElementDimension>();
-
+
for ( TrackedEntityDataElementDimension dataElement : dataElementDimensions )
{
dataElements.put( dataElement.getUid(), dataElement );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java 2014-07-12 12:52:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/eventchart/EventChart.java 2014-07-12 14:18:34 +0000
@@ -33,9 +33,12 @@
import java.util.List;
import org.hisp.dhis.chart.BaseChart;
+import org.hisp.dhis.common.AnalyticsType;
import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.DimensionalView;
import org.hisp.dhis.common.view.ExportView;
@@ -117,6 +120,31 @@
}
}
+ public List<NameableObject> series()
+ {
+ String seriesDim = columnDimensions.get( 0 );
+
+ DimensionalObject object = getDimensionalObject( seriesDim, relativePeriodDate, user, true,
+ organisationUnitsAtLevel, organisationUnitsInGroups, format );
+
+ return object != null ? object.getItems() : null;
+ }
+
+ public List<NameableObject> category()
+ {
+ String categoryDim = rowDimensions.get( 0 );
+
+ DimensionalObject object = getDimensionalObject( categoryDim, relativePeriodDate, user, true,
+ organisationUnitsAtLevel, organisationUnitsInGroups, format );
+
+ return object != null ? object.getItems() : null;
+ }
+
+ public AnalyticsType getAnalyticsType()
+ {
+ return AnalyticsType.EVENT;
+ }
+
// -------------------------------------------------------------------------
// Getters and setters properties
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2014-07-10 10:27:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2014-07-12 14:18:34 +0000
@@ -136,6 +136,8 @@
import org.hisp.dhis.system.util.SystemUtils;
import org.hisp.dhis.system.util.Timer;
import org.hisp.dhis.system.util.UniqueArrayList;
+import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
+import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.springframework.beans.factory.annotation.Autowired;
@@ -183,6 +185,9 @@
private OrganisationUnitGroupService organisationUnitGroupService;
@Autowired
+ private TrackedEntityAttributeService attributeService;
+
+ @Autowired
private ExpressionService expressionService;
@Autowired
@@ -1039,6 +1044,28 @@
return ListUtils.getList( object );
}
+ TrackedEntityAttribute tea = attributeService.getTrackedEntityAttribute( dimension );
+
+ if ( tea != null )
+ {
+ List<NameableObject> options = new ArrayList<NameableObject>(); //TODO
+
+ DimensionalObject object = new BaseDimensionalObject( dimension, DimensionType.TRACKED_ENTITY_ATTRIBUTE, null, tea.getDisplayName(), options );
+
+ return ListUtils.getList( object );
+ }
+
+ DataElement ted = dataElementService.getDataElement( dimension );
+
+ if ( ted != null )
+ {
+ List<NameableObject> options = new ArrayList<NameableObject>(); //TODO
+
+ DimensionalObject object = new BaseDimensionalObject( dimension, DimensionType.TRACKED_ENTITY_DATAELEMENT, null, ted.getDisplayName(), options );
+
+ return ListUtils.getList( object );
+ }
+
if ( allowNull )
{
return null;
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2014-07-12 13:08:26 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2014-07-12 14:18:34 +0000
@@ -28,14 +28,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.chart.Chart.TYPE_AREA;
-import static org.hisp.dhis.chart.Chart.TYPE_BAR;
-import static org.hisp.dhis.chart.Chart.TYPE_COLUMN;
-import static org.hisp.dhis.chart.Chart.TYPE_LINE;
-import static org.hisp.dhis.chart.Chart.TYPE_PIE;
-import static org.hisp.dhis.chart.Chart.TYPE_RADAR;
-import static org.hisp.dhis.chart.Chart.TYPE_STACKED_BAR;
-import static org.hisp.dhis.chart.Chart.TYPE_STACKED_COLUMN;
+import static org.hisp.dhis.chart.BaseChart.TYPE_AREA;
+import static org.hisp.dhis.chart.BaseChart.TYPE_BAR;
+import static org.hisp.dhis.chart.BaseChart.TYPE_COLUMN;
+import static org.hisp.dhis.chart.BaseChart.TYPE_LINE;
+import static org.hisp.dhis.chart.BaseChart.TYPE_PIE;
+import static org.hisp.dhis.chart.BaseChart.TYPE_RADAR;
+import static org.hisp.dhis.chart.BaseChart.TYPE_STACKED_BAR;
+import static org.hisp.dhis.chart.BaseChart.TYPE_STACKED_COLUMN;
import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
import static org.hisp.dhis.system.util.ConversionUtils.getArray;
@@ -55,6 +55,7 @@
import org.apache.commons.math.analysis.UnivariateRealInterpolator;
import org.apache.commons.math.stat.regression.SimpleRegression;
import org.hisp.dhis.analytics.AnalyticsService;
+import org.hisp.dhis.analytics.event.EventAnalyticsService;
import org.hisp.dhis.chart.BaseChart;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.chart.ChartService;
@@ -181,15 +182,11 @@
{
this.analyticsService = analyticsService;
}
-
+
// -------------------------------------------------------------------------
// ChartService implementation
// -------------------------------------------------------------------------
- // -------------------------------------------------------------------------
- // Logic
- // -------------------------------------------------------------------------
-
public JFreeChart getJFreeChart( int id, I18nFormat format )
{
Chart chart = getChart( id );
@@ -197,12 +194,12 @@
return chart != null ? getJFreeChart( chart, format ) : null;
}
- public JFreeChart getJFreeChart( Chart chart, I18nFormat format )
+ public JFreeChart getJFreeChart( BaseChart chart, I18nFormat format )
{
return getJFreeChart( chart, null, null, format );
}
- public JFreeChart getJFreeChart( Chart chart, Date date, OrganisationUnit organisationUnit, I18nFormat format )
+ public JFreeChart getJFreeChart( BaseChart chart, Date date, OrganisationUnit organisationUnit, I18nFormat format )
{
User user = currentUserService.getCurrentUser();
@@ -229,6 +226,10 @@
return getJFreeChart( chart );
}
+ // -------------------------------------------------------------------------
+ // Specific chart methods
+ // -------------------------------------------------------------------------
+
public JFreeChart getJFreePeriodChart( Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format )
{
List<Period> periods = periodService.reloadPeriods(
@@ -512,7 +513,7 @@
/**
* Returns a JFreeChart of type defined in the chart argument.
*/
- private JFreeChart getJFreeChart( Chart chart )
+ private JFreeChart getJFreeChart( BaseChart chart )
{
final BarRenderer barRenderer = getBarRenderer();
final LineAndShapeRenderer lineRenderer = getLineRenderer();
@@ -712,7 +713,7 @@
return title;
}
- private CategoryDataset[] getCategoryDataSet( Chart chart )
+ private CategoryDataset[] getCategoryDataSet( BaseChart chart )
{
Map<String, Double> valueMap = analyticsService.getAggregatedDataValueMapping( chart, chart.getFormat() );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java 2014-06-19 20:53:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventChartController.java 2014-07-12 14:18:34 +0000
@@ -29,12 +29,16 @@
*/
import static org.hisp.dhis.common.DimensionalObjectUtils.getDimensions;
+import static org.hisp.dhis.webapi.utils.ContextUtils.DATE_PATTERN;
+import java.io.IOException;
import java.io.InputStream;
+import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.hisp.dhis.chart.ChartService;
import org.hisp.dhis.common.DimensionService;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.eventchart.EventChart;
@@ -42,18 +46,25 @@
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.schema.descriptors.EventChartSchemaDescriptor;
+import org.hisp.dhis.system.util.CodecUtils;
import org.hisp.dhis.webapi.controller.AbstractCrudController;
import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.ContextUtils.CacheStrategy;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
@@ -66,6 +77,9 @@
{
@Autowired
private EventChartService eventChartService;
+
+ @Autowired
+ private ChartService chartService;
@Autowired
private DimensionService dimensionService;
@@ -75,10 +89,16 @@
@Autowired
private ProgramStageService programStageService;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
@Autowired
private I18nManager i18nManager;
+ @Autowired
+ private ContextUtils contextUtils;
+
//--------------------------------------------------------------------------
// CRUD
//--------------------------------------------------------------------------
@@ -135,6 +155,38 @@
}
//--------------------------------------------------------------------------
+ // Get data
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( value = { "/{uid}/data", "/{uid}/data.png" }, method = RequestMethod.GET )
+ public void getChart(
+ @PathVariable( "uid" ) String uid,
+ @RequestParam( value = "date", required = false ) @DateTimeFormat( pattern = DATE_PATTERN ) Date date,
+ @RequestParam( value = "ou", required = false ) String ou,
+ @RequestParam( value = "width", defaultValue = "800", required = false ) int width,
+ @RequestParam( value = "height", defaultValue = "500", required = false ) int height,
+ HttpServletResponse response ) throws IOException
+ {
+ EventChart chart = eventChartService.getEventChart( uid ); // TODO no acl?
+
+ if ( chart == null )
+ {
+ ContextUtils.notFoundResponse( response, "Chart does not exist: " + uid );
+ return;
+ }
+
+ OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit( ou ) : null;
+
+ JFreeChart jFreeChart = chartService.getJFreeChart( chart, date, unit, i18nManager.getI18nFormat() );
+
+ String filename = CodecUtils.filenameEncode( chart.getName() ) + ".png";
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, false );
+
+ ChartUtilities.writeChartAsPNG( response.getOutputStream(), jFreeChart, width, height );
+ }
+
+ //--------------------------------------------------------------------------
// Hooks
//--------------------------------------------------------------------------