mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
34321: Make CIFS virtual circuit per session limit configurable, return correct status code when virtual circuit limit is reached. Required by Terminal Server clients as they can use a single session for all connections. ALF-13156 34322: Services part of fix for ALF-13057 Nodes marked with rma:ghosted aspect (or other configurable aspects/types) should not be renditioned. 34323: Added configuration property for CIFS virtual circuits per session, required by Terminal Server clients. ALF-13156. 34332: Fix for ALF-8405 34336: Merged BRANCHES/V4.0 to BRANCHES/DEV/V4.0-BUG-FIX: 34335: Fixing a failing test as part of ALF-13057 34338: NodeDAO: re-parent "lost & found" orphan child nodes (see ALF-12358 & ALF-13066 / SYS-301) - test fix (follow-on to r34279) 34341: NodeDAO: re-parent "lost & found" orphan child nodes (see ALF-12358 & ALF-13066 / SYS-301) - ano test fix (once more with feeling) 34351: Merged V4.0 to V4.0-BUG-FIX 34335: (RECORD ONLY) Fixing a failing test as part of ALF-13057 34350: Merged V3.4 to V4.0 34327: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD Relates to ALF-10976 and ALF-10412 set of changes - TransformerOptions.sourceNodeRef now populated - Set average transformer time via global properties - TransformerDebug of active transformers added 34331: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD Relates to ALF-10976 and ALF-10412 set of changes - Fix test failures 34346: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD Relates to ALF-10976 and ALF-10412 set of changes - sourceNodeRef was not available to the first child transformer of a ComplexContentTransformer 34358: Merged V4.0 to V4.0-BUG-FIX (RECORD ONLY) 34324: Merged BRANCHES/DEV/V4.0-BUG-FIX to BRANCHES/V4.0: 34322: Services part of fix for ALF-13057 Nodes marked with rma:ghosted aspect (or other configurable aspects/types) should not be renditioned. 34360: Merged V3.4-BUG-FIX to V4.0-BUG-FIX (RECORD ONLY) 34349: Merged V3.4 to V3.4-BUG-FIX 34327: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD Relates to ALF-10976 and ALF-10412 set of changes - TransformerOptions.sourceNodeRef now populated - Set average transformer time via global properties - TransformerDebug of active transformers added 34331: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD Relates to ALF-10976 and ALF-10412 set of changes - Fix test failures 34346: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD Relates to ALF-10976 and ALF-10412 set of changes - sourceNodeRef was not available to the first child transformer of a ComplexContentTransformer 34348: Merged PATCHES/V3.4.7 to V3.4 34347: ALF-12949: Merged V4.0-BUG-FIX to PATCHES/V3.4.7 33959: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX 33950: Fix for ALF-12787: - Surf Memory usage optimizations and improvements to ModelObject and derived classes. - Reduced avg memory usage for a ModelObject in the Surf persister cache from 4.0K to 1.5K. - Related refactoring to support removal of in-memory XML DOM previously used to maintain ModelObject state. Now XML DOM only created as needed for set() operations and thrown away. - Improvements to Surf Persister cache strategy to support MRU style concurrent cache, now uses a LinkedConcurrentHashMap to provide a concurrent cache that also has a configurable maximum capacity - Added various improved spring config for persister caches and default sizes. Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX 33956: Latest SpringSurf libs: Fixed issue with overly aggressive caching of missing page View objects. 34108: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX 34107: Added missing jar lib to wcmquickstart and webeditor dependencies 34363: Merged V4.0 to V4.0-BUG-FIX 34362: Merged V3.4 to V4.0 (RECORD ONLY) 34282: ALF-13059: Windows 7 specific: It's impossible to add documents to DWS - Fix by Alex Malinovsky 34348: Merged PATCHES/V3.4.7 to V3.4 34347: ALF-12949: Merged V4.0-BUG-FIX to PATCHES/V3.4.7 33959: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX 33950: Fix for ALF-12787: - Surf Memory usage optimizations and improvements to ModelObject and derived classes. - Reduced avg memory usage for a ModelObject in the Surf persister cache from 4.0K to 1.5K. - Related refactoring to support removal of in-memory XML DOM previously used to maintain ModelObject state. Now XML DOM only created as needed for set() operations and thrown away. - Improvements to Surf Persister cache strategy to support MRU style concurrent cache, now uses a LinkedConcurrentHashMap to provide a concurrent cache that also has a configurable maximum capacity - Added various improved spring config for persister caches and default sizes. Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX 33956: Latest SpringSurf libs: Fixed issue with overly aggressive caching of missing page View objects. 34108: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX 34107: Added missing jar lib to wcmquickstart and webeditor dependencies git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@34364 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
369 lines
14 KiB
Java
369 lines
14 KiB
Java
/*
|
|
* Copyright (C) 2005-2012 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.cmis.renditions;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Set;
|
|
|
|
import org.alfresco.cmis.CMISRendition;
|
|
import org.alfresco.cmis.mapping.BaseCMISTest;
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
|
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
|
import org.alfresco.service.cmr.repository.ContentReader;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.TransformationOptions;
|
|
|
|
/**
|
|
* @author Stas Sokolovsky
|
|
*/
|
|
public class CMISRenditionServiceTest extends BaseCMISTest
|
|
{
|
|
private static final String[] THUMBNAIL_NAMES = new String[] { "doclib", "webpreview", "imgpreview" };
|
|
private static final String[] THUMBNAIL_KINDS = new String[] { "cmis:thumbnail", "alf:webpreview", "alf:webpreview" };
|
|
|
|
private NodeRef document;
|
|
private List<CMISRendition> documentRenditions = new ArrayList<CMISRendition>();
|
|
private CMISRendition icon16Rendition = new CMISRenditionImpl(null, "alf:icon16", "image/gif", "alf:icon16", 16, 16, null, null, null);
|
|
private CMISRendition icon32Rendition = new CMISRenditionImpl(null, "alf:icon32", "image/gif", "alf:icon32", 32, 32, null, null, null);
|
|
|
|
public void setUp() throws Exception
|
|
{
|
|
super.setUp();
|
|
|
|
String documentName = "TestDocument" + System.currentTimeMillis();
|
|
document = createDocument(documentName, "Test Content", MimetypeMap.MIMETYPE_PDF);
|
|
|
|
documentRenditions = new ArrayList<CMISRendition>();
|
|
for (int i = 0; i < THUMBNAIL_NAMES.length; ++i)
|
|
{
|
|
documentRenditions.add(createRendition(document, THUMBNAIL_NAMES[i], THUMBNAIL_KINDS[i]));
|
|
}
|
|
}
|
|
|
|
public void testGetAllRenditions() throws Exception
|
|
{
|
|
List<CMISRendition> receivedRenditions = cmisRenditionService.getRenditions(document, "*");
|
|
|
|
List<CMISRendition> expectedRenditions = new ArrayList<CMISRendition>();
|
|
expectedRenditions.addAll(documentRenditions);
|
|
expectedRenditions.add(icon16Rendition);
|
|
expectedRenditions.add(icon32Rendition);
|
|
|
|
assertRendiions(receivedRenditions, expectedRenditions);
|
|
}
|
|
|
|
public void testGetRenditionsByKind() throws Exception
|
|
{
|
|
testGetRenditionsByKind("cmis:thumbnail");
|
|
testGetRenditionsByKind("alf:webpreview");
|
|
testGetRenditionsByKind("alf:icon16");
|
|
testGetRenditionsByKind("alf:icon32");
|
|
|
|
testGetRenditionsByKind("alf:webpreview", "alf:icon32");
|
|
testGetRenditionsByKind("cmis:thumbnail", "alf:webpreview", "alf:icon16", "alf:icon32");
|
|
}
|
|
|
|
public void testGetRenditionsByMimetype() throws Exception
|
|
{
|
|
for (CMISRendition rendition : documentRenditions)
|
|
{
|
|
testGetRenditionsByMimetype(rendition.getMimeType());
|
|
}
|
|
testGetRenditionsByMimetype(icon16Rendition.getMimeType());
|
|
testGetRenditionsByMimetype(icon32Rendition.getMimeType());
|
|
|
|
String[] mimetypes = getDifferentMimetypes();
|
|
testGetRenditionsByMimetype(mimetypes);
|
|
}
|
|
|
|
public void testEmptyFilter() throws Exception
|
|
{
|
|
List<CMISRendition> receivedRenditions = cmisRenditionService.getRenditions(document, null);
|
|
assertTrue(receivedRenditions == null || receivedRenditions.size() == 0);
|
|
|
|
receivedRenditions = cmisRenditionService.getRenditions(document, "cmis:none");
|
|
assertTrue(receivedRenditions == null || receivedRenditions.size() == 0);
|
|
}
|
|
|
|
public void testRenditionsByBaseMimetype() throws Exception
|
|
{
|
|
String[] mimetypes = getDifferentMimetypes();
|
|
List<String> baseMimetypeFilters = new ArrayList<String>();
|
|
for (String mimetype : mimetypes)
|
|
{
|
|
String baseMimetype = getBaseType(mimetype);
|
|
String filter = baseMimetype + "/*";
|
|
baseMimetypeFilters.add(filter);
|
|
|
|
testGetRenditionsByMimetype(filter);
|
|
}
|
|
|
|
testGetRenditionsByMimetype(baseMimetypeFilters.toArray(new String[0]));
|
|
}
|
|
|
|
public void testMixedFilter() throws Exception
|
|
{
|
|
String[] mimetypes = getDifferentMimetypes();
|
|
testGetRenditions(THUMBNAIL_KINDS, mimetypes);
|
|
}
|
|
|
|
private void testGetRenditionsByMimetype(String... mimetypes) throws Exception
|
|
{
|
|
testGetRenditions(null, mimetypes);
|
|
}
|
|
|
|
private void testGetRenditionsByKind(String... kinds) throws Exception
|
|
{
|
|
testGetRenditions(kinds, null);
|
|
}
|
|
|
|
private void testGetRenditions(String[] kinds, String[] mimetypes) throws Exception
|
|
{
|
|
String filter = createFilter(kinds, mimetypes);
|
|
List<CMISRendition> receivedRenditions = cmisRenditionService.getRenditions(document, filter);
|
|
|
|
List<CMISRendition> expectedRenditions = new ArrayList<CMISRendition>();
|
|
if (kinds != null)
|
|
{
|
|
for (String kind : kinds)
|
|
{
|
|
expectedRenditions.addAll(getRenditionsByKind(kind));
|
|
}
|
|
}
|
|
if (mimetypes != null)
|
|
{
|
|
for (String mimetype : mimetypes)
|
|
{
|
|
expectedRenditions.addAll(getRenditionsByMimetype(mimetype));
|
|
}
|
|
}
|
|
|
|
assertRendiions(receivedRenditions, expectedRenditions);
|
|
}
|
|
|
|
protected void tearDown() throws Exception
|
|
{
|
|
fileFolderService.delete(document);
|
|
super.tearDown();
|
|
}
|
|
|
|
private CMISRendition createRendition(NodeRef nodeRef, String thumbnailName, String kind)
|
|
{
|
|
ThumbnailDefinition details = thumbnailService.getThumbnailRegistry().getThumbnailDefinition(thumbnailName);
|
|
NodeRef thumbnailNodeRef = thumbnailService.createThumbnail(nodeRef, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details
|
|
.getName());
|
|
|
|
CMISRenditionImpl rendition = new CMISRenditionImpl();
|
|
rendition.setStreamId(thumbnailNodeRef.toString());
|
|
rendition.setKind(kind);
|
|
rendition.setMimeType(details.getMimetype());
|
|
if (details.getTransformationOptions() instanceof ImageTransformationOptions)
|
|
{
|
|
ImageTransformationOptions imageOptions = (ImageTransformationOptions) details.getTransformationOptions();
|
|
rendition.setWidth(imageOptions.getResizeOptions().getWidth());
|
|
rendition.setHeight(imageOptions.getResizeOptions().getHeight());
|
|
}
|
|
|
|
return rendition;
|
|
}
|
|
|
|
private NodeRef createDocument(String documentName, String documentContent, String mimetype)
|
|
{
|
|
NodeRef textDocument = fileFolderService.create(rootNodeRef, "TEXT" + documentName, ContentModel.TYPE_CONTENT).getNodeRef();
|
|
ContentWriter contentWriter = fileFolderService.getWriter(textDocument);
|
|
contentWriter.setEncoding("UTF-8");
|
|
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
|
contentWriter.setLocale(Locale.ENGLISH);
|
|
contentWriter.putContent(documentContent);
|
|
ContentReader contentReader = fileFolderService.getReader(textDocument);
|
|
// contentReader will not be null as an exception will have been thrown if there was a problem
|
|
|
|
NodeRef document = fileFolderService.create(rootNodeRef, documentName, ContentModel.TYPE_CONTENT).getNodeRef();
|
|
contentWriter = fileFolderService.getWriter(document);
|
|
contentWriter.setEncoding("UTF-8");
|
|
contentWriter.setMimetype(mimetype);
|
|
contentWriter.setLocale(Locale.ENGLISH);
|
|
|
|
TransformationOptions options = new TransformationOptions();
|
|
options.setSourceNodeRef(textDocument);
|
|
|
|
if (contentService.isTransformable(contentReader, contentWriter, options))
|
|
{
|
|
contentService.transform(contentReader, contentWriter, options);
|
|
}
|
|
|
|
fileFolderService.delete(textDocument);
|
|
|
|
return document;
|
|
}
|
|
|
|
private void assertRendiions(List<CMISRendition> receivedRenditions, List<CMISRendition> expectedRenditions)
|
|
{
|
|
assertNotNull(receivedRenditions);
|
|
expectedRenditions = removeReplication(expectedRenditions);
|
|
assertTrue(receivedRenditions.size() == expectedRenditions.size());
|
|
|
|
for (CMISRendition rendition : receivedRenditions)
|
|
{
|
|
assertNotNull(rendition);
|
|
assertNotNull(rendition.getStreamId());
|
|
}
|
|
|
|
Collections.sort(receivedRenditions, renditionsComparator);
|
|
Collections.sort(expectedRenditions, renditionsComparator);
|
|
|
|
for (int i = 0; i < expectedRenditions.size(); ++i)
|
|
{
|
|
assertRendition(receivedRenditions.get(i), expectedRenditions.get(i));
|
|
}
|
|
}
|
|
|
|
private void assertRendition(CMISRendition receivedRendition, CMISRendition expectedRendition)
|
|
{
|
|
assertEquals(expectedRendition.getStreamId(), receivedRendition.getStreamId());
|
|
assertEquals(expectedRendition.getKind(), receivedRendition.getKind());
|
|
assertEquals(expectedRendition.getMimeType(), receivedRendition.getMimeType());
|
|
assertEquals(expectedRendition.getWidth(), receivedRendition.getWidth());
|
|
assertEquals(expectedRendition.getHeight(), receivedRendition.getHeight());
|
|
}
|
|
|
|
private List<CMISRendition> removeReplication(List<CMISRendition> renditions)
|
|
{
|
|
return new ArrayList<CMISRendition>(new HashSet<CMISRendition>(renditions));
|
|
}
|
|
|
|
private Comparator<CMISRendition> renditionsComparator = new Comparator<CMISRendition>()
|
|
{
|
|
public int compare(CMISRendition rendition1, CMISRendition rendition2)
|
|
{
|
|
return rendition1.getStreamId().compareTo(rendition2.getStreamId());
|
|
}
|
|
};
|
|
|
|
private List<CMISRendition> getRenditionsByKind(String kind)
|
|
{
|
|
return getRenditions(kind, null);
|
|
}
|
|
|
|
private List<CMISRendition> getRenditionsByMimetype(String mimetype)
|
|
{
|
|
return getRenditions(null, mimetype);
|
|
}
|
|
|
|
private List<CMISRendition> getRenditions(String kind, String mimetype)
|
|
{
|
|
List<CMISRendition> result = new ArrayList<CMISRendition>();
|
|
|
|
List<CMISRendition> allRenditions = new ArrayList<CMISRendition>(documentRenditions);
|
|
allRenditions.add(icon16Rendition);
|
|
allRenditions.add(icon32Rendition);
|
|
for (CMISRendition rendition : allRenditions)
|
|
{
|
|
if (isRenditionSatisfyConditions(rendition, kind, mimetype))
|
|
{
|
|
result.add(rendition);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private boolean isRenditionSatisfyConditions(CMISRendition rendition, String kind, String mimetype)
|
|
{
|
|
if (kind != null)
|
|
{
|
|
if (!kind.equals(rendition.getKind()))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
if (mimetype != null)
|
|
{
|
|
if (mimetype.endsWith("/*"))
|
|
{
|
|
String baseMimetype = getBaseType(mimetype);
|
|
if (!rendition.getMimeType().startsWith(baseMimetype))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else if (!mimetype.equals(rendition.getMimeType()))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private String[] getDifferentMimetypes()
|
|
{
|
|
List<CMISRendition> allRenditions = new ArrayList<CMISRendition>(documentRenditions);
|
|
allRenditions.add(icon16Rendition);
|
|
allRenditions.add(icon32Rendition);
|
|
Set<String> mimetypes = new HashSet<String>();
|
|
for (CMISRendition rendition : allRenditions)
|
|
{
|
|
mimetypes.add(rendition.getMimeType());
|
|
}
|
|
return mimetypes.toArray(new String[0]);
|
|
}
|
|
|
|
private String getBaseType(String mimetype)
|
|
{
|
|
String baseMymetype = mimetype;
|
|
int subTypeIndex = mimetype.indexOf("/");
|
|
if (subTypeIndex > 0 || subTypeIndex < mimetype.length())
|
|
{
|
|
baseMymetype = mimetype.substring(0, subTypeIndex);
|
|
}
|
|
return baseMymetype;
|
|
}
|
|
|
|
private String createFilter(String[] kinds, String[] mimetypes)
|
|
{
|
|
StringBuilder filter = new StringBuilder();
|
|
if (kinds != null)
|
|
{
|
|
for (String kind : kinds)
|
|
{
|
|
filter.append(kind);
|
|
filter.append(",");
|
|
}
|
|
}
|
|
if (mimetypes != null)
|
|
{
|
|
for (String mimetype : mimetypes)
|
|
{
|
|
filter.append(mimetype);
|
|
filter.append(",");
|
|
}
|
|
}
|
|
filter.delete(filter.length() - 1, filter.length());
|
|
return filter.toString();
|
|
}
|
|
|
|
}
|