mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-4362: Fix returned HTTP error status for invalid note type (#1691)
* ACS-4362: Create categories and tags - fix returned HTTP error status for invalid note type
This commit is contained in:
committed by
GitHub
parent
ee7a5370f8
commit
37ec795358
@@ -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.BAD_REQUEST;
|
||||||
import static org.springframework.http.HttpStatus.CREATED;
|
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.METHOD_NOT_ALLOWED;
|
|
||||||
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
import static org.springframework.http.HttpStatus.NOT_FOUND;
|
||||||
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
import static org.springframework.http.HttpStatus.NO_CONTENT;
|
||||||
|
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
import java.util.Collections;
|
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})
|
@Test(groups = { TestGroup.REST_API})
|
||||||
public void testLinkContentToCategory_usingTagInsteadOfContentAndExpect405()
|
public void testLinkContentToCategory_usingTagInsteadOfContentAndExpect422()
|
||||||
{
|
{
|
||||||
STEP("Try to link a tag to category and expect 405");
|
STEP("Add tag to file");
|
||||||
final RestCategoryLinkBodyModel categoryLinkModel = createCategoryLinkModelWithId(category.getId());
|
|
||||||
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
|
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
|
||||||
final RepoTestModel tagNode = createNodeModelWithId(tag.getId());
|
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.authenticateUser(dataUser.getAdminUser()).withCoreAPI().usingNode(tagNode).linkToCategory(categoryLinkModel);
|
||||||
|
|
||||||
restClient.assertStatusCodeIs(METHOD_NOT_ALLOWED);
|
restClient.assertStatusCodeIs(UNPROCESSABLE_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -28,9 +28,9 @@ package org.alfresco.rest.categories;
|
|||||||
|
|
||||||
import static org.alfresco.utility.report.log.Step.STEP;
|
import static org.alfresco.utility.report.log.Step.STEP;
|
||||||
import static org.springframework.http.HttpStatus.FORBIDDEN;
|
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.NOT_FOUND;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
import java.util.List;
|
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})
|
@Test(groups = { TestGroup.REST_API})
|
||||||
public void testListCategoriesForNode_usingTagInsteadOfContentAndExpect405()
|
public void testListCategoriesForNode_usingTagInsteadOfContentAndExpect422()
|
||||||
{
|
{
|
||||||
STEP("Add tag to file");
|
STEP("Add tag to file");
|
||||||
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
|
final RestTagModel tag = restClient.authenticateUser(user).withCoreAPI().usingNode(file).addTag("someTag");
|
||||||
final RepoTestModel tagNode = createNodeModelWithId(tag.getId());
|
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.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)
|
private void denyPermissionsForUser(final String username, final String role, final FileModel file)
|
||||||
|
@@ -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.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.UnsupportedResourceOperationException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException;
|
||||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
import org.alfresco.rest.framework.resource.parameters.ListPage;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
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_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 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 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 AuthorityService authorityService;
|
||||||
private final CategoryService categoryService;
|
private final CategoryService categoryService;
|
||||||
@@ -264,7 +264,7 @@ public class CategoriesImpl implements Categories
|
|||||||
{
|
{
|
||||||
if (!typeConstraint.matches(nodeRef))
|
if (!typeConstraint.matches(nodeRef))
|
||||||
{
|
{
|
||||||
throw new UnsupportedResourceOperationException(INVALID_NODE_TYPE);
|
throw new InvalidNodeTypeException(INVALID_NODE_TYPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* #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);
|
||||||
|
}
|
||||||
|
}
|
@@ -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.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.InsufficientStorage=The file upload exceeds the content storage allowance
|
||||||
framework.exception.JsonpCallbackNotAllowed=For security reasons the callback parameter is not allowed
|
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
|
framework.no.stacktrace=For security reasons the stack trace is no longer displayed, but the property is kept for previous versions
|
||||||
|
|
||||||
|
@@ -177,6 +177,7 @@
|
|||||||
<entry key="org.alfresco.service.cmr.dictionary.InvalidTypeException" value="409" />
|
<entry key="org.alfresco.service.cmr.dictionary.InvalidTypeException" value="409" />
|
||||||
<entry key="org.alfresco.rest.framework.core.exceptions.ArchivedContentException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_PRECONDITION_FAILED}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.ArchivedContentException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_PRECONDITION_FAILED}" />
|
||||||
<entry key="org.alfresco.rest.framework.core.exceptions.RestoreInProgressException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.RestoreInProgressException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||||
|
<entry key="org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException" value="#{T(org.apache.http.HttpStatus).SC_UNPROCESSABLE_ENTITY}" />
|
||||||
</map>
|
</map>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -62,8 +62,8 @@ import org.alfresco.rest.api.model.Category;
|
|||||||
import org.alfresco.rest.api.model.Node;
|
import org.alfresco.rest.api.model.Node;
|
||||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
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.InvalidNodeTypeException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
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.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
@@ -961,7 +961,7 @@ public class CategoriesImplTest
|
|||||||
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
||||||
then(nodeServiceMock).shouldHaveNoInteractions();
|
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||||
assertThat(actualException)
|
assertThat(actualException)
|
||||||
.isInstanceOf(UnsupportedResourceOperationException.class)
|
.isInstanceOf(InvalidNodeTypeException.class)
|
||||||
.hasMessageContaining(INVALID_NODE_TYPE);
|
.hasMessageContaining(INVALID_NODE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1125,7 +1125,7 @@ public class CategoriesImplTest
|
|||||||
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
then(typeConstraint).should().matches(CONTENT_NODE_REF);
|
||||||
then(nodeServiceMock).shouldHaveNoInteractions();
|
then(nodeServiceMock).shouldHaveNoInteractions();
|
||||||
assertThat(actualException)
|
assertThat(actualException)
|
||||||
.isInstanceOf(UnsupportedResourceOperationException.class)
|
.isInstanceOf(InvalidNodeTypeException.class)
|
||||||
.hasMessageContaining(INVALID_NODE_TYPE);
|
.hasMessageContaining(INVALID_NODE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,6 +57,7 @@
|
|||||||
<entry key="org.alfresco.rest.framework.core.exceptions.InsufficientStorageException" value="507" />
|
<entry key="org.alfresco.rest.framework.core.exceptions.InsufficientStorageException" value="507" />
|
||||||
<entry key="org.alfresco.repo.node.integrity.IntegrityException" value="422" />
|
<entry key="org.alfresco.repo.node.integrity.IntegrityException" value="422" />
|
||||||
<entry key="org.alfresco.repo.site.SiteServiceException" value="422" />
|
<entry key="org.alfresco.repo.site.SiteServiceException" value="422" />
|
||||||
|
<entry key="org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException" value="#{T(org.apache.http.HttpStatus).SC_UNPROCESSABLE_ENTITY}" />
|
||||||
</map>
|
</map>
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
Reference in New Issue
Block a user