Java Code Examples for org.alfresco.service.cmr.repository.ContentData#getSize()
The following examples show how to use
org.alfresco.service.cmr.repository.ContentData#getSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenditionsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
protected Rendition toApiRendition(NodeRef renditionNodeRef) { Rendition apiRendition = new Rendition(); String renditionName = (String) nodeService.getProperty(renditionNodeRef, ContentModel.PROP_NAME); apiRendition.setId(renditionName); ContentData contentData = getContentData(renditionNodeRef, false); ContentInfo contentInfo = null; if (contentData != null) { contentInfo = new ContentInfo(contentData.getMimetype(), getMimeTypeDisplayName(contentData.getMimetype()), contentData.getSize(), contentData.getEncoding()); } apiRendition.setContent(contentInfo); apiRendition.setStatus(RenditionStatus.CREATED); return apiRendition; }
Example 2
Source File: Document.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public Document(NodeRef nodeRef, NodeRef parentNodeRef, Map<QName, Serializable> nodeProps, Map<String, UserInfo> mapUserInfo, ServiceRegistry sr) { super(nodeRef, parentNodeRef, nodeProps, mapUserInfo, sr); Serializable val = nodeProps.get(ContentModel.PROP_CONTENT); if ((val != null) && (val instanceof ContentData)) { ContentData cd = (ContentData)val; String mimeType = cd.getMimetype(); String mimeTypeName = sr.getMimetypeService().getDisplaysByMimetype().get(mimeType); contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding()); } setIsFolder(false); setIsFile(true); }
Example 3
Source File: WebDAV.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Return the Alfresco property value for the specified WebDAV property * * @param davPropName String * @return Object */ public static Object getDAVPropertyValue( Map<QName, Serializable> props, String davPropName) { // Convert the WebDAV property name to the corresponding Alfresco property QName propName = _propertyNameMap.get( davPropName); if ( propName == null) throw new AlfrescoRuntimeException("No mapping for WebDAV property " + davPropName); // Return the property value Object value = props.get(propName); if (value instanceof ContentData) { ContentData contentData = (ContentData) value; if (davPropName.equals(WebDAV.XML_GET_CONTENT_TYPE)) { value = contentData.getMimetype(); } else if (davPropName.equals(WebDAV.XML_GET_CONTENT_LENGTH)) { value = new Long(contentData.getSize()); } } return value; }
Example 4
Source File: ContentChunkerImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ public void addContent(ContentData data) throws TransferException { logger.debug("add content size:" + data.getSize()); buffer.add(data); /** * work out whether the buffer has filled up and needs to be flushed */ Iterator<ContentData> iter = buffer.iterator(); long totalContentSize = 0; while (iter.hasNext()) { ContentData x = (ContentData)iter.next(); totalContentSize += x.getSize(); } if(logger.isDebugEnabled()) { logger.debug("elements " + buffer.size() + ", totalContentSize:" + totalContentSize); } if(totalContentSize >= chunkSize) { flush(); } }
Example 5
Source File: EventGenerationBehaviours.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onContentPropertyUpdate(NodeRef nodeRef, QName propertyQName, ContentData beforeValue, ContentData afterValue) { boolean hasContentBefore = ContentData.hasContent(beforeValue) && beforeValue.getSize() > 0; boolean hasContentAfter = ContentData.hasContent(afterValue) && afterValue.getSize() > 0; // There are some shortcuts here if (!hasContentBefore && !hasContentAfter) { // Really, nothing happened return; } else if (EqualsHelper.nullSafeEquals(beforeValue, afterValue)) { // Still, nothing happening return; } eventsService.contentWrite(nodeRef, propertyQName, afterValue); }
Example 6
Source File: ThumbnailServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private boolean validateThumbnail(NodeRef thumbnailNode) { boolean valid = true; ContentData content = (ContentData) this.nodeService.getProperty(thumbnailNode, ContentModel.PROP_CONTENT); // (MNT-17162) A thumbnail with an empty content is cached for post-transaction removal, to prevent the delete in read-only transactions. if (content.getSize() == 0) { TransactionalResourceHelper.getSet(THUMBNAIL_TO_DELETE_NODES).add(thumbnailNode); TransactionSupportUtil.bindListener(this.thumbnailsToDeleteTransactionListener, 0); valid = false; } return valid; }
Example 7
Source File: CompressingContentStore.java From alfresco-simple-content-stores with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public ContentReader getReader(final String contentUrl) { // need to use information from context (if call came via ContentService#getReader(NodeRef, QName)) to find the real size, as the // size reported by the reader from the delegate may differ due to compression // context also helps us optimise by avoiding decompressing facade if content data mimetype does not require compression at all long properSize = -1; String mimetype = null; final Object contentDataCandidate = ContentStoreContext.getContextAttribute(ContentStoreContext.DEFAULT_ATTRIBUTE_CONTENT_DATA); if (contentDataCandidate instanceof ContentData) { final ContentData contentData = (ContentData) contentDataCandidate; if (contentUrl.equals(contentData.getContentUrl())) { properSize = contentData.getSize(); mimetype = contentData.getMimetype(); } } // this differs from shouldCompress determination in compressing writer / decompressing reader // if we don't know the mimetype yet (e.g. due to missing context), we can't make the assumption that content may not need // decompression at this point - mimetype may still be set via setMimetype() on reader instance final boolean shouldCompress = this.mimetypesToCompress == null || this.mimetypesToCompress.isEmpty() || mimetype == null || this.mimetypesToCompress.contains(mimetype) || this.isMimetypeToCompressWildcardMatch(mimetype); ContentReader reader; final ContentReader backingReader = super.getReader(contentUrl); if (shouldCompress) { reader = new DecompressingContentReader(backingReader, this.compressionType, this.mimetypesToCompress, properSize); } else { reader = backingReader; } return reader; }
Example 8
Source File: ContentStreamLengthProperty.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public Serializable getValueInternal(CMISNodeInfo nodeInfo) { ContentData contentData = getContentData(nodeInfo); if (contentData != null) { return contentData.getSize(); } return null; }
Example 9
Source File: ContentUsageImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Called before a node is deleted. * * @param nodeRef the node reference */ public void beforeDeleteNode(NodeRef nodeRef) { if (stores.contains(tenantService.getBaseName(nodeRef.getStoreRef()).toString()) && (! alreadyDeleted(nodeRef))) { // TODO use data dictionary to get content property ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); if (contentData != null) { long contentSize = contentData.getSize(); // Get owner/creator String owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER); // allow for case where someone else is deleting the node if (owner == null || owner.equals(OwnableService.NO_OWNER)) { owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER); if ((owner == null) || (owner.equals(OwnableService.NO_OWNER))) { owner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR); } } if (contentSize != 0 && owner != null) { // decrement usage if node is being deleted if (logger.isDebugEnabled()) logger.debug("beforeDeleteNode: nodeRef="+nodeRef+", owner="+owner+", contentSize="+contentSize); decrementUserUsage(owner, contentSize, nodeRef); recordDelete(nodeRef); } } } }
Example 10
Source File: ContentUsageImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void onCreateNode(ChildAssociationRef childAssocRef) { NodeRef nodeRef = childAssocRef.getChildRef(); if (stores.contains(tenantService.getBaseName(nodeRef.getStoreRef()).toString()) && (! alreadyCreated(nodeRef))) { // TODO use data dictionary to get content property ContentData contentData = (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); if (contentData != null) { long contentSize = contentData.getSize(); // Get owner/creator String owner = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_OWNER); if ((owner == null) || (owner.equals(OwnableService.NO_OWNER))) { owner = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_CREATOR); } if (contentSize != 0 && owner != null) { // increment usage if node is being created if (logger.isDebugEnabled()) logger.debug("onCreateNode: nodeRef="+nodeRef+", owner="+owner+", contentSize="+contentSize); incrementUserUsage(owner, contentSize, nodeRef); recordCreate(nodeRef); } } } }
Example 11
Source File: NodeContentData.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Construct */ public NodeContentData(NodeRef nodeRef, ContentData contentData) { super(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(), contentData.getEncoding(), contentData.getLocale()); this.nodeRef = nodeRef; }
Example 12
Source File: NodeResourceHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ContentInfo getContentInfo(Map<QName, Serializable> props) { final Serializable content = props.get(ContentModel.PROP_CONTENT); ContentInfo contentInfo = null; if ((content instanceof ContentData)) { ContentData cd = (ContentData) content; contentInfo = new ContentInfo(cd.getMimetype(), cd.getSize(), cd.getEncoding()); } return contentInfo; }
Example 13
Source File: OnPropertyUpdateRuleTrigger.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private boolean havePropertiesBeenModified(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after, boolean newNode, boolean newContentOnly) { if (newContentOnly && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_NO_CONTENT)) { return false; } Set<QName> keys = new HashSet<QName>(after.keySet()); keys.addAll(before.keySet()); // Compare all properties, ignoring protected properties and giving special treatment to content properties boolean nonNullContentProperties = false; boolean newContentProperties = false; boolean nonNewModifiedContentProperties = false; boolean modifiedNonContentProperties = false; for (QName name : keys) { // Skip rule firing on this content property for performance reasons if (name.equals(ContentModel.PROP_PREFERENCE_VALUES)) { continue; } Serializable beforeValue = before.get(name); Serializable afterValue = after.get(name); PropertyDefinition propertyDefinition = this.dictionaryService.getProperty(name); if (propertyDefinition == null) { if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue)) { modifiedNonContentProperties = true; } } // Ignore protected properties else if (!propertyDefinition.isProtected()) { if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT) && !propertyDefinition.isMultiValued()) { // Remember whether the property was populated, regardless of the ignore setting if (afterValue != null) { nonNullContentProperties = true; } if (this.ignoreEmptyContent) { ContentData beforeContent = toContentData(before.get(name)); ContentData afterContent = toContentData(after.get(name)); if (!ContentData.hasContent(beforeContent) || beforeContent.getSize() == 0) { beforeValue = null; } if (!ContentData.hasContent(afterContent) || afterContent.getSize() == 0) { afterValue = null; } } if (newNode) { if (afterValue != null) { newContentProperties = true; } } else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue)) { if (beforeValue == null) { newContentProperties = true; } else { nonNewModifiedContentProperties = true; } } } else if (!EqualsHelper.nullSafeEquals(beforeValue, afterValue)) { modifiedNonContentProperties = true; } } } if (newContentOnly) { return (newNode && !nonNullContentProperties ) || newContentProperties; } else { return modifiedNonContentProperties || nonNewModifiedContentProperties; } }
Example 14
Source File: EventsServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void contentWrite(NodeRef nodeRef, QName propertyQName, ContentData value) { NodeInfo nodeInfo = getNodeInfo(nodeRef, NodeContentPutEvent.EVENT_TYPE); if(nodeInfo.checkNodeInfo()) { String username = AuthenticationUtil.getFullyAuthenticatedUser(); String networkId = TenantUtil.getCurrentDomain(); String name = nodeInfo.getName(); String objectId = nodeInfo.getNodeId(); String siteId = nodeInfo.getSiteId(); String txnId = AlfrescoTransactionSupport.getTransactionId(); List<String> nodePaths = nodeInfo.getPaths(); List<List<String>> pathNodeIds = nodeInfo.getParentNodeIds(); long timestamp = System.currentTimeMillis(); Long modificationTime = nodeInfo.getModificationTimestamp(); long size; String mimeType; String encoding; if (value != null) { size = value.getSize(); mimeType = value.getMimetype(); encoding = value.getEncoding(); } else { size = 0; mimeType = ""; encoding = ""; } String nodeType = nodeInfo.getType().toPrefixString(namespaceService); Client alfrescoClient = getAlfrescoClient(nodeInfo.getClient()); Set<String> aspects = nodeInfo.getAspectsAsStrings(); Map<String, Serializable> properties = nodeInfo.getProperties(); Event event = new NodeContentPutEvent(nextSequenceNumber(), name, txnId, timestamp, networkId, siteId, objectId, nodeType, nodePaths, pathNodeIds, username, modificationTime, size, mimeType, encoding, alfrescoClient, aspects, properties); sendEvent(event); } }
Example 15
Source File: ContentUsageImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Called after a node's properties have been changed. * * @param nodeRef reference to the updated node * @param before the node's properties before the change * @param after the node's properties after the change */ public void onUpdateProperties( NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) { if (stores.contains(tenantService.getBaseName(nodeRef.getStoreRef()).toString()) && (! alreadyCreated(nodeRef))) { // Check for change in content size // TODO use data dictionary to get content property ContentData contentDataBefore = (ContentData)before.get(ContentModel.PROP_CONTENT); Long contentSizeBefore = (contentDataBefore == null ? null : contentDataBefore.getSize()); ContentData contentDataAfter = (ContentData)after.get(ContentModel.PROP_CONTENT); Long contentSizeAfter = (contentDataAfter == null ? null : contentDataAfter.getSize()); // Check for change in owner/creator String ownerBefore = (String)before.get(ContentModel.PROP_OWNER); if ((ownerBefore == null) || (ownerBefore.equals(OwnableService.NO_OWNER))) { ownerBefore = (String)before.get(ContentModel.PROP_CREATOR); } String ownerAfter = (String)after.get(ContentModel.PROP_OWNER); if ((ownerAfter == null) || (ownerAfter.equals(OwnableService.NO_OWNER))) { ownerAfter = (String)after.get(ContentModel.PROP_CREATOR); } // check change in size (and possibly owner) if (contentSizeBefore == null && contentSizeAfter != null && contentSizeAfter != 0 && ownerAfter != null) { // new size has been added - note: ownerBefore does not matter since the contentSizeBefore is null if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateSize (null -> "+contentSizeAfter+"): nodeRef="+nodeRef+", ownerAfter="+ownerAfter); incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef); } else if (contentSizeAfter == null && contentSizeBefore != null && contentSizeBefore != 0 && ownerBefore != null) { // old size has been removed - note: ownerAfter does not matter since contentSizeAfter is null if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateSize ("+contentSizeBefore+" -> null): nodeRef="+nodeRef+", ownerBefore="+ownerBefore); decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef); } else if (contentSizeBefore != null && contentSizeAfter != null) { if (contentSizeBefore.equals(contentSizeAfter) == false) { // size has changed (and possibly owner) if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateSize ("+contentSizeBefore+" -> "+contentSizeAfter+"): nodeRef="+nodeRef+", ownerBefore="+ownerBefore+", ownerAfter="+ownerAfter); if (contentSizeBefore != 0 && ownerBefore != null) { decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef); } if (contentSizeAfter != 0 && ownerAfter != null) { incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef); } } else { // same size - check change in owner only if (ownerBefore == null && ownerAfter != null && contentSizeAfter != 0 && ownerAfter != null) { // new owner has been added if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateOwner (null -> "+ownerAfter+"): nodeRef="+nodeRef+", contentSize="+contentSizeAfter); incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef); } else if (ownerAfter == null && ownerBefore != null && contentSizeBefore != 0) { // old owner has been removed if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateOwner ("+ownerBefore+" -> null): nodeRef="+nodeRef+", contentSize="+contentSizeBefore); decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef); } else if (ownerBefore != null && ownerAfter != null && ownerBefore.equals(ownerAfter) == false) { // owner has changed (size has not) if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateOwner ("+ownerBefore+" -> "+ownerAfter+"): nodeRef="+nodeRef+", contentSize="+contentSizeBefore); if (contentSizeBefore != 0) { decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef); } if (contentSizeAfter != 0) { incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef); } } } } } }
Example 16
Source File: AbstractContentDataDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Translates the {@link ContentData} into persistable values using the helper DAOs */ protected ContentDataEntity createContentDataEntity(ContentData contentData) { // Resolve the content URL Long contentUrlId = null; String contentUrl = contentData.getContentUrl(); long size = contentData.getSize(); if (contentUrl != null) { ContentUrlEntity contentUrlEntity = new ContentUrlEntity(); contentUrlEntity.setContentUrl(contentUrl); contentUrlEntity.setSize(size); Pair<Long, ContentUrlEntity> pair = contentUrlCache.createOrGetByValue(contentUrlEntity, controlDAO); contentUrlId = pair.getFirst(); } // Resolve the mimetype Long mimetypeId = null; String mimetype = contentData.getMimetype(); if (mimetype != null) { mimetypeId = mimetypeDAO.getOrCreateMimetype(mimetype).getFirst(); } // Resolve the encoding Long encodingId = null; String encoding = contentData.getEncoding(); if (encoding != null) { encodingId = encodingDAO.getOrCreateEncoding(encoding).getFirst(); } // Resolve the locale Long localeId = null; Locale locale = contentData.getLocale(); if (locale != null) { localeId = localeDAO.getOrCreateLocalePair(locale).getFirst(); } // Create ContentDataEntity ContentDataEntity contentDataEntity = createContentDataEntity(contentUrlId, mimetypeId, encodingId, localeId); // Done return contentDataEntity; }
Example 17
Source File: CreateDownloadArchiveAction.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void contentImpl(NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index) { size = size + contentData.getSize(); fileCount = fileCount + 1; }
Example 18
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity) { if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) { throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId()); } Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef); ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT); String name = (String) nodeProps.get(ContentModel.PROP_NAME); org.alfresco.rest.framework.resource.content.ContentInfo ci = null; String mimeType = null; if (cd != null) { mimeType = cd.getMimetype(); ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(mimeType, cd.getEncoding(), cd.getSize(), cd.getLocale()); } // By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach boolean attach = true; String attachment = parameters.getParameter("attachment"); if (attachment != null) { Boolean a = Boolean.valueOf(attachment); if (!a) { if (nonAttachContentTypes.contains(mimeType)) { attach = false; } else { logger.warn("Ignored attachment=false for "+nodeRef.getId()+" since "+mimeType+" is not in the whitelist for non-attach content types"); } } } String attachFileName = (attach ? name : null); if (recordActivity) { final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef); postActivity(Activity_Type.DOWNLOADED, activityInfo, true); } return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName); }
Example 19
Source File: UpdateThumbnailActionExecuter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef) */ @Override protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { // Check if thumbnailing is generally disabled if (!thumbnailService.getThumbnailsEnabled()) { if (logger.isDebugEnabled()) { logger.debug("Thumbnail transformations are not enabled"); } return; } // Get the thumbnail NodeRef thumbnailNodeRef = (NodeRef)action.getParameterValue(PARAM_THUMBNAIL_NODE); if (thumbnailNodeRef == null) { thumbnailNodeRef = actionedUponNodeRef; } if (this.nodeService.exists(thumbnailNodeRef) == true && renditionService.isRendition(thumbnailNodeRef)) { // Get the thumbnail Name ChildAssociationRef parent = renditionService.getSourceNode(thumbnailNodeRef); String thumbnailName = parent.getQName().getLocalName(); // Get the details of the thumbnail ThumbnailRegistry registry = this.thumbnailService.getThumbnailRegistry(); ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName); if (details == null) { throw new AlfrescoRuntimeException("The thumbnail name '" + thumbnailName + "' is not registered"); } // Get the content property QName contentProperty = (QName)action.getParameterValue(PARAM_CONTENT_PROPERTY); if (contentProperty == null) { contentProperty = ContentModel.PROP_CONTENT; } Serializable contentProp = nodeService.getProperty(actionedUponNodeRef, contentProperty); if (contentProp == null) { logger.info("Creation of thumbnail, null content for " + details.getName()); return; } if(contentProp instanceof ContentData) { ContentData content = (ContentData)contentProp; String mimetype = content.getMimetype(); if (mimetypeMaxSourceSizeKBytes != null) { Long maxSourceSizeKBytes = mimetypeMaxSourceSizeKBytes.get(mimetype); if (maxSourceSizeKBytes != null && maxSourceSizeKBytes >= 0 && maxSourceSizeKBytes < (content.getSize()/1024L)) { logger.debug("Unable to create thumbnail '" + details.getName() + "' for " + mimetype + " as content is too large ("+(content.getSize()/1024L)+"K > "+maxSourceSizeKBytes+"K)"); return; //avoid transform } } } // Create the thumbnail this.thumbnailService.updateThumbnail(thumbnailNodeRef, details.getTransformationOptions()); } }
Example 20
Source File: RenditionsImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private BinaryResource getContentImpl(NodeRef nodeRef, String renditionId, Parameters parameters) { NodeRef renditionNodeRef = getRenditionByName(nodeRef, renditionId, parameters); // By default set attachment header (with rendition Id) unless attachment=false boolean attach = true; String attachment = parameters.getParameter(PARAM_ATTACHMENT); if (attachment != null) { attach = Boolean.valueOf(attachment); } final String attachFileName = (attach ? renditionId : null); if (renditionNodeRef == null) { boolean isPlaceholder = Boolean.valueOf(parameters.getParameter(PARAM_PLACEHOLDER)); if (!isPlaceholder) { throw new NotFoundException("Thumbnail was not found for [" + renditionId + ']'); } String sourceNodeMimeType = null; try { sourceNodeMimeType = (nodeRef != null ? getMimeType(nodeRef) : null); } catch (InvalidArgumentException e) { // No content for node, e.g. ASSOC_AVATAR rather than ASSOC_PREFERENCE_IMAGE } // resource based on the content's mimeType and rendition id String phPath = scriptThumbnailService.getMimeAwarePlaceHolderResourcePath(renditionId, sourceNodeMimeType); if (phPath == null) { // 404 since no thumbnail was found throw new NotFoundException("Thumbnail was not found and no placeholder resource available for [" + renditionId + ']'); } else { if (logger.isDebugEnabled()) { logger.debug("Retrieving content from resource path [" + phPath + ']'); } // get extension of resource String ext = ""; int extIndex = phPath.lastIndexOf('.'); if (extIndex != -1) { ext = phPath.substring(extIndex); } try { final String resourcePath = "classpath:" + phPath; InputStream inputStream = resourceLoader.getResource(resourcePath).getInputStream(); // create temporary file File file = TempFileProvider.createTempFile(inputStream, "RenditionsApi-", ext); return new FileBinaryResource(file, attachFileName); } catch (Exception ex) { if (logger.isErrorEnabled()) { logger.error("Couldn't load the placeholder." + ex.getMessage()); } throw new ApiException("Couldn't load the placeholder."); } } } Map<QName, Serializable> nodeProps = nodeService.getProperties(renditionNodeRef); ContentData contentData = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT); Date modified = (Date) nodeProps.get(ContentModel.PROP_MODIFIED); org.alfresco.rest.framework.resource.content.ContentInfo contentInfo = null; if (contentData != null) { contentInfo = new ContentInfoImpl(contentData.getMimetype(), contentData.getEncoding(), contentData.getSize(), contentData.getLocale()); } // add cache settings CacheDirective cacheDirective = new CacheDirective.Builder() .setNeverCache(false) .setMustRevalidate(false) .setLastModified(modified) .setETag(modified != null ? Long.toString(modified.getTime()) : null) .setMaxAge(Long.valueOf(31536000))// one year (in seconds) .build(); return new NodeBinaryResource(renditionNodeRef, ContentModel.PROP_CONTENT, contentInfo, attachFileName, cacheDirective); }