← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4019: Fix bug: Error when deleting a dataelement.

 

------------------------------------------------------------
revno: 4019
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-06-24 14:55:22 +0700
message:
  Fix bug: Error when deleting a dataelement.
added:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java
  dhis-2/dhis-services/dhis-service-patient/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-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2011-03-24 03:34:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java	2011-06-24 07:55:22 +0000
@@ -54,6 +54,8 @@
     Collection<CaseAggregationCondition> getAllCaseAggregationCondition( );
    
     CaseAggregationCondition getCaseAggregationCondition( DataElement dataElement, DataElementCategoryOptionCombo optionCombo);
+    
+    Collection<CaseAggregationCondition> getCaseAggregationCondition( DataElement dataElement );
 
     
     double parseConditition( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit, Period period );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java	2010-11-25 22:22:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStore.java	2011-06-24 07:55:22 +0000
@@ -44,6 +44,8 @@
     String ID = CaseAggregationConditionStore.class.getName();
 
     CaseAggregationCondition get( DataElement dataElement, DataElementCategoryOptionCombo optionCombo);
-
+   
+    Collection<CaseAggregationCondition> get( DataElement dataElement );
+    
     Collection<Integer> executeSQL( String sql );
 }

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionDeletionHandler.java	2011-06-24 07:55:22 +0000
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2004-2009, 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.
+ */
+
+package org.hisp.dhis.caseaggregation;
+
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ CaseAggregationConditionDeletionHandler.java Jun 24, 2011 1:52:01
+ *          PM $
+ * 
+ */
+public class CaseAggregationConditionDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private CaseAggregationConditionService aggregationConditionService;
+
+    public void setAggregationConditionService( CaseAggregationConditionService aggregationConditionService )
+    {
+        this.aggregationConditionService = aggregationConditionService;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    protected String getClassName()
+    {
+        return CaseAggregationCondition.class.getSimpleName();
+    }
+
+    @Override
+    public boolean allowDeleteDataElement( DataElement dataElement )
+    {
+        Collection<CaseAggregationCondition> conditions = aggregationConditionService
+            .getCaseAggregationCondition( dataElement );
+
+        if ( conditions != null && conditions.size() > 0 )
+        {
+            return false;
+        }
+
+        conditions = aggregationConditionService.getAllCaseAggregationCondition();
+
+        for( CaseAggregationCondition condition : conditions )
+        {
+            Collection<DataElement> dataElements = aggregationConditionService.getDataElementsInCondition( condition.getAggregationExpression() );
+            
+            if ( dataElements != null && dataElements.contains( dataElement ) )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-06-16 08:52:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-06-24 07:55:22 +0000
@@ -167,6 +167,12 @@
     {
         return aggregationConditionStore.get( dataElement, optionCombo );
     }
+    
+    @Override
+    public Collection<CaseAggregationCondition> getCaseAggregationCondition( DataElement dataElement )
+    {
+        return aggregationConditionStore.get( dataElement );
+    }
 
     @Override
     public double parseConditition( CaseAggregationCondition aggregationCondition, OrganisationUnit orgunit,

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java	2011-03-31 01:55:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java	2011-06-24 07:55:22 +0000
@@ -109,4 +109,12 @@
         return (CaseAggregationCondition) getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ),
             Restrictions.eq( "optionCombo", optionCombo ) ).uniqueResult();
     }
+
+    @SuppressWarnings( "unchecked" )
+    @Override
+    public Collection<CaseAggregationCondition> get( DataElement dataElement )
+    {
+        return getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ) )
+            .list();
+    }
 }

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java	2011-06-24 07:55:22 +0000
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2004-2009, 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.
+ */
+
+package org.hisp.dhis.patientdatavalue;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ PatientDataValueDeletionHandler.java Jun 24, 2011 1:10:46 PM $
+ * 
+ */
+public class PatientDataValueDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private JdbcTemplate jdbcTemplate;
+
+    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+    {
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    protected String getClassName()
+    {
+        return PatientDataValue.class.getSimpleName();
+    }
+
+    @Override
+    public boolean allowDeleteDataElement( DataElement dataElement )
+    {
+        String sql = "SELECT COUNT(*) FROM patientdatavalue where dataelementid=" + dataElement.getId();
+        
+        return jdbcTemplate.queryForInt( sql ) == 0;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java	2011-04-29 07:41:04 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageDataElementDeletionHandler.java	2011-06-24 07:55:22 +0000
@@ -30,6 +30,7 @@
 import java.util.Collection;
 import java.util.Set;
 
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 /**
@@ -58,7 +59,7 @@
     @Override
     public String getClassName()
     {
-        return ProgramInstance.class.getSimpleName();
+        return ProgramStageDataElement.class.getSimpleName();
     }
 
     @Override
@@ -101,5 +102,22 @@
         }
 
     }
+    
+    @Override
+    public boolean allowDeleteDataElement ( DataElement dataElement )
+    {
+        Collection<ProgramStageDataElement> psDataElements = programStageDEService.getAllProgramStageDataElements();
+        for ( ProgramStageDataElement psDataElement :  psDataElements )
+        {
+            Collection<DataElement> dataElements = programStageDEService.getListDataElement( psDataElement.getProgramStage() );
+
+            if ( dataElements.contains( dataElement ) )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-06-14 19:24:18 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-06-24 07:55:22 +0000
@@ -371,6 +371,14 @@
 		<property name="programStageDEService" ref="org.hisp.dhis.program.ProgramStageDataElementService"/>
 	</bean>
 	
+	<bean id="org.hisp.dhis.patientdatavalue.PatientDataValueDeletionHandler" class="org.hisp.dhis.patientdatavalue.PatientDataValueDeletionHandler">
+    	<property name="jdbcTemplate" ref="jdbcTemplate" />
+  	</bean>
+  	
+  	<bean id="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler" class="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler">
+    	<property name="aggregationConditionService" ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
+  	</bean>
+  
 	<!-- Startup -->
 	
 	<bean id="org.hisp.dhis.patient.startup.TableAlteror" class="org.hisp.dhis.patient.startup.TableAlteror" >
@@ -414,11 +422,14 @@
 			  <ref local="org.hisp.dhis.patientattributevalue.PatientAttributeValueDeletionHandler"/>
 			  <ref local="org.hisp.dhis.patient.PatientIdentifierDeletionHandler"/>
 			  <ref local="org.hisp.dhis.relationship.RelationshipDeletionHandler"/>
+			  <ref local="org.hisp.dhis.patientdatavalue.PatientDataValueDeletionHandler"/>
 			  
 			  <ref local="org.hisp.dhis.program.ProgramDeletionHandler"/>
 			  <ref local="org.hisp.dhis.program.ProgramInstanceDeletionHandler"/>
 			  <ref local="org.hisp.dhis.program.ProgramStageDataElementDeletionHandler"/>
 			  <ref local="org.hisp.dhis.programattributevalue.ProgramAttributeValueDeletionHandler"/>
+			  
+			  <ref local="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler"/>
 			</list>
 		  </list>
 		</property>
@@ -479,6 +490,10 @@
 		  <aop:before 
 		      pointcut="execution( * org.hisp.dhis.validation.ValidationCriteriaService.delete*(..) )" 
 		      method="intercept"/>
+		      
+		  <aop:before 
+		      pointcut="execution( * org.hisp.dhis.caseaggregation.CaseAggregationConditionService.delete*(..) )" 
+		      method="intercept"/>
 	    </aop:aspect>
       
   	</aop:config>