ACS-3616: fix exception type for missing node id (#1457)

* ACS-3616: fix exception type for missing node id

* ACS-3616: fix exception handling for missing node id

* ACS-3616: update javadoc, add a constructor for the exception
This commit is contained in:
George Evangelopoulos
2022-10-10 19:52:19 +01:00
committed by GitHub
parent 81f2bd7018
commit 6bcf33d672
8 changed files with 44 additions and 21 deletions

View File

@@ -124,7 +124,7 @@ public class CreateRulesTests extends RestTest
restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).usingDefaultRuleSet().createSingleRule(ruleModel); restClient.authenticateUser(user).withCoreAPI().usingNode(nonExistentFolder).usingDefaultRuleSet().createSingleRule(ruleModel);
restClient.assertStatusCodeIs(NOT_FOUND); 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. */ /** 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.authenticateUser(user).withCoreAPI().usingNode(ruleFolder).usingRuleSet("fake-id").createSingleRule(ruleModel);
restClient.assertStatusCodeIs(NOT_FOUND); 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. */ /** Try to create a rule without a name and check the error. */

View File

@@ -440,7 +440,7 @@ public class RuleSetLinksTests extends RestTest
STEP("Assert unlink result"); STEP("Assert unlink result");
restClient.assertStatusCodeIs(NOT_FOUND) restClient.assertStatusCodeIs(NOT_FOUND)
.assertLastError().containsSummary("The entity with id:"); .assertLastError().containsSummary("Rule set with id non-existent-id was not found");
} }
/** /**

View File

@@ -94,7 +94,7 @@ public class SetInheritanceTests extends RestTest
.retrieveSetting(); .retrieveSetting();
restClient.assertLastError().statusCodeIs(NOT_FOUND) 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. */ /** Check we get an error when trying to retrieve a non-existent setting. */
@@ -188,7 +188,7 @@ public class SetInheritanceTests extends RestTest
.updateSetting(updateBody); .updateSetting(updateBody);
restClient.assertLastError().statusCodeIs(NOT_FOUND) 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. */ /** Check we get an error when trying to set a non-existent setting. */

View File

@@ -122,7 +122,7 @@ public class UpdateRulesTests extends RestTest
.updateRule(rule.getId(), updatedRuleModel); .updateRule(rule.getId(), updatedRuleModel);
restClient.assertLastError().statusCodeIs(NOT_FOUND) 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. */ /** 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); .updateRule(rule.getId(), updatedRuleModel);
restClient.assertLastError().statusCodeIs(NOT_FOUND) 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. */ /** Check we get a 404 if trying to update a rule that doesn't exist. */

View File

@@ -400,12 +400,10 @@ public class NodesImpl implements Nodes
@Override @Override
public NodeRef validateNode(StoreRef storeRef, String nodeId) public NodeRef validateNode(StoreRef storeRef, String nodeId)
{ {
String versionLabel = null;
int idx = nodeId.indexOf(";"); int idx = nodeId.indexOf(";");
if (idx != -1) if (idx != -1)
{ {
versionLabel = nodeId.substring(idx + 1); String versionLabel = nodeId.substring(idx + 1);
nodeId = nodeId.substring(0, idx); nodeId = nodeId.substring(0, idx);
if (versionLabel.equals("pwc")) if (versionLabel.equals("pwc"))
{ {
@@ -1753,7 +1751,7 @@ public class NodesImpl implements Nodes
// default false (if not provided) // default false (if not provided)
boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT)); boolean permanentDelete = Boolean.valueOf(parameters.getParameter(PARAM_PERMANENT));
if (permanentDelete == true) if (permanentDelete)
{ {
boolean isAdmin = authorityService.hasAdminAuthority(); boolean isAdmin = authorityService.hasAdminAuthority();
if (! isAdmin) if (! isAdmin)

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.rule.RuleModel;
import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.rules.RuleSet; 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.InvalidArgumentException;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException; import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
@@ -65,14 +66,21 @@ public class NodeValidator
* @return folder node reference * @return folder node reference
* @throws InvalidArgumentException if node is not of an expected type * @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 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) public NodeRef validateFolderNode(final String folderNodeId, boolean requireChangePermission)
{ {
final NodeRef nodeRef = nodes.validateOrLookupNode(folderNodeId, null); try
validatePermission(requireChangePermission, nodeRef); {
verifyNodeType(nodeRef, ContentModel.TYPE_FOLDER, null); 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 * @param associatedFolderNodeRef - folder node ref to check the association
* @return rule set node reference * @return rule set node reference
* @throws InvalidArgumentException in case of not matching associated folder node * @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) public NodeRef validateRuleSetNode(final String ruleSetId, final NodeRef associatedFolderNodeRef)
{ {
@@ -96,13 +106,18 @@ public class NodeValidator
return ruleSetNodeRef; return ruleSetNodeRef;
} }
final NodeRef ruleSetNodeRef = validateNode(ruleSetId, ContentModel.TYPE_SYSTEM_FOLDER, RULE_SET_EXPECTED_TYPE_NAME); try {
if (!ruleService.isRuleSetAssociatedWithFolder(ruleSetNodeRef, associatedFolderNodeRef)) final NodeRef ruleSetNodeRef = validateNode(ruleSetId, ContentModel.TYPE_SYSTEM_FOLDER, RULE_SET_EXPECTED_TYPE_NAME);
{
throw new InvalidArgumentException("Rule set is not associated with folder node!");
}
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) public NodeRef validateRuleSetNode(String linkToNodeId, boolean requireChangePermission)

View File

@@ -43,4 +43,9 @@ public class EntityNotFoundException extends NotFoundException
{ {
super(DEFAULT_MESSAGE_ID, new String[] {entityId}); super(DEFAULT_MESSAGE_ID, new String[] {entityId});
} }
public EntityNotFoundException(String msgId, Throwable cause)
{
super(msgId, cause);
}
} }

View File

@@ -53,4 +53,9 @@ public class NotFoundException extends ApiException
super(msgId, notFoundObjects); super(msgId, notFoundObjects);
} }
public NotFoundException(String msgId, Throwable cause)
{
super(msgId, cause);
}
} }