diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuter.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuter.java index 94ada57f76..665c95910b 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuter.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuter.java @@ -108,7 +108,7 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute * * @return job query string */ - private String getQuery() + protected String getQuery() { if (query == null) { @@ -133,8 +133,8 @@ public class DispositionLifecycleJobExecuter extends RecordsManagementJobExecute } sb.append("))"); - sb.append(" AND ISNULL:\"rma:dispositionActionCompletedAt\" "); - sb.append(" + ( "); + sb.append(" AND ISUNSET:\"rma:dispositionActionCompletedAt\" "); + sb.append(" AND ( "); sb.append("@rma\\:dispositionEventsEligible:true "); sb.append("OR @rma\\:dispositionAsOf:[MIN TO NOW] "); sb.append(") "); diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java index db0fd4d67e..b53b82e9dc 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java @@ -228,24 +228,33 @@ public class ExtendedRuleServiceImpl extends RuleServiceImpl * @param typeQName * @return */ - private boolean shouldRuleBeAppliedToNode(Rule rule, NodeRef nodeRef, QName typeQName) + private boolean shouldRuleBeAppliedToNode(final Rule rule, final NodeRef nodeRef, final QName typeQName) { - boolean result = true; - NodeRef ruleNodeRef = getOwningNodeRef(rule); - if(filePlanService.isFilePlan(ruleNodeRef)) + return AuthenticationUtil.runAsSystem(new RunAsWork() { - // if this rule is defined at the root of the file plan then we do not want to apply - // it to holds/transfers/unfiled content... - result = !(RecordsManagementModel.TYPE_HOLD.equals(typeQName) || - RecordsManagementModel.TYPE_HOLD_CONTAINER.equals(typeQName) || - RecordsManagementModel.TYPE_TRANSFER.equals(typeQName) || - RecordsManagementModel.TYPE_TRANSFER_CONTAINER.equals(typeQName) || - RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER.equals(typeQName) || - RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(typeQName) || - nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_TRANSFERRING) || - nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FROZEN) || - !recordService.isFiled(nodeRef)); - } - return result; + public Boolean doWork() throws Exception + { + boolean result = true; + NodeRef ruleNodeRef = getOwningNodeRef(rule); + if (filePlanService.isFilePlan(ruleNodeRef)) + { + // if this rule is defined at the root of the file plan then + // we do not want to apply + // it to holds/transfers/unfiled content... + result = !(RecordsManagementModel.TYPE_HOLD.equals(typeQName) + || RecordsManagementModel.TYPE_HOLD_CONTAINER.equals(typeQName) + || RecordsManagementModel.TYPE_TRANSFER.equals(typeQName) + || RecordsManagementModel.TYPE_TRANSFER_CONTAINER.equals(typeQName) + || RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER + .equals(typeQName) + || RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(typeQName) + || nodeService.hasAspect(nodeRef, + RecordsManagementModel.ASPECT_TRANSFERRING) + || nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FROZEN) + || !recordService.isFiled(nodeRef)); + } + return result; + } + }); } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/util/SortDirection.java b/rm-community/rm-community-repo/source/java/org/alfresco/util/SortDirection.java new file mode 100644 index 0000000000..02c73d580e --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/util/SortDirection.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2005-2016 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.util; + +import org.alfresco.error.AlfrescoRuntimeException; + +/** + * Enumeration for sort direction. + * + * @author Tuna Aksoy + * @since 2.5 + */ +public enum SortDirection +{ + ASC ("asc"), + DESC ("desc"); + + /** A string representation of the sort direction. */ + private final String sortDirection; + + private SortDirection(String sortDirection) + { + this.sortDirection = sortDirection; + } + + /** + * Get the appropriate {@code SortDirection} from a string representation. + * + * @param sortDirectionString A string representation (case will be ignored). + * @return The {@code SortDirection} value. + */ + public static SortDirection getSortDirection(String sortDirectionString) + { + SortDirection sortDirection = null; + + for (SortDirection value : values()) + { + if (value.sortDirection.equalsIgnoreCase(sortDirectionString)) + { + sortDirection = value; + break; + } + } + + if (sortDirection == null) + { + throw new AlfrescoRuntimeException("Sort direction '" + sortDirection +"' unknown."); + } + + return sortDirection; + } +} diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuterUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuterUnitTest.java index ccfd819a75..595737024b 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuterUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/job/DispositionLifecycleJobExecuterUnitTest.java @@ -19,6 +19,7 @@ package org.alfresco.module.org_alfresco_module_rm.job; import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateQName; +import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyMap; import static org.mockito.Matchers.anyString; @@ -229,4 +230,17 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest // ensure no more interactions verifyNoMoreInteractions(mockedNodeService, mockedRecordsManagementActionService); } + + /** + * Brittle unit test that simply checks the generated query is an exact string when the supplied disposition actions + * are "CUTOFF" and "RETAIN" (see {@link #before}). + */ + @Test + public void testGetQuery() + { + String actual = executer.getQuery(); + + String expected = "TYPE:\"rma:dispositionAction\" + (@rma\\:dispositionAction:(\"cutoff\" OR \"retain\")) AND ISUNSET:\"rma:dispositionActionCompletedAt\" AND ( @rma\\:dispositionEventsEligible:true OR @rma\\:dispositionAsOf:[MIN TO NOW] ) "; + assertEquals(expected, actual); + } }