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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations