=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-26 07:03:53 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-26 09:13:37 +0000 @@ -138,8 +138,8 @@ deleteAttributeValues( object ); // deleteDataElementOperands( compulsoryDataElementOperands ); deleteDataElementOperands( object, "greyedFields" ); - // deleteExpression( object, "leftSide" ); - // deleteExpression( object, "rightSide" ); + deleteExpression( object, "leftSide" ); + deleteExpression( object, "rightSide" ); } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRuleDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRuleDeletionHandler.java 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRuleDeletionHandler.java 2012-06-26 09:13:37 +0000 @@ -47,7 +47,7 @@ { this.validationRuleService = validationRuleService; } - + // ------------------------------------------------------------------------- // DeletionHandler implementation // ------------------------------------------------------------------------- @@ -57,13 +57,16 @@ { return ValidationRule.class.getSimpleName(); } - + @Override public void deleteExpression( Expression expression ) { for ( ValidationRule rule : validationRuleService.getAllValidationRules() ) { - if ( rule.getLeftSide().equals( expression ) || rule.getRightSide().equals( expression ) ) + Expression leftSide = rule.getLeftSide(); + Expression rightSide = rule.getRightSide(); + + if ( (leftSide != null && leftSide.equals( expression )) || (rightSide != null && rightSide.equals( expression )) ) { validationRuleService.deleteValidationRule( rule ); } === 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 2011-12-26 10:07:59 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/deletion/DefaultDeletionManager.java 2012-06-26 09:13:37 +0000 @@ -27,16 +27,17 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import javassist.util.proxy.ProxyObject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.common.DeleteNotAllowedException; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.common.DeleteNotAllowedException; - /** * @author Lars Helge Overland * @version $Id$ @@ -45,10 +46,10 @@ implements DeletionManager { private static final Log log = LogFactory.getLog( DefaultDeletionManager.class ); - + private static final String DELETE_METHOD_PREFIX = "delete"; private static final String ALLOW_METHOD_PREFIX = "allowDelete"; - + private List handlers = new ArrayList(); // ------------------------------------------------------------------------- @@ -59,15 +60,15 @@ { this.handlers.add( handler ); } - + public void addDeletionHandlers( Collection deletionHandlers ) { this.handlers.addAll( deletionHandlers ); } - + public void execute( Object object ) { - Class clazz = object.getClass(); + Class clazz = getClazz( object ); String className = clazz.getSimpleName(); @@ -81,41 +82,41 @@ try { - Method allowMethod = DeletionHandler.class.getMethod( allowMethodName, new Class[] { clazz } ); + Method allowMethod = DeletionHandler.class.getMethod( allowMethodName, new Class[] { clazz } ); for ( DeletionHandler handler : handlers ) - { + { currentHandler = handler.getClass().getSimpleName(); Object allow = allowMethod.invoke( handler, object ); - + if ( allow != null ) { String hint = String.valueOf( allow ); - - String message = handler.getClassName() + ( hint.isEmpty() ? "" : ( " (" + hint + ")" ) ); - + + String message = handler.getClassName() + (hint.isEmpty() ? "" : (" (" + hint + ")")); + throw new DeleteNotAllowedException( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS, message ); } } - } - catch ( NoSuchMethodException ex ) + } catch ( NoSuchMethodException e ) { - log.error( "Method '" + allowMethodName + "' does not exist on class '" + clazz + "'", ex ); - } - catch ( IllegalAccessException ex ) + log.error( "Method '" + allowMethodName + "' does not exist on class '" + clazz + "'", e ); + return; + } catch ( IllegalAccessException ex ) { log.error( "Method '" + allowMethodName + "' could not be invoked on DeletionHandler '" + currentHandler + "'", ex ); - } - catch ( InvocationTargetException ex ) + return; + } catch ( InvocationTargetException ex ) { log.error( "Method '" + allowMethodName + "' threw exception on DeletionHandler '" + currentHandler + "'", ex ); + return; } // --------------------------------------------------------------------- // Delete associated objects // --------------------------------------------------------------------- - + String deleteMethodName = DELETE_METHOD_PREFIX + className; try @@ -125,15 +126,25 @@ for ( DeletionHandler handler : handlers ) { currentHandler = handler.getClass().getSimpleName(); - + deleteMethod.invoke( handler, object ); } - } - catch ( Exception ex ) + } catch ( Exception ex ) { log.error( "Failed to invoke method " + deleteMethodName + " on DeletionHandler '" + currentHandler + "'", ex ); - } - - log.info( "Deleted objects associatied with object of type " + className ); + return; + } + + log.info( "Deleted objects associated with object of type " + className ); + } + + private Class getClazz( Object object ) + { + if ( ProxyObject.class.isAssignableFrom( object.getClass() ) ) + { + return object.getClass().getSuperclass(); + } + + return object.getClass(); } }