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

The following are Jave code examples for showing how to use getContentUrl() 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: ContentDataDAOImpl.java   View Source Code Vote up 6 votes
@Override
protected int deleteContentDataEntity(Long id)
{
    // Get the content urls
    try
    {
        ContentData contentData = getContentData(id).getSecond();
        String contentUrl = contentData.getContentUrl();
        if (contentUrl != null)
        {
            // It has been dereferenced and may be orphaned - we'll check later
            registerDereferencedContentUrl(contentUrl);
        }
    }
    catch (DataIntegrityViolationException e)
    {
        // Doesn't exist.  The node doesn't enforce a FK constraint, so we protect against this.
    }
    // Issue the delete statement
    Map<String, Object> params = new HashMap<String, Object>(11);
    params.put("id", id);
    return template.delete(DELETE_CONTENT_DATA, params);
}
 
Example 2
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 3
Project: alfresco-repository   File: RepoPrimaryManifestProcessorImpl.java   View Source Code Vote up 5 votes
/**
 * @param nodeToUpdate NodeRef
 * @param contentProps Map<QName, Serializable>
 * @return true if any content property has been updated for the needToUpdate node
 */
private boolean writeContent(NodeRef nodeToUpdate, Map<QName, Serializable> contentProps)
{
    boolean contentUpdated = false;
    File stagingDir = getStagingFolder();
    for (Map.Entry<QName, Serializable> contentEntry : contentProps.entrySet())
    {
        ContentData contentData = (ContentData) contentEntry.getValue();
        String contentUrl = contentData.getContentUrl();
        if(contentUrl == null || contentUrl.isEmpty())
        {
            log.debug("content data is null or empty:" + nodeToUpdate);
            ContentData cd = new ContentData(null, null, 0, null);
            nodeService.setProperty(nodeToUpdate, contentEntry.getKey(), cd);
            contentUpdated = true;
        }
        else
        {
            String fileName = TransferCommons.URLToPartName(contentUrl);
            File stagedFile = new File(stagingDir, fileName);
            if (!stagedFile.exists())
            {
                error(MSG_REFERENCED_CONTENT_FILE_MISSING);
            }
            ContentWriter writer = contentService.getWriter(nodeToUpdate, contentEntry.getKey(), true);
            writer.setEncoding(contentData.getEncoding());
            writer.setMimetype(contentData.getMimetype());
            writer.setLocale(contentData.getLocale());
            writer.putContent(stagedFile);
            contentUpdated = true;
        }
    }
    return contentUpdated;
}
 
Example 4
Project: alfresco-repository   File: RepoPrimaryManifestProcessorImpl.java   View Source Code Vote up 5 votes
/**
 * inject transferred
 */
private void injectTransferred(Map<QName, Serializable> props)
{       
    if(!props.containsKey(TransferModel.PROP_REPOSITORY_ID))
    {
        log.debug("injecting repositoryId property");
        props.put(TransferModel.PROP_REPOSITORY_ID, header.getRepositoryId());
    }
    props.put(TransferModel.PROP_FROM_REPOSITORY_ID, header.getRepositoryId());
    
    /**
     * For each property
     */
    List<String> contentProps = new ArrayList<String>();
    for (Serializable value : props.values())
    {
        if ((value != null) && ContentData.class.isAssignableFrom(value.getClass()))
        {
            ContentData srcContent = (ContentData)value;

            if(srcContent.getContentUrl() != null && !srcContent.getContentUrl().isEmpty())
            {
                log.debug("adding part name to from content field");
                contentProps.add(TransferCommons.URLToPartName(srcContent.getContentUrl()));
            }  
        }
    }
    
    props.put(TransferModel.PROP_FROM_CONTENT, (Serializable)contentProps);
}
 
Example 5
Project: alfresco-repository   File: ContentStreamIdProperty.java   View Source Code Vote up 5 votes
public Serializable getValueInternal(CMISNodeInfo nodeInfo)
{
    ContentData contentData = getContentData(nodeInfo);

    if (contentData != null)
    {
        return contentData.getContentUrl();
    }
    return null;
}
 
Example 6
Project: alfresco-repository   File: ContentDataDAOTest.java   View Source Code Vote up 5 votes
public void testContentUrl_FetchingOrphansNoLimit() throws Exception
{
    ContentData contentData = getContentData();
    Pair<Long, ContentData> resultPair = create(contentData);
    getAndCheck(resultPair.getFirst(), contentData);
    delete(resultPair.getFirst());
    // The content URL is orphaned
    final String contentUrlOrphaned = contentData.getContentUrl();
    final boolean[] found = new boolean[] {false}; 
    
    // Iterate over all orphaned content URLs and ensure that we hit the one we just orphaned
    ContentUrlHandler handler = new ContentUrlHandler()
    {
        public void handle(Long id, String contentUrl, Long orphanTime)
        {
            // Check
            if (id == null || contentUrl == null || orphanTime == null)
            {
                fail("Invalid orphan data returned to handler: " + id + "-" + contentUrl + "-" + orphanTime);
            }
            // Did we get the one we wanted?
            if (contentUrl.equals(contentUrlOrphaned))
            {
                found[0] = true;
            }
        }
    };
    contentDataDAO.getContentUrlsOrphaned(handler, Long.MAX_VALUE, Integer.MAX_VALUE);
    assertTrue("Newly-orphaned content URL not found", found[0]);
}
 
