mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
43598: Merged HEAD to BRANCHES/DEV/V4.1-BUG-FIX *RECORD ONLY* 41906: ALF-11378: REST API has been modified to return extra information about a user whether s/he belongs to a group or not. 44003: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2012_11_22 to BRANCHES/DEV/V4.1-BUG-FIX: ALF-15210: Inconsistency in the '?' icon over the dashlets projects\slingshot\source\web\js\share.js DashletTitleBarActions_onReady() function was updated. Fix initialize the style for actionsNode elements into the DOM for IE. 44004: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2012_11_22 to V4.1-BUG-FIX: ALF-15793: edit offline hides version history projects\slingshot\source\web\components\document-details\document-actions.js onActionUploadNewVersion function was updated. Fix sets version variable correctly now using asset.workingCopy property instead asset.custom property, which is undefined. 44018: ALF-16540 : CMIS: createDocument with VersioningState.CHECKEDOUT causes NodeLockedException for types with mandatory versionable aspect The ckeck for lock was disabled when beforeCreateVersion policy is handled. Version could be created for a locked node. 44054: Fix for ALF-16337. Datalist assignee not searchable by full name. 44056: Trivial change. Fixing some compiler warnings under org.alfresco.repo.content.metadata including a noisy Tika one. 44143: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2012_10_19 to BRANCHES/DEV/V4.1-BUG-FIX: 42989: ALF-16331: Wrong user for "completed by" information provided in Group Review And Approve workflow 44147: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.1-BUG-FIX: 44146: Merged BRANCHES/DEV/BELARUS/V3.4-BUG-FIX-2012_05_22 to BRANCHES/DEV/V3.4-BUG-FIX: 37733: ALF-12051: Webdav - Cannot open files containing "?" character in the filename in WinXP 44152: ALF-17009 : Merged V3.4-BUG-FIX (3.4.12) to V4.1-BUG-FIX (4.1.3) 44151: ALF-14035 Tiny HTML file that causes Jodconverter to launch a 100% CPU soffice instance - HTML to PDF is now done via ODT as the direct transform hangs if there are <sub> tags in the HTML. - Added in 'unsupportedTransformations' to stop a bare transformer.JodConverter from doing HTML to PDF - TransformerDebug test file debugTransformers.txt no longer needs to be 18 bytes, as it made it too fiddly. - Modified debug from RuntimeExec so less editing is required to running from the command line - Removed tabs that had been added to enterprise/content-services-context.xml in 4.1-BUG-FIX 44192: ALF-16560 - CIFS: Word document version history lost after saving content in Word:mac 2011 on Mac Mountain Lion 44224: ALF-16896 Exception with TIKA meta data extractor. - Patch POI to handle parsing of Unicode properties that starts on a 4 byte boundary rather than the specified offset. Example file was created using http://www.aspose.com/ 44241: Merged DEV to V4.1-BUG-FIX 44208: ALF-14591 : Ordering not supported for IMAP properties defining IMAP sort fields in Share Make properties from imap:imapContent aspect indexable for SOLR. 44253: Merged BRANCHES/DEV/AMILLER/CLOUD1 to BRANCHES/DEV/V4.1-BUG-FIX: 38927: CLOUD-128 - Update rules works incorrectly This is a partial fix for ALF-14568. The rest is coming in a separate check-in. I made some minor adjustments to this change - trivial spelling fix and whitespace changes. 44257: ALF-16563 - CIFS: Image document version history lost after saving content in Preview on Mac Mountain Lion 44260: Fix for ALF-16430 - List of values shown in alphabetical order in Share Forms. Values now only sorted if the Forms config 'field' element has the sorted='true' attribute. 44269: Completion of fix for ALF-14568 - Update rule works incorrectly. 44318: Fix for ALF-17055 - remoteadm webscript set a Last-Modified HTTP header whose date format does not conform to RFC 2616 hence breaking proxy caching 44320: Fix for ALF-16463 - documentLibrary RSS feed does not pass the w3c validator, in particular pubDate breaks RFC-822, date not displayed when using non English locale 44352: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2012_11_12 to BRANCHES/DEV/V4.1-BUG-FIX 43860: ALF-16263: Search using a "Stop Word" not displaying any result git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@44459 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
309 lines
14 KiB
Java
309 lines
14 KiB
Java
/*
|
|
* Copyright (C) 2005-2012 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.repo.rule;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
|
|
import org.alfresco.repo.action.executer.CopyActionExecuter;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
|
import org.alfresco.service.cmr.action.Action;
|
|
import org.alfresco.service.cmr.action.ActionService;
|
|
import org.alfresco.service.cmr.repository.CopyService;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.alfresco.service.cmr.rule.RuleService;
|
|
import org.alfresco.service.cmr.rule.RuleType;
|
|
import org.alfresco.service.cmr.site.SiteInfo;
|
|
import org.alfresco.service.cmr.site.SiteService;
|
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.util.test.junitrules.AlfrescoPerson;
|
|
import org.alfresco.util.test.junitrules.ApplicationContextInit;
|
|
import org.alfresco.util.test.junitrules.RunAsFullyAuthenticatedRule;
|
|
import org.alfresco.util.test.junitrules.TemporaryNodes;
|
|
import org.alfresco.util.test.junitrules.TemporarySites;
|
|
import org.junit.Before;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.ClassRule;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.rules.RuleChain;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
|
/**
|
|
* Integration tests for Alfresco Rules. This class does not test the internals of the {@link RuleService}
|
|
* but rather sets up and runs common or previously problematic rules use cases and ensures they are correct.
|
|
*
|
|
* @author Neil Mc Erlean
|
|
* @since 4.1.3
|
|
*/
|
|
public class MiscellaneousRulesTest
|
|
{
|
|
// Static JUnit Rules
|
|
public static ApplicationContextInit APP_CTXT_INIT = new ApplicationContextInit();
|
|
public static AlfrescoPerson TEST_USER = new AlfrescoPerson(APP_CTXT_INIT);
|
|
|
|
// Rule chain to ensure they run in the right order
|
|
@ClassRule public static RuleChain STATIC_RULE_CHAIN = RuleChain.outerRule(APP_CTXT_INIT)
|
|
.around(TEST_USER);
|
|
|
|
// Non-static JUnit Rules
|
|
public RunAsFullyAuthenticatedRule runAsRule = new RunAsFullyAuthenticatedRule(TEST_USER);
|
|
public TemporarySites testSites = new TemporarySites(APP_CTXT_INIT);
|
|
public TemporaryNodes testNodes = new TemporaryNodes(APP_CTXT_INIT);
|
|
|
|
// Rule chain to ensure they run in the right order
|
|
@Rule public RuleChain ruleChain = RuleChain.outerRule(runAsRule)
|
|
.around(testSites)
|
|
.around(testNodes);
|
|
|
|
private static ActionService ACTION_SERVICE;
|
|
private static CopyService COPY_SERVICE;
|
|
private static NodeService NODE_SERVICE;
|
|
private static RetryingTransactionHelper TRANSACTION_HELPER;
|
|
private static RuleService RULE_SERVICE;
|
|
private static SiteService SITE_SERVICE;
|
|
|
|
private SiteInfo testSite;
|
|
|
|
@BeforeClass public static void initSpringBeans() throws Exception
|
|
{
|
|
final ApplicationContext appCtxt = APP_CTXT_INIT.getApplicationContext();
|
|
|
|
ACTION_SERVICE = appCtxt.getBean("ActionService", ActionService.class);
|
|
COPY_SERVICE = appCtxt.getBean("CopyService", CopyService.class);
|
|
NODE_SERVICE = appCtxt.getBean("NodeService", NodeService.class);
|
|
TRANSACTION_HELPER = appCtxt.getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
|
|
RULE_SERVICE = appCtxt.getBean("RuleService", RuleService.class);
|
|
SITE_SERVICE = appCtxt.getBean("SiteService", SiteService.class);
|
|
}
|
|
|
|
@Before public void createTestData() throws Exception
|
|
{
|
|
testSite = testSites.createSite("sitePreset", "testSiteName", "testSiteTitle", "test site description",
|
|
SiteVisibility.PUBLIC, TEST_USER.getUsername());
|
|
|
|
}
|
|
|
|
@Test public void alf14568() throws Exception
|
|
{
|
|
final NodeRef testSiteDocLib = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
|
{
|
|
public NodeRef execute() throws Throwable
|
|
{
|
|
return SITE_SERVICE.getContainer(testSite.getShortName(), SiteService.DOCUMENT_LIBRARY);
|
|
}
|
|
});
|
|
assertNotNull("Null doclib", testSiteDocLib);
|
|
|
|
// Create four folders - the first (zero'th) will not be used.
|
|
final NodeRef[] folders = new NodeRef[4];
|
|
for (int i : new int[] {0, 1, 2, 3})
|
|
{
|
|
folders[i] = testNodes.createFolder(testSiteDocLib, "folder" + i, TEST_USER.getUsername());
|
|
}
|
|
|
|
// Create an inbound rule for Folder1 - copy to Folder2.
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
// Clashes with the JUnit annotation @Rule
|
|
org.alfresco.service.cmr.rule.Rule rule = new org.alfresco.service.cmr.rule.Rule();
|
|
rule.setRuleType(RuleType.INBOUND);
|
|
rule.applyToChildren(false);
|
|
rule.setRuleDisabled(false);
|
|
rule.setTitle("Copy to folder2");
|
|
rule.setExecuteAsynchronously(false);
|
|
|
|
Map<String, Serializable> params = new HashMap<String, Serializable>();
|
|
params.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, folders[2]);
|
|
Action copyAction = ACTION_SERVICE.createAction("copy", params);
|
|
rule.setAction(copyAction);
|
|
|
|
RULE_SERVICE.saveRule(folders[1], rule);
|
|
|
|
return null;
|
|
}
|
|
});
|
|
|
|
// Create an update rule for Folder2 - copy to Folder3.
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
org.alfresco.service.cmr.rule.Rule rule = new org.alfresco.service.cmr.rule.Rule();
|
|
rule.setRuleType(RuleType.UPDATE);
|
|
rule.applyToChildren(false);
|
|
rule.setRuleDisabled(false);
|
|
rule.setTitle("Copy to folder3");
|
|
rule.setExecuteAsynchronously(false);
|
|
|
|
Map<String, Serializable> params = new HashMap<String, Serializable>();
|
|
params.put(CopyActionExecuter.PARAM_DESTINATION_FOLDER, folders[3]);
|
|
Action copyAction = ACTION_SERVICE.createAction("copy", params);
|
|
rule.setAction(copyAction);
|
|
|
|
RULE_SERVICE.saveRule(folders[2], rule);
|
|
|
|
return null;
|
|
}
|
|
});
|
|
|
|
// Now put a file in Folder1. - don't need transaction as one is included within this call
|
|
testNodes.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN, folders[1], "quick.txt", TEST_USER.getUsername());
|
|
|
|
// Which folders is the file in?
|
|
final Set<NodeRef> foldersContainingFile = new HashSet<NodeRef>();
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
for (NodeRef folder : folders)
|
|
{
|
|
NodeRef child = NODE_SERVICE.getChildByName(folder, ContentModel.ASSOC_CONTAINS, "quick.txt");
|
|
if (child != null)
|
|
{
|
|
foldersContainingFile.add(folder);
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
});
|
|
|
|
// Now disable all the rules - I don't think this should be necessary, but if we don't do this, the teardown
|
|
// parts of the JUnit Rules cause problems in the repo.
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
for (NodeRef folder : folders)
|
|
{
|
|
RULE_SERVICE.removeAllRules(folder);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
});
|
|
|
|
final Set<NodeRef> expectedFolders = new HashSet<NodeRef>();
|
|
expectedFolders.add(folders[1]);
|
|
expectedFolders.add(folders[2]);
|
|
|
|
assertEquals(expectedFolders, foldersContainingFile);
|
|
}
|
|
|
|
/**
|
|
* ALF-14568 doesn't explicitly say so, but there is a related problem on top of the
|
|
* 'creating cm:original assoc triggers rule' bug. It is the related 'deleting cm:original assoc triggers rule' bug.
|
|
* This test case validates the fix for that issue.
|
|
*/
|
|
@Test public void alf14568_supplementary() throws Exception
|
|
{
|
|
final NodeRef testSiteDocLib = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
|
{
|
|
public NodeRef execute() throws Throwable
|
|
{
|
|
return SITE_SERVICE.getContainer(testSite.getShortName(), SiteService.DOCUMENT_LIBRARY);
|
|
}
|
|
});
|
|
assertNotNull("Null doclib", testSiteDocLib);
|
|
|
|
// Create a folder to put our Alfresco Rules on - but don't put any rules on it yet.
|
|
final NodeRef ruleFolder = testNodes.createFolder(testSiteDocLib, "ruleFolder", TEST_USER.getUsername());
|
|
|
|
// Create a piece of content outside our Rules folder.
|
|
final NodeRef originalContent = testNodes.createQuickFile(MimetypeMap.MIMETYPE_TEXT_PLAIN,
|
|
testSiteDocLib,
|
|
"original.txt",
|
|
TEST_USER.getUsername());
|
|
|
|
// Now copy that node into the Ruled folder, which will create a cm:original assoc.
|
|
final NodeRef copyNode = TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
|
{
|
|
public NodeRef execute() throws Throwable
|
|
{
|
|
return COPY_SERVICE.copy(originalContent, ruleFolder, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS);
|
|
}
|
|
});
|
|
|
|
final QName exifAspectQName = QName.createQName("{http://www.alfresco.org/model/exif/1.0}exif");
|
|
|
|
// Only now do we create the update rule on our folder - put a marker aspect on the node.
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
// Clashes with the JUnit annotation @Rule
|
|
org.alfresco.service.cmr.rule.Rule rule = new org.alfresco.service.cmr.rule.Rule();
|
|
rule.setRuleType(RuleType.UPDATE);
|
|
rule.applyToChildren(false);
|
|
rule.setRuleDisabled(false);
|
|
rule.setTitle("Put EXIF aspect on changed nodes");
|
|
rule.setExecuteAsynchronously(false);
|
|
|
|
Map<String, Serializable> params = new HashMap<String, Serializable>();
|
|
params.put(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, exifAspectQName);
|
|
Action addAspectAction = ACTION_SERVICE.createAction("add-features", params);
|
|
rule.setAction(addAspectAction);
|
|
|
|
RULE_SERVICE.saveRule(ruleFolder, rule);
|
|
|
|
return null;
|
|
}
|
|
});
|
|
|
|
// Now delete the original node.
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
NODE_SERVICE.deleteNode(originalContent);
|
|
|
|
return null;
|
|
}
|
|
});
|
|
|
|
// The removal of the cm:original association should NOT have triggered the rule.
|
|
TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Void>()
|
|
{
|
|
public Void execute() throws Throwable
|
|
{
|
|
assertFalse("Rule executed when it shouldn't have.", NODE_SERVICE.hasAspect(copyNode, exifAspectQName));
|
|
|
|
return null;
|
|
}
|
|
});
|
|
}
|
|
}
|