ACS-3365 Add support for GET rule sets isInherited. (#1415)

This commit is contained in:
Tom Page
2022-09-21 09:00:34 +01:00
committed by GitHub
parent 02ba54ab3a
commit 1c69cd2e61
4 changed files with 143 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ import static org.alfresco.rest.api.model.rules.InclusionType.OWNED;
import java.util.List;
import java.util.stream.Collectors;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.rest.api.model.rules.RuleSet;
import org.alfresco.service.Experimental;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -47,6 +48,7 @@ public class RuleSetLoader
protected static final String INCLUSION_TYPE = "inclusionType";
protected static final String INHERITED_BY = "inheritedBy";
protected static final String LINKED_TO_BY = "linkedToBy";
protected static final String IS_INHERITED = "isInherited";
private static final int MAX_INHERITED_BY_SIZE = 100;
private NodeService nodeService;
private RuleService ruleService;
@@ -98,6 +100,10 @@ public class RuleSetLoader
.collect(Collectors.toList());
ruleSet.setLinkedToBy(linkedToBy);
}
if (includes.contains(IS_INHERITED))
{
ruleSet.setIsInherited(loadIsInherited(ruleSetNodeRef));
}
}
return ruleSet;
}
@@ -107,6 +113,11 @@ public class RuleSetLoader
return ruleService.getFoldersInheritingRuleSet(ruleSetNodeRef, MAX_INHERITED_BY_SIZE);
}
private boolean loadIsInherited(NodeRef ruleSetNodeRef)
{
return AuthenticationUtil.runAsSystem(() -> !ruleService.getFoldersInheritingRuleSet(ruleSetNodeRef, 1).isEmpty());
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;

View File

@@ -43,6 +43,7 @@ public class RuleSet
private InclusionType inclusionType;
private List<NodeRef> inheritedBy;
private List<NodeRef> linkedToBy;
private Boolean isInherited;
public static RuleSet of(String id)
{
@@ -109,6 +110,26 @@ public class RuleSet
this.linkedToBy = linkedToBy;
}
/**
* Set a flag indicating that the rule set is inherited by a folder.
*
* @param inherited The flag.
*/
public void setIsInherited(Boolean inherited)
{
isInherited = inherited;
}
/**
* Find if the rule set is inherited by a folder.
*
* @return The value of the flag.
*/
public Boolean getIsInherited()
{
return isInherited;
}
@Override
public String toString()
{
@@ -119,6 +140,7 @@ public class RuleSet
.add("inclusionType='" + inclusionType + "'")
.add("inheritedBy='" + inheritedBy + "'")
.add("linkedToBy='" + linkedToBy + "'")
.add("isInherited='" + isInherited + "'")
.toString()
+ '}';
}
@@ -135,13 +157,14 @@ public class RuleSet
&& Objects.equals(owningFolder, ruleSet.owningFolder)
&& inclusionType == ruleSet.inclusionType
&& Objects.equals(inheritedBy, ruleSet.inheritedBy)
&& Objects.equals(linkedToBy, ruleSet.linkedToBy);
&& Objects.equals(linkedToBy, ruleSet.linkedToBy)
&& Objects.equals(isInherited, ruleSet.isInherited);
}
@Override
public int hashCode()
{
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy);
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy, isInherited);
}
public static Builder builder()
@@ -156,6 +179,7 @@ public class RuleSet
private InclusionType inclusionType;
private List<NodeRef> inheritedBy;
private List<NodeRef> linkedToBy;
private Boolean isInherited;
public Builder id(String id)
{
@@ -187,6 +211,12 @@ public class RuleSet
return this;
}
public Builder isInherited(Boolean isInherited)
{
this.isInherited = isInherited;
return this;
}
public RuleSet create()
{
final RuleSet ruleSet = new RuleSet();
@@ -195,6 +225,7 @@ public class RuleSet
ruleSet.setInclusionType(inclusionType);
ruleSet.setInheritedBy(inheritedBy);
ruleSet.setLinkedToBy(linkedToBy);
ruleSet.setIsInherited(isInherited);
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.IS_INHERITED;
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;
@@ -159,4 +160,14 @@ public class RuleSetLoaderTest extends TestCase
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).linkedToBy(List.of(LINKING_FOLDER)).create();
assertEquals(expected, actual);
}
@Test
public void testLoadRuleSet_isInherited()
{
// Call the method under test.
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, FOLDER_NODE, List.of(IS_INHERITED));
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).isInherited(true).create();
assertEquals(expected, actual);
}
}