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)
126476 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122483 jkaabimofrad: RA-678: Updated create rendition Api + tests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126820 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -30,6 +30,7 @@ import org.alfresco.rest.api.Renditions;
|
||||
import org.alfresco.rest.api.model.ContentInfo;
|
||||
import org.alfresco.rest.api.model.Rendition;
|
||||
import org.alfresco.rest.api.model.Rendition.RenditionStatus;
|
||||
import org.alfresco.rest.framework.core.exceptions.DisabledServiceException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
@@ -198,36 +199,43 @@ public class RenditionsImpl implements Renditions
|
||||
@Override
|
||||
public void createRendition(String nodeId, Rendition rendition, Parameters parameters)
|
||||
{
|
||||
NodeRef sourceNodeRef = nodes.validateNode(nodeId);
|
||||
|
||||
// If thumbnail generation has been configured off, then don't bother with any of this.
|
||||
if (thumbnailService.getThumbnailsEnabled())
|
||||
// If thumbnail generation has been configured off, then don't bother.
|
||||
if (!thumbnailService.getThumbnailsEnabled())
|
||||
{
|
||||
// Use the thumbnail registry to get the details of the thumbnail
|
||||
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
|
||||
ThumbnailDefinition details = registry.getThumbnailDefinition(rendition.getId());
|
||||
if (details == null)
|
||||
{
|
||||
// Throw exception
|
||||
throw new InvalidArgumentException("The thumbnail name '" + rendition.getId() + "' is not registered");
|
||||
}
|
||||
|
||||
// Check if anything is currently registered to generate thumbnails for the specified mimeType
|
||||
ContentData contentData = (ContentData) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CONTENT);
|
||||
if (!ContentData.hasContent(contentData))
|
||||
{
|
||||
throw new InvalidArgumentException("Unable to create thumbnail '" + details.getName() + "' as there is no content");
|
||||
}
|
||||
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef, details))
|
||||
{
|
||||
throw new InvalidArgumentException("Unable to create thumbnail '" + details.getName() + "' for " +
|
||||
contentData.getMimetype() + " as no transformer is currently available.");
|
||||
}
|
||||
|
||||
Action action = ThumbnailHelper.createCreateThumbnailAction(details, serviceRegistry);
|
||||
// Queue async creation of thumbnail
|
||||
actionService.executeAction(action, sourceNodeRef, true, true);
|
||||
throw new DisabledServiceException("Thumbnail generation has been disabled.");
|
||||
}
|
||||
|
||||
final NodeRef sourceNodeRef = validateSourceNode(nodeId);
|
||||
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
|
||||
if (renditionNodeRef != null)
|
||||
{
|
||||
throw new InvalidArgumentException(rendition.getId() + " rendition already exists.");
|
||||
}
|
||||
|
||||
// Use the thumbnail registry to get the details of the thumbnail
|
||||
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
|
||||
ThumbnailDefinition thumbnailDefinition = registry.getThumbnailDefinition(rendition.getId());
|
||||
if (thumbnailDefinition == null)
|
||||
{
|
||||
throw new EntityNotFoundException(rendition.getId() + "' is not registered.");
|
||||
}
|
||||
|
||||
ContentData contentData = (ContentData) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CONTENT);
|
||||
if (!ContentData.hasContent(contentData))
|
||||
{
|
||||
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' as there is no content.");
|
||||
}
|
||||
// Check if anything is currently available to generate thumbnails for the specified mimeType
|
||||
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), sourceNodeRef,
|
||||
thumbnailDefinition))
|
||||
{
|
||||
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDefinition.getName() + "' for " +
|
||||
contentData.getMimetype() + " as no transformer is currently available.");
|
||||
}
|
||||
|
||||
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDefinition, serviceRegistry);
|
||||
// Queue async creation of thumbnail
|
||||
actionService.executeAction(action, sourceNodeRef, true, true);
|
||||
}
|
||||
|
||||
protected NodeRef getRenditionByName(NodeRef nodeRef, String renditionId, Parameters parameters)
|
||||
|
@@ -21,12 +21,14 @@ package org.alfresco.rest.api.nodes;
|
||||
|
||||
import org.alfresco.rest.api.Renditions;
|
||||
import org.alfresco.rest.api.model.Rendition;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -68,6 +70,7 @@ public class NodeRenditionsRelation implements RelationshipResourceAction.Read<R
|
||||
return renditions.getRendition(nodeId, renditionId, parameters);
|
||||
}
|
||||
|
||||
@WebApiDescription(title = "Create rendition", successStatus = Status.STATUS_ACCEPTED)
|
||||
@Override
|
||||
public List<Rendition> create(String nodeId, List<Rendition> entity, Parameters parameters)
|
||||
{
|
||||
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.framework.core.exceptions;
|
||||
|
||||
/**
|
||||
* Thrown when the required service is disabled.
|
||||
* Default status is <i>Not Implemented</i> server error = 501.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class DisabledServiceException extends ApiException
|
||||
{
|
||||
private static final long serialVersionUID = 1286704207931025507L;
|
||||
|
||||
public DisabledServiceException(String msgId)
|
||||
{
|
||||
super(msgId);
|
||||
}
|
||||
|
||||
public DisabledServiceException(String msgId, Object[] msgParams)
|
||||
{
|
||||
super(msgId, msgParams);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user