diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java index 4ce6a37b25..80c0cf132a 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/CreateRulesTests.java @@ -124,7 +124,7 @@ public class CreateRulesTests extends RestTest restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).usingDefaultRuleSet().createSingleRule(ruleModel); restClient.assertStatusCodeIs(NOT_FOUND); - restClient.assertLastError().containsSummary("fake-id was not found"); + restClient.assertLastError().containsSummary("Folder with id fake-id was not found"); } /** Check creating a rule in a non-existent rule set returns an error. */ @@ -138,7 +138,7 @@ public class CreateRulesTests extends RestTest restClient.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingRuleSet("fake-id").createSingleRule(ruleModel); restClient.assertStatusCodeIs(NOT_FOUND); - restClient.assertLastError().containsSummary("fake-id was not found"); + restClient.assertLastError().containsSummary("Rule set with id fake-id was not found"); } /** Try to create a rule without a name and check the error. */ diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java index cd38a5d134..e8067137b0 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/RuleSetLinksTests.java @@ -440,7 +440,7 @@ public class RuleSetLinksTests extends RestTest STEP("Assert unlink result"); restClient.assertStatusCodeIs(NOT_FOUND) - .assertLastError().containsSummary("The entity with id:"); + .assertLastError().containsSummary("Rule set with id non-existent-id was not found"); } /** diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java index c25b3dbaec..bee6b663b0 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/SetInheritanceTests.java @@ -94,7 +94,7 @@ public class SetInheritanceTests extends RestTest .retrieveSetting(); restClient.assertLastError().statusCodeIs(NOT_FOUND) - .containsSummary("The entity with id: fake-id was not found"); + .containsSummary("Folder with id fake-id was not found"); } /** Check we get an error when trying to retrieve a non-existent setting. */ @@ -188,7 +188,7 @@ public class SetInheritanceTests extends RestTest .updateSetting(updateBody); restClient.assertLastError().statusCodeIs(NOT_FOUND) - .containsSummary("The entity with id: fake-id was not found"); + .containsSummary("Folder with id fake-id was not found"); } /** Check we get an error when trying to set a non-existent setting. */ diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java index 94647e82e4..ef8edae581 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/rules/UpdateRulesTests.java @@ -122,7 +122,7 @@ public class UpdateRulesTests extends RestTest .updateRule(rule.getId(), updatedRuleModel); restClient.assertLastError().statusCodeIs(NOT_FOUND) - .containsSummary("fake-id was not found"); + .containsSummary("Folder with id fake-id was not found"); } /** Check we get a 404 if trying to update a rule in a rule set that doesn't exist. */ @@ -138,7 +138,7 @@ public class UpdateRulesTests extends RestTest .updateRule(rule.getId(), updatedRuleModel); restClient.assertLastError().statusCodeIs(NOT_FOUND) - .containsSummary("fake-id was not found"); + .containsSummary("Rule set with id fake-id was not found"); } /** Check we get a 404 if trying to update a rule that doesn't exist. */ diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java index fa3d09a7d1..435f5489d7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -400,12 +400,10 @@ public class NodesImpl implements Nodes @Override public NodeRef validateNode(StoreRef storeRef, String nodeId) { - String versionLabel = null; - int idx = nodeId.indexOf(";"); if (idx != -1) { - versionLabel = nodeId.substring(idx + 1); + String versionLabel = nodeId.substring(idx + 1); nodeId = nodeId.substring(0, idx); if (versionLabel.equals("pwc")) { @@ -1753,7 +1751,7 @@ public class NodesImpl implements Nodes // default false (if not provided) boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT)); - if (permanentDelete == true) + if (permanentDelete) { boolean isAdmin = authorityService.hasAdminAuthority(); if (! isAdmin) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/rules/NodeValidator.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/rules/NodeValidator.java index 7b8cc25c73..31b3fdf6a6 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/rules/NodeValidator.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/rules/NodeValidator.java @@ -35,6 +35,7 @@ import org.alfresco.repo.rule.RuleModel; import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.rules.RuleSet; +import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; @@ -65,14 +66,21 @@ public class NodeValidator * @return folder node reference * @throws InvalidArgumentException if node is not of an expected type * @throws PermissionDeniedException if the user doesn't have the appropriate permission for the folder. + * @throws EntityNotFoundException if the folder node isn't found */ public NodeRef validateFolderNode(final String folderNodeId, boolean requireChangePermission) { - final NodeRef nodeRef = nodes.validateOrLookupNode(folderNodeId, null); - validatePermission(requireChangePermission, nodeRef); - verifyNodeType(nodeRef, ContentModel.TYPE_FOLDER, null); + try + { + final NodeRef nodeRef = nodes.validateOrLookupNode(folderNodeId, null); + validatePermission(requireChangePermission, nodeRef); + verifyNodeType(nodeRef, ContentModel.TYPE_FOLDER, null); - return nodeRef; + return nodeRef; + } catch (EntityNotFoundException e) + { + throw new EntityNotFoundException("Folder with id " + folderNodeId + " was not found.", e); + } } /** @@ -82,6 +90,8 @@ public class NodeValidator * @param associatedFolderNodeRef - folder node ref to check the association * @return rule set node reference * @throws InvalidArgumentException in case of not matching associated folder node + * @throws RelationshipResourceNotFoundException if the folder doesn't have a -default- rule set + * @throws EntityNotFoundException if the rule set node isn't found */ public NodeRef validateRuleSetNode(final String ruleSetId, final NodeRef associatedFolderNodeRef) { @@ -96,13 +106,18 @@ public class NodeValidator return ruleSetNodeRef; } - final NodeRef ruleSetNodeRef = validateNode(ruleSetId, ContentModel.TYPE_SYSTEM_FOLDER, RULE_SET_EXPECTED_TYPE_NAME); - if (!ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, associatedFolderNodeRef)) - { - throw new InvalidArgumentException("Rule set is not associated with folder node!"); - } + try { + final NodeRef ruleSetNodeRef = validateNode(ruleSetId, ContentModel.TYPE_SYSTEM_FOLDER, RULE_SET_EXPECTED_TYPE_NAME); - return ruleSetNodeRef; + if (!ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, associatedFolderNodeRef)) + { + throw new InvalidArgumentException("Rule set is not associated with folder node!"); + } + return ruleSetNodeRef; + + } catch (EntityNotFoundException e) { + throw new EntityNotFoundException("Rule set with id " + ruleSetId + " was not found.", e); + } } public NodeRef validateRuleSetNode(String linkToNodeId, boolean requireChangePermission) diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/EntityNotFoundException.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/EntityNotFoundException.java index 488ed3f498..8ba193cff8 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/EntityNotFoundException.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/EntityNotFoundException.java @@ -43,4 +43,9 @@ public class EntityNotFoundException extends NotFoundException { super(DEFAULT_MESSAGE_ID, new String[] {entityId}); } + + public EntityNotFoundException(String msgId, Throwable cause) + { + super(msgId, cause); + } } diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/NotFoundException.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/NotFoundException.java index 62c0bcb26d..0b4e674c8c 100644 --- a/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/NotFoundException.java +++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/NotFoundException.java @@ -53,4 +53,9 @@ public class NotFoundException extends ApiException super(msgId, notFoundObjects); } + public NotFoundException(String msgId, Throwable cause) + { + super(msgId, cause); + } + }