mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3227 POST Rule Fixes. (#1235)
* ACS-3227 Don't try to load rule set node if using -default-. It might not exist yet, since it's created along with the first rule. Also avoid using id of rule before it has been created. * ACS-3227 Add a hard-coded action while we don't support supplying actions in the POST.
This commit is contained in:
@@ -86,7 +86,11 @@ public class RulesImpl implements Rules
|
||||
public List<Rule> createRules(final String folderNodeId, final String ruleSetId, final List<Rule> rules)
|
||||
{
|
||||
final NodeRef folderNodeRef = validateFolderNode(folderNodeId);
|
||||
// Don't validate the ruleset node if -default- is passed since we may need to create it.
|
||||
if (RuleSet.isNotDefaultId(ruleSetId))
|
||||
{
|
||||
validateRuleSetNode(ruleSetId, folderNodeRef);
|
||||
}
|
||||
|
||||
return rules.stream()
|
||||
.map(rule -> rule.toServiceModel(nodes))
|
||||
|
@@ -26,12 +26,19 @@
|
||||
|
||||
package org.alfresco.rest.api.model.rules;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.ActionImpl;
|
||||
import org.alfresco.repo.action.executer.SetPropertyValueActionExecuter;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.framework.resource.UniqueId;
|
||||
import org.alfresco.service.Experimental;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
@Experimental
|
||||
public class Rule
|
||||
@@ -59,9 +66,20 @@ public class Rule
|
||||
public org.alfresco.service.cmr.rule.Rule toServiceModel(Nodes nodes)
|
||||
{
|
||||
org.alfresco.service.cmr.rule.Rule ruleModel = new org.alfresco.service.cmr.rule.Rule();
|
||||
if (id != null)
|
||||
{
|
||||
NodeRef nodeRef = nodes.validateOrLookupNode(id, null);
|
||||
ruleModel.setNodeRef(nodeRef);
|
||||
}
|
||||
ruleModel.setTitle(name);
|
||||
|
||||
// TODO: Once we have actions working properly then this needs to be replaced.
|
||||
Map<String, Serializable> parameters = Map.of(
|
||||
SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_TITLE,
|
||||
SetPropertyValueActionExecuter.PARAM_VALUE, "UPDATED:" + GUID.generate());
|
||||
Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, parameters);
|
||||
ruleModel.setAction(action);
|
||||
|
||||
return ruleModel;
|
||||
}
|
||||
|
||||
|
@@ -313,8 +313,6 @@ public class RulesImplTest extends TestCase
|
||||
@Test
|
||||
public void testSaveRules_defaultRuleSet()
|
||||
{
|
||||
NodeRef defaultRuleSetNodeRef = new NodeRef("default://rule/set");
|
||||
given(ruleServiceMock.getRuleSetNode(folderNodeRef)).willReturn(defaultRuleSetNodeRef);
|
||||
Rule ruleBody = mock(Rule.class);
|
||||
List<Rule> ruleList = List.of(ruleBody);
|
||||
org.alfresco.service.cmr.rule.Rule serviceRuleBody = mock(org.alfresco.service.cmr.rule.Rule.class);
|
||||
@@ -326,7 +324,6 @@ public class RulesImplTest extends TestCase
|
||||
// when
|
||||
List<Rule> actual = rules.createRules(folderNodeRef.getId(), DEFAULT_ID, ruleList);
|
||||
|
||||
then(ruleServiceMock).should().getRuleSetNode(folderNodeRef);
|
||||
then(ruleServiceMock).should().saveRule(folderNodeRef, ruleBody.toServiceModel(nodesMock));
|
||||
then(ruleServiceMock).shouldHaveNoMoreInteractions();
|
||||
List<Rule> expected = List.of(Rule.from(serviceRule));
|
||||
|
Reference in New Issue
Block a user