Java Code Examples for org.alfresco.service.cmr.repository.ContentData.getSize()

The following are Jave code examples for showing how to use getSize() of the org.alfresco.service.cmr.repository.ContentData class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-repository   File: ContentChunkerImpl.java   View Source Code Vote up 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 2
Project: alfresco-remote-api   File: WebDAV.java   View Source Code Vote up 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 3
Project: alfresco-remote-api   File: Document.java   View Source Code Vote up 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 4
Project: alfresco-remote-api   File: RenditionsImpl.java   View Source Code Vote up 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 5
Project: alfresco-repository   File: NodeContentData.java   View Source Code Vote up 5 votes
/**
 * Construct
 */
public NodeContentData(NodeRef nodeRef, ContentData contentData)
{
    super(contentData.getContentUrl(), contentData.getMimetype(), contentData.getSize(),
            contentData.getEncoding(), contentData.getLocale());
    this.nodeRef = nodeRef;
}
 
Example 6
Project: alfresco-repository   File: ContentUsageImpl.java   View Source Code Vote up 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 7
Project: alfresco-repository   File: ContentUsageImpl.java   View Source Code Vote up 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 8
Project: alfresco-repository   File: ContentStreamLengthProperty.java   View Source Code Vote up 5 votes
public Serializable getValueInternal(CMISNodeInfo nodeInfo)
{
    ContentData contentData = getContentData(nodeInfo);

    if (contentData != null)
    {
        return contentData.getSize();
    }
    return null;
}
 
Example 9
Project: alfresco-test-assertions   File: NodeAssert.java   View Source Code Vote up 5 votes
/**
 * Check that a property contains (non-empty) content, i.e. content with
 * size &gt; 0
 *
 * @param contentQName Which property to check
 * @return The created node assertion object
 */
public NodeAssert hasContent(final QName contentQName) {
    isNotNull();
    exists();
    final Serializable prop = nodeService.getProperty(actual, contentQName);
    if (prop != null) {
        final ContentData content = (ContentData) prop;
        if (content.getSize() == 0) {
            failWithMessage("Node <%s> should have content with size > 0 ", actual);
        }
    } else {
        failWithMessage("Node <%s> should have content ", actual);
    }
    return this;
}
 
Example 10
Project: alfresco-repository   File: UpdateThumbnailActionExecuter.java   View Source Code Vote up 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 11
Project: alfresco-repository   File: CreateDownloadArchiveAction.java   View Source Code Vote up 4 votes
@Override
protected void contentImpl(NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index)
{
    size = size + contentData.getSize();
    fileCount = fileCount + 1;
}
 
Example 12
Project: alfresco-repository   File: AbstractContentDataDAOImpl.java   View Source Code Vote up 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 13
Project: alfresco-remote-api   File: NodesImpl.java   View Source Code Vote up 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 14
Project: alfresco-remote-api   File: QuickShareLinksImpl.java   View Source Code Vote up 4 votes
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam)
{
    String sharedId = (String)map.get("sharedId");

    try
    {
        Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
        ContentData cd = (ContentData)nodeProps.get(ContentModel.PROP_CONTENT);

        String mimeType = cd.getMimetype();
        String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
        ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());

        Map<String, UserInfo> mapUserInfo = new HashMap<>(2);

        // note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
        boolean displayNameOnly = noAuth;

        UserInfo modifiedByUser = Node.lookupUserInfo((String)nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);

        // TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
        String sharedByUserId = (String)nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
        UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);

        QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
        qs.setName((String) map.get("name"));
        qs.setTitle((String) map.get("title"));
        qs.setDescription((String) map.get("description"));
        qs.setContent(contentInfo);
        qs.setModifiedAt((Date) map.get("modified"));
        qs.setModifiedByUser(modifiedByUser);
        qs.setSharedByUser(sharedByUser);
        qs.setExpiresAt((Date) map.get("expiryDate"));

        // note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
        if (!noAuth)
        {
            if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS))
            {
                if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId))
                {
                    // the allowable operations for the shared link
                    qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
                }

                Node doc = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, null);
                List<String> allowableOps = doc.getAllowableOperations();
                // the allowable operations for the actual file being shared
                qs.setAllowableOperationsOnTarget(allowableOps);
            }

            
            // in noAuth mode we don't return the path info
            if (includeParam.contains(PARAM_INCLUDE_PATH))
            {
                qs.setPath(nodes.lookupPathInfo(nodeRef, null));
            }
        }


        return qs;
    }
    catch (InvalidSharedIdException ex)
    {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    }
    catch (InvalidNodeRefException inre)
    {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}