← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12077: Impl InterpretationDeletionHandler

 

------------------------------------------------------------
revno: 12077
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-09-13 13:51:49 +0200
message:
  Impl InterpretationDeletionHandler
added:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.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/interpretation/InterpretationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationService.java	2013-09-13 11:51:49 +0000
@@ -49,6 +49,8 @@
     
     List<Interpretation> getInterpretations( int first, int max );
 
+    List<Interpretation> getInterpretations( User user );
+    
     List<Interpretation> getInterpretations( User user, int first, int max );
     
     void addInterpretationComment( String uid, String text );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/interpretation/InterpretationStore.java	2013-09-13 11:51:49 +0000
@@ -39,5 +39,7 @@
 public interface InterpretationStore
     extends GenericIdentifiableObjectStore<Interpretation>
 {
+    List<Interpretation> getInterpretations( User user );
+    
     List<Interpretation> getInterpretations( User user, int first, int max );
 }

=== added file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/InterpretationDeletionHandler.java	2013-09-13 11:51:49 +0000
@@ -0,0 +1,65 @@
+package org.hisp.dhis.interpretation;
+
+/*
+ * Copyright (c) 2004-2013, 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.
+ */
+
+import java.util.List;
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.hisp.dhis.user.User;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class InterpretationDeletionHandler
+    extends DeletionHandler
+{
+    @Autowired
+    private InterpretationService interpretationService;
+    
+    @Override
+    protected String getClassName()
+    {
+        return DeletionHandler.class.getSimpleName();
+    }
+
+    public void deleteUser( User user )
+    {
+        List<Interpretation> interpretations = interpretationService.getInterpretations( user );
+        
+        for ( Interpretation interpretation : interpretations )
+        {
+            if ( interpretation.getUser() != null && interpretation.getUser().equals( user ) )
+            {
+                interpretation.setUser( null );
+                interpretationService.updateInterpretation( interpretation );
+            }
+        }
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/hibernate/HibernateInterpretationStore.java	2013-09-13 11:51:49 +0000
@@ -41,7 +41,19 @@
  */
 public class HibernateInterpretationStore
     extends HibernateIdentifiableObjectStore<Interpretation> implements InterpretationStore
-{
+{    
+    @SuppressWarnings("unchecked")
+    public List<Interpretation> getInterpretations( User user )
+    {
+        String hql = "select distinct i from Interpretation i left join i.comments c " +
+            "where i.user = :user or c.user = :user order by i.lastUpdated desc";
+        
+        Query query = getQuery( hql );
+        query.setEntity( "user", user );
+        
+        return query.list();
+    }
+    
     @SuppressWarnings("unchecked")
     public List<Interpretation> getInterpretations( User user, int first, int max )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/interpretation/impl/DefaultInterpretationService.java	2013-09-13 11:51:49 +0000
@@ -132,6 +132,11 @@
         return interpretationStore.getInterpretations( user, first, max );
     }
     
+    public List<Interpretation> getInterpretations( User user )
+    {
+        return interpretationStore.getInterpretations( user );
+    }
+    
     public void addInterpretationComment( String uid, String text )
     {
         Interpretation interpretation = getInterpretation( uid );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2013-08-29 18:09:46 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2013-09-13 11:51:49 +0000
@@ -210,6 +210,8 @@
     <property name="chartService" ref="org.hisp.dhis.chart.ChartService" />
   </bean>
 
+  <bean id="org.hisp.dhis.interpretation.InterpretationDeletionHandler" class="org.hisp.dhis.interpretation.InterpretationDeletionHandler" />
+
   <!-- DeletionManager -->
 
   <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
@@ -221,6 +223,7 @@
           <ref local="org.hisp.dhis.report.ReportDeletionHandler" />
           <ref local="org.hisp.dhis.reporttable.ReportTableDeletionHandler" />
           <ref local="org.hisp.dhis.chart.ChartDeletionHandler" />
+          <ref local="org.hisp.dhis.interpretation.InterpretationDeletionHandler" />
         </list>
       </list>
     </property>

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-08-27 10:49:43 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2013-09-13 11:51:49 +0000
@@ -33,6 +33,7 @@
 import org.hibernate.Criteria;
 import org.hibernate.Query;
 import org.hibernate.SQLQuery;
+import org.hibernate.Session;
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Restrictions;
@@ -130,6 +131,16 @@
     // -------------------------------------------------------------------------
 
     /**
+     * Returns the current session.
+     * 
+     * @return the current session.
+     */
+    protected final Session getSession()
+    {
+        return sessionFactory.getCurrentSession();
+    }
+    
+    /**
      * Creates a Query.
      *
      * @param hql the hql query.

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionHandler.java	2013-09-13 11:51:49 +0000
@@ -54,6 +54,7 @@
 import org.hisp.dhis.indicator.IndicatorGroup;
 import org.hisp.dhis.indicator.IndicatorGroupSet;
 import org.hisp.dhis.indicator.IndicatorType;
+import org.hisp.dhis.interpretation.Interpretation;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.mapping.MapLegend;
 import org.hisp.dhis.mapping.MapLegendSet;
@@ -714,5 +715,13 @@
     {
         return null;
     }
-
+    
+    public void deleteIntepretation( Interpretation interpretation )
+    {
+    }
+    
+    public String allowDeleteInterpretation( Interpretation interpretation )
+    {
+        return null;
+    }
 }