,
+ InitializingBean
+{
+ private RuleSettings ruleSettings;
+
+ @Override
+ public void afterPropertiesSet() throws Exception
+ {
+ PropertyCheck.mandatory(this, "ruleSettings", ruleSettings);
+ }
+
+ /**
+ * Get the given configuration value for the specified folder.
+ *
+ * - GET /nodes/{folderId}/rule-settings/{ruleSettingKey}
+ *
+ * @param folderId The id of the folder.
+ * @param ruleSettingKey The setting to retrieve.
+ * @param parameters Unused.
+ * @return {@link RuleSetting} The current value of the setting.
+ */
+ @WebApiDescription (
+ title = "Get a folder node rule setting",
+ description = "Returns the specified rule setting for the given folder",
+ successStatus = HttpServletResponse.SC_OK
+ )
+ @Override
+ public RuleSetting readById(String folderId, String ruleSettingKey, Parameters parameters) throws RelationshipResourceNotFoundException
+ {
+ return ruleSettings.getRuleSetting(folderId, ruleSettingKey);
+ }
+
+ /**
+ * Set the value of a rule setting for the specified folder.
+ *
+ * PUT /nodes/{folderId}/rule-settings/{ruleSettingKey}
+ *
+ * @param folderId The id of the folder.
+ * @param ruleSetting The new value of the rule setting.
+ * @param parameters Unused.
+ * @return The updated rule setting.
+ */
+ @WebApiDescription (
+ title = "Update folder node rule setting",
+ description = "Update a rule setting for given node",
+ successStatus = HttpServletResponse.SC_OK
+ )
+ @Override
+ public RuleSetting update(String folderId, RuleSetting ruleSetting, Parameters parameters)
+ {
+ return ruleSettings.setRuleSetting(folderId, ruleSetting);
+ }
+
+ public void setRuleSettings(RuleSettings ruleSettings)
+ {
+ this.ruleSettings = ruleSettings;
+ }
+}
diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml
index 33990e8451..074af5be3b 100644
--- a/remote-api/src/main/resources/alfresco/public-rest-context.xml
+++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml
@@ -912,6 +912,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSetsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSetsImplTest.java
index 06c6b39b53..16094b1aa1 100644
--- a/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSetsImplTest.java
+++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSetsImplTest.java
@@ -63,12 +63,12 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith (MockitoJUnitRunner.class)
public class RuleSetsImplTest extends TestCase
{
- private static final String FOLDER_NODE_ID = "dummy-folder-node-id";
+ private static final String FOLDER_ID = "dummy-folder-id";
private static final String LINK_TO_NODE_ID = "dummy-link-to-node-id";
private static final String RULE_SET_ID = "dummy-rule-set-id";
- private static final NodeRef FOLDER_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_NODE_ID);
- private static final NodeRef LINK_TO_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, LINK_TO_NODE_ID);
- private static final NodeRef RULE_SET_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
+ private static final NodeRef FOLDER_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_ID);
+ private static final NodeRef LINK_TO_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, LINK_TO_NODE_ID);
+ private static final NodeRef RULE_SET_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
private static final Paging PAGING = Paging.DEFAULT;
private static final List INCLUDES = List.of("dummy-includes");
@@ -94,24 +94,25 @@ public class RuleSetsImplTest extends TestCase
public void setUp()
{
MockitoAnnotations.openMocks(this);
- given(nodeValidatorMock.validateFolderNode(eq(LINK_TO_NODE_ID), anyBoolean())).willReturn(LINK_TO_NODE_REF);
- given(nodeValidatorMock.validateFolderNode(eq(FOLDER_NODE_ID), anyBoolean())).willReturn(FOLDER_NODE_REF);
- given(nodeValidatorMock.validateRuleSetNode(RULE_SET_ID, FOLDER_NODE_REF)).willReturn(RULE_SET_NODE_REF);
- given(ruleServiceMock.getRuleSetNode(FOLDER_NODE_REF)).willReturn(RULE_SET_NODE_REF);
- given(ruleSetLoaderMock.loadRuleSet(RULE_SET_NODE_REF, FOLDER_NODE_REF, INCLUDES)).willReturn(ruleSetMock);
+ given(nodeValidatorMock.validateFolderNode(eq(LINK_TO_NODE_ID), anyBoolean())).willReturn(LINK_TO_NODE);
+ given(nodeValidatorMock.validateFolderNode(eq(FOLDER_ID), anyBoolean())).willReturn(FOLDER_NODE);
+ given(nodeValidatorMock.validateRuleSetNode(RULE_SET_ID, FOLDER_NODE)).willReturn(RULE_SET_NODE);
+
+ given(ruleServiceMock.getRuleSetNode(FOLDER_NODE)).willReturn(RULE_SET_NODE);
+ given(ruleSetLoaderMock.loadRuleSet(RULE_SET_NODE, FOLDER_NODE, INCLUDES)).willReturn(ruleSetMock);
}
@Test
public void testGetRuleSets()
{
// Call the method under test.
- CollectionWithPagingInfo actual = ruleSets.getRuleSets(FOLDER_NODE_ID, INCLUDES, PAGING);
+ CollectionWithPagingInfo actual = ruleSets.getRuleSets(FOLDER_ID, INCLUDES, PAGING);
- then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
+ then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
- then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE_REF);
+ then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE);
then(ruleServiceMock).shouldHaveNoMoreInteractions();
Collection expected = List.of(ruleSetMock);
@@ -123,15 +124,15 @@ public class RuleSetsImplTest extends TestCase
public void testGetZeroRuleSets()
{
// Simulate no rule sets for the folder.
- given(ruleServiceMock.getRuleSetNode(FOLDER_NODE_REF)).willReturn(null);
+ given(ruleServiceMock.getRuleSetNode(FOLDER_NODE)).willReturn(null);
// Call the method under test.
- CollectionWithPagingInfo actual = ruleSets.getRuleSets(FOLDER_NODE_ID, INCLUDES, PAGING);
+ CollectionWithPagingInfo actual = ruleSets.getRuleSets(FOLDER_ID, INCLUDES, PAGING);
- then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
+ then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
- then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE_REF);
+ then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE);
then(ruleServiceMock).shouldHaveNoMoreInteractions();
assertEquals(emptyList(), actual.getCollection());
@@ -142,10 +143,10 @@ public class RuleSetsImplTest extends TestCase
public void testGetRuleSetById()
{
// Call the method under test.
- RuleSet actual = ruleSets.getRuleSetById(FOLDER_NODE_ID, RULE_SET_ID, INCLUDES);
+ RuleSet actual = ruleSets.getRuleSetById(FOLDER_ID, RULE_SET_ID, INCLUDES);
- then(nodeValidatorMock).should().validateFolderNode(FOLDER_NODE_ID, false);
- then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, FOLDER_NODE_REF);
+ then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
+ then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, FOLDER_NODE);
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
assertEquals(ruleSetMock, actual);
@@ -161,28 +162,28 @@ public class RuleSetsImplTest extends TestCase
given(assocRef.getChildRef()).willReturn(childNodeRef);
//when
- assertEquals(ruleSets.linkToRuleSet(FOLDER_NODE_ID,LINK_TO_NODE_ID).getId(), childNodeRef.getId());
+ assertEquals(ruleSets.linkToRuleSet(FOLDER_ID,LINK_TO_NODE_ID).getId(), childNodeRef.getId());
- then(ruleServiceMock).should().hasRules(LINK_TO_NODE_REF);
- then(ruleServiceMock).should().hasRules(FOLDER_NODE_REF);
- then(runtimeRuleServiceMock).should().getSavedRuleFolderAssoc(LINK_TO_NODE_REF);
+ then(ruleServiceMock).should().hasRules(LINK_TO_NODE);
+ then(ruleServiceMock).should().hasRules(FOLDER_NODE);
+ then(runtimeRuleServiceMock).should().getSavedRuleFolderAssoc(LINK_TO_NODE);
then(runtimeRuleServiceMock).shouldHaveNoMoreInteractions();
- then(nodeServiceMock).should().addChild(FOLDER_NODE_REF, childNodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER);
+ then(nodeServiceMock).should().addChild(FOLDER_NODE, childNodeRef, RuleModel.ASSOC_RULE_FOLDER, RuleModel.ASSOC_RULE_FOLDER);
then(nodeServiceMock).shouldHaveNoMoreInteractions();
}
@Test
public void testLinkToRuleSet_targetFolderHasNoRules()
{
- given(ruleServiceMock.hasRules(LINK_TO_NODE_REF)).willReturn(false);
+ given(ruleServiceMock.hasRules(LINK_TO_NODE)).willReturn(false);
//when
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
- () -> ruleSets.linkToRuleSet(FOLDER_NODE_ID, LINK_TO_NODE_ID)
+ () -> ruleSets.linkToRuleSet(FOLDER_ID, LINK_TO_NODE_ID)
);
then(nodeServiceMock).shouldHaveNoMoreInteractions();
- then(ruleServiceMock).should().hasRules(LINK_TO_NODE_REF);
+ then(ruleServiceMock).should().hasRules(LINK_TO_NODE);
then(ruleServiceMock).shouldHaveNoMoreInteractions();
then(runtimeRuleServiceMock).shouldHaveNoInteractions();
}
@@ -194,11 +195,11 @@ public class RuleSetsImplTest extends TestCase
//when
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
- () -> ruleSets.linkToRuleSet(FOLDER_NODE_ID, LINK_TO_NODE_ID));
+ () -> ruleSets.linkToRuleSet(FOLDER_ID, LINK_TO_NODE_ID));
then(nodeServiceMock).shouldHaveNoMoreInteractions();
- then(ruleServiceMock).should().hasRules(LINK_TO_NODE_REF);
- then(ruleServiceMock).should().hasRules(FOLDER_NODE_REF);
+ then(ruleServiceMock).should().hasRules(LINK_TO_NODE);
+ then(ruleServiceMock).should().hasRules(FOLDER_NODE);
then(ruleServiceMock).shouldHaveNoMoreInteractions();
then(runtimeRuleServiceMock).shouldHaveNoInteractions();
}
diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSettingsImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSettingsImplTest.java
new file mode 100644
index 0000000000..0f635a73c1
--- /dev/null
+++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/rules/RuleSettingsImplTest.java
@@ -0,0 +1,145 @@
+/*
+ * #%L
+ * Alfresco Remote API
+ * %%
+ * 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.rest.api.impl.rules;
+
+import static java.util.Collections.emptyMap;
+
+import static org.alfresco.repo.rule.RuleModel.ASPECT_IGNORE_INHERITED_RULES;
+import static org.alfresco.rest.api.model.rules.RuleSetting.IS_INHERITANCE_ENABLED_KEY;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+
+import junit.framework.TestCase;
+import org.alfresco.rest.api.model.rules.RuleSetting;
+import org.alfresco.rest.framework.core.exceptions.NotFoundException;
+import org.alfresco.service.Experimental;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.cmr.repository.StoreRef;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+/** Unit tests for {@link RuleSettingsImpl}. */
+@Experimental
+@RunWith (MockitoJUnitRunner.class)
+public class RuleSettingsImplTest extends TestCase
+{
+ private static final String FOLDER_ID = "dummy-folder-id";
+ private static final NodeRef FOLDER_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_ID);
+
+ @InjectMocks
+ private RuleSettingsImpl ruleSettings;
+ @Mock
+ private NodeValidator nodeValidatorMock;
+ @Mock
+ private NodeService nodeServiceMock;
+
+ @Before
+ @Override
+ public void setUp()
+ {
+ given(nodeValidatorMock.validateFolderNode(eq(FOLDER_ID), anyBoolean())).willReturn(FOLDER_NODE);
+ }
+
+ @Test
+ public void testGetRuleSetting_disabled()
+ {
+ given(nodeServiceMock.hasAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES)).willReturn(true);
+
+ // Call the method under test.
+ RuleSetting ruleSetting = ruleSettings.getRuleSetting(FOLDER_ID, IS_INHERITANCE_ENABLED_KEY);
+
+ RuleSetting expected = RuleSetting.builder().key(IS_INHERITANCE_ENABLED_KEY).value(false).create();
+ assertEquals(expected, ruleSetting);
+ }
+
+ @Test
+ public void testGetRuleSetting_enabled()
+ {
+ given(nodeServiceMock.hasAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES)).willReturn(false);
+
+ // Call the method under test.
+ RuleSetting ruleSetting = ruleSettings.getRuleSetting(FOLDER_ID, IS_INHERITANCE_ENABLED_KEY);
+
+ RuleSetting expected = RuleSetting.builder().key(IS_INHERITANCE_ENABLED_KEY).value(true).create();
+ assertEquals(expected, ruleSetting);
+ }
+
+ @Test
+ public void testGetRuleSetting_unrecognisedKey()
+ {
+ assertThatExceptionOfType(NotFoundException.class)
+ .isThrownBy(() -> ruleSettings.getRuleSetting(FOLDER_ID, "-fakeSetting-"));
+ }
+
+ @Test
+ public void testSetRuleSetting_enable()
+ {
+ RuleSetting ruleSetting = RuleSetting.builder().key(IS_INHERITANCE_ENABLED_KEY).value(true).create();
+
+ // Call the method under test.
+ RuleSetting actual = ruleSettings.setRuleSetting(FOLDER_ID, ruleSetting);
+
+ assertEquals(ruleSetting, actual);
+ then(nodeServiceMock).should().removeAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES);
+ }
+
+ @Test
+ public void testSetRuleSetting_disable()
+ {
+ RuleSetting ruleSetting = RuleSetting.builder().key(IS_INHERITANCE_ENABLED_KEY).value(false).create();
+
+ // Call the method under test.
+ RuleSetting actual = ruleSettings.setRuleSetting(FOLDER_ID, ruleSetting);
+
+ assertEquals(ruleSetting, actual);
+ then(nodeServiceMock).should().addAspect(FOLDER_NODE, ASPECT_IGNORE_INHERITED_RULES, emptyMap());
+ }
+
+ @Test
+ public void testSetRuleSetting_unrecognisedKey()
+ {
+ RuleSetting ruleSetting = RuleSetting.builder().key("-fakeSetting-").value(true).create();
+ assertThatExceptionOfType(NotFoundException.class)
+ .isThrownBy(() -> ruleSettings.setRuleSetting(FOLDER_ID, ruleSetting));
+ }
+
+ @Test
+ public void testSetRuleSetting_nonBooleanValue()
+ {
+ RuleSetting ruleSetting = RuleSetting.builder().key(IS_INHERITANCE_ENABLED_KEY).value(123456).create();
+
+ assertThatExceptionOfType(IllegalArgumentException.class)
+ .isThrownBy(() -> ruleSettings.setRuleSetting(FOLDER_ID, ruleSetting));
+ }
+}