mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
ACS-3229: Rules v1 REST API - Get rule definition - mapping of actions (#1245)
ACS-3229: Rules v1 REST API - Get rule definition - adding mapping of "actions"
This commit is contained in:
@@ -27,6 +27,7 @@ package org.alfresco.rest.rules;
|
|||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||||
import static org.alfresco.utility.model.FileModel.getRandomFileModel;
|
import static org.alfresco.utility.model.FileModel.getRandomFileModel;
|
||||||
import static org.alfresco.utility.model.FileType.TEXT_PLAIN;
|
import static org.alfresco.utility.model.FileType.TEXT_PLAIN;
|
||||||
@@ -73,14 +74,12 @@ public class CreateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||||
public void createRule()
|
public void createRule()
|
||||||
{
|
{
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
RestRuleModel ruleModel = createRuleModel("ruleName");
|
||||||
ruleModel.setName("ruleName");
|
|
||||||
|
|
||||||
RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
RestRuleModel rule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||||
.createSingleRule(ruleModel);
|
.createSingleRule(ruleModel);
|
||||||
|
|
||||||
restClient.assertStatusCodeIs(CREATED);
|
restClient.assertStatusCodeIs(CREATED);
|
||||||
|
|
||||||
rule.assertThat().field("id").isNotNull()
|
rule.assertThat().field("id").isNotNull()
|
||||||
.assertThat().field("name").is("ruleName");
|
.assertThat().field("name").is("ruleName");
|
||||||
}
|
}
|
||||||
@@ -133,8 +132,7 @@ public class CreateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void duplicateRuleNameIsAcceptable()
|
public void duplicateRuleNameIsAcceptable()
|
||||||
{
|
{
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
RestRuleModel ruleModel = createRuleModel("duplicateRuleName");
|
||||||
ruleModel.setName("duplicateRuleName");
|
|
||||||
|
|
||||||
STEP("Create two identical rules");
|
STEP("Create two identical rules");
|
||||||
RestRuleModel ruleA = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
RestRuleModel ruleA = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
@@ -205,12 +203,7 @@ public class CreateRulesTests extends RestTest
|
|||||||
{
|
{
|
||||||
STEP("Create a list of rules in one POST request");
|
STEP("Create a list of rules in one POST request");
|
||||||
List<String> ruleNames = List.of("ruleA", "ruleB", "ruleC");
|
List<String> ruleNames = List.of("ruleA", "ruleB", "ruleC");
|
||||||
List<RestRuleModel> ruleModels = ruleNames.stream().map(ruleName ->
|
List<RestRuleModel> ruleModels = ruleNames.stream().map(RulesTestsUtils::createRuleModel).collect(toList());
|
||||||
{
|
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
|
||||||
ruleModel.setName(ruleName);
|
|
||||||
return ruleModel;
|
|
||||||
}).collect(toList());
|
|
||||||
|
|
||||||
RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
RestRuleModelsCollection rules = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||||
.createListOfRules(ruleModels);
|
.createListOfRules(ruleModels);
|
||||||
@@ -229,12 +222,10 @@ public class CreateRulesTests extends RestTest
|
|||||||
public void createRulesWithOneError()
|
public void createRulesWithOneError()
|
||||||
{
|
{
|
||||||
STEP("Try to create a three rules but the middle one has an error.");
|
STEP("Try to create a three rules but the middle one has an error.");
|
||||||
RestRuleModel ruleA = new RestRuleModel();
|
RestRuleModel ruleA = createRuleModel("ruleA");
|
||||||
ruleA.setName("ruleA");
|
|
||||||
RestRuleModel ruleB = new RestRuleModel();
|
RestRuleModel ruleB = new RestRuleModel();
|
||||||
// Don't set a name for Rule B.
|
// Don't set a name for Rule B.
|
||||||
RestRuleModel ruleC = new RestRuleModel();
|
RestRuleModel ruleC = createRuleModel("ruleC");
|
||||||
ruleC.setName("ruleC");
|
|
||||||
List<RestRuleModel> ruleModels = List.of(ruleA, ruleB, ruleC);
|
List<RestRuleModel> ruleModels = List.of(ruleA, ruleB, ruleC);
|
||||||
|
|
||||||
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createListOfRules(ruleModels);
|
restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createListOfRules(ruleModels);
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.rest.rules;
|
|||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||||
import static org.alfresco.utility.constants.UserRole.SiteContributor;
|
import static org.alfresco.utility.constants.UserRole.SiteContributor;
|
||||||
import static org.alfresco.utility.constants.UserRole.SiteManager;
|
import static org.alfresco.utility.constants.UserRole.SiteManager;
|
||||||
@@ -82,8 +83,7 @@ public class DeleteRulesTests extends RestTest
|
|||||||
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
final FolderModel ruleFolder = dataContent.usingUser(user).usingSite(site).createFolder();
|
||||||
final List<RestRuleModel> createdRules = Stream.of("ruleA", "ruleB", "ruleC")
|
final List<RestRuleModel> createdRules = Stream.of("ruleA", "ruleB", "ruleC")
|
||||||
.map(ruleName -> {
|
.map(ruleName -> {
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
RestRuleModel ruleModel = createRuleModel(ruleName);
|
||||||
ruleModel.setName(ruleName);
|
|
||||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||||
.createSingleRule(ruleModel);
|
.createSingleRule(ruleModel);
|
||||||
})
|
})
|
||||||
@@ -187,8 +187,7 @@ public class DeleteRulesTests extends RestTest
|
|||||||
final UserModel privateUser = dataUser.createRandomTestUser();
|
final UserModel privateUser = dataUser.createRandomTestUser();
|
||||||
final SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
final SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||||
final FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
final FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||||
final RestRuleModel ruleModel = new RestRuleModel();
|
final RestRuleModel ruleModel = createRuleModel("Private site rule");
|
||||||
ruleModel.setName("Private site rule");
|
|
||||||
final RestRuleModel createdRule =
|
final RestRuleModel createdRule =
|
||||||
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
||||||
.createSingleRule(ruleModel);
|
.createSingleRule(ruleModel);
|
||||||
@@ -229,8 +228,7 @@ public class DeleteRulesTests extends RestTest
|
|||||||
final UserModel privateUser = dataUser.createRandomTestUser();
|
final UserModel privateUser = dataUser.createRandomTestUser();
|
||||||
final SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
final SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||||
final FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
final FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||||
final RestRuleModel ruleModel = new RestRuleModel();
|
final RestRuleModel ruleModel = createRuleModel("Private site rule");
|
||||||
ruleModel.setName("Private site rule");
|
|
||||||
final RestRuleModel createdRule =
|
final RestRuleModel createdRule =
|
||||||
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet()
|
||||||
.createSingleRule(ruleModel);
|
.createSingleRule(ruleModel);
|
||||||
@@ -250,8 +248,7 @@ public class DeleteRulesTests extends RestTest
|
|||||||
private RestRuleModel createRule(FolderModel ruleFolder)
|
private RestRuleModel createRule(FolderModel ruleFolder)
|
||||||
{
|
{
|
||||||
STEP("Create a rule in the folder");
|
STEP("Create a rule in the folder");
|
||||||
final RestRuleModel ruleModel = new RestRuleModel();
|
final RestRuleModel ruleModel = createRuleModel("Test rule");
|
||||||
ruleModel.setName("Test rule");
|
|
||||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.rest.rules;
|
|||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||||
import static org.alfresco.utility.report.log.Step.STEP;
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -70,8 +71,7 @@ public class GetRulesTests extends RestTest
|
|||||||
|
|
||||||
STEP("Create rules in the folder");
|
STEP("Create rules in the folder");
|
||||||
createdRules = Stream.of("ruleA", "ruleB").map(ruleName -> {
|
createdRules = Stream.of("ruleA", "ruleB").map(ruleName -> {
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
RestRuleModel ruleModel = createRuleModel(ruleName);
|
||||||
ruleModel.setName(ruleName);
|
|
||||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
}).collect(toList());
|
}).collect(toList());
|
||||||
createdRuleA = createdRules.get(0);
|
createdRuleA = createdRules.get(0);
|
||||||
@@ -200,8 +200,7 @@ public class GetRulesTests extends RestTest
|
|||||||
UserModel privateUser = dataUser.createRandomTestUser();
|
UserModel privateUser = dataUser.createRandomTestUser();
|
||||||
SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
SiteModel privateSite = dataSite.usingUser(privateUser).createPrivateRandomSite();
|
||||||
FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
FolderModel privateFolder = dataContent.usingUser(privateUser).usingSite(privateSite).createFolder();
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
RestRuleModel ruleModel = createRuleModel("Private site rule");
|
||||||
ruleModel.setName("Private site rule");
|
|
||||||
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
restClient.authenticateUser(privateUser).withCoreAPI().usingNode(privateFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
|
||||||
|
|
||||||
STEP("Create a collaborator in the private site");
|
STEP("Create a collaborator in the private site");
|
||||||
|
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Repository
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.rules;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
|
||||||
|
import org.alfresco.rest.model.RestRuleModel;
|
||||||
|
|
||||||
|
public class RulesTestsUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
public static RestRuleModel createRuleModel(String name) {
|
||||||
|
return createRuleModel(name, List.of(createActionModel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a rule model.
|
||||||
|
*
|
||||||
|
* @param name The name for the rule.
|
||||||
|
* @param restActionModels Rule's actions.
|
||||||
|
* @return The created rule model.
|
||||||
|
*/
|
||||||
|
public static RestRuleModel createRuleModel(String name, List<RestActionBodyExecTemplateModel> restActionModels)
|
||||||
|
{
|
||||||
|
RestRuleModel ruleModel = new RestRuleModel();
|
||||||
|
ruleModel.setName(name);
|
||||||
|
ruleModel.setActions(restActionModels);
|
||||||
|
return ruleModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a rule's action model.
|
||||||
|
*
|
||||||
|
* @return The created action model.
|
||||||
|
*/
|
||||||
|
public static RestActionBodyExecTemplateModel createActionModel()
|
||||||
|
{
|
||||||
|
RestActionBodyExecTemplateModel restActionModel = new RestActionBodyExecTemplateModel();
|
||||||
|
restActionModel.setActionDefinitionId("add-features");
|
||||||
|
restActionModel.setParams(Map.of("aspect-name", "{http://www.alfresco.org/model/audio/1.0}audio", "actionContext", "rule"));
|
||||||
|
return restActionModel;
|
||||||
|
}
|
||||||
|
}
|
@@ -25,19 +25,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.rules;
|
package org.alfresco.rest.rules;
|
||||||
|
|
||||||
|
import static org.alfresco.rest.rules.RulesTestsUtils.createActionModel;
|
||||||
|
import static org.alfresco.rest.rules.RulesTestsUtils.createRuleModel;
|
||||||
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
import static org.alfresco.utility.constants.UserRole.SiteCollaborator;
|
||||||
import static org.alfresco.utility.report.log.Step.STEP;
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
import static org.springframework.http.HttpStatus.CREATED;
|
|
||||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.rest.RestTest;
|
import org.alfresco.rest.RestTest;
|
||||||
|
import org.alfresco.rest.model.RestActionBodyExecTemplateModel;
|
||||||
import org.alfresco.rest.model.RestRuleModel;
|
import org.alfresco.rest.model.RestRuleModel;
|
||||||
import org.alfresco.rest.model.RestRuleSetModel;
|
|
||||||
import org.alfresco.utility.constants.UserRole;
|
|
||||||
import org.alfresco.utility.model.FolderModel;
|
import org.alfresco.utility.model.FolderModel;
|
||||||
import org.alfresco.utility.model.SiteModel;
|
import org.alfresco.utility.model.SiteModel;
|
||||||
import org.alfresco.utility.model.TestGroup;
|
import org.alfresco.utility.model.TestGroup;
|
||||||
@@ -67,11 +68,10 @@ public class UpdateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES, TestGroup.SANITY })
|
||||||
public void updateRule()
|
public void updateRule()
|
||||||
{
|
{
|
||||||
RestRuleModel rule = createRule("Rule name");
|
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||||
|
|
||||||
STEP("Try to update the rule.");
|
STEP("Try to update the rule.");
|
||||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
RestRuleModel updatedRuleModel = createRuleModel("Updated rule name");
|
||||||
updatedRuleModel.setName("Updated rule name");
|
|
||||||
RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||||
.updateRule(rule.getId(), updatedRuleModel);
|
.updateRule(rule.getId(), updatedRuleModel);
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class UpdateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void updateRuleForNonExistentFolder()
|
public void updateRuleForNonExistentFolder()
|
||||||
{
|
{
|
||||||
RestRuleModel rule = createRule("Rule name");
|
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||||
|
|
||||||
STEP("Try to update a rule in a non-existent folder.");
|
STEP("Try to update a rule in a non-existent folder.");
|
||||||
FolderModel nonExistentFolder = FolderModel.getRandomFolderModel();
|
FolderModel nonExistentFolder = FolderModel.getRandomFolderModel();
|
||||||
@@ -103,7 +103,7 @@ public class UpdateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void updateRuleForNonExistentRuleSet()
|
public void updateRuleForNonExistentRuleSet()
|
||||||
{
|
{
|
||||||
RestRuleModel rule = createRule("Rule name");
|
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||||
|
|
||||||
STEP("Try to update a rule in a non-existent rule set.");
|
STEP("Try to update a rule in a non-existent rule set.");
|
||||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
RestRuleModel updatedRuleModel = new RestRuleModel();
|
||||||
@@ -153,7 +153,7 @@ public class UpdateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void updateRuleToHaveEmptyName()
|
public void updateRuleToHaveEmptyName()
|
||||||
{
|
{
|
||||||
RestRuleModel rule = createRule("Rule name");
|
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||||
|
|
||||||
STEP("Try to update the rule to have no name.");
|
STEP("Try to update the rule to have no name.");
|
||||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
RestRuleModel updatedRuleModel = new RestRuleModel();
|
||||||
@@ -168,29 +168,33 @@ public class UpdateRulesTests extends RestTest
|
|||||||
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
@Test (groups = { TestGroup.REST_API, TestGroup.RULES })
|
||||||
public void tryToUpdateRuleId()
|
public void tryToUpdateRuleId()
|
||||||
{
|
{
|
||||||
RestRuleModel rule = createRule("Rule name");
|
RestRuleModel rule = createAndSaveRule("Rule name");
|
||||||
|
|
||||||
STEP("Try to update the rule id and check it isn't changed.");
|
STEP("Try to update the rule id and check it isn't changed.");
|
||||||
RestRuleModel updatedRuleModel = new RestRuleModel();
|
RestRuleModel updatedRuleModel = createRuleModel("Rule name");
|
||||||
updatedRuleModel.setId("new-rule-id");
|
updatedRuleModel.setId("new-rule-id");
|
||||||
updatedRuleModel.setName("Rule name");
|
|
||||||
RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
RestRuleModel updatedRule = restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||||
.updateRule(rule.getId(), updatedRuleModel);
|
.updateRule(rule.getId(), updatedRuleModel);
|
||||||
|
|
||||||
updatedRule.assertThat().field("id").is(rule.getId());
|
updatedRule.assertThat().field("id").is(rule.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RestRuleModel createAndSaveRule(String name)
|
||||||
|
{
|
||||||
|
return createAndSaveRule(name, List.of(createActionModel()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a rule.
|
* Create a rule for folder and store it.
|
||||||
*
|
*
|
||||||
* @param name The name for the rule.
|
* @param name The name for the rule.
|
||||||
|
* @param restActionModels Rule's actions.
|
||||||
* @return The created rule.
|
* @return The created rule.
|
||||||
*/
|
*/
|
||||||
private RestRuleModel createRule(String name)
|
private RestRuleModel createAndSaveRule(String name, List<RestActionBodyExecTemplateModel> restActionModels)
|
||||||
{
|
{
|
||||||
STEP("Create a rule called " + name);
|
STEP("Create a rule called " + name + ", containing actions: " + restActionModels);
|
||||||
RestRuleModel ruleModel = new RestRuleModel();
|
RestRuleModel ruleModel = createRuleModel(name, restActionModels);
|
||||||
ruleModel.setName(name);
|
|
||||||
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
return restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingDefaultRuleSet()
|
||||||
.createSingleRule(ruleModel);
|
.createSingleRule(ruleModel);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.rest.api.model.rules;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
|
import org.alfresco.repo.action.CompositeActionImpl;
|
||||||
|
import org.alfresco.repo.action.executer.SetPropertyValueActionExecuter;
|
||||||
|
import org.alfresco.service.Experimental;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.util.GUID;
|
||||||
|
|
||||||
|
@Experimental
|
||||||
|
public class Action
|
||||||
|
{
|
||||||
|
private String actionDefinitionId;
|
||||||
|
private Map<String, Serializable> params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts service POJO action to REST model action.
|
||||||
|
*
|
||||||
|
* @param actionModel - {@link org.alfresco.service.cmr.action.Action} service POJO
|
||||||
|
* @return {@link Action} REST model
|
||||||
|
*/
|
||||||
|
public static Action from(final org.alfresco.service.cmr.action.Action actionModel)
|
||||||
|
{
|
||||||
|
if (actionModel == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Action.Builder builder = builder().actionDefinitionId(actionModel.getActionDefinitionName());
|
||||||
|
if (actionModel.getParameterValues() != null)
|
||||||
|
{
|
||||||
|
builder.params(new HashMap<>(actionModel.getParameterValues()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the REST model object to the equivalent service POJO.
|
||||||
|
*
|
||||||
|
* @param nodeRef The node reference.
|
||||||
|
* @return The action service POJO.
|
||||||
|
*/
|
||||||
|
public org.alfresco.service.cmr.action.Action toServiceModel(final NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
return new ActionImpl(nodeRef, GUID.generate(), SetPropertyValueActionExecuter.NAME, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the REST model objects to composite action service POJO.
|
||||||
|
*
|
||||||
|
* @param actions List of actions.
|
||||||
|
* @return The composite action service POJO.
|
||||||
|
*/
|
||||||
|
public static org.alfresco.service.cmr.action.Action toCompositeAction(final List<Action> actions) {
|
||||||
|
if (actions == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final org.alfresco.service.cmr.action.CompositeAction compositeAction = new CompositeActionImpl(null, GUID.generate());
|
||||||
|
actions.forEach(action -> compositeAction.addAction(action.toServiceModel(null)));
|
||||||
|
return compositeAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActionDefinitionId()
|
||||||
|
{
|
||||||
|
return actionDefinitionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActionDefinitionId(String actionDefinitionId)
|
||||||
|
{
|
||||||
|
this.actionDefinitionId = actionDefinitionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Serializable> getParams()
|
||||||
|
{
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParams(Map<String, Serializable> params)
|
||||||
|
{
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "Action{" + "actionDefinitionId='" + actionDefinitionId + '\'' + ", params=" + params + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
Action action = (Action) o;
|
||||||
|
return Objects.equals(actionDefinitionId, action.actionDefinitionId) && Objects.equals(params, action.params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return Objects.hash(actionDefinitionId, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder()
|
||||||
|
{
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder
|
||||||
|
{
|
||||||
|
private String actionDefinitionId;
|
||||||
|
private Map<String, Serializable> params;
|
||||||
|
|
||||||
|
public Builder actionDefinitionId(String actionDefinitionId)
|
||||||
|
{
|
||||||
|
this.actionDefinitionId = actionDefinitionId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder params(Map<String, Serializable> params)
|
||||||
|
{
|
||||||
|
this.params = params;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action create() {
|
||||||
|
final Action action = new Action();
|
||||||
|
action.setActionDefinitionId(actionDefinitionId);
|
||||||
|
action.setParams(params);
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -26,22 +26,16 @@
|
|||||||
|
|
||||||
package org.alfresco.rest.api.model.rules;
|
package org.alfresco.rest.api.model.rules;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
|
||||||
import org.alfresco.repo.action.ActionImpl;
|
|
||||||
import org.alfresco.repo.action.executer.ScriptActionExecuter;
|
import org.alfresco.repo.action.executer.ScriptActionExecuter;
|
||||||
import org.alfresco.repo.action.executer.SetPropertyValueActionExecuter;
|
|
||||||
import org.alfresco.rest.api.Nodes;
|
import org.alfresco.rest.api.Nodes;
|
||||||
import org.alfresco.rest.framework.resource.UniqueId;
|
import org.alfresco.rest.framework.resource.UniqueId;
|
||||||
import org.alfresco.service.Experimental;
|
import org.alfresco.service.Experimental;
|
||||||
|
import org.alfresco.service.cmr.action.CompositeAction;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.util.GUID;
|
|
||||||
|
|
||||||
@Experimental
|
@Experimental
|
||||||
public class Rule
|
public class Rule
|
||||||
@@ -55,6 +49,7 @@ public class Rule
|
|||||||
private boolean shared;
|
private boolean shared;
|
||||||
private String errorScript;
|
private String errorScript;
|
||||||
private List<RuleTrigger> triggers;
|
private List<RuleTrigger> triggers;
|
||||||
|
private List<Action> actions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts service POJO rule to REST model rule.
|
* Converts service POJO rule to REST model rule.
|
||||||
@@ -84,10 +79,17 @@ public class Rule
|
|||||||
{
|
{
|
||||||
builder.triggers(ruleModel.getRuleTypes().stream().map(RuleTrigger::of).collect(Collectors.toList()));
|
builder.triggers(ruleModel.getRuleTypes().stream().map(RuleTrigger::of).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
if (ruleModel.getAction() != null && ruleModel.getAction().getCompensatingAction() != null && ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF) != null)
|
if (ruleModel.getAction() != null)
|
||||||
|
{
|
||||||
|
if (ruleModel.getAction().getCompensatingAction() != null && ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF) != null)
|
||||||
{
|
{
|
||||||
builder.errorScript(ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF).toString());
|
builder.errorScript(ruleModel.getAction().getCompensatingAction().getParameterValue(ScriptActionExecuter.PARAM_SCRIPTREF).toString());
|
||||||
}
|
}
|
||||||
|
if (ruleModel.getAction() instanceof CompositeAction && ((CompositeAction) ruleModel.getAction()).getActions() != null)
|
||||||
|
{
|
||||||
|
builder.actions(((CompositeAction) ruleModel.getAction()).getActions().stream().map(Action::from).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
@@ -100,20 +102,12 @@ public class Rule
|
|||||||
*/
|
*/
|
||||||
public org.alfresco.service.cmr.rule.Rule toServiceModel(Nodes nodes)
|
public org.alfresco.service.cmr.rule.Rule toServiceModel(Nodes nodes)
|
||||||
{
|
{
|
||||||
org.alfresco.service.cmr.rule.Rule ruleModel = new org.alfresco.service.cmr.rule.Rule();
|
final org.alfresco.service.cmr.rule.Rule ruleModel = new org.alfresco.service.cmr.rule.Rule();
|
||||||
if (id != null)
|
final NodeRef nodeRef = (id != null) ? nodes.validateOrLookupNode(id, null) : null;
|
||||||
{
|
|
||||||
NodeRef nodeRef = nodes.validateOrLookupNode(id, null);
|
|
||||||
ruleModel.setNodeRef(nodeRef);
|
ruleModel.setNodeRef(nodeRef);
|
||||||
}
|
|
||||||
ruleModel.setTitle(name);
|
ruleModel.setTitle(name);
|
||||||
|
|
||||||
// TODO: Once we have actions working properly then this needs to be replaced.
|
ruleModel.setAction(Action.toCompositeAction(actions));
|
||||||
Map<String, Serializable> parameters = Map.of(
|
|
||||||
SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_TITLE,
|
|
||||||
SetPropertyValueActionExecuter.PARAM_VALUE, "UPDATED:" + GUID.generate());
|
|
||||||
org.alfresco.service.cmr.action.Action action = new ActionImpl(null, GUID.generate(), SetPropertyValueActionExecuter.NAME, parameters);
|
|
||||||
ruleModel.setAction(action);
|
|
||||||
|
|
||||||
return ruleModel;
|
return ruleModel;
|
||||||
}
|
}
|
||||||
@@ -209,16 +203,21 @@ public class Rule
|
|||||||
this.triggers = triggers;
|
this.triggers = triggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Void> getActions()
|
public List<Action> getActions()
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActions(List<Action> actions)
|
||||||
|
{
|
||||||
|
this.actions = actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "Rule{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", description='" + description + '\'' + ", enabled=" + enabled + ", cascade=" + cascade
|
return "Rule{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", description='" + description + '\'' + ", enabled=" + enabled + ", cascade=" + cascade
|
||||||
+ ", asynchronous=" + asynchronous + ", shared=" + shared + ", errorScript='" + errorScript + '\'' + ", triggers=" + triggers + '}';
|
+ ", asynchronous=" + asynchronous + ", shared=" + shared + ", errorScript='" + errorScript + '\'' + ", triggers=" + triggers + ", actions=" + actions + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -230,13 +229,14 @@ public class Rule
|
|||||||
return false;
|
return false;
|
||||||
Rule rule = (Rule) o;
|
Rule rule = (Rule) o;
|
||||||
return enabled == rule.enabled && cascade == rule.cascade && asynchronous == rule.asynchronous && shared == rule.shared && Objects.equals(id, rule.id) && Objects.equals(
|
return enabled == rule.enabled && cascade == rule.cascade && asynchronous == rule.asynchronous && shared == rule.shared && Objects.equals(id, rule.id) && Objects.equals(
|
||||||
name, rule.name) && Objects.equals(description, rule.description) && Objects.equals(errorScript, rule.errorScript) && Objects.equals(triggers, rule.triggers);
|
name, rule.name) && Objects.equals(description, rule.description) && Objects.equals(errorScript, rule.errorScript) && Objects.equals(triggers, rule.triggers)
|
||||||
|
&& Objects.equals(actions, rule.actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return Objects.hash(id, name, description, enabled, cascade, asynchronous, shared, errorScript, triggers);
|
return Objects.hash(id, name, description, enabled, cascade, asynchronous, shared, errorScript, triggers, actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder()
|
public static Builder builder()
|
||||||
@@ -256,6 +256,7 @@ public class Rule
|
|||||||
private boolean shared;
|
private boolean shared;
|
||||||
private String errorScript;
|
private String errorScript;
|
||||||
private List<RuleTrigger> triggers;
|
private List<RuleTrigger> triggers;
|
||||||
|
private List<Action> actions;
|
||||||
|
|
||||||
public Builder id(String id)
|
public Builder id(String id)
|
||||||
{
|
{
|
||||||
@@ -311,6 +312,12 @@ public class Rule
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder actions(List<Action> actions)
|
||||||
|
{
|
||||||
|
this.actions = actions;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Rule create()
|
public Rule create()
|
||||||
{
|
{
|
||||||
Rule rule = new Rule();
|
Rule rule = new Rule();
|
||||||
@@ -323,6 +330,7 @@ public class Rule
|
|||||||
rule.setShared(shared);
|
rule.setShared(shared);
|
||||||
rule.setErrorScript(errorScript);
|
rule.setErrorScript(errorScript);
|
||||||
rule.setTriggers(triggers);
|
rule.setTriggers(triggers);
|
||||||
|
rule.setActions(actions);
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
package org.alfresco.rest.api;
|
package org.alfresco.rest.api;
|
||||||
|
|
||||||
import org.alfresco.rest.api.impl.RulesImplTest;
|
import org.alfresco.rest.api.impl.RulesImplTest;
|
||||||
|
import org.alfresco.rest.api.model.rules.ActionTest;
|
||||||
import org.alfresco.rest.api.model.rules.RuleTest;
|
import org.alfresco.rest.api.model.rules.RuleTest;
|
||||||
import org.alfresco.rest.api.nodes.NodeRulesRelationTest;
|
import org.alfresco.rest.api.nodes.NodeRulesRelationTest;
|
||||||
import org.alfresco.service.Experimental;
|
import org.alfresco.service.Experimental;
|
||||||
@@ -38,7 +39,8 @@ import org.junit.runners.Suite;
|
|||||||
@Suite.SuiteClasses({
|
@Suite.SuiteClasses({
|
||||||
NodeRulesRelationTest.class,
|
NodeRulesRelationTest.class,
|
||||||
RulesImplTest.class,
|
RulesImplTest.class,
|
||||||
RuleTest.class
|
RuleTest.class,
|
||||||
|
ActionTest.class
|
||||||
})
|
})
|
||||||
public class RulesUnitTests
|
public class RulesUnitTests
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.alfresco.rest.api.model.rules;
|
||||||
|
|
||||||
|
import static org.alfresco.repo.action.executer.SetPropertyValueActionExecuter.PARAM_PROPERTY;
|
||||||
|
import static org.alfresco.repo.action.executer.SetPropertyValueActionExecuter.PARAM_VALUE;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
|
import org.alfresco.service.Experimental;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@Experimental
|
||||||
|
public class ActionTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String ACTION_DEFINITION_NAME = "actionDefName";
|
||||||
|
private static final Map<String, Serializable> parameters = new HashMap<>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
parameters.put(PARAM_PROPERTY, "propertyName");
|
||||||
|
parameters.put(PARAM_VALUE, "propertyValue");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFrom()
|
||||||
|
{
|
||||||
|
final NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "ruleId");
|
||||||
|
final org.alfresco.service.cmr.action.Action actionModel = new ActionImpl(nodeRef, "actionId", ACTION_DEFINITION_NAME, parameters);
|
||||||
|
final Action expectedAction = Action.builder().actionDefinitionId(ACTION_DEFINITION_NAME).params(parameters).create();
|
||||||
|
|
||||||
|
final Action actualAction = Action.from(actionModel);
|
||||||
|
|
||||||
|
assertThat(actualAction).isNotNull().usingRecursiveComparison().isEqualTo(expectedAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFromActionModelWithNullValues()
|
||||||
|
{
|
||||||
|
final org.alfresco.service.cmr.action.Action actionModel = new ActionImpl(null, null, null);
|
||||||
|
final Action expectedAction = Action.builder().params(Collections.emptyMap()).create();
|
||||||
|
|
||||||
|
final Action actualAction = Action.from(actionModel);
|
||||||
|
|
||||||
|
assertThat(actualAction).isNotNull().usingRecursiveComparison().isEqualTo(expectedAction);
|
||||||
|
}
|
||||||
|
}
|
@@ -39,7 +39,6 @@ import org.alfresco.service.cmr.action.ActionCondition;
|
|||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.alfresco.service.cmr.rule.RuleType;
|
import org.alfresco.service.cmr.rule.RuleType;
|
||||||
import org.assertj.core.api.Condition;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@Experimental
|
@Experimental
|
||||||
@@ -50,7 +49,7 @@ public class RuleTest
|
|||||||
private static final String RULE_DESCRIPTION = "rule description";
|
private static final String RULE_DESCRIPTION = "rule description";
|
||||||
private static final boolean RULE_ENABLED = true;
|
private static final boolean RULE_ENABLED = true;
|
||||||
private static final boolean RULE_CASCADE = true;
|
private static final boolean RULE_CASCADE = true;
|
||||||
private static final boolean RULE_ASYNC = false;
|
private static final boolean RULE_ASYNC = true;
|
||||||
private static final boolean RULE_SHARED = true;
|
private static final boolean RULE_SHARED = true;
|
||||||
private static final String ERROR_SCRIPT = "error-script-ref";
|
private static final String ERROR_SCRIPT = "error-script-ref";
|
||||||
|
|
||||||
|
@@ -862,10 +862,7 @@ public class RuleServiceImpl
|
|||||||
{
|
{
|
||||||
// Get the action definition from the rule
|
// Get the action definition from the rule
|
||||||
Action action = rule.getAction();
|
Action action = rule.getAction();
|
||||||
if (action == null)
|
ParameterCheck.mandatory("Rule action", action);
|
||||||
{
|
|
||||||
throw new RuleServiceException("An action must be specified when defining a rule.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the current action node reference
|
// Get the current action node reference
|
||||||
NodeRef actionNodeRef = null;
|
NodeRef actionNodeRef = null;
|
||||||
|
@@ -136,7 +136,7 @@ public class RuleServiceImplUnitTest
|
|||||||
when(mockRule.getAction()).thenReturn(null);
|
when(mockRule.getAction()).thenReturn(null);
|
||||||
|
|
||||||
// Call the method under test.
|
// Call the method under test.
|
||||||
assertThatExceptionOfType(RuleServiceException.class).isThrownBy(() -> ruleService.saveRule(FOLDER_NODE, mockRule));
|
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> ruleService.saveRule(FOLDER_NODE, mockRule));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user