RM-4101 (Link to, Copy to and File to rules fail when not run in background)

This commit is contained in:
Tuna Aksoy
2016-10-01 17:21:57 +01:00
parent c336a70846
commit 228bcbd960
3 changed files with 135 additions and 15 deletions

View File

@@ -125,15 +125,7 @@ public abstract class CopyMoveLinkFileToBaseAction extends RMActionExecuterAbstr
NodeRef recordFolder = (NodeRef)action.getParameterValue(PARAM_DESTINATION_RECORD_FOLDER);
if (recordFolder == null)
{
final boolean finaltargetIsUnfiledRecords = targetIsUnfiledRecords;
recordFolder = getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
// get the reference to the record folder based on the relative path
return createOrResolvePath(action, actionedUponNodeRef, finaltargetIsUnfiledRecords);
}
}, false, true);
recordFolder = createOrResolvePath(action, actionedUponNodeRef, targetIsUnfiledRecords);
}
// now we have the reference to the target folder we can do some final checks to see if the action is valid
@@ -259,23 +251,29 @@ public abstract class CopyMoveLinkFileToBaseAction extends RMActionExecuterAbstr
* @param targetisUnfiledRecords true is the target is in unfiled records
* @return
*/
private NodeRef createOrResolvePath(Action action, NodeRef actionedUponNodeRef, boolean targetisUnfiledRecords)
private NodeRef createOrResolvePath(final Action action, final NodeRef actionedUponNodeRef, final boolean targetisUnfiledRecords)
{
// get the starting context
NodeRef context = getContext(action, actionedUponNodeRef, targetisUnfiledRecords);
final NodeRef context = getContext(action, actionedUponNodeRef, targetisUnfiledRecords);
NodeRef path = context;
// get the path we wish to resolve
String pathParameter = (String)action.getParameterValue(PARAM_PATH);
String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true);
if((pathElementsArray != null) && (pathElementsArray.length > 0))
{
// get the create parameter
Boolean createValue = (Boolean)action.getParameterValue(PARAM_CREATE_RECORD_PATH);
boolean create = createValue == null ? false : createValue.booleanValue();
final boolean create = createValue == null ? false : createValue.booleanValue();
// create or resolve the specified path
path = createOrResolvePath(action, context, actionedUponNodeRef, Arrays.asList(pathElementsArray), targetisUnfiledRecords, create, false);
path = getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Throwable
{
return createOrResolvePath(action, context, actionedUponNodeRef, Arrays.asList(pathElementsArray), targetisUnfiledRecords, create, false);
}
}, false, true);
}
return path;
}

View File

@@ -46,7 +46,8 @@ import org.junit.runners.Suite.SuiteClasses;
RM1814Test.class,
RM978Test.class,
RM1887Test.class,
RM1914Test.class
RM1914Test.class,
RM4101Test.class
})
public class IssueTestSuite
{

View File

@@ -0,0 +1,121 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.issue;
import java.util.UUID;
import org.alfresco.module.org_alfresco_module_rm.action.impl.LinkToAction;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
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;
/**
* Tests issue #4101: Link to, Copy to and File to rules fail when not run in background
*
* @author Tuna Aksoy
* @since 2.3.0.8
*/
public class RM4101Test extends BaseRMTestCase
{
private RuleService ruleService;
@Override
protected void initServices()
{
super.initServices();
ruleService = (RuleService) applicationContext.getBean("RuleService");
}
@Override
protected boolean isRecordTest()
{
return true;
}
public void testRunRuleNotInBackground() throws Exception
{
final String categoryName = "category1" + UUID.randomUUID().toString();
final NodeRef category1 = doTestInTransaction(new Test<NodeRef>()
{
@Override
public NodeRef run()
{
return filePlanService.createRecordCategory(filePlan, categoryName);
}
});
final NodeRef folder1 = doTestInTransaction(new Test<NodeRef>()
{
@Override
public NodeRef run()
{
return recordFolderService.createRecordFolder(category1, "folder1WithRule" + UUID.randomUUID().toString());
}
});
final String folder2Name = "folder2FolderToLinkTo" + UUID.randomUUID().toString();
final NodeRef folder2 = doTestInTransaction(new Test<NodeRef>()
{
@Override
public NodeRef run()
{
return recordFolderService.createRecordFolder(category1, folder2Name);
}
});
doTestInTransaction(new Test<Void>()
{
@Override
public Void run()
{
Action linkToAction = actionService.createAction(LinkToAction.NAME);
linkToAction.setParameterValue(LinkToAction.PARAM_PATH, "/" + categoryName + "/" + folder2Name);
Rule rule = new Rule();
rule.setRuleType(RuleType.INBOUND);
rule.setTitle("LinkTo");
rule.setAction(linkToAction);
rule.setExecuteAsynchronously(false);
ruleService.saveRule(folder1, rule);
return null;
}
});
doTestInTransaction(new Test<Void>()
{
@Override
public Void run()
{
utils.createRecord(folder1, "record1" + UUID.randomUUID().toString());
return null;
}
@Override
public void test(Void result) throws Exception
{
assertEquals(1, nodeService.getChildAssocs(folder2).size());
}
});
}
}