list = new ArrayList<>();
+ for (int i = 0; i < size; i++) {
+ list.add(mock(clazz));
+ }
+ Collections.shuffle(list);
+
+ return list;
+ }
+
+ private static final class PageFormat
+ {
+ private final int size;
+ private final int offset;
+
+ public PageFormat(int size, int offset)
+ {
+ this.size = size;
+ this.offset = offset;
+ }
+ }
+}
\ No newline at end of file
diff --git a/repository/src/main/java/org/alfresco/repo/rule/RuleServiceImpl.java b/repository/src/main/java/org/alfresco/repo/rule/RuleServiceImpl.java
index 220a0167d4..7cc3e777f8 100644
--- a/repository/src/main/java/org/alfresco/repo/rule/RuleServiceImpl.java
+++ b/repository/src/main/java/org/alfresco/repo/rule/RuleServiceImpl.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -25,15 +25,6 @@
*/
package org.alfresco.repo.rule;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.action.ActionModel;
@@ -66,12 +57,22 @@ import org.alfresco.service.cmr.rule.RuleType;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName;
+import org.alfresco.service.namespace.QNamePattern;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.ParameterCheck;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Rule service implementation.
*
@@ -1611,4 +1612,15 @@ public class RuleServiceImpl
}
return result;
}
+
+ @Override
+ public boolean isRuleSetAssociatedWithFolder(final NodeRef ruleSetNodeRef, final NodeRef folderNodeRef) {
+ return findAssociatedParents(ruleSetNodeRef, RuleModel.ASSOC_RULE_FOLDER).stream()
+ .map(ChildAssociationRef::getParentRef)
+ .anyMatch(folderNodeRef::equals);
+ }
+
+ private List findAssociatedParents(final NodeRef nodeRef, final QNamePattern pattern) {
+ return runtimeNodeService.getParentAssocs(nodeRef, pattern, pattern);
+ }
}
diff --git a/repository/src/main/java/org/alfresco/service/cmr/rule/Rule.java b/repository/src/main/java/org/alfresco/service/cmr/rule/Rule.java
index 43631e3614..db8d3f5cd2 100644
--- a/repository/src/main/java/org/alfresco/service/cmr/rule/Rule.java
+++ b/repository/src/main/java/org/alfresco/service/cmr/rule/Rule.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * 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 .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2022 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 .
+ * #L%
+ */
package org.alfresco.service.cmr.rule;
import java.io.Serializable;
@@ -70,7 +70,7 @@ public class Rule implements Serializable
/**
* The associated action
*/
- private Action action;
+ private Action action;
/**
* Indicates whether the rule should execute the action asynchronously or not
diff --git a/repository/src/main/java/org/alfresco/service/cmr/rule/RuleService.java b/repository/src/main/java/org/alfresco/service/cmr/rule/RuleService.java
index 9367052f36..175c2e2347 100644
--- a/repository/src/main/java/org/alfresco/service/cmr/rule/RuleService.java
+++ b/repository/src/main/java/org/alfresco/service/cmr/rule/RuleService.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * 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 .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2022 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 .
+ * #L%
+ */
package org.alfresco.service.cmr.rule;
import java.util.List;
@@ -329,4 +329,14 @@ public interface RuleService
*/
@Auditable(parameters = {"nodeRef"})
public List getLinkedFromRuleNodes(NodeRef nodeRef);
+
+ /**
+ * Check if rule set's associated parent is equal to folder node.
+ *
+ * @param ruleSetNodeRef - node reference of a rule set
+ * @param folderNodeRef - node reference of a folder
+ * @return true if rule set is associated with folder
+ */
+ @Auditable(parameters = {"nodeRef"})
+ boolean isRuleSetAssociatedWithFolder(NodeRef ruleSetNodeRef, NodeRef folderNodeRef);
}
diff --git a/repository/src/test/java/org/alfresco/repo/rule/RuleLinkTest.java b/repository/src/test/java/org/alfresco/repo/rule/RuleLinkTest.java
index 1e4f492cf2..b1db17102d 100644
--- a/repository/src/test/java/org/alfresco/repo/rule/RuleLinkTest.java
+++ b/repository/src/test/java/org/alfresco/repo/rule/RuleLinkTest.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -25,12 +25,6 @@
*/
package org.alfresco.repo.rule;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
@@ -41,6 +35,7 @@ import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.model.FileFolderService;
+import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -56,6 +51,12 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.transaction.annotation.Transactional;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* Parameter definition implementation unit test.
*
@@ -350,7 +351,41 @@ public class RuleLinkTest extends BaseSpringTest
assertTrue(nodeService.hasAspect(folderThree, RuleModel.ASPECT_RULES));
assertEquals(rules1, rules3);
}
-
+
+ @Test
+ public void testIsRuleSetAssociatedWithFolder()
+ {
+ final Rule rule = createTestRule(false, "luke");
+ this.ruleService.saveRule(folderOne, rule);
+ final NodeRef ruleSetNodeRef = nodeService.getChildAssocs(folderOne, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER).stream()
+ .filter(ChildAssociationRef::isPrimary)
+ .map(ChildAssociationRef::getChildRef)
+ .findFirst()
+ .orElse(null);
+
+ // when
+ final boolean associated = ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderOne);
+
+ assertTrue(associated);
+ }
+
+ @Test
+ public void testIsRuleSetNotAssociatedWithFolder()
+ {
+ final Rule rule = createTestRule(false, "luke");
+ this.ruleService.saveRule(folderTwo , rule);
+ final NodeRef ruleSetNodeRef = nodeService.getChildAssocs(folderTwo, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER).stream()
+ .filter(ChildAssociationRef::isPrimary)
+ .map(ChildAssociationRef::getChildRef)
+ .findFirst()
+ .orElse(null);
+
+ // when
+ final boolean associated = ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, folderOne);
+
+ assertFalse(associated);
+ }
+
protected Rule createTestRule(boolean isAppliedToChildren, String title)
{
// Rule properties