← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21346: DeletionManager. Using @autowiring to register deletion handlers as opposed to explicit registrat...

 

------------------------------------------------------------
revno: 21346
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-12-05 11:23:42 +0100
message:
  DeletionManager. Using @autowiring to register deletion handlers as opposed to explicit registration through a factory bean. Less config and less coupling.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionManager.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-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	2015-12-01 10:19:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-12-05 10:23:42 +0000
@@ -1748,75 +1748,6 @@
   <bean id="org.hisp.dhis.sms.command.code.SMSCodesDeletionHandler"
     class="org.hisp.dhis.sms.command.code.SMSCodesDeletionHandler" />
 
-  <!-- DeletionManager -->
-
-  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
-    <property name="targetObject" ref="deletionManager" />
-    <property name="targetMethod" value="addDeletionHandlers" />
-    <property name="arguments">
-      <list>
-        <list>
-          <ref bean="org.hisp.dhis.dataapproval.DataApprovalDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementCategoryOptionDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementCategoryOptionComboDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementCategoryComboDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementCategoryDimensionDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataset.DataSetDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataset.CompleteDataSetRegistrationDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataset.SectionDeletionHandler" />
-          <ref bean="org.hisp.dhis.expression.ExpressionDeletionHandler" />
-          <ref bean="org.hisp.dhis.indicator.IndicatorDeletionHandler" />
-          <ref bean="org.hisp.dhis.indicator.IndicatorGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.indicator.IndicatorGroupSetDeletionHandler" />
-          <ref bean="org.hisp.dhis.minmax.MinMaxDataElementDeletionHandler" />
-          <ref bean="org.hisp.dhis.validation.ValidationRuleDeletionHandler" />
-          <ref bean="org.hisp.dhis.validation.ValidationRuleGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.datavalue.DataValueDeletionHandler" />
-          <ref bean="org.hisp.dhis.datavalue.DataValueAuditDeletionHandler" />
-          <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitDeletionHandler" />
-          <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDeletionHandler" />
-          <ref bean="org.hisp.dhis.user.UserDeletionHandler" />
-          <ref bean="org.hisp.dhis.user.UserGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.user.UserAuthorityGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.user.UserSettingDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementCategoryDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.DataElementGroupSetDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.CategoryOptionGroupDeletionHandler" />
-          <ref bean="org.hisp.dhis.dataelement.CategoryOptionGroupSetDeletionHandler" />
-          <ref bean="org.hisp.dhis.configuration.ConfigurationDeletionHandler" />
-          <ref bean="org.hisp.dhis.message.MessageConversationDeletionHandler" />
-          <ref bean="org.hisp.dhis.translation.TranslationDeletionHandler" />
-          <ref bean="org.hisp.dhis.attribute.AttributeValueDeletionHandler" />
-          <ref bean="org.hisp.dhis.legend.LegendSetDeletionHandler" />
-          <ref bean="org.hisp.dhis.mapping.MapViewDeletionHandler" />
-          <ref bean="org.hisp.dhis.trackedentity.TrackedEntityInstanceDeletionHandler" />
-          <ref bean="org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueDeletionHandler" />
-          <ref bean="org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueDeletionHandler" />
-          <ref bean="org.hisp.dhis.relationship.RelationshipDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramStageDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramStageSectionDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramInstanceDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramStageInstanceDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramStageDataElementDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramValidationDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramDataEntryFormDeletionHandler" />
-          <ref bean="org.hisp.dhis.program.ProgramIndicatorDeletionHandler" />
-          <ref bean="org.hisp.dhis.programrule.ProgramRuleDeletionHandler" />
-          <ref bean="org.hisp.dhis.programrule.ProgramRuleVariableDeletionHandler" />
-          <ref bean="org.hisp.dhis.programrule.ProgramRuleActionDeletionHandler" />
-          <ref bean="org.hisp.dhis.eventchart.EventChartDeletionHandler" />
-          <ref bean="org.hisp.dhis.eventreport.EventReportDeletionHandler" />
-          <ref bean="org.hisp.dhis.sms.command.SMSCommandDeletionHandler" />
-          <ref bean="org.hisp.dhis.sms.command.code.SMSCodesDeletionHandler" />
-        </list>
-      </list>
-    </property>
-  </bean>
-
   <!-- AOP definitions -->
 
   <aop:config>

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml	2015-02-27 13:42:52 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/resources/META-INF/dhis/beans.xml	2015-12-05 10:23:42 +0000
@@ -99,23 +99,10 @@
 	
 	<!-- DeletionManager -->
 
