← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2552: Added services for DataElement Target

 

------------------------------------------------------------
revno: 2552
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2011-01-13 14:32:15 +0530
message:
  Added services for DataElement Target
modified:
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValue.java
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueService.java
  local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueStore.java
  local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/DefaultDeTargetDataValueService.java
  local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/hibernate/HibernateDeTargetDataValueStore.java
  local/in/dhis-in-services/dhis-in-service-survey/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 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValue.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValue.java	2011-01-13 07:06:44 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValue.java	2011-01-13 09:02:15 +0000
@@ -201,7 +201,7 @@
         return period;
     }
 
-    public void setPeriodId( Period period )
+    public void setPeriod( Period period )
     {
         this.period = period;
     }

=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueService.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueService.java	2011-01-13 07:06:44 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueService.java	2011-01-13 09:02:15 +0000
@@ -44,7 +44,7 @@
  */
 public interface DeTargetDataValueService
 {
-   
+    
     String ID = DeTargetDataValueService.class.getName();
     
     // -------------------------------------------------------------------------

=== modified file 'local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueStore.java'
--- local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueStore.java	2011-01-13 07:06:44 +0000
+++ local/in/dhis-in-api/src/main/java/org/hisp/dhis/detargetdatavalue/DeTargetDataValueStore.java	2011-01-13 09:02:15 +0000
@@ -31,6 +31,7 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.detarget.DeTarget;
+import org.hisp.dhis.detarget.DeTargetMember;
 import org.hisp.dhis.source.Source;
 
 /**
@@ -40,6 +41,7 @@
  */
 public interface DeTargetDataValueStore
 {
+    
     String ID = DeTargetDataValueStore.class.getName();
     
     // -------------------------------------------------------------------------
@@ -185,7 +187,7 @@
      *         and Sources, limited by the firstResult and maxResults property.
      */
     Collection<DeTargetDataValue> getDeTargetDataValues( Collection<DeTarget> deTargets,  Collection<? extends Source> sources, int firstResult, int maxResults );    
-    
+    Collection<DeTargetDataValue> getDeTargetMemberDataValues( DeTargetMember deTargetMember ,DataElement dataelement ,DataElementCategoryOptionCombo decategoryOptionCombo );
     /**
      * Returns all DeTargetDataValue for a given collection of DeTarget.
      * 

=== modified file 'local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/DefaultDeTargetDataValueService.java'
--- local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/DefaultDeTargetDataValueService.java	2011-01-13 07:06:44 +0000
+++ local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/DefaultDeTargetDataValueService.java	2011-01-13 09:02:15 +0000
@@ -26,12 +26,129 @@
  */
 package org.hisp.dhis.detargetdatavalue;
 
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.detarget.DeTarget;
+import org.hisp.dhis.detarget.DeTargetMember;
+import org.hisp.dhis.source.Source;
+
 /**
  * @author Mithilesh Kumar Thakur
  *
  * @version DefaultDeTargetDataValueService.java Jan 13, 2011 10:36:40 AM
  */
-public class DefaultDeTargetDataValueService
+public class DefaultDeTargetDataValueService implements DeTargetDataValueService
 {
+    
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DeTargetDataValueStore deTargetDataValueStore;
+
+    public void setDeTargetDataValueStore( DeTargetDataValueStore deTargetDataValueStore )
+    {
+        this.deTargetDataValueStore = deTargetDataValueStore;
+    }
+
+    // -------------------------------------------------------------------------
+    // Basic DeTargetDataValue
+    // -------------------------------------------------------------------------
+    
+    public void addDeTargetDataValue( DeTargetDataValue deTargetDataValue )
+    {
+        if ( deTargetDataValue.getValue() != null )
+        {
+            deTargetDataValueStore.addDeTargetDataValue( deTargetDataValue );
+        }
+    }
+    
+    public void updateDeTargetDataValue( DeTargetDataValue deTargetDataValue )
+    {
+        deTargetDataValueStore.updateDeTargetDataValue( deTargetDataValue );
+    }
+
+    public void deleteDeTargetDataValue( DeTargetDataValue deTargetDataValue )
+    {
+        deTargetDataValueStore.deleteDeTargetDataValue( deTargetDataValue );
+    }
+        
+    public  int deleteDeTargetDataValuesBySource( Source source )
+    {
+        return deTargetDataValueStore.deleteDeTargetDataValuesBySource( source );
+    }
+    
+    public int deleteDeTargetDataValuesByDeTarget( DeTarget deTarget )
+    {
+        return deTargetDataValueStore.deleteDeTargetDataValuesByDeTarget( deTarget );
+    }
+    
+    public int deleteDeTargetDataValuesByDataElementAndCategoryOptionCombo( DataElement dataelement ,DataElementCategoryOptionCombo deoptioncombo )
+    {
+        return deTargetDataValueStore.deleteDeTargetDataValuesByDataElementAndCategoryOptionCombo( dataelement, deoptioncombo );
+    }
+    
+    public int deleteDeTargetDataValuesByDeTargetDataElementCategoryOptionComboAndSource( DeTarget deTarget, DataElement dataelement ,DataElementCategoryOptionCombo deoptioncombo, Source source )
+    {
+        return deTargetDataValueStore.deleteDeTargetDataValuesByDeTargetDataElementCategoryOptionComboAndSource( deTarget, dataelement, deoptioncombo, source );
+    }
+    
+    public DeTargetDataValue getDeTargetDataValue( Source source, DeTarget deTarget )
+    {
+        return deTargetDataValueStore.getDeTargetDataValue( source, deTarget );
+    }
+    
+    public Collection<DeTargetDataValue> getAllDeTargetDataValues()
+    {
+        return deTargetDataValueStore.getAllDeTargetDataValues();
+    }
+    
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Source source )
+    {
+        return deTargetDataValueStore.getDeTargetDataValues( source );
+    }
+   
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Source source, DeTarget deTarget )
+    {
+        return deTargetDataValueStore.getDeTargetDataValues( source, deTarget );
+    }
+    
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Collection<Source> sources, DeTarget deTarget )
+    {
+        return deTargetDataValueStore.getDeTargetDataValues( sources, deTarget );
+    }
+    
+   public Collection<DeTargetDataValue> getDeTargetDataValues( Source source, Collection<DeTarget> deTargets )
+   {
+       return deTargetDataValueStore.getDeTargetDataValues( source, deTargets );
+   }
+   
+   public Collection<DeTargetDataValue> getDeTargetDataValues( DeTarget deTarget, Collection<? extends Source> sources )
+   {
+       return deTargetDataValueStore.getDeTargetDataValues( deTarget, sources );
+   }
+    
+   public Collection<DeTargetDataValue> getDeTargetDataValues( Collection<DeTarget> deTargets,  Collection<? extends Source> sources, int firstResult, int maxResults )
+   {
+       return deTargetDataValueStore.getDeTargetDataValues( deTargets, sources, firstResult, maxResults );
+   }
+    
+   public Collection<DeTargetDataValue> getDeTargetDataValues( DeTarget deTarget )
+   {
+       return deTargetDataValueStore.getDeTargetDataValues( deTarget );
+   }
+   
+   public DeTargetDataValue getDeTargetDataValue( Source source, DeTarget deTarget, DataElement dataelement ,DataElementCategoryOptionCombo deoptioncombo )
+   {
+       return deTargetDataValueStore.getDeTargetDataValue( source, deTarget, dataelement, deoptioncombo );
+   }
+   
+   public Collection<DeTargetDataValue> getDeTargetMemberDataValues( DeTargetMember deTargetMember ,DataElement dataelement ,DataElementCategoryOptionCombo decategoryOptionCombo )
+   {
+       return deTargetDataValueStore.getDeTargetMemberDataValues( deTargetMember ,dataelement ,decategoryOptionCombo );
+   }
 
 }
