mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126472 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122394 jkaabimofrad: RA-677: Added node's renditions REST API. - Retrieve information about a rendition of a node + test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126816 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.google.common.collect.Ordering;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -165,11 +166,8 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
assertEquals(3, expectedPaging.getMaxItems().intValue());
|
||||
assertTrue(expectedPaging.getTotalItems() >= 5);
|
||||
|
||||
// Create rendition
|
||||
Rendition renditionRequest = new Rendition();
|
||||
renditionRequest.setId(docLib.getId());
|
||||
// FIXME the response status code should be changed to 202 when we fix the fwk
|
||||
post(getRenditionsUrl(contentNodeId), userOneN1.getId(), RestApiUtil.toJsonAsString(renditionRequest), 201);
|
||||
// Create 'doclib' rendition
|
||||
createRendition(contentNodeId, docLib.getId());
|
||||
|
||||
// This should be long enough for compensating the action to run.
|
||||
Thread.sleep(3000);
|
||||
@@ -201,6 +199,16 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
docLib = getRendition(renditions, "doclib");
|
||||
assertNull("'doclib' rendition has already been created.", docLib);
|
||||
|
||||
// Test returned renditions are ordered (natural sort order)
|
||||
// List all renditions
|
||||
response = getAll(getRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200);
|
||||
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
|
||||
assertTrue(Ordering.natural().isOrdered(renditions));
|
||||
// Try again to make sure the ordering wasn't coincidental
|
||||
response = getAll(getRenditionsUrl(contentNodeId), userOneN1.getId(), paging, params, 200);
|
||||
renditions = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Rendition.class);
|
||||
assertTrue(Ordering.natural().isOrdered(renditions));
|
||||
|
||||
// nodeId in the path parameter does not represent a file
|
||||
getAll(getRenditionsUrl(folder_Id), userOneN1.getId(), paging, params, 400);
|
||||
|
||||
@@ -208,6 +216,68 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
getAll(getRenditionsUrl(UUID.randomUUID().toString()), userOneN1.getId(), paging, params, 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests get node rendition.
|
||||
* <p>GET:</p>
|
||||
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/renditions/<renditionId>}
|
||||
*/
|
||||
@Test
|
||||
public void testGetNodeRendition() throws Exception
|
||||
{
|
||||
// Create a folder within the site document's library
|
||||
String folderName = "folder" + System.currentTimeMillis();
|
||||
String folder_Id = addNode(userOneN1Site, folderName, ContentModel.TYPE_FOLDER, userOneN1.getId());
|
||||
|
||||
// Create multipart request
|
||||
String fileName = "quick.pdf";
|
||||
File file = getResourceFile(fileName);
|
||||
MultiPartBuilder multiPartBuilder = MultiPartBuilder.create().setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_PDF));
|
||||
MultiPartRequest reqBody = multiPartBuilder.build();
|
||||
|
||||
// Upload quick.pdf file into 'folder'
|
||||
HttpResponse response = post("nodes/" + folder_Id + "/children", userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201);
|
||||
Document document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
String contentNodeId = document.getId();
|
||||
|
||||
// Get rendition (not created yet) information for node
|
||||
response = getSingle(getRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib", 200);
|
||||
Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
|
||||
assertNotNull(rendition);
|
||||
assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus());
|
||||
ContentInfo contentInfo = rendition.getContent();
|
||||
assertNotNull(contentInfo);
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, contentInfo.getMimeType());
|
||||
assertEquals("PNG Image", contentInfo.getMimeTypeName());
|
||||
assertNull("Shouldn't have returned the encoding, as the rendition hasn't been created yet.", contentInfo.getEncoding());
|
||||
assertNull("Shouldn't have returned the size, as the rendition hasn't been created yet.", contentInfo.getSizeInBytes());
|
||||
|
||||
// Create 'doclib' rendition
|
||||
createRendition(contentNodeId, "doclib");
|
||||
|
||||
// This should be long enough for compensating the action to run.
|
||||
Thread.sleep(3000);
|
||||
// Get rendition information for node
|
||||
response = getSingle(getRenditionsUrl(contentNodeId), userOneN1.getId(), "doclib", 200);
|
||||
rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
|
||||
assertNotNull(rendition);
|
||||
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
|
||||
contentInfo = rendition.getContent();
|
||||
assertNotNull(contentInfo);
|
||||
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG, contentInfo.getMimeType());
|
||||
assertEquals("PNG Image", contentInfo.getMimeTypeName());
|
||||
assertNotNull(contentInfo.getEncoding());
|
||||
assertTrue(contentInfo.getSizeInBytes() > 0);
|
||||
|
||||
// nodeId in the path parameter does not represent a file
|
||||
getSingle(getRenditionsUrl(folder_Id), userOneN1.getId(), "doclib", 400);
|
||||
|
||||
// nodeId in the path parameter does not exist
|
||||
getSingle(getRenditionsUrl(UUID.randomUUID().toString()), userOneN1.getId(), "doclib", 404);
|
||||
|
||||
// renditionId in the path parameter is not registered/available
|
||||
getSingle(getRenditionsUrl(contentNodeId), userOneN1.getId(), ("renditionId" + System.currentTimeMillis()), 404);
|
||||
}
|
||||
|
||||
private String addNode(final TestSite testSite, final String name, final QName type, String user)
|
||||
{
|
||||
return TenantUtil.runAsUserTenant(new TenantUtil.TenantRunAsWork<String>()
|
||||
@@ -220,6 +290,14 @@ public class RenditionsTest extends AbstractBaseApiTest
|
||||
}, user, testSite.getNetworkId());
|
||||
}
|
||||
|
||||
private void createRendition(String sourceNodeId, String renditionId) throws Exception
|
||||
{
|
||||
Rendition renditionRequest = new Rendition();
|
||||
renditionRequest.setId(renditionId);
|
||||
// FIXME the response status code should be changed to 202 when we fix the fwk
|
||||
post(getRenditionsUrl(sourceNodeId), userOneN1.getId(), RestApiUtil.toJsonAsString(renditionRequest), 201);
|
||||
}
|
||||
|
||||
private Rendition getRendition(List<Rendition> renditions, String renditionName)
|
||||
{
|
||||
for (Rendition rn : renditions)
|
||||
|
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2016 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.tests.client.data;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -10,22 +29,22 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class ContentInfo
|
||||
{
|
||||
private String mimeType;
|
||||
private String mimeType;
|
||||
private String mimeTypeName;
|
||||
private Long sizeInBytes;
|
||||
private String encoding;
|
||||
private Long sizeInBytes;
|
||||
private String encoding;
|
||||
|
||||
public ContentInfo()
|
||||
{
|
||||
}
|
||||
public ContentInfo()
|
||||
{
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public void setMimeType(String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
public void setMimeType(String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
public String getMimeTypeName() {
|
||||
return mimeTypeName;
|
||||
@@ -62,4 +81,16 @@ public class ContentInfo
|
||||
AssertUtil.assertEquals("sizeInBytes", sizeInBytes, other.getSizeInBytes());
|
||||
AssertUtil.assertEquals("encoding", encoding, other.getEncoding());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder(150);
|
||||
sb.append("ContentInfo [mimeType='").append(mimeType)
|
||||
.append(", mimeTypeName='").append(mimeTypeName)
|
||||
.append(", sizeInBytes=").append(sizeInBytes)
|
||||
.append(", encoding='").append(encoding)
|
||||
.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import static org.junit.Assert.assertTrue;
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class Rendition implements ExpectedComparison
|
||||
public class Rendition implements ExpectedComparison, Comparable<Rendition>
|
||||
{
|
||||
public enum RenditionStatus
|
||||
{
|
||||
@@ -98,6 +98,12 @@ public class Rendition implements ExpectedComparison
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Rendition other)
|
||||
{
|
||||
return this.id.compareTo(other.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
Reference in New Issue
Block a user