From 3b7bad9dfaf7cebaae64daf7ba46f7972aea9e0b Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 23 Sep 2015 08:33:16 +0000 Subject: [PATCH] Merged BRANCHES/V2.2 to BRANCHES/V2.3: 99087: Upgrade Alfresco version to 4.2.4.6 99088: RM-2026: Unable to complete historical records when mandatory meta-data missing 99089: Merged HEAD to V2.2: 89735: RM-1677- No items error for RM Admin if record was declared from moderated/private site git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@112663 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco-global.properties | 2 +- .../rm-action-context.xml | 3 +- .../action/impl/DeclareRecordAction.java | 14 +- .../jscript/app/JSONConversionComponent.java | 17 ++ .../dod/RM1194ExcludeDoDRecordTypesTest.java | 2 +- .../record/CompleteRecordTest.java | 233 ++++++++++++++++++ .../integration/record/RecordTestSuite.java | 1 + .../legacy/service/RecordServiceImplTest.java | 2 +- rm-server/test/resources/test-context.xml | 9 +- rm-server/test/resources/test-model.xml | 9 + 10 files changed, 286 insertions(+), 6 deletions(-) create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CompleteRecordTest.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties b/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties index d28ff30e4f..40134471ca 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties @@ -58,7 +58,7 @@ rm.record.contributors.group.enabled=false # record contributors group, default value 'RECORD_CONTRIBUTORS' rm.record.contributors.group.name=RECORD_CONTRIBUTORS -## Indicates whether mandatory properties are checked before completing a record +# Indicates whether mandatory properties are checked before completing a record # rm.completerecord.mandatorypropertiescheck.enabled=true diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml index 8aeaa34a0a..f5e8590fde 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-action-context.xml @@ -265,7 +265,7 @@ - + @@ -384,6 +384,7 @@ + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/DeclareRecordAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/DeclareRecordAction.java index 1d946695fb..50d51fd4f3 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/DeclareRecordAction.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/DeclareRecordAction.java @@ -54,6 +54,17 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase /** Logger */ private static Log logger = LogFactory.getLog(DeclareRecordAction.class); + + /** check mandatory properties */ + private boolean checkMandatoryPropertiesEnabled = true; + + /** + * @param checkMandatoryPropertiesEnabled true if check mandatory properties is enabled, false otherwise + */ + public void setCheckMandatoryPropertiesEnabled(boolean checkMandatoryPropertiesEnabled) + { + this.checkMandatoryPropertiesEnabled = checkMandatoryPropertiesEnabled; + } /** * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) @@ -69,7 +80,8 @@ public class DeclareRecordAction extends RMActionExecuterAbstractBase { List missingProperties = new ArrayList(5); // Aspect not already defined - check mandatory properties then add - if (mandatoryPropertiesSet(actionedUponNodeRef, missingProperties)) + if (!checkMandatoryPropertiesEnabled || + mandatoryPropertiesSet(actionedUponNodeRef, missingProperties)) { getRecordService().disablePropertyEditableCheck(); try diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java index 931752d6ef..33ee47b069 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java @@ -347,6 +347,23 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JS rootJSONObject.put("originatingLocationPath", originatingLocationPath.toString()); } } + + /** + * Helper method to get the display path. + * + * @param nodeRef node reference + * @return String display path + */ + private String getDisplayPath(final NodeRef nodeRef) + { + return AuthenticationUtil.runAs(new RunAsWork() + { + public String doWork() throws Exception + { + return PathUtil.getDisplayPath(nodeService.getPath(nodeRef), true); + } + }, AuthenticationUtil.getAdminUserName()); + } /** * Helper method to get the display path. diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/dod/RM1194ExcludeDoDRecordTypesTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/dod/RM1194ExcludeDoDRecordTypesTest.java index 5019fc9114..f44d4bb753 100755 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/dod/RM1194ExcludeDoDRecordTypesTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/dod/RM1194ExcludeDoDRecordTypesTest.java @@ -108,7 +108,7 @@ public class RM1194ExcludeDoDRecordTypesTest extends BaseRMTestCase implements D assertNotNull(record); Set aspects = recordService.getRecordMetadataAspects(record); assertNotNull(aspects); - assertEquals(1, aspects.size()); + assertEquals(2, aspects.size()); } }); } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CompleteRecordTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CompleteRecordTest.java new file mode 100644 index 0000000000..c86a12e277 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CompleteRecordTest.java @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2005-2014 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.module.org_alfresco_module_rm.test.integration.record; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionResult; +import org.alfresco.module.org_alfresco_module_rm.action.impl.DeclareRecordAction; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; + +/** + * Complete record tests. + * + * @author Roy Wetherall + * @since 2.2.1 + */ +public class CompleteRecordTest extends BaseRMTestCase +{ + private static final QName ASPECT_TEST = QName.createQName("http://www.alfresco.org/model/rmtest/1.0", "recordMetaDataWithProperty"); + private static final QName PROP_TEST = QName.createQName("http://www.alfresco.org/model/rmtest/1.0", "customMandatoryProperty"); + + /** complete record action */ + private DeclareRecordAction action; + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices() + */ + @Override + protected void initServices() + { + super.initServices(); + + // get the action + action = (DeclareRecordAction)applicationContext.getBean("declareRecord"); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#tearDownImpl() + */ + @Override + protected void tearDownImpl() + { + super.tearDownImpl(); + + // ensure action is returned to original state + action.setCheckMandatoryPropertiesEnabled(true); + } + + /** + * Given the the application is configured to check for mandatory values before complete + * And a filed record is missing mandatory values + * When I try to complete the record + * Then the missing properties parameter of the action will be populated + * And the record will not be complete + */ + public void testCheckForMandatoryValuesMissing() throws Exception + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private RecordsManagementActionResult result; + + public void given() + { + // enable mandatory parameter check + action.setCheckMandatoryPropertiesEnabled(true); + + // create a record + record = utils.createRecord(rmFolder, "record.txt", "title"); + + // add the record aspect (that has a mandatory property) + nodeService.addAspect(record, ASPECT_TEST, null); + } + + public void when() + { + // complete record + result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); + } + + public void then() + { + assertNotNull(result); + assertNotNull(result.getValue()); + assertFalse(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); + } + }); + } + + /** + * Given the the application is configured to check for mandatory values before complete + * And a filed record has all mandatory values + * When I try to complete the record + * Then the record is completed + */ + public void testCheckForMandatoryValuePresent() throws Exception + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private RecordsManagementActionResult result; + + public void given() + { + // enable mandatory parameter check + action.setCheckMandatoryPropertiesEnabled(true); + + // create a record + record = utils.createRecord(rmFolder, "record.txt", "title"); + + // add the record aspect (that has a mandatory property) + Map properties = new HashMap(1); + properties.put(PROP_TEST, "something"); + nodeService.addAspect(record, ASPECT_TEST, properties); + } + + public void when() + { + // complete record + result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); + } + + public void then() + { + assertNotNull(result); + assertNull(result.getValue()); + assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); + } + }); + } + + /** + * Given the the application is configured not to check for mandatory values before complete + * And a filed record is missing mandatory values + * When I try to complete the record + * Then the record is completed + */ + public void testDontCheckForMandatoryValuesMissing() throws Exception + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private RecordsManagementActionResult result; + + public void given() + { + // disable mandatory parameter check + action.setCheckMandatoryPropertiesEnabled(false); + + // create a record + record = utils.createRecord(rmFolder, "record.txt", "title"); + + // add the record aspect (that has a mandatory property) + nodeService.addAspect(record, ASPECT_TEST, null); + } + + public void when() + { + // complete record + result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); + } + + public void then() + { + assertNotNull(result); + assertNull(result.getValue()); + assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); + } + }); + } + + /** + * Given the the application is configured to not to check for mandatory values before complete + * And a filed record has all mandatory values + * When I try to complete the record + * Then the record is completed + */ + public void testDontCheckForMandatoryValuePresent() throws Exception + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + private NodeRef record; + private RecordsManagementActionResult result; + + public void given() + { + // enable mandatory parameter check + action.setCheckMandatoryPropertiesEnabled(false); + + // create a record + record = utils.createRecord(rmFolder, "record.txt", "title"); + + // add the record aspect (that has a mandatory property) + Map properties = new HashMap(1); + properties.put(PROP_TEST, "something"); + nodeService.addAspect(record, ASPECT_TEST, properties); + } + + public void when() + { + // complete record + result = rmActionService.executeRecordsManagementAction(record, "declareRecord"); + } + + public void then() + { + assertNotNull(result); + assertNull(result.getValue()); + assertTrue(nodeService.hasAspect(record, ASPECT_DECLARED_RECORD)); + } + }); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/RecordTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/RecordTestSuite.java index d2b3b8e498..40d7495bd6 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/RecordTestSuite.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/RecordTestSuite.java @@ -34,6 +34,7 @@ import org.junit.runners.Suite.SuiteClasses; RejectRecordTest.class, CreateRecordTest.class, MoveRecordTest.class, + CompleteRecordTest.class, HideInplaceRecordTest.class, MoveInplaceRecordTest.class, ViewRecordTest.class, diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordServiceImplTest.java index 600a54854d..1cf86bb235 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordServiceImplTest.java @@ -93,7 +93,7 @@ public class RecordServiceImplTest extends BaseRMTestCase { Set aspects = recordService.getRecordMetadataAspects(filePlan); assertNotNull(aspects); - assertEquals(1, aspects.size()); + assertEquals(2, aspects.size()); assertTrue(aspects.containsAll(getAspectList())); return null; diff --git a/rm-server/test/resources/test-context.xml b/rm-server/test/resources/test-context.xml index f5e35faf58..e4d4131b90 100644 --- a/rm-server/test/resources/test-context.xml +++ b/rm-server/test/resources/test-context.xml @@ -217,7 +217,14 @@ - + + + + + + + + false diff --git a/rm-server/test/resources/test-model.xml b/rm-server/test/resources/test-model.xml index 2f7b137c3a..41869338d5 100644 --- a/rm-server/test/resources/test-model.xml +++ b/rm-server/test/resources/test-model.xml @@ -54,6 +54,15 @@ + + + + + d:text + true + + +