mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129790 jvonka: REPO-164 / REPO-1141: fix error mapping when unable to update content due to locked node (should be 409 not 500) - also minor cleanup of error handling/mapping (handle within common "writeContent") git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130230 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -157,8 +157,10 @@
|
||||
<entry key="org.alfresco.service.cmr.lock.UnableToReleaseLockException" value="422" />
|
||||
<entry key="org.alfresco.service.cmr.repository.DuplicateChildNodeNameException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||
<entry key="org.alfresco.rest.framework.core.exceptions.StaleEntityException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_CONFLICT}" />
|
||||
<entry key="org.alfresco.repo.content.ContentLimitViolationException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_REQUEST_ENTITY_TOO_LARGE}" />
|
||||
<entry key="org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_REQUEST_ENTITY_TOO_LARGE}" />
|
||||
<entry key="org.alfresco.rest.framework.core.exceptions.DisabledServiceException" value="#{T(org.springframework.extensions.webscripts.Status).STATUS_NOT_IMPLEMENTED}" />
|
||||
<entry key="org.alfresco.service.cmr.usage.ContentQuotaException" 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.site.SiteServiceException" value="422" />
|
||||
|
@@ -124,6 +124,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.lock.LockStatus;
|
||||
import org.alfresco.service.cmr.lock.NodeLockedException;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
@@ -131,6 +132,7 @@ import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.AssociationExistsException;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
|
||||
@@ -2375,16 +2377,17 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
|
||||
private void writeContent(NodeRef nodeRef, String fileName, InputStream stream, boolean guessEncoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
|
||||
String mimeType = mimetypeService.guessMimetype(fileName);
|
||||
if ((mimeType != null) && (! mimeType.equals(MimetypeMap.MIMETYPE_BINARY)))
|
||||
if ((mimeType != null) && (!mimeType.equals(MimetypeMap.MIMETYPE_BINARY)))
|
||||
{
|
||||
// quick/weak guess based on file extension
|
||||
writer.setMimetype(mimeType);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
// stronger guess based on file stream
|
||||
writer.guessMimetype(fileName);
|
||||
@@ -2400,22 +2403,37 @@ public class NodesImpl implements Nodes
|
||||
try
|
||||
{
|
||||
is.reset();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
} catch (IOException ioe)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Failed to reset stream after trying to guess encoding: " + ioe.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
is = stream;
|
||||
}
|
||||
|
||||
writer.putContent(is);
|
||||
}
|
||||
catch (ContentQuotaException cqe)
|
||||
{
|
||||
throw new InsufficientStorageException();
|
||||
}
|
||||
catch (ContentLimitViolationException clv)
|
||||
{
|
||||
throw new RequestEntityTooLargeException(clv.getMessage());
|
||||
}
|
||||
catch (ContentIOException cioe)
|
||||
{
|
||||
if (cioe.getCause() instanceof NodeLockedException)
|
||||
{
|
||||
throw (NodeLockedException)cioe.getCause();
|
||||
}
|
||||
throw cioe;
|
||||
}
|
||||
}
|
||||
|
||||
private String guessEncoding(InputStream in, String mimeType, boolean close)
|
||||
{
|
||||
@@ -2660,14 +2678,6 @@ public class NodesImpl implements Nodes
|
||||
{
|
||||
throw new PermissionDeniedException(ade.getMessage());
|
||||
}
|
||||
catch (ContentQuotaException cqe)
|
||||
{
|
||||
throw new InsufficientStorageException();
|
||||
}
|
||||
catch (ContentLimitViolationException clv)
|
||||
{
|
||||
throw new RequestEntityTooLargeException(clv.getMessage());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
/*
|
||||
|
@@ -764,16 +764,29 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
|
||||
// create empty file
|
||||
HttpResponse response = post(getNodeChildrenUrl(parentFolderId), toJsonAsStringNonNull(d1), params, null, "alfresco", expectedStatus);
|
||||
if (expectedStatus != 201)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
|
||||
protected Document updateTextFile(String contentId, String textContent, Map<String, String> params) throws IOException, Exception
|
||||
protected Document updateTextFile(String contentId, String textContent, Map<String, String> params) throws Exception
|
||||
{
|
||||
return updateTextFile(contentId, textContent, params, 200);
|
||||
}
|
||||
|
||||
protected Document updateTextFile(String contentId, String textContent, Map<String, String> params, int expectedStatus) throws Exception
|
||||
{
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(textContent.getBytes());
|
||||
File txtFile = TempFileProvider.createTempFile(inputStream, getClass().getSimpleName(), ".txt");
|
||||
BinaryPayload payload = new BinaryPayload(txtFile);
|
||||
|
||||
HttpResponse response = putBinary(getNodeContentUrl(contentId), payload, null, params, 200);
|
||||
HttpResponse response = putBinary(getNodeContentUrl(contentId), payload, null, params, expectedStatus);
|
||||
if (expectedStatus != 200)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
|
||||
|
@@ -3631,6 +3631,8 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
// Test delete on a folder which contains a locked node - NodeLockedException
|
||||
deleteNode(folderId, true, HttpStatus.SC_CONFLICT);
|
||||
|
||||
updateTextFile(d1Id, "Updated text", null, 409);
|
||||
|
||||
// Test lock children
|
||||
// create folder
|
||||
String folderAName = "folder" + RUNID + "_A";
|
||||
@@ -3683,6 +3685,9 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
assertNotNull(child.getProperties().get("cm:lockType"));
|
||||
assertNotNull(child.getProperties().get("cm:lockOwner"));
|
||||
assertTrue(child.getIsLocked());
|
||||
|
||||
// note: these can be updated by the owner since the lock type is "ALLOW_OWNER_CHANGES"
|
||||
updateTextFile(child.getId(), "Updated text", null, 200);
|
||||
}
|
||||
|
||||
// Lock body properties - boundary values
|
||||
|
Reference in New Issue
Block a user