-	<bean
-		id="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler"
+	<bean id="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler"
 		class="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler">
 		<property name="aggregationConditionService"
 			ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
 	</bean>
-
-	<bean
-		class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
-		<property name="targetObject" ref="deletionManager" />
-		<property name="targetMethod" value="addDeletionHandlers" />
-		<property name="arguments">
-			<list>
-				<list>
-					<ref bean="org.hisp.dhis.caseaggregation.CaseAggregationConditionDeletionHandler" />
-				</list>
-			</list>
-		</property>
-	</bean>
+	
 </beans>

=== 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	2015-11-05 02:57:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml	2015-12-05 10:23:42 +0000
@@ -238,24 +238,6 @@
   <bean id="org.hisp.dhis.interpretation.InterpretationDeletionHandler"
     class="org.hisp.dhis.interpretation.InterpretationDeletionHandler" />
 
-  <!-- DeletionManager -->
-
-  <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
-    <property name="targetObject" ref="deletionManager" />
-    <property name="targetMethod" value="addDeletionHandlers" />
-    <property name="arguments">
-      <list>
-        <list>
-          <ref bean="org.hisp.dhis.report.ReportDeletionHandler" />
-          <ref bean="org.hisp.dhis.reporttable.ReportTableDeletionHandler" />
-          <ref bean="org.hisp.dhis.chart.ChartDeletionHandler" />
-          <ref bean="org.hisp.dhis.interpretation.InterpretationDeletionHandler" />
-          <ref bean="org.hisp.dhis.dashboard.impl.DashboardItemDeletionHandler" />
-        </list>
-      </list>
-    </property>
-  </bean>
-
   <!-- AOP definitions -->
 
   <aop:config>

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java	2015-12-05 09:30:42 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java	2015-12-05 10:23:42 +0000
@@ -30,15 +30,13 @@
 
 import javassist.util.proxy.ProxyObject;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 
 /**
@@ -55,27 +53,28 @@
     private static final String DELETE_METHOD_PREFIX = "delete";
     private static final String ALLOW_METHOD_PREFIX = "allowDelete";
 
-    private final List<DeletionHandler> handlers = new ArrayList<>();
+    /**
+     * Deletion handlers registered in context are subscribed to deletion 
+     * notifications through auto-wiring.
+     */
+    @Autowired(required = false)
+    private List<DeletionHandler> deletionHandlers;
 
     // -------------------------------------------------------------------------
     // DeletionManager implementation
     // -------------------------------------------------------------------------
 
     @Override
-    public void addDeletionHandler( DeletionHandler handler )
-    {
-        this.handlers.add( handler );
-    }
-
-    @Override
-    public void addDeletionHandlers( Collection<DeletionHandler> deletionHandlers )
-    {
-        this.handlers.addAll( deletionHandlers );
-    }
-
-    @Override
     public void execute( Object object )
     {
+        if ( deletionHandlers == null || deletionHandlers.isEmpty() )
+        {
+            log.info( "No deletion handlers registered, aborting deletion handling" );
+            return;
+        }
+        
+        log.debug( "Deletion handlers detected: " + deletionHandlers.size() );
+        
         Class<?> clazz = getClazz( object );
 
         String className = clazz.getSimpleName();
@@ -92,7 +91,7 @@
         {
             Method allowMethod = DeletionHandler.class.getMethod( allowMethodName, new Class[]{ clazz } );
 
-            for ( DeletionHandler handler : handlers )
+            for ( DeletionHandler handler : deletionHandlers )
             {
                 currentHandler = handler.getClass().getSimpleName();
 
@@ -138,7 +137,7 @@
         {
             Method deleteMethod = DeletionHandler.class.getMethod( deleteMethodName, new Class[]{ clazz } );
 
-            for ( DeletionHandler handler : handlers )
+            for ( DeletionHandler handler : deletionHandlers )
             {
                 currentHandler = handler.getClass().getSimpleName();
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionManager.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionManager.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DeletionManager.java	2015-12-05 10:23:42 +0000
@@ -28,19 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Collection;
-
 /**
  * @author Lars Helge Overland
- * @version $Id$
  */
 public interface DeletionManager
 {
     String ID = DeletionManager.class.getName();
     
-    void addDeletionHandler( DeletionHandler handler );
-    
-    void addDeletionHandlers( Collection<DeletionHandler> handlers );
-    
     void execute( Object object );
 }