From 43ea2e5bc499ed89c2ca8d219ec2d5116a0d0e85 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Mon, 10 Aug 2015 10:24:57 +0000 Subject: [PATCH] RM-2477 Treat the empty string in the same way as null. Fix an issue in the behaviour checking where the empty string was being passed as the instructions when nothing was set. +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@109843 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../model/clf/aspect/ClassifiedAspect.java | 15 ++++++++++++++- .../clf/aspect/ClassifiedAspectUnitTest.java | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspect.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspect.java index 7fe1638fef..402beb0181 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspect.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspect.java @@ -144,10 +144,23 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo Serializable downgradeDate = nodeService.getProperty(nodeRef, PROP_DOWNGRADE_DATE); Serializable downgradeEvent = nodeService.getProperty(nodeRef, PROP_DOWNGRADE_EVENT); Serializable downgradeInstructions = nodeService.getProperty(nodeRef, PROP_DOWNGRADE_INSTRUCTIONS); - if (downgradeInstructions == null && (downgradeDate != null || downgradeEvent != null)) + if (isEmpty(downgradeInstructions) && !(isEmpty(downgradeDate) && isEmpty(downgradeEvent))) { throw new MissingDowngradeInstructions(nodeRef); } } } + + /** + * Check if a property is null or the empty string. Note that this is the same as + * {@link org.apache.commons.lang.StringUtils#isEmpty(String)}, except that it takes a Serializable rather than a + * String. This avoids awkward casting exceptions when working with properties. + * + * @param value The (probably String) value to check. + * @return true if the supplied value is null or the empty string. + */ + private boolean isEmpty(Serializable value) + { + return (value == null || value.equals("")); + } } diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspectUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspectUnitTest.java index e407e8682c..86ab1bd54c 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspectUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/clf/aspect/ClassifiedAspectUnitTest.java @@ -98,4 +98,16 @@ public class ClassifiedAspectUnitTest implements ClassifiedContentModel classifiedAspect.checkConsistencyOfProperties(NODE_REF); } + + /** Check that blank instructions are treated in the same way as null instructions. */ + @Test(expected = MissingDowngradeInstructions.class) + public void testCheckConsistencyOfProperties_emptyStringsSupplied() + { + when(mockNodeService.hasAspect(NODE_REF, ASPECT_CLASSIFIED)).thenReturn(true); + when(mockNodeService.getProperty(NODE_REF, PROP_DOWNGRADE_DATE)).thenReturn(""); + when(mockNodeService.getProperty(NODE_REF, PROP_DOWNGRADE_EVENT)).thenReturn("Event"); + when(mockNodeService.getProperty(NODE_REF, PROP_DOWNGRADE_INSTRUCTIONS)).thenReturn(""); + + classifiedAspect.checkConsistencyOfProperties(NODE_REF); + } }