Search in sources :

Example 11 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method createRendition.

@Override
public void createRendition(NodeRef nodeRef, Rendition rendition, boolean executeAsync, Parameters parameters) {
    // If thumbnail generation has been configured off, then don't bother.
    if (!thumbnailService.getThumbnailsEnabled()) {
        throw new DisabledServiceException("Thumbnail generation has been disabled.");
    }
    final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
    final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, rendition.getId(), parameters);
    if (renditionNodeRef != null) {
        throw new ConstraintViolatedException(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 NotFoundException(rendition.getId() + " is not registered.");
    }
    ContentData contentData = getContentData(sourceNodeRef, true);
    // 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);
    // Create thumbnail - or else queue for async creation
    actionService.executeAction(action, sourceNodeRef, true, executeAsync);
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) Action(org.alfresco.service.cmr.action.Action) ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)

Example 12 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-remote-api by Alfresco.

the class RenditionsDataCollector method collectData.

@Override
public List<HBData> collectData() {
    List<HBData> collectedData = new LinkedList<>();
    String systemId = this.currentRepoDescriptorDAO.getDescriptor().getId();
    String collectorId = this.getCollectorId();
    String collectorVersion = this.getCollectorVersion();
    Date timestamp = new Date();
    // We don't mind if new renditions are added while we iterate, as we will pick them up next time.
    for (ThumbnailDefinition rendition : renditionRequests.keySet()) {
        String renditionName = rendition.getName();
        String targetMimetype = rendition.getMimetype();
        for (Map.Entry<String, AtomicInteger> entry : renditionRequests.remove(rendition).entrySet()) {
            String sourceMimetype = entry.getKey();
            AtomicInteger count = entry.getValue();
            Map<String, Object> values = new HashMap<>();
            values.put("rendition", renditionName);
            values.put("count", count.intValue());
            values.put("sourceMimetype", sourceMimetype);
            values.put("targetMimetype", targetMimetype);
            // Decided it would be simpler to be able to combine results in Kibana from different nodes
            // and days if the data was flattened (denormalized) out at this point. It is very likely
            // that different nodes would have different sets of sourceMimetypes which would make summing
            // the counts harder to do, if there was a single entry for each rendition with a nested
            // structure for each sourceMimetype.
            collectedData.add(new HBData(systemId, collectorId, collectorVersion, timestamp, values));
            if (logger.isDebugEnabled()) {
                logger.debug(renditionName + " " + count + " " + sourceMimetype + " " + targetMimetype);
            }
        }
    }
    return collectedData;
}
Also used : ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HBData(org.alfresco.heartbeat.datasender.HBData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 13 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.

the class ScriptThumbnailService method getPlaceHolderResourcePath.

/**
 * Gets the resource path for the place holder thumbnail for the given named thumbnail.
 *
 * Returns null if none set.
 *
 * @param thumbnailName     the thumbnail name
 * @return String           the place holder thumbnail resource path, null if none set
 */
public String getPlaceHolderResourcePath(String thumbnailName) {
    String result = null;
    ThumbnailDefinition details = this.serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(thumbnailName);
    if (details != null) {
        result = details.getPlaceHolderResourcePath();
    }
    return result;
}
Also used : ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition)

Example 14 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.

the class ScriptThumbnailService method getMimeAwarePlaceHolderResourcePath.

/**
 * Gets the resource path for the place holder thumbnail for the given named thumbnail and the given mime type.
 * If there is no icon available for the specified MIME type, a generic icon will be used instead.
 * The generic icon is that returned by {@link #getPlaceHolderResourcePath(String)}
 * If neither a MIME-specific icon nor a generic icon is available, <code>null</code> is returned.
 *
 * @param thumbnailName     the thumbnail name
 * @param mimetype          the mimetype of the piece of content.
 * @return String           the place holder thumbnail resource path
 * @see #getPlaceHolderResourcePath(String)
 */
public String getMimeAwarePlaceHolderResourcePath(String thumbnailName, String mimetype) {
    String result = null;
    // Sanity check
    if (mimetype == null || mimetype.trim().length() == 0) {
        return getPlaceHolderResourcePath(thumbnailName);
    }
    Map<String, String> extensionsByMimetype = serviceRegistry.getMimetypeService().getExtensionsByMimetype();
    // We get the extension for the mime type directly from the Map as we need
    // to know if a mimetype is not recognised by the system. (The MimetypeService gives us ".bin"
    // for unrecognised mimetypes.)
    // The mime fragment is the part of the resource path that refers to the mime type
    // e.g. "_pdf" in alfresco/thumbnail/thumbnail_placeholder_doclib_pdf.png
    String extension = extensionsByMimetype.get(mimetype);
    if (extension != null) {
        StringBuilder sb = new StringBuilder();
        sb.append("_").append(String.valueOf(extension));
        String mimeFragment = sb.toString();
        ThumbnailDefinition details = serviceRegistry.getThumbnailService().getThumbnailRegistry().getThumbnailDefinition(thumbnailName);
        if (details != null) {
            String resourcePath = details.getMimeAwarePlaceHolderResourcePath();
            if (resourcePath != null) {
                // It's possible that the mimetype service recognises mime types for which we have no icon.
                String formattedResourcePath = MessageFormat.format(resourcePath, mimeFragment);
                boolean iconResourceExists = classpathResourceExists("/" + formattedResourcePath);
                if (iconResourceExists) {
                    result = formattedResourcePath;
                }
            }
        }
    }
    return result == null ? getPlaceHolderResourcePath(thumbnailName) : result;
}
Also used : ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition)

