dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31164
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15853: DimensionService, impl method for getting a dimension object as a copy. Helpful in order to avoid...
------------------------------------------------------------
revno: 15853
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-25 16:38:50 +0200
message:
DimensionService, impl method for getting a dimension object as a copy. Helpful in order to avoid dirty check issues with hibernate on filtering items. Added method to dimension resource for getting relevant dimensions for a data set.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseDimensionalObject.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.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/common/BaseDimensionalObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseDimensionalObject.java 2014-06-06 07:44:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseDimensionalObject.java 2014-06-25 14:38:50 +0000
@@ -35,6 +35,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
import org.hisp.dhis.common.view.DimensionalView;
import java.util.ArrayList;
@@ -209,12 +210,30 @@
{
this.filter = filter;
}
-
+
//--------------------------------------------------------------------------
// Supportive methods
//--------------------------------------------------------------------------
@Override
+ public void mergeWith( IdentifiableObject other )
+ {
+ super.mergeWith( other );
+
+ if ( other.getClass().isInstance( this ) )
+ {
+ DimensionalObject dimensionalObject = (DimensionalObject) other;
+
+ dimensionType = dimensionalObject.getDimensionType() == null ? dimensionType : dimensionalObject.getDimensionType();
+ dimensionName = dimensionalObject.getDimensionName() == null ? dimensionName : dimensionalObject.getDimensionName();
+ filter = dimensionalObject.getFilter() == null ? filter : dimensionalObject.getFilter();
+
+ items.clear();
+ items.addAll( dimensionalObject.getItems() );
+ }
+ }
+
+ @Override
public String toString()
{
return "[" + uid + ", type: " + dimensionType + ", " + items + "]";
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java 2014-05-31 13:38:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java 2014-06-25 14:38:50 +0000
@@ -49,5 +49,7 @@
List<DimensionalObject> getDimensionConstraints();
+ DimensionalObject getDimensionalObjectCopy( String uid, boolean filterCanRead );
+
void mergeAnalyticalObject( BaseAnalyticalObject object );
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2014-05-31 13:38:30 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2014-06-25 14:38:50 +0000
@@ -30,6 +30,7 @@
import org.hisp.dhis.acl.AclService;
import org.hisp.dhis.common.BaseAnalyticalObject;
+import org.hisp.dhis.common.BaseDimensionalObject;
import org.hisp.dhis.common.DimensionService;
import org.hisp.dhis.common.DimensionType;
import org.hisp.dhis.common.DimensionalObject;
@@ -118,6 +119,7 @@
if ( cat != null )
{
+ cat.setDimensionType( DimensionType.CATEGORY );
return cat;
}
@@ -125,6 +127,7 @@
if ( degs != null )
{
+ degs.setDimensionType( DimensionType.DATAELEMENT_GROUPSET );
return degs;
}
@@ -132,6 +135,7 @@
if ( ougs != null )
{
+ ougs.setDimensionType( DimensionType.ORGANISATIONUNIT_GROUPSET );
return ougs;
}
@@ -139,6 +143,7 @@
if ( cogs != null )
{
+ cogs.setDimensionType( DimensionType.CATEGORYOPTION_GROUPSET );
return cogs;
}
@@ -146,14 +151,16 @@
if ( tea != null )
{
+ tea.setDimensionType( DimensionType.TRACKED_ENTITY_ATTRIBUTE );
return tea;
}
- DataElement de = identifiableObjectManager.get( DataElement.class, uid );
+ DataElement tde = identifiableObjectManager.get( DataElement.class, uid );
- if ( de != null )
+ if ( tde != null )
{
- return de;
+ tde.setDimensionType( DimensionType.TRACKED_ENTITY_DATAELEMENT );
+ return tde;
}
return null;
@@ -304,6 +311,23 @@
mergeDimensionalObjects( object, object.getFilters() );
}
}
+
+ public DimensionalObject getDimensionalObjectCopy( String uid, boolean filterCanRead )
+ {
+ DimensionalObject dimension = getDimension( uid );
+
+ BaseDimensionalObject object = new BaseDimensionalObject();
+ object.mergeWith( dimension );
+
+ if ( filterCanRead )
+ {
+ User user = currentUserService.getCurrentUser();
+ List<NameableObject> items = filterCanRead( user, object.getItems() );
+ object.setItems( items );
+ }
+
+ return dimension;
+ }
//--------------------------------------------------------------------------
// Supportive methods
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2014-06-18 07:15:48 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DimensionController.java 2014-06-25 14:38:50 +0000
@@ -30,11 +30,15 @@
import org.hisp.dhis.common.DimensionService;
import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.common.PagerUtils;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.webapi.service.LinkService;
+import org.hisp.dhis.webapi.utils.ContextUtils;
import org.hisp.dhis.webapi.webdomain.WebMetaData;
import org.hisp.dhis.webapi.webdomain.WebOptions;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,6 +51,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -65,6 +71,9 @@
private DimensionService dimensionService;
@Autowired
+ private IdentifiableObjectManager identifiableObjectManager;
+
+ @Autowired
private LinkService linkService;
// -------------------------------------------------------------------------
@@ -115,8 +124,7 @@
}
@RequestMapping( method = RequestMethod.GET )
- public String getDimensions(
- @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links,
+ public String getDimensions( @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links,
Model model )
{
WebMetaData metaData = new WebMetaData();
@@ -134,8 +142,7 @@
}
@RequestMapping( value = "/constraints", method = RequestMethod.GET )
- public String getDimensionConstraints(
- @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links,
+ public String getDimensionConstraints( @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links,
Model model )
{
WebMetaData metaData = new WebMetaData();
@@ -151,4 +158,44 @@
return "dimensions";
}
+
+ @RequestMapping( value = "/dataSet/{uid}", method = RequestMethod.GET )
+ public String getDimensionsForDataSet( @PathVariable String uid,
+ @RequestParam( value = "links", defaultValue = "true", required = false ) Boolean links,
+ Model model, HttpServletResponse response )
+ {
+ WebMetaData metaData = new WebMetaData();
+
+ DataSet dataSet = identifiableObjectManager.get( DataSet.class, uid );
+
+ if ( dataSet == null )
+ {
+ ContextUtils.notFoundResponse( response, "Data set does not exist: " + uid );
+ return null;
+ }
+
+ if ( !dataSet.hasCategoryCombo() )
+ {
+ ContextUtils.conflictResponse( response, "Data set does not have a category combination: " + uid );
+ return null;
+ }
+
+ List<DimensionalObject> dimensions = new ArrayList<>();
+ dimensions.addAll( dataSet.getCategoryCombo().getCategories() );
+ dimensions.addAll( identifiableObjectManager.getAll( CategoryOptionGroupSet.class ) );
+
+ for ( DimensionalObject dim : dimensions )
+ {
+ metaData.getDimensions().add( dimensionService.getDimensionalObjectCopy( dim.getUid(), true ) );
+ }
+
+ model.addAttribute( "model", metaData );
+
+ if ( links )
+ {
+ linkService.generateLinks( metaData );
+ }
+
+ return "dimensions";
+ }
}