Merge branch 'feature-2.4/RM-3300' into 'release/V2.4'

Feature 2.4/rm 3300

On versioning, document can be declared as record if adding record and version aspect is done running as System.
I noticed that the aspect is added only like this in other places where it is used; and the method for creating new recorded version, where the aspect is added, is not used in other places such that changing behavior elsewhere.

See merge request !152
This commit is contained in:
Roxana Lucanu-Ghetu
2016-06-15 10:19:48 +01:00
3 changed files with 143 additions and 2 deletions

View File

@@ -393,7 +393,7 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
final NodeRef record = recordService.createRecordFromCopy(filePlan, nodeRef);
// apply version record aspect to record
PropertyMap versionRecordProps = new PropertyMap(3);
final PropertyMap versionRecordProps = new PropertyMap(3);
versionRecordProps.put(PROP_VERSIONED_NODEREF, nodeRef);
versionRecordProps.put(RecordableVersionModel.PROP_VERSION_LABEL,
standardVersionProperties.get(
@@ -403,7 +403,16 @@ public class RecordableVersionServiceImpl extends Version2ServiceImpl
standardVersionProperties.get(
QName.createQName(Version2Model.NAMESPACE_URI,
Version2Model.PROP_VERSION_DESCRIPTION)));
nodeService.addAspect(record, ASPECT_VERSION_RECORD, versionRecordProps);
// run as system as we can't be sure if the user has add aspect rights
authenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
nodeService.addAspect(record, ASPECT_VERSION_RECORD, versionRecordProps);
return null;
}
});
// wire record up to previous record
linkToPreviousVersionRecord(nodeRef, record);

View File

@@ -0,0 +1,126 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.module.org_alfresco_module_rm.test.legacy.action;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction;
import org.alfresco.module.org_alfresco_module_rm.action.dm.DeclareAsVersionRecordAction;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionServiceImpl;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
public class DeclareVersionAsRecordActionTest extends BaseRMTestCase
{
private RuleService ruleService;
private NodeRef ruleFile;
protected static final String DESCRIPTION = "description";
@Override
protected void initServices()
{
super.initServices();
ruleService = (RuleService)applicationContext.getBean("RuleService");
}
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
@Override
protected boolean isRecordTest()
{
return true;
}
/**
* Given a node set to auto-declare documents as records for minor and major versions
* When I try to upload a minor or major version
* Then the version record aspect is added
*/
public void testUpdateNextDispositionAction_RM3060() throws Exception
{
doBehaviourDrivenTest(new BehaviourDrivenTest(dmContributor)
{
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(4);
Version recordedVersion;
@Override
public void given()
{
// create the file
ruleFile = fileFolderService.create(documentLibrary, "mytestfile", ContentModel.TYPE_CONTENT).getNodeRef();
Action action = actionService.createAction(DeclareAsVersionRecordAction.NAME);
action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
rule.setTitle("my rule");
rule.setAction(action);
rule.setExecuteAsynchronously(true);
ruleService.saveRule(ruleFile, rule);
// setup version properties
versionProperties.put(Version.PROP_DESCRIPTION, DESCRIPTION);
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
versionProperties.put(RecordableVersionServiceImpl.KEY_RECORDABLE_VERSION, true);
versionProperties.put(RecordableVersionServiceImpl.KEY_FILE_PLAN, filePlan);
}
@Override
public void when()
{
recordedVersion = versionService.createVersion(ruleFile, versionProperties);
}
@Override
public void then() throws Exception
{
NodeRef recordedVersionNodeRef= (NodeRef)recordedVersion.getVersionProperties().get(RecordableVersionModel.PROP_RECORD_NODE_REF.getLocalName());
assertNotNull("Recorded version shouldn't be null.", recordedVersionNodeRef);
assertTrue(nodeService.hasAspect(recordedVersionNodeRef, RecordableVersionModel.ASPECT_VERSION_RECORD));
}
});
}
}

View File

@@ -271,6 +271,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
/** collaboration site users */
protected String dmConsumer;
protected NodeRef dmConsumerNodeRef;
protected String dmContributor;
protected NodeRef dmContributorNodeRef;
protected String dmCollaborator;
protected NodeRef dmCollaboratorNodeRef;
@@ -772,6 +774,10 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
dmConsumer = GUID.generate();
dmConsumerNodeRef = createPerson(dmConsumer);
siteService.setMembership(collabSiteId, dmConsumer, SiteModel.SITE_CONSUMER);
dmContributor = GUID.generate();
dmContributorNodeRef = createPerson(dmContributor);
siteService.setMembership(collabSiteId, dmContributor, SiteModel.SITE_CONTRIBUTOR);
dmCollaborator = GUID.generate();
dmCollaboratorNodeRef = createPerson(dmCollaborator);