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:
Tom Page
2022-09-20 08:09:29 +01:00
committed by GitHub
parent 15ba054b16
commit d290c129bc
5 changed files with 85 additions and 4 deletions

View File

@@ -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 java.util.List;
import java.util.stream.Collectors;
import org.alfresco.rest.api.model.rules.RuleSet;
import org.alfresco.service.Experimental;
@@ -45,7 +46,8 @@ public class RuleSetLoader
protected static final String OWNING_FOLDER = "owningFolder";
protected static final String INCLUSION_TYPE = "inclusionType";
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 RuleService ruleService;
@@ -87,6 +89,15 @@ public class RuleSetLoader
{
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;
}

View File

@@ -42,6 +42,7 @@ public class RuleSet
private NodeRef owningFolder;
private InclusionType inclusionType;
private List<NodeRef> inheritedBy;
private List<NodeRef> linkedToBy;
public static RuleSet of(String id)
{
@@ -98,6 +99,16 @@ public class RuleSet
this.inheritedBy = inheritedBy;
}
public List<NodeRef> getLinkedToBy()
{
return linkedToBy;
}
public void setLinkedToBy(List<NodeRef> linkedToBy)
{
this.linkedToBy = linkedToBy;
}
@Override
public String toString()
{
@@ -107,6 +118,7 @@ public class RuleSet
.add("owningFolder='" + owningFolder + "'")
.add("inclusionType='" + inclusionType + "'")
.add("inheritedBy='" + inheritedBy + "'")
.add("linkedToBy='" + linkedToBy + "'")
.toString()
+ '}';
}
@@ -122,13 +134,14 @@ public class RuleSet
return Objects.equals(id, ruleSet.id)
&& Objects.equals(owningFolder, ruleSet.owningFolder)
&& inclusionType == ruleSet.inclusionType
&& Objects.equals(inheritedBy, ruleSet.inheritedBy);
&& Objects.equals(inheritedBy, ruleSet.inheritedBy)
&& Objects.equals(linkedToBy, ruleSet.linkedToBy);
}
@Override
public int hashCode()
{
return Objects.hash(id, owningFolder, inclusionType, inheritedBy);
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy);
}
public static Builder builder()
@@ -142,6 +155,7 @@ public class RuleSet
private NodeRef owningFolder;
private InclusionType inclusionType;
private List<NodeRef> inheritedBy;
private List<NodeRef> linkedToBy;
public Builder id(String id)
{
@@ -167,6 +181,12 @@ public class RuleSet
return this;
}
public Builder linkedToBy(List<NodeRef> linkedToBy)
{
this.linkedToBy = linkedToBy;
return this;
}
public RuleSet create()
{
final RuleSet ruleSet = new RuleSet();
@@ -174,6 +194,7 @@ public class RuleSet
ruleSet.setOwningFolder(owningFolder);
ruleSet.setInclusionType(inclusionType);
ruleSet.setInheritedBy(inheritedBy);
ruleSet.setLinkedToBy(linkedToBy);
return ruleSet;
}
}

View File

@@ -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.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.model.rules.InclusionType.INHERITED;
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();
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);
}
}