+

=== modified file 'local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/hibernate/HibernateDeTargetDataValueStore.java'
--- local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/hibernate/HibernateDeTargetDataValueStore.java	2011-01-13 07:06:44 +0000
+++ local/in/dhis-in-services/dhis-in-service-survey/src/main/java/org/hisp/dhis/detargetdatavalue/hibernate/HibernateDeTargetDataValueStore.java	2011-01-13 09:02:15 +0000
@@ -26,12 +26,245 @@
  */
 package org.hisp.dhis.detargetdatavalue.hibernate;
 
+import java.util.Collection;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.detarget.DeTarget;
+import org.hisp.dhis.detarget.DeTargetMember;
+import org.hisp.dhis.detargetdatavalue.DeTargetDataValue;
+import org.hisp.dhis.detargetdatavalue.DeTargetDataValueStore;
+
+import org.hisp.dhis.source.Source;
+
+
 /**
  * @author Mithilesh Kumar Thakur
  *
  * @version HibernateDeTargetDataValueStore.java Jan 13, 2011 10:37:20 AM
  */
-public class HibernateDeTargetDataValueStore
+public class HibernateDeTargetDataValueStore implements DeTargetDataValueStore
 {
-
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+    
+    private SessionFactory sessionFactory;
+
+    public void setSessionFactory( SessionFactory sessionFactory )
+    {
+        this.sessionFactory = sessionFactory;
+    }
+    
+    // -------------------------------------------------------------------------
+    // HibernateSurveyDataValueStore's methods
+    // -------------------------------------------------------------------------
+
+    public void addDeTargetDataValue( DeTargetDataValue deTargetDataValue )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.save( deTargetDataValue );
+    }
+        
+    public void updateDeTargetDataValue( DeTargetDataValue deTargetDataValue )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( deTargetDataValue );
+    }
+    
+    public void deleteDeTargetDataValue( DeTargetDataValue deTargetDataValue )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        session.delete( deTargetDataValue );
+    }
+    
+    public int deleteDeTargetDataValuesBySource( Source source )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "delete DataValue where source = :source" );
+        query.setEntity( "source", source );
+
+        return query.executeUpdate();
+    }
+    
+    public int deleteDeTargetDataValuesByDeTarget( DeTarget deTarget )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "delete SurveyDataValue where survey = :survey" );
+        query.setEntity( "survey", deTarget );
+
+        return query.executeUpdate();
+    }
+    
+    public int deleteDeTargetDataValuesByDataElementAndCategoryOptionCombo( DataElement dataelement ,DataElementCategoryOptionCombo deoptioncombo )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "delete SurveyDataValue where dataelement = :dataelement ,deoptioncombo =:deoptioncombo" );
+        query.setEntity( "dataelement", dataelement );
+        query.setEntity( "dataelement", dataelement );
+
+        return query.executeUpdate();
+    }
+    
+    public int deleteDeTargetDataValuesByDeTargetDataElementCategoryOptionComboAndSource( DeTarget deTarget, DataElement dataelement ,DataElementCategoryOptionCombo deoptioncombo, Source source )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Query query = session.createQuery( "delete SurveyDataValue where survey = :survey,dataelement = :dataelement, deoptioncombo = :deoptioncombo ,source = :source" );
+        query.setEntity( "deTarget", deTarget );
+        query.setEntity( "dataelement", dataelement );
+        query.setEntity( "deoptioncombo", deoptioncombo );
+        query.setEntity( "source", source );
+
+        return query.executeUpdate();
+    }
+   
+    public DeTargetDataValue getDeTargetDataValue( Source source, DeTarget deTarget )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.eq( "source", source ) );
+        criteria.add( Restrictions.eq( "deTarget", deTarget ) );
+
+        return (DeTargetDataValue) criteria.uniqueResult();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getAllDeTargetDataValues()
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+
+        return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Source source )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.eq( "source", source ) );
+
+        return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Source source, DeTarget deTarget )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.eq( "source", source ) );
+        criteria.add( Restrictions.eq( "deTarget", deTarget ) );
+
+        return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public  Collection<DeTargetDataValue> getDeTargetDataValues( Collection<Source> sources, DeTarget deTarget )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.in( "sources", sources ) );
+        criteria.add( Restrictions.eq( "deTarget", deTarget ) );
+
+        return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Source source, Collection<DeTarget> deTargets )
+    {
+       Session session = sessionFactory.getCurrentSession();
+
+       Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+       criteria.add( Restrictions.eq( "source", source ) );
+       criteria.add( Restrictions.in( "deTargets", deTargets ) );
+
+       return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetDataValues( DeTarget deTarget, Collection<? extends Source> sources )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.in( "source", sources ) );
+        criteria.add( Restrictions.eq( "deTarget", deTarget ) );
+
+        return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetDataValues( Collection<DeTarget> deTargets,  Collection<? extends Source> sources, int firstResult, int maxResults )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DataValue.class );
+        criteria.add( Restrictions.in( "deTargets", deTargets ) );
+        criteria.add( Restrictions.in( "source", sources ) );
+
+        if ( maxResults != 0 )
+        {
+            criteria.addOrder( Order.asc( "deTargets" ) );
+            criteria.addOrder( Order.asc( "source" ) );
+
+            criteria.setFirstResult( firstResult );
+            criteria.setMaxResults( maxResults );
+        }
+
+        return criteria.list();
+    }
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetMemberDataValues( DeTargetMember deTargetMember ,DataElement dataelement ,DataElementCategoryOptionCombo decategoryOptionCombo )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.eq( "deTargetMember", deTargetMember ) );
+        criteria.add( Restrictions.eq( "dataelement", dataelement ) );
+        criteria.add( Restrictions.eq( "decategoryOptionCombo", decategoryOptionCombo ) );
+
+        return criteria.list();
+    }
+    
+    @SuppressWarnings( "unchecked" )
+    public Collection<DeTargetDataValue> getDeTargetDataValues( DeTarget deTarget )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        
+        criteria.add( Restrictions.eq( "deTarget", deTarget ) );
+
+        return criteria.list();
+    }
+   
+    public DeTargetDataValue getDeTargetDataValue( Source source, DeTarget deTarget, DataElement dataelement ,DataElementCategoryOptionCombo deoptioncombo )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( DeTargetDataValue.class );
+        criteria.add( Restrictions.eq( "source", source ) );
+        criteria.add( Restrictions.eq( "deTarget", deTarget ) );
+        criteria.add( Restrictions.eq( "dataelement", dataelement ) );
+        criteria.add( Restrictions.eq( "deoptioncombo", deoptioncombo ) );
+
+        return (DeTargetDataValue) criteria.uniqueResult();
+    }
+    
 }
