← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 216: New MapLegend object introduced.

 

------------------------------------------------------------
revno: 216
committer: Jan Henrik Overland janhenrik.overland@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-04-21 18:21:49 +0200
message:
  New MapLegend object introduced.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
  dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2009-04-16 15:30:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2009-04-21 16:21:49 +0000
@@ -29,6 +29,9 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.gis.Legend;
+import org.hisp.dhis.gis.LegendSet;
+import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 
@@ -242,4 +245,18 @@
      * @return a Collection of MapOrganisationUnitRelations.
      */
     Collection<MapOrganisationUnitRelation> getAvailableMapOrganisationUnitRelations( String mapLayerPath );
-}
+    
+    // -------------------------------------------------------------------------
+    // LegendSet
+    // -------------------------------------------------------------------------    
+    
+    int addLegendSet( LegendSet legendSet );
+    
+    void deleteLegendSet( LegendSet legendSet );
+    
+    LegendSet getLegendSet( int id );
+    
+    LegendSet getLegendSetByIndicator( int indicatorId );
+    
+    Collection<LegendSet> getAllLegendSets();
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java	2009-04-16 15:30:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java	2009-04-21 16:21:49 +0000
@@ -29,6 +29,9 @@
 
 import java.util.Collection;
 
+import org.hisp.dhis.gis.Legend;
+import org.hisp.dhis.gis.LegendSet;
+import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 
@@ -161,4 +164,16 @@
      *         given Map.
      */
     Collection<MapOrganisationUnitRelation> getMapOrganisationUnitRelationByMap( Map map );
+    
+    // -------------------------------------------------------------------------
+    // LegendSet
+    // -------------------------------------------------------------------------    
+    
+    int addLegendSet( LegendSet legendSet );
+    
+    void deleteLegendSet( LegendSet legendSet );
+    
+    LegendSet getLegendSet( int id );
+    
+    Collection<LegendSet> getAllLegendSets();    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-04-21 11:38:54 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2009-04-21 16:21:49 +0000
@@ -31,6 +31,10 @@
 import java.util.Collection;
 import java.util.Set;
 
+import org.hisp.dhis.gis.Legend;
+import org.hisp.dhis.gis.LegendSet;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -46,13 +50,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private MappingService mappingService;
-
-    public void setMappingService( MappingService mappingService )
-    {
-        this.mappingService = mappingService;
-    }
-
     private MappingStore mappingStore;
 
     public void setMappingStore( MappingStore mappingStore )
@@ -66,6 +63,13 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    private IndicatorService indicatorService;
+    
+    public void setIndicatorService( IndicatorService indicatorService )
+    {
+        this.indicatorService = indicatorService;
+    }
 
     // -------------------------------------------------------------------------
     // MappingService implementation
@@ -93,13 +97,13 @@
         Map map = new Map( mapLayerPath, organisationUnit, organisationUnitLevel, uniqueColumn, nameColumn, longitude,
             latitude, zoom, staticMapLayerPaths );
 
-        return mappingService.addMap( map );
+        return addMap( map );
     }
 
     public void addOrUpdateMap( String mapLayerPath, int organisationUnitId, int organisationUnitLevelId,
         String uniqueColumn, String nameColumn, String longitude, String latitude, int zoom )
     {
-        Map map = mappingService.getMapByMapLayerPath( mapLayerPath );
+        Map map = getMapByMapLayerPath( mapLayerPath );
 
         if ( map != null )
         {
@@ -109,7 +113,7 @@
             map.setLatitude( latitude );
             map.setZoom( zoom );
 
-            mappingService.updateMap( map );
+            updateMap( map );
         }
         else
         {
@@ -121,7 +125,7 @@
             map = new Map( mapLayerPath, organisationUnit, organisationUnitLevel, uniqueColumn, nameColumn, longitude,
                 latitude, zoom, null );
 
-            mappingService.addMap( map );
+            addMap( map );
         }
     }
 
@@ -137,9 +141,9 @@
 
     public void deleteMapByMapLayerPath( String mapLayerPath )
     {
-        Map map = mappingService.getMapByMapLayerPath( mapLayerPath );
+        Map map = getMapByMapLayerPath( mapLayerPath );
 
-        mappingService.deleteMap( map );
+        deleteMap( map );
     }
 
     public Map getMap( int id )
