mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS_3362 GET rule set can include optional owningFolder field. (#1280)
* ACS_3362 GET rule set can include optional owningFolder field. [skip ci] * ACS_3362 Update to use release version of TAS. [tas] * ACS_3362 Refactor RuleSetLoader into its own class. [tas]
This commit is contained in:
@@ -53,6 +53,7 @@ public class GetRuleSetsTests extends RestTest
|
||||
private SiteModel site;
|
||||
private FolderModel ruleFolder;
|
||||
private RestRuleModel rule;
|
||||
private String ruleSetId;
|
||||
|
||||
@BeforeClass (alwaysRun = true)
|
||||
public void dataPreparation()
|
||||
@@ -66,6 +67,12 @@ public class GetRuleSetsTests extends RestTest
|
||||
RestRuleModel ruleModel = createRuleModel("ruleName");
|
||||
rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||
.createSingleRule(ruleModel);
|
||||
|
||||
STEP("Get the rule sets for the folder and find the rule set id");
|
||||
RestRuleSetModelsCollection ruleSets = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getListOfRuleSets();
|
||||
ruleSets.assertThat().entriesListCountIs(1);
|
||||
ruleSetId = ruleSets.getEntries().get(0).onModel().getId();
|
||||
}
|
||||
|
||||
/** Check we can get an empty list of rule sets. */
|
||||
@@ -108,16 +115,27 @@ public class GetRuleSetsTests extends RestTest
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/** Check we can get the id of the folder that owns a list of rule sets. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getRuleSetsAndOwningFolders()
|
||||
{
|
||||
STEP("Get the rule sets and owning folders");
|
||||
RestRuleSetModelsCollection ruleSets = restClient.authenticateUser(user).withCoreAPI()
|
||||
.usingNode(ruleFolder)
|
||||
.usingParams("include=owningFolder")
|
||||
.getListOfRuleSets();
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSets.getEntries().get(0).onModel()
|
||||
.assertThat().field("owningFolder").is(ruleFolder.getNodeRef())
|
||||
.assertThat().field("id").is(ruleSetId);
|
||||
ruleSets.assertThat().entriesListCountIs(1);
|
||||
}
|
||||
|
||||
/** Check we can get a rule set by its id. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
public void getRuleSetById()
|
||||
{
|
||||
STEP("Get the rule sets for the folder and find the rule set id");
|
||||
RestRuleSetModelsCollection ruleSets = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getListOfRuleSets();
|
||||
ruleSets.assertThat().entriesListCountIs(1);
|
||||
String ruleSetId = ruleSets.getEntries().get(0).onModel().getId();
|
||||
|
||||
STEP("Get the rule set using its rule set id");
|
||||
RestRuleSetModel ruleSet = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder)
|
||||
.getRuleSet(ruleSetId);
|
||||
@@ -150,12 +168,27 @@ public class GetRuleSetsTests extends RestTest
|
||||
}
|
||||
|
||||
/** Check we get 404 for a non-existing rule set id. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getRuleSetByNonExistingId()
|
||||
{
|
||||
STEP("Get the rule set using fake rule set id");
|
||||
String ruleSetId = "fake-rule-set-id";
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).getRuleSet(ruleSetId);
|
||||
String fakeRuleSetId = "fake-rule-set-id";
|
||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).getRuleSet(fakeRuleSetId);
|
||||
restClient.assertStatusCodeIs(NOT_FOUND);
|
||||
}
|
||||
|
||||
/** Check we can get the id of the folder that owns a rule set. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getRuleSetAndOwningFolder()
|
||||
{
|
||||
STEP("Get the rule set and owning folder");
|
||||
RestRuleSetModel ruleSet = restClient.authenticateUser(user).withCoreAPI()
|
||||
.usingNode(ruleFolder)
|
||||
.usingParams("include=owningFolder")
|
||||
.getRuleSet(ruleSetId);
|
||||
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("owningFolder").is(ruleFolder.getNodeRef())
|
||||
.assertThat().field("id").is(ruleSetId);
|
||||
}
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@@ -120,7 +120,7 @@
|
||||
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
||||
<dependency.tas-utility.version>3.0.49</dependency.tas-utility.version>
|
||||
<dependency.rest-assured.version>3.3.0</dependency.rest-assured.version>
|
||||
<dependency.tas-restapi.version>1.101</dependency.tas-restapi.version>
|
||||
<dependency.tas-restapi.version>1.102</dependency.tas-restapi.version>
|
||||
<dependency.tas-cmis.version>1.31</dependency.tas-cmis.version>
|
||||
<dependency.tas-email.version>1.8</dependency.tas-email.version>
|
||||
<dependency.tas-webdav.version>1.6</dependency.tas-webdav.version>
|
||||
|
@@ -37,12 +37,14 @@ import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/** Responsible for validating nodes when working with rules. */
|
||||
@Experimental
|
||||
public class NodeValidator
|
||||
{
|
||||
private static final String RULE_SET_EXPECTED_TYPE_NAME = "rule set";
|
||||
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
|
||||
/** Responsible for converting a NodeRef into a {@link RuleSet} object. */
|
||||
@Experimental
|
||||
public class RuleSetLoader
|
||||
{
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Load a rule set for the given node ref.
|
||||
*
|
||||
* @param ruleSetNodeRef The rule set node.
|
||||
* @param includes A list of fields to include.
|
||||
* @return The rule set object.
|
||||
*/
|
||||
protected RuleSet loadRuleSet(NodeRef ruleSetNodeRef, List<String> includes)
|
||||
{
|
||||
String ruleSetId = ruleSetNodeRef.getId();
|
||||
RuleSet ruleSet = RuleSet.of(ruleSetId);
|
||||
|
||||
if (includes != null && includes.contains("owningFolder"))
|
||||
{
|
||||
NodeRef parentRef = nodeService.getPrimaryParent(ruleSetNodeRef).getParentRef();
|
||||
ruleSet.setOwningFolder(parentRef);
|
||||
}
|
||||
return ruleSet;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
}
|
@@ -43,6 +43,7 @@ import org.alfresco.service.cmr.rule.RuleService;
|
||||
@Experimental
|
||||
public class RuleSetsImpl implements RuleSets
|
||||
{
|
||||
private RuleSetLoader ruleSetLoader;
|
||||
private RuleService ruleService;
|
||||
private NodeValidator validator;
|
||||
|
||||
@@ -53,8 +54,7 @@ public class RuleSetsImpl implements RuleSets
|
||||
|
||||
NodeRef ruleSetNode = ruleService.getRuleSetNode(folderNode);
|
||||
List<RuleSet> ruleSets = Optional.ofNullable(ruleSetNode)
|
||||
.map(NodeRef::getId)
|
||||
.map(RuleSet::of).stream().collect(toList());
|
||||
.map(nodeRef -> ruleSetLoader.loadRuleSet(nodeRef, includes)).stream().collect(toList());
|
||||
|
||||
return ListPage.of(ruleSets, paging);
|
||||
}
|
||||
@@ -65,7 +65,12 @@ public class RuleSetsImpl implements RuleSets
|
||||
NodeRef folderNode = validator.validateFolderNode(folderNodeId, false);
|
||||
NodeRef ruleSetNode = validator.validateRuleSetNode(ruleSetId, folderNode);
|
||||
|
||||
return RuleSet.of(ruleSetNode.getId());
|
||||
return ruleSetLoader.loadRuleSet(ruleSetNode, includes);
|
||||
}
|
||||
|
||||
public void setRuleSetLoader(RuleSetLoader ruleSetLoader)
|
||||
{
|
||||
this.ruleSetLoader = ruleSetLoader;
|
||||
}
|
||||
|
||||
public void setValidator(NodeValidator validator)
|
||||
|
@@ -29,6 +29,7 @@ package org.alfresco.rest.api.model.rules;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
@Experimental
|
||||
public class RuleSet
|
||||
@@ -36,6 +37,7 @@ public class RuleSet
|
||||
public static final String DEFAULT_ID = "-default-";
|
||||
|
||||
private String id;
|
||||
private NodeRef owningFolder;
|
||||
|
||||
public static RuleSet of(String id)
|
||||
{
|
||||
@@ -62,6 +64,16 @@ public class RuleSet
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public NodeRef getOwningFolder()
|
||||
{
|
||||
return owningFolder;
|
||||
}
|
||||
|
||||
public void setOwningFolder(NodeRef owningFolder)
|
||||
{
|
||||
this.owningFolder = owningFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -76,13 +88,14 @@ public class RuleSet
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RuleSet ruleSet = (RuleSet) o;
|
||||
return Objects.equals(id, ruleSet.id);
|
||||
return Objects.equals(id, ruleSet.id)
|
||||
&& Objects.equals(owningFolder, ruleSet.owningFolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id);
|
||||
return Objects.hash(id, owningFolder);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -93,6 +106,7 @@ public class RuleSet
|
||||
public static class Builder
|
||||
{
|
||||
private String id;
|
||||
private NodeRef owningFolder;
|
||||
|
||||
public Builder id(String id)
|
||||
{
|
||||
@@ -100,10 +114,17 @@ public class RuleSet
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder owningFolder(NodeRef owningFolder)
|
||||
{
|
||||
this.owningFolder = owningFolder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RuleSet create()
|
||||
{
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
ruleSet.setId(id);
|
||||
ruleSet.setOwningFolder(owningFolder);
|
||||
return ruleSet;
|
||||
}
|
||||
}
|
||||
|
@@ -860,7 +860,12 @@
|
||||
<property name="rules" ref="Rules" />
|
||||
</bean>
|
||||
|
||||
<bean id="ruleSetLoader" class="org.alfresco.rest.api.impl.rules.RuleSetLoader">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
</bean>
|
||||
|
||||
<bean id="ruleSets" class="org.alfresco.rest.api.impl.rules.RuleSetsImpl">
|
||||
<property name="ruleSetLoader" ref="ruleSetLoader" />
|
||||
<property name="validator" ref="nodeValidator" />
|
||||
<property name="ruleService" ref="RuleService" />
|
||||
</bean>
|
||||
|
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
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;
|
||||
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 RuleSetLoader}. */
|
||||
@Experimental
|
||||
@RunWith (MockitoJUnitRunner.class)
|
||||
public class RuleSetLoaderTest extends TestCase
|
||||
{
|
||||
private static final String FOLDER_ID = "dummy-folder-id";
|
||||
private static final String RULE_SET_ID = "dummy-rule-set-id";
|
||||
private static final NodeRef FOLDER_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_ID);
|
||||
private static final NodeRef RULE_SET_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, RULE_SET_ID);
|
||||
|
||||
@InjectMocks
|
||||
private RuleSetLoader ruleSetLoader;
|
||||
@Mock
|
||||
private NodeService nodeServiceMock;
|
||||
@Mock
|
||||
private ChildAssociationRef ruleSetAssociationMock;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
given(ruleSetAssociationMock.getParentRef()).willReturn(FOLDER_NODE);
|
||||
given(nodeServiceMock.getPrimaryParent(RULE_SET_NODE)).willReturn(ruleSetAssociationMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadRuleSet_noIncludes()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, null);
|
||||
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadRuleSet_includeOwningFolder()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, List.of("owningFolder"));
|
||||
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).owningFolder(FOLDER_NODE).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
@@ -40,7 +40,9 @@ import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.Experimental;
|
||||
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;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.junit.Before;
|
||||
@@ -61,13 +63,18 @@ public class RuleSetsImplTest extends TestCase
|
||||
private static final NodeRef FOLDER_NODE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, FOLDER_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<String> INCLUDES = List.of("dummy-includes");
|
||||
|
||||
@InjectMocks
|
||||
private RuleSetsImpl ruleSets;
|
||||
@Mock
|
||||
private RuleSetLoader ruleSetLoaderMock;
|
||||
@Mock
|
||||
private NodeValidator nodeValidatorMock;
|
||||
@Mock
|
||||
private RuleService ruleServiceMock;
|
||||
@Mock
|
||||
private RuleSet ruleSetMock;
|
||||
|
||||
@Before
|
||||
@Override
|
||||
@@ -80,13 +87,14 @@ public class RuleSetsImplTest extends TestCase
|
||||
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, INCLUDES)).willReturn(ruleSetMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleSets()
|
||||
{
|
||||
// Call the method under test.
|
||||
CollectionWithPagingInfo<RuleSet> actual = ruleSets.getRuleSets(FOLDER_ID, null, PAGING);
|
||||
CollectionWithPagingInfo<RuleSet> actual = ruleSets.getRuleSets(FOLDER_ID, INCLUDES, PAGING);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
@@ -94,7 +102,7 @@ public class RuleSetsImplTest extends TestCase
|
||||
then(ruleServiceMock).should().getRuleSetNode(FOLDER_NODE);
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
Collection<RuleSet> expected = List.of(RuleSet.of(RULE_SET_ID));
|
||||
Collection<RuleSet> expected = List.of(ruleSetMock);
|
||||
assertEquals(expected, actual.getCollection());
|
||||
assertEquals(PAGING, actual.getPaging());
|
||||
}
|
||||
@@ -106,7 +114,7 @@ public class RuleSetsImplTest extends TestCase
|
||||
given(ruleServiceMock.getRuleSetNode(FOLDER_NODE)).willReturn(null);
|
||||
|
||||
// Call the method under test.
|
||||
CollectionWithPagingInfo<RuleSet> actual = ruleSets.getRuleSets(FOLDER_ID, null, PAGING);
|
||||
CollectionWithPagingInfo<RuleSet> actual = ruleSets.getRuleSets(FOLDER_ID, INCLUDES, PAGING);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
@@ -122,12 +130,12 @@ public class RuleSetsImplTest extends TestCase
|
||||
public void testGetRuleSetById()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSets.getRuleSetById(FOLDER_ID, RULE_SET_ID, null);
|
||||
RuleSet actual = ruleSets.getRuleSetById(FOLDER_ID, RULE_SET_ID, INCLUDES);
|
||||
|
||||
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID, false);
|
||||
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID, FOLDER_NODE);
|
||||
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
assertEquals(RuleSet.of(RULE_SET_ID), actual);
|
||||
assertEquals(ruleSetMock, actual);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user