use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-remote-api by Alfresco.
the class NodesImpl method requestRenditions.
private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode) {
if (thumbnailDefs != null) {
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
for (ThumbnailDefinition thumbnailDef : thumbnailDefs) {
NodeRef sourceNodeRef = fileNode.getNodeRef();
String mimeType = fileNode.getContent().getMimeType();
long size = fileNode.getContent().getSizeInBytes();
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (!registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef)) {
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " + mimeType + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
// Queue async creation of thumbnail
actionService.executeAction(action, sourceNodeRef, true, true);
}
}
}
use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method getRenditions.
@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, Parameters parameters) {
final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
String contentMimeType = getMimeType(validatedNodeRef);
Query query = parameters.getQuery();
boolean includeCreated = true;
boolean includeNotCreated = true;
String status = getStatus(parameters);
if (status != null) {
includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
includeNotCreated = !includeCreated;
}
Map<String, Rendition> apiRenditions = new TreeMap<>();
if (includeNotCreated) {
// List all available thumbnail definitions
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
}
}
List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(validatedNodeRef);
if (!nodeRefRenditions.isEmpty()) {
for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
NodeRef renditionNodeRef = childAssociationRef.getChildRef();
Rendition apiRendition = toApiRendition(renditionNodeRef);
if (includeCreated) {
// Replace/append any thumbnail definitions with created rendition info
apiRenditions.put(apiRendition.getId(), apiRendition);
} else {
// Remove any thumbnail definitions that has been created from the list,
// as the filter requires only the Not_Created renditions
apiRenditions.remove(apiRendition.getId());
}
}
}
// Wrap paging info, as the core service doesn't support paging
Paging paging = parameters.getPaging();
PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.
the class CMISConnector method createThumbnails.
/**
* Asynchronously generates thumbnails for the given node.
*
* @param nodeRef NodeRef
*/
public void createThumbnails(NodeRef nodeRef, Set<String> thumbnailNames) {
if (thumbnailNames == null || thumbnailNames.size() == 0) {
return;
}
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
// If there's nothing currently registered to generate thumbnails for the
// specified mimetype, then log a message and bail out
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
if (contentData == null) {
logger.info("Unable to create thumbnails as there is no content");
return;
}
long size = contentData.getSize();
String mimeType = contentData.getMimetype();
for (String thumbnailName : thumbnailNames) {
// Use the thumbnail registy to get the details of the thumbail
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
if (details == null) {
// Throw exception
logger.warn("The thumbnail name '" + thumbnailName + "' is not registered");
continue;
} else {
if (registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), mimeType, size, nodeRef, details)) {
org.alfresco.service.cmr.action.Action action = ThumbnailHelper.createCreateThumbnailAction(details, serviceRegistry);
// Queue async creation of thumbnail
actionService.executeAction(action, nodeRef, true, true);
} else {
logger.info("Unable to create thumbnail '" + details.getName() + "' for " + mimeType + " as no transformer is currently available");
}
}
}
}
use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.
the class ScriptThumbnail method update.
/**
* Updates the thumbnails content
*/
public void update() {
List<ChildAssociationRef> parentRefs = services.getNodeService().getParentAssocs(nodeRef, RenditionModel.ASSOC_RENDITION, RegexQNamePattern.MATCH_ALL);
// There should in fact only ever be one parent association of type rendition on any rendition node.
if (parentRefs.size() != 1) {
StringBuilder msg = new StringBuilder();
msg.append("Node ").append(nodeRef).append(" has ").append(parentRefs.size()).append(" rendition parents. Unable to update.");
if (logger.isWarnEnabled()) {
logger.warn(msg.toString());
}
throw new AlfrescoRuntimeException(msg.toString());
}
String name = parentRefs.get(0).getQName().getLocalName();
ThumbnailDefinition def = services.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(name);
services.getThumbnailService().updateThumbnail(this.nodeRef, def.getTransformationOptions());
}
use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.
the class ScriptNode method getThumbnailDefinitions.
/**
* Returns the names of the thumbnail defintions that can be applied to the content property of
* this node.
* <p>
* Thumbanil defintions only appear in this list if they can produce a thumbnail for the content
* found in the content property. This will be determined by looking at the mimetype of the content
* and the destinatino mimetype of the thumbnail.
*
* @return String[] array of thumbnail names that are valid for the current content type
*/
public String[] getThumbnailDefinitions() {
ThumbnailService thumbnailService = this.services.getThumbnailService();
List<String> result = new ArrayList<String>(7);
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
if (ContentData.hasContent(contentData)) {
String mimetype = contentData.getMimetype();
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(mimetype, contentData.getSize());
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
result.add(thumbnailDefinition.getName());
}
}
return (String[]) result.toArray(new String[result.size()]);
}
Aggregations