@@ -173,36 +177,36 @@
 
     public int addMapOrganisationUnitRelation( String mapLayerPath, int organisationUnitId, String featureId )
     {
-        Map map = mappingService.getMapByMapLayerPath( mapLayerPath );
+        Map map = getMapByMapLayerPath( mapLayerPath );
 
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
 
         MapOrganisationUnitRelation mapOrganisationUnitRelation = new MapOrganisationUnitRelation( map,
             organisationUnit, featureId );
 
-        return mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelation );
+        return addMapOrganisationUnitRelation( mapOrganisationUnitRelation );
     }
 
     public void addOrUpdateMapOrganisationUnitRelation( String mapLayerPath, int organisationUnitId, String featureId )
     {
-        Map map = mappingService.getMapByMapLayerPath( mapLayerPath );
+        Map map = getMapByMapLayerPath( mapLayerPath );
 
         OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
 
-        MapOrganisationUnitRelation mapOrganisationUnitRelation = mappingService.getMapOrganisationUnitRelation( map,
+        MapOrganisationUnitRelation mapOrganisationUnitRelation = getMapOrganisationUnitRelation( map,
             organisationUnit );
 
         if ( mapOrganisationUnitRelation != null )
         {
             mapOrganisationUnitRelation.setFeatureId( featureId );
 
-            mappingService.updateMapOrganisationUnitRelation( mapOrganisationUnitRelation );
+            updateMapOrganisationUnitRelation( mapOrganisationUnitRelation );
         }
         else
         {
             mapOrganisationUnitRelation = new MapOrganisationUnitRelation( map, organisationUnit, featureId );
 
-            mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelation );
+            addMapOrganisationUnitRelation( mapOrganisationUnitRelation );
         }
     }
 
@@ -255,8 +259,66 @@
 
     public Collection<MapOrganisationUnitRelation> getAvailableMapOrganisationUnitRelations( String mapLayerPath )
     {
-        Map map = mappingService.getMapByMapLayerPath( mapLayerPath );
+        Map map = getMapByMapLayerPath( mapLayerPath );
 
-        return mappingService.getAvailableMapOrganisationUnitRelations( map );
+        return getAvailableMapOrganisationUnitRelations( map );
+    }
+    
+    // -------------------------------------------------------------------------
+    // LegendSet
+    // -------------------------------------------------------------------------    
+    
+    public int addLegendSet( LegendSet legendSet )
+    {
+        return mappingStore.addLegendSet( legendSet );
+    }
+    
+    public void deleteLegendSet( LegendSet legendSet )
+    {
+        mappingStore.deleteLegendSet( legendSet );
+    }
+    
+    public LegendSet getLegendSet( int id )
+    {
+        return mappingStore.getLegendSet( id );
+    }
+    
+    public LegendSet getLegendSetByIndicator( int indicatorId )
+    {
+        Indicator indicator = indicatorService.getIndicator( indicatorId );
+        
+        Collection<LegendSet> legendSets = mappingStore.getAllLegendSets();
+        
+        for ( LegendSet legendSet : legendSets )
+        {
+            if ( legendSet.getIndicators().contains( indicator ))
+            {
+                return legendSet;
+            }
+        }
+        
+        return null;
+    }
+    
+    public Collection<LegendSet> getAllLegendSets()
+    {
+        return mappingStore.getAllLegendSets();
+    }
+    
+    public boolean indicatorHasLegendSet( int indicatorId )
+    {
+        Indicator indicator = indicatorService.getIndicator( indicatorId );
+        
+        Collection<LegendSet> legendSets = mappingStore.getAllLegendSets();
+        
+        for ( LegendSet legendSet : legendSets )
+        {
+            if ( legendSet.getIndicators().contains( indicator ))
+            {
+                return true;
+            }
+        }
+        
+        return false;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java	2009-04-06 18:55:31 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java	2009-04-21 16:21:49 +0000
@@ -33,7 +33,10 @@
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.gis.Legend;
+import org.hisp.dhis.gis.LegendSet;
 import org.hisp.dhis.hibernate.HibernateSessionManager;
+import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.mapping.MapOrganisationUnitRelation;
 import org.hisp.dhis.mapping.MappingStore;
@@ -189,4 +192,39 @@
 
         return criteria.list();        
     }
+    
+    // -------------------------------------------------------------------------
+    // LegendSet
+    // -------------------------------------------------------------------------    
+    
+    public int addLegendSet( LegendSet legendSet )
+    {
+        Session session = sessionManager.getCurrentSession();
+
+        return (Integer) session.save( legendSet );
+    }
+    
+    public void deleteLegendSet( LegendSet legendSet )
+    {
+        Session session = sessionManager.getCurrentSession();
+
+        session.update( legendSet );
+    }
+    
+    public LegendSet getLegendSet( int id )
+    {
+        Session session = sessionManager.getCurrentSession();
+
+        return (LegendSet) session.get( LegendSet.class, id );
+    }
+    
+    @SuppressWarnings("unchecked")
+    public Collection<LegendSet> getAllLegendSets()
+    {
+        Session session = sessionManager.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( MapOrganisationUnitRelation.class );
+
+        return criteria.list();
+    }
 }



--
Trunk
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.