dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22468
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10796: Chart, made it possible to persist associated category/category options. Introduced join-class Da...
------------------------------------------------------------
revno: 10796
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-05-10 18:29:19 +0200
message:
Chart, made it possible to persist associated category/category options. Introduced join-class DataElementCategoryDimension to represent the category dimension, ie. which category/dimension the persisted category options represent.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDimension.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryDimension.hbm.xml
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml
dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.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/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java 2013-05-10 12:07:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java 2013-05-10 16:29:19 +0000
@@ -57,6 +57,7 @@
import org.hisp.dhis.common.view.DimensionalView;
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryDimension;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataset.DataSet;
@@ -153,6 +154,9 @@
private RelativePeriods relatives;
@Scanned
+ private List<DataElementCategoryDimension> categoryDimensions = new ArrayList<DataElementCategoryDimension>();
+
+ @Scanned
private List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>();
@Scanned
@@ -242,6 +246,13 @@
{
List<DimensionalObject> objects = new ArrayList<DimensionalObject>();
+ List<String> categoryDims = new ArrayList<String>();
+
+ for ( DataElementCategoryDimension dim : categoryDimensions )
+ {
+ categoryDims.add( dim.getDimension().getDimension() );
+ }
+
if ( DATA_X_DIM_ID.equals( dimension ) )
{
if ( !indicators.isEmpty() )
@@ -284,7 +295,13 @@
{
objects.add( new BaseDimensionalObject( dimension, organisationUnits ) );
}
- else // Dynamic dimension
+ else if ( categoryDims.contains( dimension ) )
+ {
+ DataElementCategoryDimension categoryDimension = categoryDimensions.get( categoryDims.indexOf( dimension ) );
+
+ objects.add( new BaseDimensionalObject( dimension, categoryDimension.getItems() ) );
+ }
+ else // Group set
{
ListMap<String, IdentifiableObject> listMap = new ListMap<String, IdentifiableObject>();
@@ -297,9 +314,7 @@
{
listMap.putValue( group.getGroupSet().getUid(), group );
}
-
- //TODO categories
-
+
if ( listMap.containsKey( dimension ) )
{
objects.add( new BaseDimensionalObject( dimension, listMap.get( dimension ) ) );
@@ -709,7 +724,7 @@
}
@JsonProperty
- @JsonSerialize( contentAs = BaseNameableObject.class )
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JsonView( {DetailedView.class, ExportView.class} )
@JacksonXmlElementWrapper( localName = "dataElementOperands", namespace = DxfNamespaces.DXF_2_0)
@JacksonXmlProperty( localName = "dataElementOperand", namespace = DxfNamespaces.DXF_2_0)
@@ -782,6 +797,16 @@
this.relatives = relatives;
}
+ public List<DataElementCategoryDimension> getCategoryDimensions()
+ {
+ return categoryDimensions;
+ }
+
+ public void setCategoryDimensions( List<DataElementCategoryDimension> categoryDimensions )
+ {
+ this.categoryDimensions = categoryDimensions;
+ }
+
@JsonProperty
@JsonView( {DetailedView.class, ExportView.class} )
@JacksonXmlElementWrapper( localName = "dataElementGroups", namespace = DxfNamespaces.DXF_2_0)
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDimension.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDimension.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDimension.java 2013-05-10 16:29:19 +0000
@@ -0,0 +1,73 @@
+package org.hisp.dhis.dataelement;
+
+/*
+ * Copyright (c) 2004-2012, 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+* @author Lars Helge Overland
+*/
+public class DataElementCategoryDimension
+{
+ private int id;
+
+ private DataElementCategory dimension;
+
+ private List<DataElementCategoryOption> items = new ArrayList<DataElementCategoryOption>();
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+ public DataElementCategory getDimension()
+ {
+ return dimension;
+ }
+
+ public void setDimension( DataElementCategory dimension )
+ {
+ this.dimension = dimension;
+ }
+
+ public List<DataElementCategoryOption> getItems()
+ {
+ return items;
+ }
+
+ public void setItems( List<DataElementCategoryOption> items )
+ {
+ this.items = items;
+ }
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2013-04-22 17:49:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2013-05-10 16:29:19 +0000
@@ -175,6 +175,14 @@
Collection<DataElementCategoryOption> getDataElementCategoryOptions( Collection<Integer> identifiers );
/**
+ * Retrieves the DataElementCategoryOptions with the given uids.
+ *
+ * @param uids the uids of the DataElementCategoryOption to retrieve.
+ * @return a Collection of DataElementCategoryOptions.
+ */
+ Collection<DataElementCategoryOption> getDataElementCategoryOptionsByUid( Collection<String> uids );
+
+ /**
* Retrieves the DataElementCategoryOption with the given name.
*
* @param name the name.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 2013-05-10 08:28:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 2013-05-10 16:29:19 +0000
@@ -54,6 +54,13 @@
@Override
public DimensionalObject getDimension( String uid )
{
+ DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid );
+
+ if ( cat != null )
+ {
+ return cat;
+ }
+
DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid );
if ( degs != null )
@@ -68,18 +75,18 @@
return ougs;
}
- DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid );
-
- if ( cat != null )
- {
- return cat;
- }
-
return null;
}
public DimensionType getDimensionType( String uid )
{
+ DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid );
+
+ if ( cat != null )
+ {
+ return DimensionType.CATEGORY;
+ }
+
DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid );
if ( degs != null )
@@ -94,13 +101,6 @@
return DimensionType.ORGANISATIONUNIT_GROUPSET;
}
- DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid );
-
- if ( cat != null )
- {
- return DimensionType.CATEGORY;
- }
-
final Map<String, DimensionType> dimObjectTypeMap = new HashMap<String, DimensionType>();
dimObjectTypeMap.put( DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X );
@@ -117,15 +117,15 @@
@Override
public List<DimensionalObject> getAllDimensions()
{
+ Collection<DataElementCategory> dcs = categoryService.getDataDimensionDataElementCategories();
Collection<DataElementGroupSet> degs = identifiableObjectManager.getAll( DataElementGroupSet.class );
Collection<OrganisationUnitGroupSet> ougs = identifiableObjectManager.getAll( OrganisationUnitGroupSet.class );
- Collection<DataElementCategory> dcs = categoryService.getDataDimensionDataElementCategories();
final List<DimensionalObject> dimensions = new ArrayList<DimensionalObject>();
-
+
+ dimensions.addAll( dcs );
dimensions.addAll( degs );
dimensions.addAll( ougs );
- dimensions.addAll( dcs );
return dimensions;
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2013-04-22 17:49:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2013-05-10 16:29:19 +0000
@@ -235,6 +235,11 @@
} );
}
+ public Collection<DataElementCategoryOption> getDataElementCategoryOptionsByUid( Collection<String> uids )
+ {
+ return dataElementCategoryOptionStore.getByUid( uids );
+ }
+
public Collection<DataElementCategoryOption> getAllDataElementCategoryOptions()
{
return i18n( i18nService, dataElementCategoryOptionStore.getAll() );
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryDimension.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryDimension.hbm.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryDimension.hbm.xml 2013-05-10 16:29:19 +0000
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping>
+ <class name="org.hisp.dhis.dataelement.DataElementCategoryDimension" table="categorydimension">
+
+ <cache usage="read-write" />
+
+ <id name="id" column="categorydimensionid">
+ <generator class="native" />
+ </id>
+
+ <many-to-one name="dimension" class="org.hisp.dhis.dataelement.DataElementCategory" column="categoryid"
+ foreign-key="fk_categorydimension_category" />
+
+ <list name="items" table="categorydimension_items">
+ <cache usage="read-write" />
+ <key column="categorydimensionid" foreign-key="fk_categorydimension_items_categorydimensionid" />
+ <list-index column="sort_order" base="0" />
+ <many-to-many class="org.hisp.dhis.dataelement.DataElementCategoryOption" column="categoryoptionid"
+ foreign-key="fk_categorydimension_items_categoryoptionid" />
+ </list>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml 2013-05-10 12:07:51 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml 2013-05-10 16:29:19 +0000
@@ -106,6 +106,14 @@
<many-to-one name="relatives" unique="true" class="org.hisp.dhis.period.RelativePeriods" column="relativeperiodsid"
cascade="all-delete-orphan" foreign-key="fk_report_relativeperiodsid" />
+ <list name="categoryDimensions" table="chart_categorydimensions" cascade="all-delete-orphan">
+ <cache usage="read-write" />
+ <key column="chartid" foreign-key="fk_chart_categorydimensions_chartid" />
+ <list-index column="sort_order" base="0" />
+ <many-to-many column="categorydimensionid" class="org.hisp.dhis.dataelement.DataElementCategoryDimension"
+ foreign-key="fk_chart_categorydimensions_categorydimensionid" />
+ </list>
+
<list name="dataElementGroups" table="chart_dataelementgroups">
<cache usage="read-write" />
<key column="chartid" foreign-key="fk_chart_dataelementgroups_chartid" />
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2013-03-20 12:40:07 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2013-05-10 16:29:19 +0000
@@ -23,6 +23,8 @@
<cache name="org.hisp.dhis.dataelement.DataElementCategoryOption" maxElementsInMemory="400" />
<cache name="org.hisp.dhis.dataelement.DataElementCategoryOptionCombo" maxElementsInMemory="800" />
+
+ <cache name="org.hisp.dhis.dataelement.DataElementCategoryDimension" maxElementsInMemory="2000" />
<cache name="org.hisp.dhis.dataelement.DataElementGroup" maxElementsInMemory="200" />
@@ -177,6 +179,8 @@
<cache name="org.hisp.dhis.reporttable.ReportTable.organisationUnitGroups" maxElementsInMemory="500" />
<cache name="org.hisp.dhis.chart.Chart.dataElements" maxElementsInMemory="2000" />
+
+ <cache name="org.hisp.dhis.chart.Chart.dataElementOperands" maxElementsInMemory="2000" />
<cache name="org.hisp.dhis.chart.Chart.indicators" maxElementsInMemory="2000" />
@@ -184,6 +188,12 @@
<cache name="org.hisp.dhis.chart.Chart.organisationUnits" maxElementsInMemory="2000" />
+ <cache name="org.hisp.dhis.chart.Chart.dataElementGroups" maxElementsInMemory="2000" />
+
+ <cache name="org.hisp.dhis.chart.Chart.categoryDimensions" maxElementsInMemory="2000" />
+
+ <cache name="org.hisp.dhis.chart.Chart.organisationUnitGroups" maxElementsInMemory="2000" />
+
<cache name="org.hisp.dhis.chart.Chart.dataSets" maxElementsInMemory="200" />
<cache name="org.hisp.dhis.mapping.Map.mapViews" maxElementsInMemory="1000" />
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java 2013-05-10 12:07:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java 2013-05-10 16:29:19 +0000
@@ -35,6 +35,7 @@
import static org.hisp.dhis.common.DimensionType.ORGANISATIONUNIT;
import static org.hisp.dhis.common.DimensionType.ORGANISATIONUNIT_GROUPSET;
import static org.hisp.dhis.common.DimensionType.PERIOD;
+import static org.hisp.dhis.common.DimensionType.CATEGORY;
import static org.hisp.dhis.common.DimensionalObject.DATA_X_DIMS;
import static org.hisp.dhis.common.DimensionalObject.DATA_X_DIM_ID;
import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
@@ -59,6 +60,8 @@
import org.hisp.dhis.common.DimensionService;
import org.hisp.dhis.common.DimensionType;
import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.dataelement.DataElementCategoryDimension;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementOperandService;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataset.DataSetService;
@@ -108,6 +111,9 @@
private DataElementService dataElementService;
@Autowired
+ private DataElementCategoryService categoryService;
+
+ @Autowired
private DataElementOperandService operandService;
@Autowired
@@ -301,6 +307,8 @@
{
DimensionType type = dimensionService.getDimensionType( dimension.getDimension() );
+ String dimensionId = dimension.getDimension();
+
List<String> uids = getUids( dimension.getItems() );
if ( INDICATOR.equals( type ) )
@@ -371,6 +379,14 @@
chart.setOrganisationUnits( ous );
}
+ else if ( CATEGORY.equals( type ) )
+ {
+ DataElementCategoryDimension categoryDimension = new DataElementCategoryDimension();
+ categoryDimension.setDimension( categoryService.getDataElementCategory( dimensionId ) );
+ categoryDimension.getItems().addAll( categoryService.getDataElementCategoryOptionsByUid( uids ) );
+
+ chart.getCategoryDimensions().add( categoryDimension );
+ }
else if ( DATAELEMENT_GROUPSET.equals( type ) )
{
chart.getDataElementGroups().addAll( dataElementService.getDataElementGroupsByUid( uids ) );
@@ -379,8 +395,6 @@
{
chart.getOrganisationUnitGroups().addAll( organisationUnitGroupService.getOrganisationUnitGroupsByUid( uids ) );
}
-
- //TODO categories and operands
}
}