mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Changed ThumbnailServiceImpl to create renditions of type cm:thumbnail and set the thumbnail name property on them correctly.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19184 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,10 +39,7 @@
|
|||||||
<!-- Thumbnail service implementation bean -->
|
<!-- Thumbnail service implementation bean -->
|
||||||
<bean id="thumbnailService" class="org.alfresco.repo.thumbnail.ThumbnailServiceImpl">
|
<bean id="thumbnailService" class="org.alfresco.repo.thumbnail.ThumbnailServiceImpl">
|
||||||
<property name="nodeService" ref="nodeService"/>
|
<property name="nodeService" ref="nodeService"/>
|
||||||
<property name="contentService" ref="contentService"/>
|
|
||||||
<property name="mimetypeMap" ref="mimetypeService"/>
|
|
||||||
<property name="renditionService" ref="renditionService" />
|
<property name="renditionService" ref="renditionService" />
|
||||||
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
|
||||||
<property name="thumbnailRegistry" ref="thumbnailRegistry" />
|
<property name="thumbnailRegistry" ref="thumbnailRegistry" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
*
|
*
|
||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
*/
|
*/
|
||||||
public class ActionImpl extends ParameterizedItemImpl implements Serializable, Action
|
public class ActionImpl extends ParameterizedItemImpl implements Action
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Serial version UID
|
* Serial version UID
|
||||||
@@ -432,4 +432,10 @@ public class ActionImpl extends ParameterizedItemImpl implements Serializable, A
|
|||||||
{
|
{
|
||||||
this.nodeRef = nodeRef;
|
this.nodeRef = nodeRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addParameterValues(Map<String, Serializable> values)
|
||||||
|
{
|
||||||
|
getParameterValues().putAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.rendition;
|
package org.alfresco.repo.rendition;
|
||||||
|
|
||||||
|
import org.alfresco.repo.rendition.executer.AbstractRenderingEngineTest;
|
||||||
import org.alfresco.repo.thumbnail.ThumbnailServiceImplParameterTest;
|
import org.alfresco.repo.thumbnail.ThumbnailServiceImplParameterTest;
|
||||||
import org.alfresco.repo.thumbnail.ThumbnailServiceImplTest;
|
import org.alfresco.repo.thumbnail.ThumbnailServiceImplTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -33,6 +34,7 @@ import org.junit.runners.Suite;
|
|||||||
@RunWith(Suite.class)
|
@RunWith(Suite.class)
|
||||||
@Suite.SuiteClasses({
|
@Suite.SuiteClasses({
|
||||||
RenditionServiceImplTest.class,
|
RenditionServiceImplTest.class,
|
||||||
|
AbstractRenderingEngineTest.class,
|
||||||
ThumbnailServiceImplParameterTest.class,
|
ThumbnailServiceImplParameterTest.class,
|
||||||
ThumbnailServiceImplTest.class,
|
ThumbnailServiceImplTest.class,
|
||||||
StandardRenditionLocationResolverTest.class,
|
StandardRenditionLocationResolverTest.class,
|
||||||
|
@@ -492,6 +492,8 @@ public class PerformRenditionActionExecuter extends ActionExecuterAbstractBase
|
|||||||
log.debug(msg.toString());
|
log.debug(msg.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QName type = nodeService.getType(sourceNode);
|
||||||
|
nodeService.setType(targetNode, type);
|
||||||
Map<QName, Serializable> newProps = nodeService.getProperties(sourceNode);
|
Map<QName, Serializable> newProps = nodeService.getProperties(sourceNode);
|
||||||
for (QName propKey : unchangedProperties)
|
for (QName propKey : unchangedProperties)
|
||||||
{
|
{
|
||||||
|
@@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package org.alfresco.repo.rendition;
|
package org.alfresco.repo.rendition;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.repo.action.ActionImpl;
|
import org.alfresco.repo.action.ActionImpl;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.rendition.RenderCallback;
|
import org.alfresco.service.cmr.rendition.RenderCallback;
|
||||||
@@ -33,7 +36,6 @@ import org.alfresco.service.namespace.QName;
|
|||||||
*/
|
*/
|
||||||
public class RenditionDefinitionImpl extends ActionImpl implements RenditionDefinition
|
public class RenditionDefinitionImpl extends ActionImpl implements RenditionDefinition
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serial version UID
|
* Serial version UID
|
||||||
*/
|
*/
|
||||||
@@ -45,9 +47,12 @@ public class RenditionDefinitionImpl extends ActionImpl implements RenditionDefi
|
|||||||
private RenderCallback renderCallback;
|
private RenderCallback renderCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id the action id
|
* @param id
|
||||||
* @param renditionName a unique name for the rendering action.
|
* the action id
|
||||||
* @param renderingEngineName the name of the rendering action definition
|
* @param renditionName
|
||||||
|
* a unique name for the rendering action.
|
||||||
|
* @param renderingEngineName
|
||||||
|
* the name of the rendering action definition
|
||||||
*/
|
*/
|
||||||
public RenditionDefinitionImpl(String id, QName renditionName, String renderingEngineName)
|
public RenditionDefinitionImpl(String id, QName renditionName, String renderingEngineName)
|
||||||
{
|
{
|
||||||
@@ -114,7 +119,10 @@ public class RenditionDefinitionImpl extends ActionImpl implements RenditionDefi
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.alfresco.service.cmr.rendition.RenditionDefinition#setCallback(org.alfresco.service.cmr.rendition.RenderCallback)
|
*
|
||||||
|
* @see
|
||||||
|
* org.alfresco.service.cmr.rendition.RenditionDefinition#setCallback(org
|
||||||
|
* .alfresco.service.cmr.rendition.RenderCallback)
|
||||||
*/
|
*/
|
||||||
public void setCallback(RenderCallback callback)
|
public void setCallback(RenderCallback callback)
|
||||||
{
|
{
|
||||||
@@ -123,7 +131,10 @@ public class RenditionDefinitionImpl extends ActionImpl implements RenditionDefi
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.alfresco.service.cmr.rendition.RenditionDefinition#setCallback(org.alfresco.service.cmr.rendition.RenderCallback)
|
*
|
||||||
|
* @see
|
||||||
|
* org.alfresco.service.cmr.rendition.RenditionDefinition#setCallback(org
|
||||||
|
* .alfresco.service.cmr.rendition.RenderCallback)
|
||||||
*/
|
*/
|
||||||
public RenderCallback getCallback()
|
public RenderCallback getCallback()
|
||||||
{
|
{
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.alfresco.repo.rendition.executer;
|
package org.alfresco.repo.rendition.executer;
|
||||||
|
|
||||||
import static org.alfresco.service.cmr.rendition.RenditionService.*;
|
import static org.alfresco.service.cmr.rendition.RenditionService.*;
|
||||||
@@ -326,7 +325,7 @@ public abstract class AbstractRenderingEngine extends ActionExecuterAbstractBase
|
|||||||
* @param renditionDefinition
|
* @param renditionDefinition
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public QName getRenditionNodeType(RenditionDefinition renditionDefinition)
|
private QName getRenditionNodeType(RenditionDefinition renditionDefinition)
|
||||||
{
|
{
|
||||||
return getParamWithDefault(PARAM_RENDITION_NODETYPE, defaultRenditionNodeType, renditionDefinition);
|
return getParamWithDefault(PARAM_RENDITION_NODETYPE, defaultRenditionNodeType, renditionDefinition);
|
||||||
}
|
}
|
||||||
@@ -378,7 +377,7 @@ public abstract class AbstractRenderingEngine extends ActionExecuterAbstractBase
|
|||||||
// The ThumbnailService puts a cm:name property on its thumbnail nodes.
|
// The ThumbnailService puts a cm:name property on its thumbnail nodes.
|
||||||
Map<QName, Serializable> nodeProps = new HashMap<QName, Serializable>();
|
Map<QName, Serializable> nodeProps = new HashMap<QName, Serializable>();
|
||||||
nodeProps.put(ContentModel.PROP_NAME, renditionName.getLocalName());
|
nodeProps.put(ContentModel.PROP_NAME, renditionName.getLocalName());
|
||||||
nodeProps.put(ContentModel.PROP_CONTENT_PROPERTY_NAME, getDefaultRenditionContentProp());
|
nodeProps.put(ContentModel.PROP_CONTENT_PROPERTY_NAME, getRenditionContentProp(renditionDefinition));
|
||||||
QName assocName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, GUID.generate());
|
QName assocName = QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, GUID.generate());
|
||||||
NodeRef parentNode = renditionDefinition.getRenditionParent();
|
NodeRef parentNode = renditionDefinition.getRenditionParent();
|
||||||
QName assocType = renditionDefinition.getRenditionAssociationType();
|
QName assocType = renditionDefinition.getRenditionAssociationType();
|
||||||
@@ -387,6 +386,11 @@ public abstract class AbstractRenderingEngine extends ActionExecuterAbstractBase
|
|||||||
return childAssoc;
|
return childAssoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Serializable getRenditionContentProp(RenditionDefinition renditionDefinition)
|
||||||
|
{
|
||||||
|
return getParamWithDefault(PARAM_TARGET_CONTENT_PROPERTY, getDefaultRenditionContentProp(), renditionDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value for the named parameter. Checks the type of the parameter
|
* Gets the value for the named parameter. Checks the type of the parameter
|
||||||
* is correct and throws a {@link RenditionServiceException} if it isn't.
|
* is correct and throws a {@link RenditionServiceException} if it isn't.
|
||||||
|
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2010 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.repo.rendition.executer;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.action.executer.ActionExecuter;
|
||||||
|
import org.alfresco.repo.rendition.RenditionDefinitionImpl;
|
||||||
|
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext;
|
||||||
|
import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
||||||
|
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||||
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nick Smith
|
||||||
|
*/
|
||||||
|
public class AbstractRenderingEngineTest extends TestCase
|
||||||
|
{
|
||||||
|
private ContentService contentService;
|
||||||
|
private NodeService nodeService;
|
||||||
|
private TestRenderingEngine engine;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
this.contentService = mock(ContentService.class);
|
||||||
|
NodeService nodeService1 = makeNodeService();
|
||||||
|
this.nodeService = nodeService1;
|
||||||
|
engine = new TestRenderingEngine();
|
||||||
|
engine.setContentService(contentService);
|
||||||
|
engine.setNodeService(nodeService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a mock node service which fails with a helpful message by default if createNode is called.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private NodeService makeNodeService()
|
||||||
|
{
|
||||||
|
NodeService nodeService1 = mock(NodeService.class);
|
||||||
|
return nodeService1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testCreateRenditionNodeAssoc() throws Exception
|
||||||
|
{
|
||||||
|
NodeRef source = new NodeRef("http://test/sourceId");
|
||||||
|
when(nodeService.exists(source)).thenReturn(true);
|
||||||
|
|
||||||
|
QName assocType = ContentModel.ASSOC_CONTAINS;
|
||||||
|
QName assocName = QName.createQName("url", "renditionName");
|
||||||
|
QName nodeType = ContentModel.TYPE_CONTENT;
|
||||||
|
ChildAssociationRef renditionAssoc = mock(ChildAssociationRef.class);
|
||||||
|
|
||||||
|
// Set up the rendition definition.
|
||||||
|
String id = "definitionId";
|
||||||
|
RenditionDefinition definition = new RenditionDefinitionImpl(id, assocName, TestRenderingEngine.NAME);
|
||||||
|
definition.setRenditionAssociationType(assocType);
|
||||||
|
definition.setRenditionParent(source);
|
||||||
|
|
||||||
|
// Stub the createNode() method to return renditionAssoc.
|
||||||
|
when(nodeService
|
||||||
|
.createNode(eq(source), eq(assocType), any(QName.class), any(QName.class), anyMap()))
|
||||||
|
.thenReturn(renditionAssoc);
|
||||||
|
engine.execute(definition, source);
|
||||||
|
|
||||||
|
// Check the createNode method was called with the correct parameters.
|
||||||
|
// Check the nodeType defaults to cm:content.
|
||||||
|
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
|
||||||
|
verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture());
|
||||||
|
Map<String, Serializable> props = captor.getValue();
|
||||||
|
|
||||||
|
// Check the node name is set to match teh rendition name local name.
|
||||||
|
assertEquals(assocName.getLocalName(), props.get(ContentModel.PROP_NAME));
|
||||||
|
|
||||||
|
// Check content property name defaults to cm:content
|
||||||
|
assertEquals(ContentModel.PROP_CONTENT, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME));
|
||||||
|
|
||||||
|
// Check the returned result is the association created by the call to nodeServcie.createNode().
|
||||||
|
Serializable result = definition.getParameterValue(ActionExecuter.PARAM_RESULT);
|
||||||
|
assertEquals("The returned rendition association is not the one created by the node service!",
|
||||||
|
renditionAssoc, result);
|
||||||
|
|
||||||
|
// Check that setting the default content property and default node type
|
||||||
|
// on the rendition engine works.
|
||||||
|
nodeType = QName.createQName("url", "someNodeType");
|
||||||
|
QName contentPropName = QName.createQName("url", "someContentProp");
|
||||||
|
engine.setDefaultRenditionContentProp(contentPropName.toString());
|
||||||
|
engine.setDefaultRenditionNodeType(nodeType.toString());
|
||||||
|
engine.execute(definition, source);
|
||||||
|
verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture());
|
||||||
|
props=captor.getValue();
|
||||||
|
assertEquals(contentPropName, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME));
|
||||||
|
|
||||||
|
// Check that settign the rendition node type param works.
|
||||||
|
nodeType = ContentModel.TYPE_THUMBNAIL;
|
||||||
|
contentPropName = ContentModel.PROP_CONTENT;
|
||||||
|
definition.setParameterValue(RenditionService.PARAM_RENDITION_NODETYPE, nodeType);
|
||||||
|
definition.setParameterValue(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, contentPropName);
|
||||||
|
engine.execute(definition, source);
|
||||||
|
verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture());
|
||||||
|
props=captor.getValue();
|
||||||
|
assertEquals(contentPropName, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestRenderingEngine extends AbstractRenderingEngine
|
||||||
|
{
|
||||||
|
private RenderingContext context;
|
||||||
|
|
||||||
|
public static String NAME = "Test";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void render(RenderingContext context1)
|
||||||
|
{
|
||||||
|
this.context = context1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RenderingContext getContext()
|
||||||
|
{
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -24,10 +24,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
|
||||||
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
||||||
import org.alfresco.repo.content.transform.swf.SWFTransformationOptions;
|
import org.alfresco.repo.content.transform.swf.SWFTransformationOptions;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
|
||||||
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine;
|
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine;
|
||||||
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
|
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
|
||||||
import org.alfresco.repo.rendition.executer.ReformatRenderingEngine;
|
import org.alfresco.repo.rendition.executer.ReformatRenderingEngine;
|
||||||
@@ -37,7 +35,6 @@ import org.alfresco.service.cmr.rendition.RenditionService;
|
|||||||
import org.alfresco.service.cmr.rendition.RenditionServiceException;
|
import org.alfresco.service.cmr.rendition.RenditionServiceException;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||||
@@ -61,7 +58,7 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
private static Log logger = LogFactory.getLog(ThumbnailServiceImpl.class);
|
private static Log logger = LogFactory.getLog(ThumbnailServiceImpl.class);
|
||||||
|
|
||||||
/** Error messages */
|
/** Error messages */
|
||||||
private static final String ERR_NO_CREATE = "Thumbnail could not be created as required transformation is not supported from {0} to {1}";
|
// private static final String ERR_NO_CREATE = "Thumbnail could not be created as required transformation is not supported from {0} to {1}";
|
||||||
private static final String ERR_DUPLICATE_NAME = "Thumbnail could not be created because of a duplicate name";
|
private static final String ERR_DUPLICATE_NAME = "Thumbnail could not be created because of a duplicate name";
|
||||||
private static final String ERR_NO_PARENT = "Thumbnail has no parent so update cannot take place.";
|
private static final String ERR_NO_PARENT = "Thumbnail has no parent so update cannot take place.";
|
||||||
|
|
||||||
@@ -71,15 +68,6 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
/** Node service */
|
/** Node service */
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
|
|
||||||
/** Content service */
|
|
||||||
private ContentService contentService;
|
|
||||||
|
|
||||||
/** Mimetype map */
|
|
||||||
private MimetypeMap mimetypeMap;
|
|
||||||
|
|
||||||
/** Behaviour filter */
|
|
||||||
private BehaviourFilter behaviourFilter;
|
|
||||||
|
|
||||||
/** Thumbnail registry */
|
/** Thumbnail registry */
|
||||||
private ThumbnailRegistry thumbnailRegistry;
|
private ThumbnailRegistry thumbnailRegistry;
|
||||||
|
|
||||||
@@ -106,34 +94,6 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the content service
|
|
||||||
*
|
|
||||||
* @param contentService content service
|
|
||||||
*/
|
|
||||||
public void setContentService(ContentService contentService)
|
|
||||||
{
|
|
||||||
this.contentService = contentService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the mimetype map
|
|
||||||
*
|
|
||||||
* @param mimetypeMap the mimetype map
|
|
||||||
*/
|
|
||||||
public void setMimetypeMap(MimetypeMap mimetypeMap)
|
|
||||||
{
|
|
||||||
this.mimetypeMap = mimetypeMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param behaviourFilter policy behaviour filter
|
|
||||||
*/
|
|
||||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
|
||||||
{
|
|
||||||
this.behaviourFilter = behaviourFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set thumbnail registry
|
* Set thumbnail registry
|
||||||
*
|
*
|
||||||
@@ -167,17 +127,38 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
final TransformationOptions transformationOptions, final String thumbnailName, final ThumbnailParentAssociationDetails assocDetails)
|
final TransformationOptions transformationOptions, final String thumbnailName, final ThumbnailParentAssociationDetails assocDetails)
|
||||||
{
|
{
|
||||||
// Parameter check
|
// Parameter check
|
||||||
ParameterCheck.mandatory("node", node);
|
ParameterCheck.mandatory("node", node);
|
||||||
ParameterCheck.mandatory("contentProperty", contentProperty);
|
ParameterCheck.mandatory("contentProperty", contentProperty);
|
||||||
ParameterCheck.mandatoryString( "mimetype", mimetype);
|
ParameterCheck.mandatoryString("mimetype", mimetype);
|
||||||
ParameterCheck.mandatory("transformationOptions", transformationOptions);
|
ParameterCheck.mandatory("transformationOptions", transformationOptions);
|
||||||
|
|
||||||
if (logger.isDebugEnabled() == true)
|
if (logger.isDebugEnabled() == true)
|
||||||
{
|
{
|
||||||
logger.debug("Creating thumbnail (node=" + node.toString() + "; contentProperty=" + contentProperty.toString() + "; mimetype=" + mimetype);
|
logger.debug("Creating thumbnail (node=" + node.toString() + "; contentProperty="
|
||||||
|
+ contentProperty.toString() + "; mimetype=" + mimetype);
|
||||||
}
|
}
|
||||||
|
checkThumbnailNameIsUnique(node, thumbnailName, contentProperty, mimetype);
|
||||||
// Check for duplicate names
|
return AuthenticationUtil.runAs(
|
||||||
|
new AuthenticationUtil.RunAsWork<NodeRef>()
|
||||||
|
{
|
||||||
|
public NodeRef doWork() throws Exception
|
||||||
|
{
|
||||||
|
return createThumbnailNode(node, contentProperty,
|
||||||
|
mimetype, transformationOptions, thumbnailName, assocDetails);
|
||||||
|
}
|
||||||
|
}, AuthenticationUtil.getSystemUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws a ThumbnailException if a thumbnail of this name already exists.
|
||||||
|
* @param node
|
||||||
|
* @param thumbnailName
|
||||||
|
* @param contentProperty
|
||||||
|
* @param mimetype
|
||||||
|
*/
|
||||||
|
private void checkThumbnailNameIsUnique(final NodeRef node, final String thumbnailName,
|
||||||
|
final QName contentProperty, final String mimetype)
|
||||||
|
{
|
||||||
if (thumbnailName != null && getThumbnailByName(node, contentProperty, thumbnailName) != null)
|
if (thumbnailName != null && getThumbnailByName(node, contentProperty, thumbnailName) != null)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled() == true)
|
if (logger.isDebugEnabled() == true)
|
||||||
@@ -188,57 +169,20 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
// We can't continue because there is already a thumbnail with the given name for that content property
|
// We can't continue because there is already a thumbnail with the given name for that content property
|
||||||
throw new ThumbnailException(ERR_DUPLICATE_NAME);
|
throw new ThumbnailException(ERR_DUPLICATE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChildAssociationRef thumbnailRef = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<ChildAssociationRef>()
|
|
||||||
{
|
|
||||||
public ChildAssociationRef doWork() throws Exception
|
|
||||||
{
|
|
||||||
// Need a variable scoped to this inner class in order to assign a new value to it.
|
|
||||||
String localThumbnailName = thumbnailName;
|
|
||||||
// Get the name of the thumbnail and add to properties map
|
|
||||||
if (localThumbnailName == null || localThumbnailName.length() == 0)
|
|
||||||
{
|
|
||||||
localThumbnailName = GUID.generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're prepending the cm namespace here.
|
|
||||||
QName thumbnailQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localThumbnailName);
|
|
||||||
|
|
||||||
// Convert the TransformationOptions and ThumbnailParentAssocDetails to
|
|
||||||
// rendition-style parameters
|
|
||||||
Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, assocDetails);
|
|
||||||
// Add the other parameters given in this method signature.
|
|
||||||
params.put(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, contentProperty);
|
|
||||||
params.put(AbstractRenderingEngine.PARAM_MIME_TYPE, mimetype);
|
|
||||||
|
|
||||||
// Create the renditionDefinition
|
|
||||||
String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
|
|
||||||
RenditionDefinition renderingAction = renditionService.createRenditionDefinition(thumbnailQName, renderingEngineName);
|
|
||||||
|
|
||||||
// Set the parameters
|
|
||||||
for (String key : params.keySet())
|
|
||||||
{
|
|
||||||
renderingAction.setParameterValue(key, params.get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ChildAssociationRef chAssRef = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
chAssRef = renditionService.render(node, renderingAction);
|
|
||||||
} catch (RenditionServiceException rsx)
|
|
||||||
{
|
|
||||||
throw new ThumbnailException(rsx.getMessage(), rsx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return chAssRef;
|
|
||||||
}
|
|
||||||
}, AuthenticationUtil.getSystemUserName());
|
|
||||||
|
|
||||||
// Return the created thumbnail
|
|
||||||
return getThumbnailNode(thumbnailRef);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private QName getThumbnailQName(String localThumbnailName)
|
||||||
|
{
|
||||||
|
if (localThumbnailName == null || localThumbnailName.length() == 0)
|
||||||
|
{
|
||||||
|
localThumbnailName = GUID.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're prepending the cm namespace here.
|
||||||
|
QName thumbnailQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localThumbnailName);
|
||||||
|
return thumbnailQName;
|
||||||
|
}
|
||||||
|
|
||||||
private String getRenderingEngineNameFor(TransformationOptions options)
|
private String getRenderingEngineNameFor(TransformationOptions options)
|
||||||
{
|
{
|
||||||
if (options instanceof ImageTransformationOptions)
|
if (options instanceof ImageTransformationOptions)
|
||||||
@@ -449,4 +393,83 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link RenditionDefinition} with no parameters set.
|
||||||
|
* @param thumbnailName
|
||||||
|
* @param transformationOptions
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private RenditionDefinition createRawRenditionDefinition(QName thumbnailQName,
|
||||||
|
final TransformationOptions transformationOptions)
|
||||||
|
{
|
||||||
|
// Create the renditionDefinition
|
||||||
|
String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
|
||||||
|
RenditionDefinition definition = renditionService.createRenditionDefinition(thumbnailQName, renderingEngineName);
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a fully parameterized {@link RenditionDefinition}.
|
||||||
|
* @param contentProperty
|
||||||
|
* @param mimetype
|
||||||
|
* @param transformationOptions
|
||||||
|
* @param thumbnailName
|
||||||
|
* @param assocDetails
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private RenditionDefinition createRenditionDefinition(final QName contentProperty, final String mimetype,
|
||||||
|
final TransformationOptions transformationOptions, final QName thumbnailQName,
|
||||||
|
final ThumbnailParentAssociationDetails assocDetails)
|
||||||
|
{
|
||||||
|
RenditionDefinition definition = createRawRenditionDefinition(thumbnailQName, transformationOptions);
|
||||||
|
|
||||||
|
// Convert the TransformationOptions and ThumbnailParentAssocDetails to
|
||||||
|
// rendition-style parameters
|
||||||
|
Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, assocDetails);
|
||||||
|
// Add the other parameters given in this method signature.
|
||||||
|
params.put(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, contentProperty);
|
||||||
|
params.put(AbstractRenderingEngine.PARAM_MIME_TYPE, mimetype);
|
||||||
|
params.put(RenditionService.PARAM_RENDITION_NODETYPE, ContentModel.TYPE_THUMBNAIL);
|
||||||
|
|
||||||
|
// Set the parameters on the rendition definition.
|
||||||
|
definition.addParameterValues(params);
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NodeRef createThumbnailNode(final NodeRef node, final QName contentProperty,
|
||||||
|
final String mimetype, final TransformationOptions transformationOptions, final String thumbnailName,
|
||||||
|
final ThumbnailParentAssociationDetails assocDetails)
|
||||||
|
{
|
||||||
|
// Get the name of the thumbnail and add to properties map
|
||||||
|
QName thumbnailQName = getThumbnailQName(thumbnailName);
|
||||||
|
RenditionDefinition definition = createRenditionDefinition(contentProperty, mimetype,
|
||||||
|
transformationOptions, thumbnailQName, assocDetails);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ChildAssociationRef thumbnailAssoc = renditionService.render(node, definition);
|
||||||
|
NodeRef thumbnail = getThumbnailNode(thumbnailAssoc);
|
||||||
|
setThumbnailNameProperty(thumbnail, thumbnailName);
|
||||||
|
return thumbnail;
|
||||||
|
} catch (RenditionServiceException rsx)
|
||||||
|
{
|
||||||
|
throw new ThumbnailException(rsx.getMessage(), rsx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the thumbnail name if the rendition is of type cm:thumbnail.
|
||||||
|
* @param thumbnailAssoc
|
||||||
|
* @param thumbnailName
|
||||||
|
*/
|
||||||
|
private void setThumbnailNameProperty(NodeRef thumbnail, String thumbnailName)
|
||||||
|
{
|
||||||
|
if (thumbnailName != null && thumbnailName.length() > 0)
|
||||||
|
{
|
||||||
|
if (ContentModel.TYPE_THUMBNAIL.equals(nodeService.getType(thumbnail)))
|
||||||
|
{
|
||||||
|
nodeService.setProperty(thumbnail, ContentModel.PROP_THUMBNAIL_NAME, thumbnailName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,7 @@ import org.alfresco.service.cmr.rendition.RenditionDefinition;
|
|||||||
import org.alfresco.service.cmr.rendition.RenditionService;
|
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails;
|
import org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails;
|
||||||
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
@@ -121,6 +122,7 @@ public class ThumbnailServiceImplParameterTest
|
|||||||
return new ThumbnailRenditionConvertor();
|
return new ThumbnailRenditionConvertor();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
thumbs.setNodeService(mock(NodeService.class));
|
||||||
thumbnailService = thumbs;
|
thumbnailService = thumbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -323,6 +323,13 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
// Check the content property value
|
// Check the content property value
|
||||||
assertEquals(ContentModel.PROP_CONTENT, this.nodeService.getProperty(thumbnail,
|
assertEquals(ContentModel.PROP_CONTENT, this.nodeService.getProperty(thumbnail,
|
||||||
ContentModel.PROP_CONTENT_PROPERTY_NAME));
|
ContentModel.PROP_CONTENT_PROPERTY_NAME));
|
||||||
|
|
||||||
|
// Check the thumbnail is of type cm:thumbnail.
|
||||||
|
assertEquals("The thumbnail node should be of type cm:thumbnail!",
|
||||||
|
ContentModel.TYPE_THUMBNAIL, nodeService.getType(thumbnail));
|
||||||
|
|
||||||
|
// Check the thumbnail name property is correctly set on thumbnail.
|
||||||
|
assertEquals( thumbnailName, nodeService.getProperty(thumbnail, ContentModel.PROP_THUMBNAIL_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void outputThumbnailTempContentLocation(NodeRef thumbnail, String ext, String message) throws IOException
|
private void outputThumbnailTempContentLocation(NodeRef thumbnail, String ext, String message) throws IOException
|
||||||
|
@@ -18,8 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.service.cmr.action;
|
package org.alfresco.service.cmr.action;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
@@ -200,4 +202,10 @@ public interface Action extends ParameterizedItem
|
|||||||
* Removes all action conditions
|
* Removes all action conditions
|
||||||
*/
|
*/
|
||||||
void removeAllActionConditions();
|
void removeAllActionConditions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a {@link Map} of parameter values to the {@link Action}
|
||||||
|
* @param values A map of values to be added
|
||||||
|
*/
|
||||||
|
void addParameterValues(Map<String, Serializable> values);
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
/**
|
/**
|
||||||
* @return the name which uniquely identifies this rendering action.
|
* @return the name which uniquely identifies this rendering action.
|
||||||
*/
|
*/
|
||||||
public QName getRenditionName();
|
QName getRenditionName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the node to which the rendition is linked when it is first
|
* Returns the node to which the rendition is linked when it is first
|
||||||
@@ -51,7 +51,7 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
*
|
*
|
||||||
* @return the renditionParent
|
* @return the renditionParent
|
||||||
*/
|
*/
|
||||||
public NodeRef getRenditionParent();
|
NodeRef getRenditionParent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the node to which the rendition is linked when it is first created.
|
* Sets the node to which the rendition is linked when it is first created.
|
||||||
@@ -61,7 +61,7 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
*
|
*
|
||||||
* @param renditionParent the renditionParent to set
|
* @param renditionParent the renditionParent to set
|
||||||
*/
|
*/
|
||||||
public void setRenditionParent(NodeRef renditionParent);
|
void setRenditionParent(NodeRef renditionParent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the association type used to link the rendition to its parent
|
* Returns the association type used to link the rendition to its parent
|
||||||
@@ -71,7 +71,7 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
*
|
*
|
||||||
* @return the renditionAssociationType
|
* @return the renditionAssociationType
|
||||||
*/
|
*/
|
||||||
public QName getRenditionAssociationType();
|
QName getRenditionAssociationType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the association type used to link the rendition to its parent node
|
* Sets the association type used to link the rendition to its parent node
|
||||||
@@ -81,7 +81,7 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
*
|
*
|
||||||
* @param renditionAssociationType the renditionAssociationType to set
|
* @param renditionAssociationType the renditionAssociationType to set
|
||||||
*/
|
*/
|
||||||
public void setRenditionAssociationType(QName renditionAssociationType);
|
void setRenditionAssociationType(QName renditionAssociationType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sets a callback object for use in asynchronous renditions. It is
|
* This method sets a callback object for use in asynchronous renditions. It is
|
||||||
@@ -90,7 +90,7 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
*
|
*
|
||||||
* @param callback a callback object, which may be null.
|
* @param callback a callback object, which may be null.
|
||||||
*/
|
*/
|
||||||
public void setCallback(RenderCallback callback);
|
void setCallback(RenderCallback callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method gets the registered callback object for use with asynchronous
|
* This method gets the registered callback object for use with asynchronous
|
||||||
@@ -98,5 +98,5 @@ public interface RenditionDefinition extends Action, Serializable
|
|||||||
*
|
*
|
||||||
* @return the callback object
|
* @return the callback object
|
||||||
*/
|
*/
|
||||||
public RenderCallback getCallback();
|
RenderCallback getCallback();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user