Example 7
Project: alfresco-file-transfer-receiver   File: FileTransferReceiverRequisiteManifestProcessor.java   View Source Code Vote up 5 votes
protected void processNode(TransferManifestNormalNode node)
{

    //Skip over any nodes that are not parented with a cm:contains association or 
    //are not content nodes (we don't need their content)
    if (!ContentModel.ASSOC_CONTAINS.equals(node.getPrimaryParentAssoc().getTypeQName()) ||
            !ContentModel.TYPE_CONTENT.equals(node.getAncestorType()))
    {
        return;
    }

    Serializable value = node.getProperties().get(ContentModel.PROP_CONTENT);
    if ((value != null) && ContentData.class.isAssignableFrom(value.getClass()))
    {
        ContentData srcContent = (ContentData) value;
        if (srcContent.getContentUrl() != null && !srcContent.getContentUrl().isEmpty())
        {
            // Only ask for content if content is new or if contentUrl is modified
            boolean contentisMissing = fileTransferReceiver.isContentNewOrModified(
                    node.getNodeRef().toString(), srcContent.getContentUrl());
            if (contentisMissing)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("No node on destination, content is required: " + srcContent.getContentUrl());
                }
                out.missingContent(node.getNodeRef(), ContentModel.PROP_CONTENT, 
                        TransferCommons.URLToPartName(srcContent.getContentUrl()));
            }
        }
    }
}
 
Example 8
Project: alfresco-file-transfer-receiver   File: ManifestProcessorImpl.java   View Source Code Vote up 5 votes
public static NodeContext buildNodeContext(TransferManifestNormalNode node, FileTransferInfoEntity nodeEntity, 
        FileTransferInfoEntity parentEntity)
{
    NodeContext result = new NodeContext();
    //Pull some useful information out of the supplied node object
    result.newName = (String) node.getProperties().get(ContentModel.PROP_NAME);
    result.nodeId = node.getNodeRef().toString();
    result.isFolder = ContentModel.TYPE_FOLDER.equals(node.getAncestorType());
    result.newParentId = node.getPrimaryParentAssoc().getParentRef().toString();
    
    //Look up the node id in our database and extract some info from what we find
    result.isNew = (nodeEntity == null);
    result.isRenamed = (!result.isNew && !result.newName.equals(nodeEntity.getContentName()));
    result.parentHasChanged = (!result.isNew && !result.newParentId.equals(nodeEntity.getParent()));
    result.hasMoved = result.parentHasChanged || result.isRenamed;
    result.currentParentPath = result.isNew ? null : nodeEntity.getPath();
    result.currentParentId = result.isNew ? null : nodeEntity.getParent();
    result.currentContentUrl = result.isNew ? null : nodeEntity.getContentUrl();
    result.currentName = result.isNew ? null : nodeEntity.getContentName();
    
    //Look up the target parent node id in our database and extract some info from what we find
    result.parentAlreadyExists = (parentEntity != null);
    result.newParentPath = result.parentAlreadyExists ? (parentEntity.getPath() + parentEntity.getContentName() + "/") : null;
    result.tempName = getNextTempName();
    
    ContentData contentData = (ContentData) node.getProperties().get(ContentModel.PROP_CONTENT);
    result.newContentUrl = "";
    if (contentData != null)
    {
        result.newContentUrl = contentData.getContentUrl();
    }

    return result;
}
 
Example 9
Project: alfresco-repository   File: ImporterComponent.java   View Source Code Vote up 4 votes
/**
 * Import Node Content.
 * <p>
 * The content URL, if present, will be a local URL.  This import copies the content
 * from the local URL to a server-assigned location.
 *
 * @param nodeRef containing node
 * @param propertyName the name of the content-type property
 * @param importContentData the identifier of the content to import
 */
