← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5102: Fixed final (hopefully!) snags on organisation unit store.

 

------------------------------------------------------------
revno: 5102
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2011-11-03 14:27:18 +0000
message:
  Fixed final (hopefully!) snags on organisation unit store.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml


--
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-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2011-05-22 12:19:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2011-11-03 14:27:18 +0000
@@ -33,7 +33,6 @@
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
-import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -68,11 +67,6 @@
 
     public int addOrganisationUnitGroup( OrganisationUnitGroup organisationUnitGroup )
     {
-        if ( organisationUnitGroup.getUuid() == null )
-        {
-            organisationUnitGroup.setUuid( UUIdUtils.getUUId() );
-        }
-        
         return organisationUnitGroupStore.save( organisationUnitGroup );
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-10-08 13:09:04 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-11-03 14:27:18 +0000
@@ -97,15 +97,9 @@
     // OrganisationUnit
     // -------------------------------------------------------------------------
 
+    @Override
     public int addOrganisationUnit( OrganisationUnit organisationUnit )
     {
-        if ( organisationUnit.getUuid() == null )
-        {
-            organisationUnit.setUuid( UUIdUtils.getUUId() );
-        }
-
-        organisationUnit.setLastUpdated( new Date() );
-
         int id = organisationUnitStore.save( organisationUnit );
 
         log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_ADD,

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2011-10-08 13:09:04 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java	2011-11-03 14:27:18 +0000
@@ -29,7 +29,9 @@
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -43,7 +45,7 @@
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.hibernate.HibernateGenericStore;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
@@ -60,7 +62,7 @@
  *          larshelg $
  */
 public class HibernateOrganisationUnitStore
-    extends HibernateGenericStore<OrganisationUnit>
+    extends HibernateIdentifiableObjectStore<OrganisationUnit>
     implements OrganisationUnitStore
 {
     // -------------------------------------------------------------------------
@@ -74,17 +76,19 @@
         this.statementManager = statementManager;
     }
 
-    private JdbcTemplate jdbcTemplate;
+    private HibernateIdentifiableObjectStore<OrganisationUnitLevel> orgLevelStore;
 
-    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    public void setOrgLevelStore( HibernateIdentifiableObjectStore<OrganisationUnitLevel> orgLevelStore )
     {
-        this.jdbcTemplate = jdbcTemplate;
+        this.orgLevelStore = orgLevelStore;
     }
-
+    
+    
     // -------------------------------------------------------------------------
     // OrganisationUnit
     // -------------------------------------------------------------------------
 
+    @Override
     public OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name )
     {
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( OrganisationUnit.class );
@@ -222,10 +226,12 @@
 
     public void updateOrganisationUnitParent( int organisationUnitId, int parentId )
     {
+        Timestamp now = new Timestamp( new Date().getTime() );
+        
         StatementHolder holder = statementManager.getHolder();
 
-        final String sql = "UPDATE organisationunit " + "SET parentid='" + parentId + "' "
-            + "WHERE organisationunitid='" + organisationUnitId + "'";
+        final String sql = "UPDATE organisationunit " + "SET parentid='" + parentId + "', SET lastUpdated='"
+            + now + "' " + "WHERE organisationunitid='" + organisationUnitId + "'";
 
         holder.executeUpdate( sql );
     }
@@ -236,22 +242,22 @@
 
     public int addOrganisationUnitLevel( OrganisationUnitLevel level )
     {
-        return (Integer) sessionFactory.getCurrentSession().save( level );
+        return orgLevelStore.save( level );
     }
 
     public void updateOrganisationUnitLevel( OrganisationUnitLevel level )
     {
-        sessionFactory.getCurrentSession().update( level );
+        orgLevelStore.update( level );
     }
 
     public OrganisationUnitLevel getOrganisationUnitLevel( int id )
     {
-        return (OrganisationUnitLevel) sessionFactory.getCurrentSession().get( OrganisationUnitLevel.class, id );
+        return orgLevelStore.get(  id );
     }
 
     public void deleteOrganisationUnitLevel( OrganisationUnitLevel level )
     {
-        sessionFactory.getCurrentSession().delete( level );
+        orgLevelStore.delete( level );
     }
 
     public void deleteOrganisationUnitLevels()
@@ -292,6 +298,8 @@
     @Override
     public void update( Collection<OrganisationUnit> units )
     {
+        Timestamp now = new Timestamp( new Date().getTime() );
+        
         Collection<Integer> unitIds = new HashSet<Integer>();
 
         for ( OrganisationUnit orgunit : units )
@@ -301,19 +309,21 @@
 
         if ( unitIds.size() > 0 )
         {
-            String sql = "update OrganisationUnit set hasPatients=true where organisationunitid in (:unitIds)";
+            String sql = "update OrganisationUnit set hasPatients=true,lastUpdated='" + now + 
+                "' where organisationunitid in (:unitIds)";
             Query query = sessionFactory.getCurrentSession().createQuery( sql );
             query.setParameterList( "unitIds", unitIds );
             query.executeUpdate();
 
-            sql = "UPDATE OrganisationUnit SET hasPatients=false WHERE organisationunitid not in ( :unitIds )";
+            sql = "UPDATE OrganisationUnit SET hasPatients=false,lastUpdated='" + now + 
+                "' WHERE organisationunitid not in ( :unitIds )";
             query = sessionFactory.getCurrentSession().createQuery( sql );
             query.setParameterList( "unitIds", unitIds );
             query.executeUpdate();
         }
         else
         {
-            String sql = "update OrganisationUnit set hasPatients=false";
+            String sql = "update OrganisationUnit set hasPatients=false,,lastUpdated='" + now +"'";
             Query query = sessionFactory.getCurrentSession().createQuery( sql );
             query.executeUpdate();
         }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-11-03 12:18:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-11-03 14:27:18 +0000
@@ -143,12 +143,19 @@
     <property name="cacheable" value="true" />
   </bean>
 
+  <bean id="org.hisp.dhis.organisationunit.OrganisationUnitLevelStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
+    <property name="clazz" value="org.hisp.dhis.organisationunit.OrganisationUnitLevel" />
+    <property name="sessionFactory" ref="sessionFactory" />
+    <property name="cacheable" value="true" />
+  </bean>
+
   <bean id="org.hisp.dhis.organisationunit.OrganisationUnitStore" class="org.hisp.dhis.organisationunit.hibernate.HibernateOrganisationUnitStore">
     <property name="clazz" value="org.hisp.dhis.organisationunit.OrganisationUnit" />
     <property name="sessionFactory" ref="sessionFactory" />
     <property name="statementManager" ref="statementManager" />
     <property name="jdbcTemplate" ref="jdbcTemplate" />
     <property name="cacheable" value="true" />
+    <property name="orgLevelStore" ref="org.hisp.dhis.organisationunit.OrganisationUnitLevelStore" />
   </bean>
 
   <bean id="org.hisp.dhis.organisationunit.OrganisationUnitGroupStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">