mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3291: Support for unlinking rule sets (#1421)
* ACS-3291: Support for unlinking rule sets * ACS-3291: add unit tests and edge case exceptions * ACS-3291: add support for -default- ruleSetId Co-authored-by: Tom Page <tpage-alfresco@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
4bc36ae18d
commit
91e2421d7c
@@ -63,4 +63,9 @@ public interface RuleSets
|
|||||||
* Link a rule set to a folder
|
* Link a rule set to a folder
|
||||||
*/
|
*/
|
||||||
RuleSetLink linkToRuleSet(String folderNodeId, String linkToNodeId);
|
RuleSetLink linkToRuleSet(String folderNodeId, String linkToNodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the link between a rule set and a folder
|
||||||
|
*/
|
||||||
|
void unlinkRuleSet(String folderNodeId, String ruleSetId);
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,7 @@ import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.service.Experimental;
|
import org.alfresco.service.Experimental;
|
||||||
|
import org.alfresco.service.cmr.repository.AspectMissingException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.rule.RuleService;
|
import org.alfresco.service.cmr.rule.RuleService;
|
||||||
@@ -110,6 +111,22 @@ public class RuleSetsImpl implements RuleSets
|
|||||||
return ruleSetLink;
|
return ruleSetLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlinkRuleSet(String folderNodeId, String ruleSetId)
|
||||||
|
{
|
||||||
|
final NodeRef folderNodeRef = validator.validateFolderNode(folderNodeId,true);
|
||||||
|
final NodeRef ruleSetNodeRef = validator.validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||||
|
|
||||||
|
//The folder should be linked to a rule set
|
||||||
|
if (!ruleService.isLinkedToRuleNode(folderNodeRef))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException("The folder is not linked to a rule set.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//The following line also handles the deletion of the parent-child association that gets created during linking
|
||||||
|
nodeService.removeAspect(folderNodeRef,RuleModel.ASPECT_RULES);
|
||||||
|
}
|
||||||
|
|
||||||
public void setRuleSetLoader(RuleSetLoader ruleSetLoader)
|
public void setRuleSetLoader(RuleSetLoader ruleSetLoader)
|
||||||
{
|
{
|
||||||
this.ruleSetLoader = ruleSetLoader;
|
this.ruleSetLoader = ruleSetLoader;
|
||||||
|
@@ -35,6 +35,7 @@ import org.alfresco.rest.api.model.rules.RuleSetLink;
|
|||||||
import org.alfresco.rest.framework.WebApiDescription;
|
import org.alfresco.rest.framework.WebApiDescription;
|
||||||
import org.alfresco.rest.framework.WebApiParam;
|
import org.alfresco.rest.framework.WebApiParam;
|
||||||
import org.alfresco.rest.framework.core.ResourceParameter;
|
import org.alfresco.rest.framework.core.ResourceParameter;
|
||||||
|
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
@@ -42,8 +43,9 @@ import org.alfresco.util.PropertyCheck;
|
|||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
|
||||||
@RelationshipResource(name = "rule-set-links", entityResource = NodesEntityResource.class, title = "Linking to a rule set")
|
@RelationshipResource(name = "rule-set-links", entityResource = NodesEntityResource.class, title = "Rule set links")
|
||||||
public class NodeRuleSetLinksRelation implements InitializingBean, RelationshipResourceAction.Create<RuleSetLink>
|
public class NodeRuleSetLinksRelation implements InitializingBean, RelationshipResourceAction.Create<RuleSetLink>,
|
||||||
|
RelationshipResourceAction.Delete
|
||||||
{
|
{
|
||||||
|
|
||||||
private final RuleSets ruleSets;
|
private final RuleSets ruleSets;
|
||||||
@@ -67,6 +69,24 @@ public class NodeRuleSetLinksRelation implements InitializingBean, RelationshipR
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove link between a rule set and a folder for given rule set's and folder's node IDs.
|
||||||
|
* <p>
|
||||||
|
* - DELETE /nodes/{folderNodeId}/rule-set-links/{ruleSetId}
|
||||||
|
*
|
||||||
|
* @param folderNodeId - folder node ID
|
||||||
|
* @param ruleSetNodeId - rule set node ID (associated with folder node)
|
||||||
|
* @throws RelationshipResourceNotFoundException in case resource was not found
|
||||||
|
*/
|
||||||
|
@WebApiDescription(title = "Remove link between a rule set and a folder node",
|
||||||
|
description = "Submits a request to unlink a rule set from a folder",
|
||||||
|
successStatus = HttpServletResponse.SC_NO_CONTENT)
|
||||||
|
@Override
|
||||||
|
public void delete(String folderNodeId, String ruleSetNodeId, Parameters parameters)
|
||||||
|
{
|
||||||
|
ruleSets.unlinkRuleSet(folderNodeId, ruleSetNodeId);
|
||||||
|
}
|
||||||
|
|
||||||
public NodeRuleSetLinksRelation(RuleSets ruleSets)
|
public NodeRuleSetLinksRelation(RuleSets ruleSets)
|
||||||
{
|
{
|
||||||
this.ruleSets = ruleSets;
|
this.ruleSets = ruleSets;
|
||||||
|
@@ -46,6 +46,7 @@ import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.service.Experimental;
|
import org.alfresco.service.Experimental;
|
||||||
|
import org.alfresco.service.cmr.repository.AspectMissingException;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
@@ -294,4 +295,38 @@ public class RuleSetsImplTest extends TestCase
|
|||||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||||
then(runtimeRuleServiceMock).shouldHaveNoInteractions();
|
then(runtimeRuleServiceMock).shouldHaveNoInteractions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnlinkRuleSet()
|
||||||
|
{
|
||||||
|
given(ruleServiceMock.isLinkedToRuleNode(FOLDER_NODE)).willReturn(true);
|
||||||
|
|
||||||
|
//when
|
||||||
|
ruleSets.unlinkRuleSet(FOLDER_ID,RULE_SET_ID);
|
||||||
|
|
||||||
|
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID,true);
|
||||||
|
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID,FOLDER_NODE);
|
||||||
|
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||||
|
then(ruleServiceMock).should().isLinkedToRuleNode(FOLDER_NODE);
|
||||||
|
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||||
|
then(nodeServiceMock).should().removeAspect(FOLDER_NODE,RuleModel.ASPECT_RULES);
|
||||||
|
then(nodeServiceMock).shouldHaveNoMoreInteractions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnlinkRuleSet_folderIsNotLinkedToRuleSet()
|
||||||
|
{
|
||||||
|
given(ruleServiceMock.isLinkedToRuleNode(FOLDER_NODE)).willReturn(false);
|
||||||
|
|
||||||
|
//when
|
||||||
|
assertThatExceptionOfType(InvalidArgumentException.class).isThrownBy(
|
||||||
|
() -> ruleSets.unlinkRuleSet(FOLDER_ID,RULE_SET_ID));
|
||||||
|
|
||||||
|
then(nodeValidatorMock).should().validateFolderNode(FOLDER_ID,true);
|
||||||
|
then(nodeValidatorMock).should().validateRuleSetNode(RULE_SET_ID,FOLDER_NODE);
|
||||||
|
then(nodeValidatorMock).shouldHaveNoMoreInteractions();
|
||||||
|
then(ruleServiceMock).should().isLinkedToRuleNode(FOLDER_NODE);
|
||||||
|
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||||
|
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
package org.alfresco.rest.api.nodes;
|
package org.alfresco.rest.api.nodes;
|
||||||
|
|
||||||
|
import static org.mockito.BDDMockito.then;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.alfresco.rest.api.RuleSets;
|
import org.alfresco.rest.api.RuleSets;
|
||||||
import org.alfresco.rest.api.model.rules.RuleSetLink;
|
import org.alfresco.rest.api.model.rules.RuleSetLink;
|
||||||
@@ -46,6 +48,7 @@ public class NodeRuleSetsRelationTest extends TestCase
|
|||||||
{
|
{
|
||||||
private static final String FOLDER_NODE_ID = "dummy-folder-node-id";
|
private static final String FOLDER_NODE_ID = "dummy-folder-node-id";
|
||||||
private static final String LINK_TO_NODE_ID = "dummy-link-to-node-id";
|
private static final String LINK_TO_NODE_ID = "dummy-link-to-node-id";
|
||||||
|
private static final String RULE_SET_NODE_ID = "dummy-rule-set-node-id";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private RuleSets ruleSets;
|
private RuleSets ruleSets;
|
||||||
@@ -71,5 +74,15 @@ public class NodeRuleSetsRelationTest extends TestCase
|
|||||||
Assert.assertEquals(ruleResult, actual);
|
Assert.assertEquals(ruleResult, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnlinkRuleSet()
|
||||||
|
{
|
||||||
|
//when
|
||||||
|
ruleSets.unlinkRuleSet(FOLDER_NODE_ID,RULE_SET_NODE_ID);
|
||||||
|
|
||||||
|
then(ruleSets).should().unlinkRuleSet(FOLDER_NODE_ID,RULE_SET_NODE_ID);
|
||||||
|
then(ruleSets).shouldHaveNoMoreInteractions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user