Search in sources :

Example 16 with ContentData

use of org.alfresco.service.cmr.repository.ContentData in project acs-community-packaging by Alfresco.

the class EditContentPropertiesDialog method formatErrorMessage.

/**
 * Formats the error message to display if an error occurs during finish processing
 *
 * @param exception The exception
 * @return The formatted message
 */
@Override
protected String formatErrorMessage(Throwable exception) {
    if (editableNode != null) {
        // special case for Mimetype - since this is a sub-property of the ContentData object
        // we must extract it so it can be edited in the client, then we check for it later
        // and create a new ContentData object to wrap it and it's associated URL
        ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
        if (content != null) {
            this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
            this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
        }
    }
    if (exception instanceof FileExistsException) {
        return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_EXISTS), ((FileExistsException) exception).getName());
    } else if (exception instanceof InvalidNodeRefException) {
        return MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { this.browseBean.getDocument().getId() });
    } else {
        return super.formatErrorMessage(exception);
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 17 with ContentData

use of org.alfresco.service.cmr.repository.ContentData in project acs-community-packaging by Alfresco.

the class EditContentPropertiesDialog method init.

// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters) {
    super.init(parameters);
    // setup the editable node
    this.editableNode = initEditableNode();
    if (editableNode != null) {
        // special case for Mimetype - since this is a sub-property of the ContentData object
        // we must extract it so it can be edited in the client, then we check for it later
        // and create a new ContentData object to wrap it and it's associated URL
        ContentData content = (ContentData) this.editableNode.getProperties().get(ContentModel.PROP_CONTENT);
        if (content != null) {
            this.editableNode.getProperties().put(TEMP_PROP_MIMETYPE, content.getMimetype());
            this.editableNode.getProperties().put(TEMP_PROP_ENCODING, content.getEncoding());
        }
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData)

Example 18 with ContentData

use of org.alfresco.service.cmr.repository.ContentData in project alfresco-remote-api by Alfresco.

the class PeopleImpl method processPersonProperties.

protected void processPersonProperties(String userName, final Map<QName, Serializable> nodeProps) {
    if (!contentUsageService.getEnabled()) {
        // quota used will always be 0 in this case so remove from the person properties
        nodeProps.remove(ContentModel.PROP_SIZE_QUOTA);
        nodeProps.remove(ContentModel.PROP_SIZE_CURRENT);
    }
    // The person description is located in a separate content file located at cm:persondescription
    // "Inline" this data, by removing the cm:persondescription property and adding a temporary property
    // (Person.PROP_PERSON_DESCRIPTION) containing the actual content as a string.
    final ContentData personDescription = (ContentData) nodeProps.get(ContentModel.PROP_PERSONDESC);
    if (personDescription != null) {
        nodeProps.remove(ContentModel.PROP_PERSONDESC);
        AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                ContentReader reader = contentService.getRawReader(personDescription.getContentUrl());
                if (reader != null && reader.exists()) {
                    String description = reader.getContentString();
                    nodeProps.put(Person.PROP_PERSON_DESCRIPTION, description);
                }
                return null;
            }
        });
    }
}
Also used : ContentData(org.alfresco.service.cmr.repository.ContentData) ContentReader(org.alfresco.service.cmr.repository.ContentReader) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) ResetPasswordWorkflowInvalidUserException(org.alfresco.repo.security.authentication.ResetPasswordServiceImpl.ResetPasswordWorkflowInvalidUserException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) ResetPasswordWorkflowException(org.alfresco.repo.security.authentication.ResetPasswordServiceImpl.ResetPasswordWorkflowException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 19 with ContentData

use of org.alfresco.service.cmr.repository.ContentData in project alfresco-remote-api by Alfresco.

the class QuickShareLinksImpl method getQuickShareInfo.

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);
    }
}
Also used : Serializable(java.io.Serializable) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Example 20 with ContentData

use of org.alfresco.service.cmr.repository.ContentData 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)

Aggregations

ContentData (org.alfresco.service.cmr.repository.ContentData)29 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 Date (java.util.Date)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 HashMap (java.util.HashMap)4 InputStream (java.io.InputStream)3 Map (java.util.Map)3 ContentInfo (org.alfresco.rest.api.model.ContentInfo)3 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)3 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)3 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)3 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)3 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)3 Node (org.alfresco.web.bean.repository.Node)3 SessionUser (org.alfresco.repo.SessionUser)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)2