mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3366 Add support for isLinkedTo to GET rule sets. (#1427)
* ACS-3364 Add permission handling to linkedToBy. * ACS-3366 Add support for isLinkedTo to GET rule sets.
This commit is contained in:
@@ -48,6 +48,7 @@ public class RuleSetLoader
|
||||
protected static final String INHERITED_BY = "inheritedBy";
|
||||
protected static final String LINKED_TO_BY = "linkedToBy";
|
||||
protected static final String IS_INHERITED = "isInherited";
|
||||
protected static final String IS_LINKED_TO = "isLinkedTo";
|
||||
private static final int MAX_INHERITED_BY_SIZE = 100;
|
||||
private NodeService nodeService;
|
||||
private RuleService ruleService;
|
||||
@@ -98,6 +99,10 @@ public class RuleSetLoader
|
||||
{
|
||||
ruleSet.setIsInherited(loadIsInherited(ruleSetNodeRef));
|
||||
}
|
||||
if (includes.contains(IS_LINKED_TO))
|
||||
{
|
||||
ruleSet.setIsLinkedTo(loadIsLinkedTo(ruleSetNodeRef, parentRef));
|
||||
}
|
||||
}
|
||||
return ruleSet;
|
||||
}
|
||||
@@ -117,6 +122,23 @@ public class RuleSetLoader
|
||||
return AuthenticationUtil.runAsSystem(() -> !ruleService.getFoldersInheritingRuleSet(ruleSetNodeRef, 1).isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any parents of the rule set node are not the owning folder.
|
||||
*
|
||||
* @param ruleSetNodeRef The rule set node.
|
||||
* @param parentRef The owning folder.
|
||||
* @return True if another folder links to the rule set.
|
||||
*/
|
||||
private Boolean loadIsLinkedTo(NodeRef ruleSetNodeRef, NodeRef parentRef)
|
||||
{
|
||||
return AuthenticationUtil.runAsSystem(() ->
|
||||
nodeService.getParentAssocs(ruleSetNodeRef)
|
||||
.stream()
|
||||
.map(ChildAssociationRef::getParentRef)
|
||||
.anyMatch(folder -> !folder.equals(parentRef))
|
||||
);
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
|
@@ -44,6 +44,7 @@ public class RuleSet
|
||||
private List<NodeRef> inheritedBy;
|
||||
private List<NodeRef> linkedToBy;
|
||||
private Boolean isInherited;
|
||||
private Boolean isLinkedTo;
|
||||
|
||||
public static RuleSet of(String id)
|
||||
{
|
||||
@@ -130,6 +131,26 @@ public class RuleSet
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag indicating that the rule set is linked to by a folder.
|
||||
*
|
||||
* @param isLinkedTo The flag.
|
||||
*/
|
||||
public void setIsLinkedTo(Boolean isLinkedTo)
|
||||
{
|
||||
this.isLinkedTo = isLinkedTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find if the rule set is linked to by a folder.
|
||||
*
|
||||
* @return The value of the flag.
|
||||
*/
|
||||
public Boolean getIsLinkedTo()
|
||||
{
|
||||
return isLinkedTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -141,6 +162,7 @@ public class RuleSet
|
||||
.add("inheritedBy='" + inheritedBy + "'")
|
||||
.add("linkedToBy='" + linkedToBy + "'")
|
||||
.add("isInherited='" + isInherited + "'")
|
||||
.add("isLinkedTo='" + isLinkedTo + "'")
|
||||
.toString()
|
||||
+ '}';
|
||||
}
|
||||
@@ -158,13 +180,14 @@ public class RuleSet
|
||||
&& inclusionType == ruleSet.inclusionType
|
||||
&& Objects.equals(inheritedBy, ruleSet.inheritedBy)
|
||||
&& Objects.equals(linkedToBy, ruleSet.linkedToBy)
|
||||
&& Objects.equals(isInherited, ruleSet.isInherited);
|
||||
&& Objects.equals(isInherited, ruleSet.isInherited)
|
||||
&& Objects.equals(isLinkedTo, ruleSet.isLinkedTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy, isInherited);
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy, linkedToBy, isInherited, isLinkedTo);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -180,6 +203,7 @@ public class RuleSet
|
||||
private List<NodeRef> inheritedBy;
|
||||
private List<NodeRef> linkedToBy;
|
||||
private Boolean isInherited;
|
||||
private Boolean isLinkedTo;
|
||||
|
||||
public Builder id(String id)
|
||||
{
|
||||
@@ -217,6 +241,12 @@ public class RuleSet
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder isLinkedTo(Boolean isLinkedTo)
|
||||
{
|
||||
this.isLinkedTo = isLinkedTo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RuleSet create()
|
||||
{
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
@@ -226,6 +256,7 @@ public class RuleSet
|
||||
ruleSet.setInheritedBy(inheritedBy);
|
||||
ruleSet.setLinkedToBy(linkedToBy);
|
||||
ruleSet.setIsInherited(isInherited);
|
||||
ruleSet.setIsLinkedTo(isLinkedTo);
|
||||
return ruleSet;
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,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.IS_LINKED_TO;
|
||||
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;
|
||||
@@ -170,4 +171,14 @@ public class RuleSetLoaderTest extends TestCase
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).isInherited(true).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadRuleSet_isLinkedTo()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, FOLDER_NODE, List.of(IS_LINKED_TO));
|
||||
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).isLinkedTo(true).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user