mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3363 Support inheritedBy in GET rule sets. (#1387)
* ACS-3363 E2E test for inheritedBy. * ACS-3363 Support optional inheritedBy field in GET rule sets. * ACS-3363 Update to new version of TAS REST API. * ACS-3363 Remove user from private site before calling method under test.
This commit is contained in:
@@ -36,6 +36,7 @@ import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
|
||||
/** Responsible for converting a NodeRef into a {@link RuleSet} object. */
|
||||
@Experimental
|
||||
@@ -43,7 +44,10 @@ 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;
|
||||
private NodeService nodeService;
|
||||
private RuleService ruleService;
|
||||
|
||||
/**
|
||||
* Load a rule set for the given node ref.
|
||||
@@ -79,12 +83,26 @@ public class RuleSetLoader
|
||||
ruleSet.setInclusionType(linked ? LINKED : INHERITED);
|
||||
}
|
||||
}
|
||||
if (includes.contains(INHERITED_BY))
|
||||
{
|
||||
ruleSet.setInheritedBy(loadInheritedBy(ruleSetNodeRef));
|
||||
}
|
||||
}
|
||||
return ruleSet;
|
||||
}
|
||||
|
||||
private List<NodeRef> loadInheritedBy(NodeRef ruleSetNodeRef)
|
||||
{
|
||||
return ruleService.getFoldersInheritingRuleSet(ruleSetNodeRef, MAX_INHERITED_BY_SIZE);
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setRuleService(RuleService ruleService)
|
||||
{
|
||||
this.ruleService = ruleService;
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
@@ -40,6 +41,7 @@ public class RuleSet
|
||||
private String id;
|
||||
private NodeRef owningFolder;
|
||||
private InclusionType inclusionType;
|
||||
private List<NodeRef> inheritedBy;
|
||||
|
||||
public static RuleSet of(String id)
|
||||
{
|
||||
@@ -86,6 +88,16 @@ public class RuleSet
|
||||
this.inclusionType = inclusionType;
|
||||
}
|
||||
|
||||
public List<NodeRef> getInheritedBy()
|
||||
{
|
||||
return inheritedBy;
|
||||
}
|
||||
|
||||
public void setInheritedBy(List<NodeRef> inheritedBy)
|
||||
{
|
||||
this.inheritedBy = inheritedBy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
@@ -94,6 +106,7 @@ public class RuleSet
|
||||
.add("id='" + id + "'")
|
||||
.add("owningFolder='" + owningFolder + "'")
|
||||
.add("inclusionType='" + inclusionType + "'")
|
||||
.add("inheritedBy='" + inheritedBy + "'")
|
||||
.toString()
|
||||
+ '}';
|
||||
}
|
||||
@@ -108,13 +121,14 @@ public class RuleSet
|
||||
RuleSet ruleSet = (RuleSet) o;
|
||||
return Objects.equals(id, ruleSet.id)
|
||||
&& Objects.equals(owningFolder, ruleSet.owningFolder)
|
||||
&& inclusionType == ruleSet.inclusionType;
|
||||
&& inclusionType == ruleSet.inclusionType
|
||||
&& Objects.equals(inheritedBy, ruleSet.inheritedBy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(id, owningFolder, inclusionType);
|
||||
return Objects.hash(id, owningFolder, inclusionType, inheritedBy);
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -127,6 +141,7 @@ public class RuleSet
|
||||
private String id;
|
||||
private NodeRef owningFolder;
|
||||
private InclusionType inclusionType;
|
||||
private List<NodeRef> inheritedBy;
|
||||
|
||||
public Builder id(String id)
|
||||
{
|
||||
@@ -146,12 +161,19 @@ public class RuleSet
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder inheritedBy(List<NodeRef> inheritedBy)
|
||||
{
|
||||
this.inheritedBy = inheritedBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RuleSet create()
|
||||
{
|
||||
final RuleSet ruleSet = new RuleSet();
|
||||
ruleSet.setId(id);
|
||||
ruleSet.setOwningFolder(owningFolder);
|
||||
ruleSet.setInclusionType(inclusionType);
|
||||
ruleSet.setInheritedBy(inheritedBy);
|
||||
return ruleSet;
|
||||
}
|
||||
}
|
||||
|
@@ -863,6 +863,7 @@
|
||||
|
||||
<bean id="ruleSetLoader" class="org.alfresco.rest.api.impl.rules.RuleSetLoader">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="ruleService" ref="RuleService" />
|
||||
</bean>
|
||||
|
||||
<bean id="ruleSets" class="org.alfresco.rest.api.impl.rules.RuleSetsImpl">
|
||||
|
@@ -26,11 +26,14 @@
|
||||
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.OWNING_FOLDER;
|
||||
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;
|
||||
import static org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
import java.util.List;
|
||||
@@ -41,6 +44,7 @@ import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -66,6 +70,8 @@ public class RuleSetLoaderTest extends TestCase
|
||||
@Mock
|
||||
private NodeService nodeServiceMock;
|
||||
@Mock
|
||||
private RuleService ruleServiceMock;
|
||||
@Mock
|
||||
private ChildAssociationRef ruleSetAssociationMock;
|
||||
@Mock
|
||||
private ChildAssociationRef linkAssociationMock;
|
||||
@@ -79,6 +85,8 @@ public class RuleSetLoaderTest extends TestCase
|
||||
|
||||
given(linkAssociationMock.getParentRef()).willReturn(LINKING_FOLDER);
|
||||
given(nodeServiceMock.getParentAssocs(RULE_SET_NODE)).willReturn(List.of(ruleSetAssociationMock, linkAssociationMock));
|
||||
|
||||
given(ruleServiceMock.getFoldersInheritingRuleSet(eq(RULE_SET_NODE), anyInt())).willReturn(List.of(INHERITING_FOLDER));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,4 +138,14 @@ public class RuleSetLoaderTest extends TestCase
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).inclusionType(INHERITED).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadRuleSet_inheritedBy()
|
||||
{
|
||||
// Call the method under test.
|
||||
RuleSet actual = ruleSetLoader.loadRuleSet(RULE_SET_NODE, INHERITING_FOLDER, List.of(INHERITED_BY));
|
||||
|
||||
RuleSet expected = RuleSet.builder().id(RULE_SET_ID).inheritedBy(List.of(INHERITING_FOLDER)).create();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user