Example 15 with ThumbnailDefinition

use of org.alfresco.repo.thumbnail.ThumbnailDefinition in project alfresco-repository by Alfresco.

the class QuickShareServiceImpl method getMetaData.

@SuppressWarnings("unchecked")
@Override
public Map<String, Object> getMetaData(NodeRef nodeRef) {
    // TODO This functionality MUST be available when quickshare is also disabled, therefor refactor it out from the quickshare package to a more common package.
    Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
    ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
    String modifierUserName = (String) nodeProps.get(ContentModel.PROP_MODIFIER);
    Map<QName, Serializable> personProps = null;
    if (modifierUserName != null) {
        try {
            NodeRef personRef = personService.getPerson(modifierUserName);
            if (personRef != null) {
                personProps = nodeService.getProperties(personRef);
            }
        } catch (NoSuchPersonException nspe) {
            // absorb this exception - eg. System (or maybe the user has been deleted)
            if (logger.isInfoEnabled()) {
                logger.info("MetaDataGet - no such person: " + modifierUserName);
            }
        }
    }
    Map<String, Object> metadata = new HashMap<String, Object>(8);
    metadata.put("nodeRef", nodeRef.toString());
    metadata.put("name", nodeProps.get(ContentModel.PROP_NAME));
    metadata.put("title", nodeProps.get(ContentModel.PROP_TITLE));
    metadata.put("description", nodeProps.get(ContentModel.PROP_DESCRIPTION));
    if (contentData != null) {
        metadata.put("mimetype", contentData.getMimetype());
        metadata.put("size", contentData.getSize());
    } else {
        metadata.put("size", 0L);
    }
    metadata.put("modified", nodeProps.get(ContentModel.PROP_MODIFIED));
    if (personProps != null) {
        metadata.put("modifierFirstName", personProps.get(ContentModel.PROP_FIRSTNAME));
        metadata.put("modifierLastName", personProps.get(ContentModel.PROP_LASTNAME));
    }
    // thumbnail defs for this nodeRef
    List<String> thumbnailDefs = new ArrayList<String>(7);
    if (contentData != null) {
        // Note: thumbnail defs only appear in this list if they can produce a thumbnail for the content
        // found in the content property of this node. This will be determined by looking at the mimetype of the content
        // and the destination mimetype of the thumbnail.
        List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentData.getMimetype(), contentData.getSize());
        for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
            thumbnailDefs.add(thumbnailDefinition.getName());
        }
    }
    metadata.put("thumbnailDefinitions", thumbnailDefs);
    // thumbnail instances for this nodeRef
    List<NodeRef> thumbnailRefs = thumbnailService.getThumbnails(nodeRef, ContentModel.PROP_CONTENT, null, null);
    List<String> thumbnailNames = new ArrayList<String>(thumbnailRefs.size());
    for (NodeRef thumbnailRef : thumbnailRefs) {
        thumbnailNames.add((String) nodeService.getProperty(thumbnailRef, ContentModel.PROP_NAME));
    }
    metadata.put("thumbnailNames", thumbnailNames);
    metadata.put("lastThumbnailModificationData", (List<String>) nodeProps.get(ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA));
    if (nodeProps.containsKey(QuickShareModel.PROP_QSHARE_SHAREDID)) {
        metadata.put("sharedId", nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDID));
        metadata.put("expiryDate", nodeProps.get(QuickShareModel.PROP_QSHARE_EXPIRY_DATE));
    } else {
        QName type = nodeService.getType(nodeRef);
        boolean sharable = isSharable(type);
        metadata.put("sharable", sharable);
    }
    Map<String, Object> model = new HashMap<String, Object>(2);
    model.put("item", metadata);
    return model;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) NoSuchPersonException(org.alfresco.service.cmr.security.NoSuchPersonException) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) ContentData(org.alfresco.service.cmr.repository.ContentData)

Aggregations

ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)16 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 ThumbnailRegistry (org.alfresco.repo.thumbnail.ThumbnailRegistry)5 ContentData (org.alfresco.service.cmr.repository.ContentData)5 Serializable (java.io.Serializable)4 Action (org.alfresco.service.cmr.action.Action)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 StringJoiner (java.util.StringJoiner)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 ThumbnailService (org.alfresco.service.cmr.thumbnail.ThumbnailService)2 Test (org.junit.Test)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1