← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1677: (GIS) New object MapLegend added. MappingService and MappingStore updated.

 

------------------------------------------------------------
revno: 1677
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-03-19 15:39:43 +0100
message:
  (GIS) New object MapLegend added. MappingService and MappingStore updated.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java
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


--
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.
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegend.java	2010-03-19 14:39:43 +0000
@@ -0,0 +1,145 @@
+package org.hisp.dhis.mapping;
+
+/*
+ * Copyright (c) 2004-2007, 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 Jan Henrik Overland
+ * @version $Id$
+ */
+public class MapLegend
+{
+    private int id;
+
+    private String name;
+    
+    private Double startValue;
+    
+    private Double endValue;
+    
+    private String color; 
+    
+    public MapLegend()
+    {
+    }
+
+    public MapLegend( String name, Double startValue, Double endValue, String color )
+    {
+        this.name = name;
+        this.startValue = startValue;
+        this.endValue = endValue;
+        this.color = color;
+    }
+    
+    // -------------------------------------------------------------------------
+    // hashCode, equals and toString
+    // -------------------------------------------------------------------------
+    
+    @Override
+    public int hashCode()
+    {
+        return name.hashCode();
+    }
+
+    @Override
+    public boolean equals( Object object )
+    {
+        if ( this == object )
+        {
+            return true;
+        }
+        
+        if ( object == null )
+        {
+            return false;
+        }
+        
+        if ( getClass() != object.getClass() )
+        {
+            return false;
+        }
+        
+        MapLegend other = (MapLegend) object;
+        
+        return name.equals( other.name );
+    }
+    
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------    
+
+    public int getId()
+    {
+        return id;
+    }
+
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public Double getStartValue()
+    {
+        return startValue;
+    }
+
+    public void setStartValue( Double startValue )
+    {
+        this.startValue = startValue;
+    }
+
+    public Double getEndValue()
+    {
+        return endValue;
+    }
+
+    public void setEndValue( Double endValue )
+    {
+        this.endValue = endValue;
+    }
+
+    public String getColor()
+    {
+        return color;
+    }
+
+    public void setColor( String color )
+    {
+        this.color = color;
+    }
+}

=== 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	2010-02-24 14:11:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java	2010-03-19 14:39:43 +0000
@@ -313,6 +313,20 @@
      * @return the number of deleted objects.
      */
     int deleteMapOrganisationUnitRelations( Map map );
+    
+    // -------------------------------------------------------------------------
+    // MapLegend
+    // -------------------------------------------------------------------------
+    
+    void addOrUpdateMapLegend( String name, Double startValue, Double endValue, String color );
+    
+    void deleteMapLegend( MapLegend legend );
+    
+    MapLegend getMapLegend( int id );
+    
+    MapLegend getMapLegendByName( String name );
+    
+    Collection<MapLegend> getAllMapLegends();
 
     // -------------------------------------------------------------------------
     // MapLegendSet

=== 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-09-29 16:17:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java	2010-03-19 14:39:43 +0000
@@ -199,6 +199,22 @@
     int deleteMapOrganisationUnitRelations( Map map );
     
     // -------------------------------------------------------------------------
+    // MapLegend
+    // -------------------------------------------------------------------------
+    
+    int addMapLegend( MapLegend legend );
+    
+    void updateMapLegend( MapLegend legend );
+    
+    void deleteMapLegend( MapLegend legend );
+    
+    MapLegend getMapLegend( int id );
+    
+    MapLegend getMapLegendByName( String name );
+    
+    Collection<MapLegend> getAllMapLegends();
+    
+    // -------------------------------------------------------------------------
     // MapLegendSet
     // -------------------------------------------------------------------------    
     

=== 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	2010-02-24 14:11:32 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2010-03-19 14:39:43 +0000
@@ -489,6 +489,51 @@
     }
 
     // -------------------------------------------------------------------------
+    // MapLegend
+    // -------------------------------------------------------------------------
+    
+    public void addOrUpdateMapLegend( String name, Double startValue, Double endValue, String color )
+    {
+        MapLegend mapLegend = getMapLegendByName( name );
+
+        if ( mapLegend != null )
+        {
+            mapLegend.setName( name );
+            mapLegend.setStartValue( startValue );
+            mapLegend.setEndValue( endValue );
+            mapLegend.setColor( color );
+
+            mappingStore.updateMapLegend( mapLegend );
+        }
+        else
+        {
+            mapLegend = new MapLegend( name, startValue, endValue, color );
+
+            mappingStore.addMapLegend( mapLegend );
+        }
+    }
+    
+    public void deleteMapLegend( MapLegend mapLegend )
+    {
+        mappingStore.deleteMapLegend( mapLegend );
+    }
+
+    public MapLegend getMapLegend( int id )
+    {
+        return mappingStore.getMapLegend( id );
+    }
+
+    public MapLegend getMapLegendByName( String name )
+    {
+        return mappingStore.getMapLegendByName( name );
+    }
+    
+    public Collection<MapLegend> getAllMapLegends()
+    {
+        return mappingStore.getAllMapLegends();
+    }
+    
+    // -------------------------------------------------------------------------
     // MapLegendSet
     // -------------------------------------------------------------------------
 

=== 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-09-29 16:17:58 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java	2010-03-19 14:39:43 +0000
@@ -36,6 +36,7 @@
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.mapping.MapLayer;
+import org.hisp.dhis.mapping.MapLegend;
 import org.hisp.dhis.mapping.MapLegendSet;
 import org.hisp.dhis.mapping.MapOrganisationUnitRelation;
 import org.hisp.dhis.mapping.MapView;
@@ -234,6 +235,59 @@
 
         return query.setParameter( "map", map ).executeUpdate();
     }
+    
+    // -------------------------------------------------------------------------
+    // MapLegendSet
+    // -------------------------------------------------------------------------
+
+    public int addMapLegend( MapLegend legend )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return (Integer) session.save( legend );
+    }
+
+    public void updateMapLegend( MapLegend legend )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.update( legend );
+    }
+
+    public void deleteMapLegend( MapLegend legend )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( legend );
+    }
+
+    public MapLegend getMapLegend( int id )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        return (MapLegend) session.get( MapLegend.class, id );
+    }
+
+    public MapLegend getMapLegendByName( String name )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( MapLegendSet.class );
+
+        criteria.add( Restrictions.eq( "name", name ) );
+
+        return (MapLegend) criteria.uniqueResult();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<MapLegend> getAllMapLegends()
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( MapLegend.class );
+
+        return criteria.list();
+    }
 
     // -------------------------------------------------------------------------
     // MapLegendSet