private void importContent(NodeRef nodeRef, QName propertyName, String importContentData)
{
    ImporterContentCache contentCache = (binding == null) ? null : binding.getImportConentCache();
    
    // bind import content data description
    importContentData = bindPlaceHolder(importContentData, binding);
    if (importContentData != null && importContentData.length() > 0)
    {
        DataTypeDefinition dataTypeDef = dictionaryService.getDataType(DataTypeDefinition.CONTENT);
        ContentData contentData = (ContentData)DefaultTypeConverter.INSTANCE.convert(dataTypeDef, importContentData);
        String contentUrl = contentData.getContentUrl();
        if (contentUrl != null && contentUrl.length() > 0)
        {
            Map<QName, Serializable> propsBefore = null;
            if (contentUsageImpl != null && contentUsageImpl.getEnabled())
            {
                propsBefore = nodeService.getProperties(nodeRef);
            }

            if (contentCache != null)
            {
                // import content from source
                ContentData cachedContentData = contentCache.getContent(streamHandler, contentData);
                nodeService.setProperty(nodeRef, propertyName, cachedContentData);
            }
            else
            {
                // import the content from the import source file
                InputStream contentStream = streamHandler.importStream(contentUrl);
                ContentWriter writer = contentService.getWriter(nodeRef, propertyName, true);
                writer.setEncoding(contentData.getEncoding());
                writer.setMimetype(contentData.getMimetype());
                writer.putContent(contentStream);
            }
                                
            if (contentUsageImpl != null && contentUsageImpl.getEnabled())
            {
                // Since behaviours for content nodes have all been disabled,
                // it is necessary to update the user's usage stats.
                Map<QName, Serializable> propsAfter = nodeService.getProperties(nodeRef);
                contentUsageImpl.onUpdateProperties(nodeRef, propsBefore, propsAfter);
            }
            
            reportContentCreated(nodeRef, contentUrl);
        }
    }
}
 
Example 10
Project: alfresco-repository   File: DefaultImporterContentCache.java   View Source Code Vote up 4 votes
@Override
public ContentData getContent(final ImportPackageHandler handler, final ContentData sourceContentData)
{
    ContentData cachedContentData = null;
    final String sourceContentUrl = sourceContentData.getContentUrl();

    contentUrlsLock.readLock().lock();
    
    try
    {
        cachedContentData = contentUrls.get(sourceContentUrl);
        if (cachedContentData == null)
        {
            contentUrlsLock.readLock().unlock();
            contentUrlsLock.writeLock().lock();
            
            try
            {
                cachedContentData = contentUrls.get(sourceContentUrl);
                if (cachedContentData == null)
                {
                    cachedContentData = TenantUtil.runAsTenant(new TenantRunAsWork<ContentData>()
                    {
                        @Override
                        public ContentData doWork() throws Exception
                        {
                            InputStream contentStream = handler.importStream(sourceContentUrl);
                            ContentWriter writer = contentService.getWriter(null, null, false);
                            writer.setEncoding(sourceContentData.getEncoding());
                            writer.setMimetype(sourceContentData.getMimetype());
                            writer.putContent(contentStream);
                            return writer.getContentData();
                        }
                    }, TenantService.DEFAULT_DOMAIN);
                    
                    contentUrls.put(sourceContentUrl, cachedContentData);
                }
            }
            finally
            {
                contentUrlsLock.readLock().lock();
                contentUrlsLock.writeLock().unlock();
            }
        }
    }
    finally
    {
        contentUrlsLock.readLock().unlock();
    }
    
    if (logger.isDebugEnabled())
        logger.debug("Mapped contentUrl " + sourceContentUrl + " to " + cachedContentData);
        
    return cachedContentData;
}
 
Example 11
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 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 int updateContentDataEntity(ContentDataEntity contentDataEntity, ContentData contentData)
{
    // Resolve the content URL
    Long oldContentUrlId = contentDataEntity.getContentUrlId();
    ContentUrlEntity contentUrlEntity = null;
    if(oldContentUrlId != null)
    {
        Pair<Long, ContentUrlEntity> entityPair = contentUrlCache.getByKey(oldContentUrlId);
        if (entityPair == null)
        {
            throw new DataIntegrityViolationException("No ContentUrl value exists for ID " + oldContentUrlId);
        }
        contentUrlEntity = entityPair.getSecond();
    }

    String oldContentUrl = (contentUrlEntity != null ? contentUrlEntity.getContentUrl() : null);
    String newContentUrl = contentData.getContentUrl();
    if (!EqualsHelper.nullSafeEquals(oldContentUrl, newContentUrl))
    {
        if (oldContentUrl != null)
        {
            // We have a changed value.  The old content URL has been dereferenced.
            registerDereferencedContentUrl(oldContentUrl);
        }
        if (newContentUrl != null)
        {
            if(contentUrlEntity == null)
            {
                contentUrlEntity = new ContentUrlEntity();
                contentUrlEntity.setContentUrl(newContentUrl);
            }
            Pair<Long, ContentUrlEntity> pair = contentUrlCache.getOrCreateByValue(contentUrlEntity);
            Long newContentUrlId = pair.getFirst();
            contentUrlEntity.setId(newContentUrlId);
            contentDataEntity.setContentUrlId(newContentUrlId);
        }
        else
        {
            contentDataEntity.setId(null);
            contentDataEntity.setContentUrlId(null);
        }
    }

    // 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();
    }

    contentDataEntity.setMimetypeId(mimetypeId);
    contentDataEntity.setEncodingId(encodingId);
    contentDataEntity.setLocaleId(localeId);

    return updateContentDataEntity(contentDataEntity);
}