mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3364 Add support for linkedToBy field in GET rule sets. (#1402)
* ACS-3364 Update TAS REST API for linkedTo field. * ACS-3364 TAS test for linkedToBy field. * ACS-3364 Implementation for linkedToBy field.
This commit is contained in:
@@ -27,6 +27,7 @@ package org.alfresco.rest.rules;
|
|||||||
|
|
||||||
import static org.alfresco.rest.requests.RuleSettings.IS_INHERITANCE_ENABLED;
|
import static org.alfresco.rest.requests.RuleSettings.IS_INHERITANCE_ENABLED;
|
||||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||||
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModelWithDefaultValues;
|
||||||
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModelWithModifiedValues;
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModelWithModifiedValues;
|
||||||
import static org.alfresco.utility.report.log.Step.STEP;
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -322,6 +323,43 @@ public class GetRuleSetsTests extends RestTest
|
|||||||
.assertThat().field("id").is(ruleSetId);
|
.assertThat().field("id").is(ruleSetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check we can get the folders that link to a rule set and that this respects permissions. */
|
||||||
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
|
public void getRuleSetsAndLinkedToBy()
|
||||||
|
{
|
||||||
|
STEP("Create a site owned by admin and add user as a contributor");
|
||||||
|
SiteModel siteModel = dataSite.usingAdmin().createPrivateRandomSite();
|
||||||
|
dataUser.addUserToSite(user, siteModel, UserRole.SiteContributor);
|
||||||
|
|
||||||
|
STEP("Create the folder structure");
|
||||||
|
FolderModel ruleFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||||
|
FolderModel publicFolder = dataContent.usingUser(user).usingSite(siteModel).createFolder();
|
||||||
|
FolderModel privateFolder = dataContent.usingAdmin().usingSite(siteModel).createFolder();
|
||||||
|
dataContent.usingAdmin().usingResource(privateFolder).setInheritPermissions(false);
|
||||||
|
|
||||||
|
STEP("Remove the user from the site");
|
||||||
|
dataUser.removeUserFromSite(user, siteModel);
|
||||||
|
|
||||||
|
STEP("Create a rule in the folder and link to it from the other two.");
|
||||||
|
RestRuleModel ruleModel = createRuleModelWithDefaultValues();
|
||||||
|
coreAPIForUser().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
|
RestRuleSetModelsCollection ruleSets = coreAPIForAdmin().usingNode(ruleFolder).getListOfRuleSets();
|
||||||
|
String ruleSetId = ruleSets.getEntries().get(0).onModel().getId();
|
||||||
|
RestRuleSetLinkModel ruleSetLink = new RestRuleSetLinkModel();
|
||||||
|
ruleSetLink.setId(ruleFolder.getNodeRef());
|
||||||
|
coreAPIForUser().usingNode(publicFolder).createRuleLink(ruleSetLink);
|
||||||
|
coreAPIForUser().usingNode(privateFolder).createRuleLink(ruleSetLink);
|
||||||
|
|
||||||
|
STEP("Get the rule set and linkedToBy field");
|
||||||
|
RestRuleSetModel ruleSet = coreAPIForUser().usingNode(ruleFolder)
|
||||||
|
.include("linkedToBy")
|
||||||
|
.getRuleSet(ruleSetId);
|
||||||
|
|
||||||
|
restClient.assertStatusCodeIs(OK);
|
||||||
|
ruleSet.assertThat().field("linkedToBy").is(List.of(publicFolder.getNodeRef()))
|
||||||
|
.assertThat().field("id").is(ruleSetId);
|
||||||
|
}
|
||||||
|
|
||||||
private RestCoreAPI coreAPIForUser()
|
private RestCoreAPI coreAPIForUser()
|
||||||
{
|
{
|
||||||
return restClient.authenticateUser(user).withCoreAPI();
|
return restClient.authenticateUser(user).withCoreAPI();
|
||||||
|
2
pom.xml
2
pom.xml
@@ -123,7 +123,7 @@
|
|||||||
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
<dependency.mariadb.version>2.7.4</dependency.mariadb.version>
|
||||||
<dependency.tas-utility.version>3.0.49</dependency.tas-utility.version>
|
<dependency.tas-utility.version>3.0.49</dependency.tas-utility.version>
|
||||||
<dependency.rest-assured.version>5.2.0</dependency.rest-assured.version>
|
<dependency.rest-assured.version>5.2.0</dependency.rest-assured.version>
|
||||||
<dependency.tas-restapi.version>1.117</dependency.tas-restapi.version>
|
<dependency.tas-restapi.version>1.119</dependency.tas-restapi.version>
|
||||||
<dependency.tas-cmis.version>1.32</dependency.tas-cmis.version>
|
<dependency.tas-cmis.version>1.32</dependency.tas-cmis.version>
|
||||||
<dependency.tas-email.version>1.9</dependency.tas-email.version>
|
<dependency.tas-email.version>1.9</dependency.tas-email.version>
|
||||||
<dependency.tas-webdav.version>1.7</dependency.tas-webdav.version>
|
<dependency.tas-webdav.version>1.7</dependency.tas-webdav.version>
|
||||||
|
@@ -30,6 +30,7 @@ import static org.alfresco.rest.api.model.rules.InclusionType.LINKED;
|
|||||||
import static org.alfresco.rest.api.model.rules.InclusionType.OWNED;
|
import static org.alfresco.rest.api.model.rules.InclusionType.OWNED;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.alfresco.rest.api.model.rules.RuleSet;
|
import org.alfresco.rest.api.model.rules.RuleSet;
|
||||||
import org.alfresco.service.Experimental;
|
import org.alfresco.service.Experimental;
|
||||||
@@ -45,7 +46,8 @@ public class RuleSetLoader
|
|||||||
protected static final String OWNING_FOLDER = "owningFolder";
|
protected static final String OWNING_FOLDER = "owningFolder";
|
||||||
protected static final String INCLUSION_TYPE = "inclusionType";
|
protected static final String INCLUSION_TYPE = "inclusionType";
|
||||||
protected static final String INHERITED_BY = "inheritedBy";
|
protected static final String INHERITED_BY = "inheritedBy";
|
||||||
public static final int MAX_INHERITED_BY_SIZE = 100;
|
protected static final String LINKED_TO_BY = "linkedToBy";
|
||||||
|
private static final int MAX_INHERITED_BY_SIZE = 100;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
private RuleService ruleService;
|
private RuleService ruleService;
|
||||||
|
|
||||||
@@ -87,6 +89,15 @@ public class RuleSetLoader
|
|||||||
{
|
{
|
||||||
ruleSet.setInheritedBy(loadInheritedBy(ruleSetNodeRef));
|
ruleSet.setInheritedBy(loadInheritedBy(ruleSetNodeRef));
|
||||||
}
|
}
|
||||||
|
if (includes.contains(LINKED_TO_BY))
|
||||||
|
{
|
||||||
|
List<NodeRef> linkedToBy = nodeService.getParentAssocs(ruleSetNodeRef)
|
||||||
|
.stream()
|
||||||
|
.map(ChildAssociationRef::getParentRef)
|
||||||
|
.filter(folder -> !folder.equals(parentRef))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
ruleSet.setLinkedToBy(linkedToBy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ruleSet;
|
return ruleSet;
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ public class RuleSet
|
|||||||
private NodeRef owningFolder;
|
private NodeRef owningFolder;
|
||||||
private InclusionType inclusionType;
|
private InclusionType inclusionType;
|
||||||
private List<NodeRef> inheritedBy;
|
private List<NodeRef> inheritedBy;
|
||||||
|
private List<NodeRef> linkedToBy;
|
||||||
|
|
||||||
public static RuleSet of(String id)
|
public static RuleSet of(String id)
|
||||||
{
|
{
|
||||||
@@ -98,6 +99,16 @@ public class RuleSet
|
|||||||
this.inheritedBy = inheritedBy;
|
this.inheritedBy = inheritedBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<NodeRef> getLinkedToBy()
|
||||||
|
{
|
||||||
|
return linkedToBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLinkedToBy(List<NodeRef> linkedToBy)
|
||||||
|
{
|
||||||
|
this.linkedToBy = linkedToBy;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
@@ -107,6 +118,7 @@ public class RuleSet
|
|||||||
.add("owningFolder='" + owningFolder + "'")
|
.add("owningFolder='" + owningFolder + "'")
|
||||||
.add("inclusionType='" + inclusionType + "'")
|
.add("inclusionType='" + inclusionType + "'")
|
||||||
.add("inheritedBy='" + inheritedBy + "'")
|
.add("inheritedBy='" + inheritedBy + "'")
|
||||||
|
.add("linkedToBy='" + linkedToBy + "'")
|
||||||
.toString()
|
.toString()
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
@@ -122,13 +134,14 @@ public class RuleSet
|
|||||||
return Objects.equals(id, ruleSet.id)
|
return Objects.equals(id, ruleSet.id)
|
||||||
&& Objects.equals(owningFolder, ruleSet.owningFolder)
|
&& Objects.equals(owningFolder, ruleSet.owningFolder)
|
||||||
&& inclusionType == ruleSet.inclusionType
|
&& inclusionType == ruleSet.inclusionType
|
||||||
&& Objects.equals(inheritedBy, ruleSet.inheritedBy);
|
&& Objects.equals(inheritedBy, ruleSet.inheritedBy)
|
||||||
|
&& Objects.equals(linkedToBy, ruleSet.linkedToBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy);
|
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder()
|
public static Builder builder()
|
||||||
@@ -142,6 +155,7 @@ public class RuleSet
|
|||||||
private NodeRef owningFolder;
|
private NodeRef owningFolder;
|
||||||
private InclusionType inclusionType;
|
private InclusionType inclusionType;
|
||||||
private List<NodeRef> inheritedBy;
|
private List<NodeRef> inheritedBy;
|
||||||
|
private List<NodeRef> linkedToBy;
|
||||||
|
|
||||||
public Builder id(String id)
|
public Builder id(String id)
|
||||||
{
|
{
|
||||||
@@ -167,6 +181,12 @@ public class RuleSet
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder linkedToBy(List<NodeRef> linkedToBy)
|
||||||
|
{
|
||||||
|
this.linkedToBy = linkedToBy;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public RuleSet create()
|
public RuleSet create()
|
||||||
{
|
{
|
||||||
final RuleSet ruleSet = new RuleSet();
|
final RuleSet ruleSet = new RuleSet();
|
||||||
@@ -174,6 +194,7 @@ public class RuleSet
|
|||||||
ruleSet.setOwningFolder(owningFolder);
|
ruleSet.setOwningFolder(owningFolder);
|
||||||
ruleSet.setInclusionType(inclusionType);
|
ruleSet.setInclusionType(inclusionType);
|
||||||
ruleSet.setInheritedBy(inheritedBy);
|
ruleSet.setInheritedBy(inheritedBy);
|
||||||
|
ruleSet.setLinkedToBy(linkedToBy);
|
||||||
return ruleSet;
|
return ruleSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.rest.api.impl.rules;
|
|||||||
|
|
||||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.INCLUSION_TYPE;
|
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.INCLUSION_TYPE;
|
||||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.INHERITED_BY;
|
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.INHERITED_BY;
|
||||||
|
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.LINKED_TO_BY;
|
||||||
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.OWNING_FOLDER;
|
import static org.alfresco.rest.api.impl.rules.RuleSetLoader.OWNING_FOLDER;
|
||||||
import static org.alfresco.rest.api.model.rules.InclusionType.INHERITED;
|
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.LINKED;
|
||||||
@@ -148,4 +149,14 @@ public class RuleSetLoaderTest extends TestCase
|
|||||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).inheritedBy(List.of(INHERITING_FOLDER)).create();
|
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).inheritedBy(List.of(INHERITING_FOLDER)).create();
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadRuleSet_linkedToBy()
|
||||||
|
{
|
||||||
|
// Call the method under test.
|
||||||
|
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, FOLDER_NODE, List.of(LINKED_TO_BY));
|
||||||
|
|
||||||
|
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).linkedToBy(List.of(LINKING_FOLDER)).create();
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user