mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3376 GET rule order within rule set.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.rules;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.alfresco.rest.RestTest;
|
||||
import org.alfresco.rest.model.RestRuleModel;
|
||||
import org.alfresco.rest.model.RestRuleSetModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
import org.alfresco.utility.model.SiteModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.alfresco.utility.model.UserModel;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test (groups = { TestGroup.RULES })
|
||||
public class ReorderRules extends RestTest
|
||||
{
|
||||
private UserModel user;
|
||||
private SiteModel site;
|
||||
|
||||
@BeforeClass (alwaysRun = true)
|
||||
public void dataPreparation()
|
||||
{
|
||||
STEP("Create a user and site.");
|
||||
user = dataUser.createRandomTestUser();
|
||||
site = dataSite.usingUser(user).createPublicRandomSite();
|
||||
}
|
||||
|
||||
/** Check we can get the ordered list of rules in a rule set. */
|
||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||
public void getOrderedRuleIds()
|
||||
{
|
||||
STEP("Create a folder containing three rules in the existing site");
|
||||
FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||
List<RestRuleModel> rules = IntStream.range(0, 3).mapToObj(index -> {
|
||||
RestRuleModel ruleModel = createRuleModel("ruleName");
|
||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(folder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||
}).collect(toList());
|
||||
|
||||
STEP("Get the default rule set for the folder including the ordered rule ids");
|
||||
RestRuleSetModel ruleSet = restClient.authenticateUser(user).withCoreAPI().usingNode(folder)
|
||||
.include("ruleIds").getDefaultRuleSet();
|
||||
|
||||
List<String> expectedRuleIds = rules.stream().map(RestRuleModel::getId).collect(toList());
|
||||
restClient.assertStatusCodeIs(OK);
|
||||
ruleSet.assertThat().field("ruleIds").is(expectedRuleIds);
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
@@ -123,7 +123,7 @@
|
||||
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
||||
<dependency.tas-utility.version>3.0.56</dependency.tas-utility.version>
|
||||
<dependency.rest-assured.version>5.2.0</dependency.rest-assured.version>
|
||||
<dependency.tas-restapi.version>1.124</dependency.tas-restapi.version>
|
||||
<dependency.tas-restapi.version>1.126</dependency.tas-restapi.version>
|
||||
<dependency.tas-email.version>1.9</dependency.tas-email.version>
|
||||
<dependency.tas-webdav.version>1.7</dependency.tas-webdav.version>
|
||||
<dependency.tas-ftp.version>1.7</dependency.tas-ftp.version>
|
||||
|
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.impl.rules;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import static org.alfresco.rest.api.model.rules.InclusionType.INHERITED;
|
||||
import static org.alfresco.rest.api.model.rules.InclusionType.LINKED;
|
||||
import static org.alfresco.rest.api.model.rules.InclusionType.OWNED;
|
||||
@@ -32,6 +34,8 @@ import static org.alfresco.rest.api.model.rules.InclusionType.OWNED;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.rest.api.impl.mapper.rules.RestRuleModelMapper;
|
||||
import org.alfresco.rest.api.model.rules.Rule;
|
||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
@@ -49,9 +53,11 @@ public class RuleSetLoader
|
||||
protected static final String LINKED_TO_BY = "linkedToBy";
|
||||
protected static final String IS_INHERITED = "isInherited";
|
||||
protected static final String IS_LINKED_TO = "isLinkedTo";
|
||||
protected static final String RULE_IDS = "ruleIds";
|
||||
private static final int MAX_INHERITED_BY_SIZE = 100;
|
||||
private NodeService nodeService;
|
||||
private RuleService ruleService;
|
||||
private RestRuleModelMapper restRuleModelMapper;
|
||||
|
||||
/**
|
||||
* Load a rule set for the given node ref.
|
||||
@@ -103,6 +109,10 @@ public class RuleSetLoader
|
||||
{
|
||||
ruleSet.setIsLinkedTo(loadIsLinkedTo(ruleSetNodeRef, parentRef));
|
||||
}
|
||||
if (includes.contains(RULE_IDS))
|
||||
{
|
||||
ruleSet.setRuleIds(loadRuleIds(parentRef));
|
||||
}
|
||||
}
|
||||
return ruleSet;
|
||||
}
|
||||
@@ -139,6 +149,14 @@ public class RuleSetLoader
|
||||
);
|
||||
}
|
||||
|
||||
private List<String> loadRuleIds(NodeRef folderNodeRef)
|
||||
{
|
||||
return ruleService.getRules(folderNodeRef, false).stream()
|
||||
.map(restRuleModelMapper::toRestModel)
|
||||
.map(Rule::getId)
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
@@ -148,4 +166,9 @@ public class RuleSetLoader
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
|
||||
public void setRestRuleModelMapper(RestRuleModelMapper restRuleModelMapper)
|
||||
{
|
||||
this.restRuleModelMapper = restRuleModelMapper;
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ public class RuleSet
|
||||
private List<NodeRef> linkedToBy;
|
||||
private Boolean isInherited;
|
||||
private Boolean isLinkedTo;
|
||||
private List<String> ruleIds;
|
||||
|
||||
public static RuleSet of(String id)
|
||||
{
|
||||
@@ -151,6 +152,16 @@ public class RuleSet
|
||||
return isLinkedTo;
|
||||
}
|
||||
|
||||
public List<String> getRuleIds()
|
||||
{
|
||||
return ruleIds;
|
||||
}
|
||||
|
||||
public void setRuleIds(List<String> ruleIds)
|
||||
{
|
||||
this.ruleIds = ruleIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -163,6 +174,7 @@ public class RuleSet
|
||||
.add("linkedToBy='" + linkedToBy + "'")
|
||||
.add("isInherited='" + isInherited + "'")
|
||||
.add("isLinkedTo='" + isLinkedTo + "'")
|
||||
.add("ruleIds='" + ruleIds + "'")
|
||||
.toString()
|
||||
+ '}';
|
||||
}
|
||||
@@ -181,13 +193,14 @@ public class RuleSet
|
||||
&& Objects.equals(inheritedBy, ruleSet.inheritedBy)
|
||||
&& Objects.equals(linkedToBy, ruleSet.linkedToBy)
|
||||
&& Objects.equals(isInherited, ruleSet.isInherited)
|
||||
&& Objects.equals(isLinkedTo, ruleSet.isLinkedTo);
|
||||
&& Objects.equals(isLinkedTo, ruleSet.isLinkedTo)
|
||||
&& Objects.equals(ruleIds, ruleSet.ruleIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy, isInherited, isLinkedTo);
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy, isInherited, isLinkedTo, ruleIds);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -204,6 +217,7 @@ public class RuleSet
|
||||
private List<NodeRef> linkedToBy;
|
||||
private Boolean isInherited;
|
||||
private Boolean isLinkedTo;
|
||||
private List<String> ruleIds;
|
||||
|
||||
public Builder id(String id)
|
||||
{
|
||||
@@ -247,6 +261,12 @@ public class RuleSet
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder ruleIds(List<String> ruleIds)
|
||||
{
|
||||
this.ruleIds = ruleIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RuleSet create()
|
||||
{
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
@@ -257,6 +277,7 @@ public class RuleSet
|
||||
ruleSet.setLinkedToBy(linkedToBy);
|
||||
ruleSet.setIsInherited(isInherited);
|
||||
ruleSet.setIsLinkedTo(isLinkedTo);
|
||||
ruleSet.setRuleIds(ruleIds);
|
||||
return ruleSet;
|
||||
}
|
||||
}
|
||||
|
@@ -864,6 +864,7 @@
|
||||
<bean id="ruleSetLoader" class="org.alfresco.rest.api.impl.rules.RuleSetLoader">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="ruleService" ref="RuleService" />
|
||||
<property name="restRuleModelMapper" ref="ruleMapper" />
|
||||
</bean>
|
||||
|
||||
<bean id="ruleSets" class="org.alfresco.rest.api.impl.rules.RuleSetsImpl">
|
||||
|
Reference in New Issue
Block a user