diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/LinkToCategoriesTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/LinkToCategoriesTests.java
index 8561576444..a8c4468764 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/LinkToCategoriesTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/LinkToCategoriesTests.java
@@ -31,9 +31,9 @@ import static org.alfresco.utility.report.log.Step.STEP;
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.METHOD_NOT_ALLOWED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
+import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import javax.json.Json;
import java.util.Collections;
@@ -356,18 +356,20 @@ public class LinkToCategoriesTests extends CategoriesRestTest
}
/**
- * Try to link non-content node to category and expect 405 (Method Not Allowed)
+ * Try to link non-content node to category and expect 422 (Unprocessable Entity)
*/
@Test(groups = { TestGroup.REST_API})
- public void testLinkContentToCategory_usingTagInsteadOfContentAndExpect405()
+ public void testLinkContentToCategory_usingTagInsteadOfContentAndExpect422()
{
- STEP("Try to link a tag to category and expect 405");
- final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
+ STEP("Add tag to file");
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
final RepoTestModel tagNode = createNodeModelWithId(tag.getId());
+
+ STEP("Try to link a tag to category and expect 422");
+ final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
restClient.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingNode(tagNode).linkToCategory(categoryLinkModel);
- restClient.assertStatusCodeIs(METHOD_NOT_ALLOWED);
+ restClient.assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
/**
diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/ListCategoriesForNodeTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/ListCategoriesForNodeTests.java
index be311704bf..b8de59d338 100644
--- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/ListCategoriesForNodeTests.java
+++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/categories/ListCategoriesForNodeTests.java
@@ -28,9 +28,9 @@ package org.alfresco.rest.categories;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.springframework.http.HttpStatus.FORBIDDEN;
-import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.OK;
+import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import javax.json.Json;
import java.util.List;
@@ -190,19 +190,19 @@ public class ListCategoriesForNodeTests extends CategoriesRestTest
}
/**
- * Try to get linked categories using tag instead of a content and expect 405 (Method Not Allowed)
+ * Try to get linked categories using tag instead of a content and expect 422 (Unprocessable Entity)
*/
@Test(groups = { TestGroup.REST_API})
- public void testListCategoriesForNode_usingTagInsteadOfContentAndExpect405()
+ public void testListCategoriesForNode_usingTagInsteadOfContentAndExpect422()
{
STEP("Add tag to file");
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
final RepoTestModel tagNode = createNodeModelWithId(tag.getId());
- STEP("Try to get linked categories for a tag and expect 405");
+ STEP("Try to get linked categories for a tag and expect 422");
restClient.authenticateUser(user).withCoreAPI().usingNode(tagNode).getLinkedCategories();
- restClient.assertStatusCodeIs(METHOD_NOT_ALLOWED);
+ restClient.assertStatusCodeIs(UNPROCESSABLE_ENTITY);
}
private void denyPermissionsForUser(final String username, final String role, final FileModel file)
diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/CategoriesImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/CategoriesImpl.java
index 14a21651ea..e8e6ff4470 100644
--- a/remote-api/src/main/java/org/alfresco/rest/api/impl/CategoriesImpl.java
+++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/CategoriesImpl.java
@@ -47,7 +47,7 @@ import org.alfresco.rest.api.model.Node;
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.UnsupportedResourceOperationException;
+import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.ListPage;
import org.alfresco.rest.framework.resource.parameters.Parameters;
@@ -74,7 +74,7 @@ public class CategoriesImpl implements Categories
static final String NO_PERMISSION_TO_READ_CONTENT = "Current user does not have read permission to content";
static final String NO_PERMISSION_TO_CHANGE_CONTENT = "Current user does not have change permission to content";
static final String NOT_NULL_OR_EMPTY = "Category name must not be null or empty";
- static final String INVALID_NODE_TYPE = "Cannot categorize this node type";
+ static final String INVALID_NODE_TYPE = "Cannot categorize this type of node";
private final AuthorityService authorityService;
private final CategoryService categoryService;
@@ -264,7 +264,7 @@ public class CategoriesImpl implements Categories
{
if (!typeConstraint.matches(nodeRef))
{
- throw new UnsupportedResourceOperationException(INVALID_NODE_TYPE);
+ throw new InvalidNodeTypeException(INVALID_NODE_TYPE);
}
}
diff --git a/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/InvalidNodeTypeException.java b/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/InvalidNodeTypeException.java
new file mode 100644
index 0000000000..706608072a
--- /dev/null
+++ b/remote-api/src/main/java/org/alfresco/rest/framework/core/exceptions/InvalidNodeTypeException.java
@@ -0,0 +1,51 @@
+/*
+ * #%L
+ * Alfresco Remote API
+ * %%
+ * Copyright (C) 2005 - 2023 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 .
+ * #L%
+ */
+package org.alfresco.rest.framework.core.exceptions;
+
+/**
+ * Type of provided node is invalid.
+ */
+public class InvalidNodeTypeException extends ApiException
+{
+ private static final long serialVersionUID = -672100019820298939L;
+
+ public static String DEFAULT_MESSAGE_ID = "framework.exception.InvalidNodeType";
+
+ public InvalidNodeTypeException(String msgId)
+ {
+ super(msgId);
+ }
+
+ public InvalidNodeTypeException(Object[] msgParams)
+ {
+ super(DEFAULT_MESSAGE_ID, msgParams);
+ }
+
+ public InvalidNodeTypeException(String msgId, Object[] msgParams)
+ {
+ super(msgId, msgParams);
+ }
+}
diff --git a/remote-api/src/main/resources/alfresco/messages/rest-framework-messages.properties b/remote-api/src/main/resources/alfresco/messages/rest-framework-messages.properties
index 8f23a8784c..a842f44129 100644
--- a/remote-api/src/main/resources/alfresco/messages/rest-framework-messages.properties
+++ b/remote-api/src/main/resources/alfresco/messages/rest-framework-messages.properties
@@ -15,5 +15,6 @@ framework.exception.DeletedResource=In this version of the REST API resource {0}
framework.exception.RequestEntityTooLarge=The file can't be uploaded because it's larger than the maximum upload size
framework.exception.InsufficientStorage=The file upload exceeds the content storage allowance
framework.exception.JsonpCallbackNotAllowed=For security reasons the callback parameter is not allowed
+framework.exception.InvalidNodeType=Type of provided node with id: {0} is invalid
framework.no.stacktrace=For security reasons the stack trace is no longer displayed, but the property is kept for previous versions
diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml
index f7149c921e..6c3ed290ca 100644
--- a/remote-api/src/main/resources/alfresco/public-rest-context.xml
+++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml
@@ -177,6 +177,7 @@
+
diff --git a/remote-api/src/test/java/org/alfresco/rest/api/impl/CategoriesImplTest.java b/remote-api/src/test/java/org/alfresco/rest/api/impl/CategoriesImplTest.java
index 197dbd8f41..80d110571a 100644
--- a/remote-api/src/test/java/org/alfresco/rest/api/impl/CategoriesImplTest.java
+++ b/remote-api/src/test/java/org/alfresco/rest/api/impl/CategoriesImplTest.java
@@ -62,8 +62,8 @@ import org.alfresco.rest.api.model.Category;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
+import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
-import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -961,7 +961,7 @@ public class CategoriesImplTest
then(typeConstraint).should().matches(CONTENT_NODE_REF);
then(nodeServiceMock).shouldHaveNoInteractions();
assertThat(actualException)
- .isInstanceOf(UnsupportedResourceOperationException.class)
+ .isInstanceOf(InvalidNodeTypeException.class)
.hasMessageContaining(INVALID_NODE_TYPE);
}
@@ -1125,7 +1125,7 @@ public class CategoriesImplTest
then(typeConstraint).should().matches(CONTENT_NODE_REF);
then(nodeServiceMock).shouldHaveNoInteractions();
assertThat(actualException)
- .isInstanceOf(UnsupportedResourceOperationException.class)
+ .isInstanceOf(InvalidNodeTypeException.class)
.hasMessageContaining(INVALID_NODE_TYPE);
}
diff --git a/remote-api/src/test/resources/test-rest-context.xml b/remote-api/src/test/resources/test-rest-context.xml
index ce960a71e5..d834203679 100644
--- a/remote-api/src/test/resources/test-rest-context.xml
+++ b/remote-api/src/test/resources/test-rest-context.xml
@@ -57,6 +57,7 @@
+