+
+    
+    
+

=== modified file 'local/in/dhis-in-services/dhis-in-service-survey/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-in-services/dhis-in-service-survey/src/main/resources/META-INF/dhis/beans.xml	2011-01-13 07:06:44 +0000
+++ local/in/dhis-in-services/dhis-in-service-survey/src/main/resources/META-INF/dhis/beans.xml	2011-01-13 09:02:15 +0000
@@ -52,19 +52,13 @@
     <property name="deTargetStore"
       ref="org.hisp.dhis.detarget.DeTargetStore"/>
   </bean>
-<!--  
-  <bean id="org.hisp.dhis.surveydatavalue.SurveyDataValueService"
-    class="org.hisp.dhis.surveydatavalue.DefaultSurveyDataValueService">
-    <property name="surveyDataValueStore"
-      ref="org.hisp.dhis.surveydatavalue.SurveyDataValueStore"/>
+ 
+  <bean id="org.hisp.dhis.detargetdatavalue.DeTargetDataValueService"
+    class="org.hisp.dhis.detargetdatavalue.DefaultDeTargetDataValueService">
+    <property name="deTargetDataValueStore"
+      ref="org.hisp.dhis.detargetdatavalue.DeTargetDataValueStore"/>
   </bean>   
-  
-  <bean id="org.hisp.dhis.target.DeTargetMappingService"
-    class="org.hisp.dhis.target.DefaultDeTargetMappingService">
-    <property name="deTargetMappingStore"
-      ref="org.hisp.dhis.target.DeTargetMappingStore"/>
-  </bean>	
--->	
+
 <!-- DeTarget Store definitions -->
 
   <bean id="org.hisp.dhis.detarget.DeTargetStore"
@@ -73,16 +67,10 @@
     <property name="deTargetDataValueService"
       ref="org.hisp.dhis.detargetdatavalue.DeTargetDataValueService"/>        
   </bean>
- <!-- 
-  <bean id="org.hisp.dhis.surveydatavalue.SurveyDataValueStore"
-    class="org.hisp.dhis.surveydatavalue.hibernate.HibernateSurveyDataValueStore">
+ 
+  <bean id="org.hisp.dhis.detargetdatavalue.DeTargetDataValueStore"
+    class="org.hisp.dhis.detargetdatavalue.hibernate.HibernateDeTargetDataValueStore">
       <property name="sessionFactory" ref="sessionFactory"/>
   </bean>
-    
-  <bean id="org.hisp.dhis.target.DeTargetMappingStore"
-    class="org.hisp.dhis.target.HibernateDeTargetMappingStore">
-    <property name="sessionFactory" ref="sessionFactory"/>    
-  </bean>
--->	
-	
+
 </beans>