Search in sources :

Example 1 with NodeRef

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

the class NodesImpl method requestRenditions.

private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode) {
    if (thumbnailDefs != null) {
        ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
        for (ThumbnailDefinition thumbnailDef : thumbnailDefs) {
            NodeRef sourceNodeRef = fileNode.getNodeRef();
            String mimeType = fileNode.getContent().getMimeType();
            long size = fileNode.getContent().getSizeInBytes();
            // Check if anything is currently available to generate thumbnails for the specified mimeType
            if (!registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef)) {
                throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " + mimeType + " as no transformer is currently available.");
            }
            Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
            // Queue async creation of thumbnail
            actionService.executeAction(action, sourceNodeRef, true, true);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition) Action(org.alfresco.service.cmr.action.Action) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ThumbnailRegistry(org.alfresco.repo.thumbnail.ThumbnailRegistry)

Example 2 with NodeRef

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

the class RenditionsImpl method getRenditions.

@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, Parameters parameters) {
    final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
    String contentMimeType = getMimeType(validatedNodeRef);
    Query query = parameters.getQuery();
    boolean includeCreated = true;
    boolean includeNotCreated = true;
    String status = getStatus(parameters);
    if (status != null) {
        includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
        includeNotCreated = !includeCreated;
    }
    Map<String, Rendition> apiRenditions = new TreeMap<>();
    if (includeNotCreated) {
        // List all available thumbnail definitions
        List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
        for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
            apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
        }
    }
    List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(validatedNodeRef);
    if (!nodeRefRenditions.isEmpty()) {
        for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
            NodeRef renditionNodeRef = childAssociationRef.getChildRef();
            Rendition apiRendition = toApiRendition(renditionNodeRef);
            if (includeCreated) {
                // Replace/append any thumbnail definitions with created rendition info
                apiRenditions.put(apiRendition.getId(), apiRendition);
            } else {
                // Remove any thumbnail definitions that has been created from the list,
                // as the filter requires only the Not_Created renditions
                apiRenditions.remove(apiRendition.getId());
            }
        }
    }
    // Wrap paging info, as the core service doesn't support paging
    Paging paging = parameters.getPaging();
    PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
    return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) Rendition(org.alfresco.rest.api.model.Rendition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) TreeMap(java.util.TreeMap) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition)

Example 3 with NodeRef

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

the class BaseDetailsBean method applyTemplate.

// ------------------------------------------------------------------------------
// Action event handlers
/**
 * Action handler to apply the selected Template and Templatable aspect to the current node
 */
public void applyTemplate(ActionEvent event) {
    if (this.template != null && this.template.equals(TemplateSupportBean.NO_SELECTION) == false) {
        try {
            // apply the templatable aspect if required
            if (getNode().hasAspect(ContentModel.ASPECT_TEMPLATABLE) == false) {
                this.getNodeService().addAspect(getNode().getNodeRef(), ContentModel.ASPECT_TEMPLATABLE, null);
            }
            // get the selected template from the Template Picker
            NodeRef templateRef = new NodeRef(Repository.getStoreRef(), this.template);
            // set the template NodeRef into the templatable aspect property
            this.getNodeService().setProperty(getNode().getNodeRef(), ContentModel.PROP_TEMPLATE, templateRef);
            // reset node details for next refresh of details page
            getNode().reset();
        } catch (Exception e) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), e.getMessage()), e);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ReportedException(org.alfresco.web.ui.common.ReportedException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 4 with NodeRef

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

the class BaseDetailsBean method getWorkflowProperties.

/**
 * Returns the properties for the attached workflow as a map
 *
 * @return Properties of the attached workflow, null if there is no workflow
 */
public Map<String, Serializable> getWorkflowProperties() {
    if (this.workflowProperties == null && getNode().hasAspect(ApplicationModel.ASPECT_SIMPLE_WORKFLOW)) {
        // get the exisiting properties for the node
        Map<String, Object> props = getNode().getProperties();
        String approveStepName = (String) props.get(ApplicationModel.PROP_APPROVE_STEP.toString());
        String rejectStepName = (String) props.get(ApplicationModel.PROP_REJECT_STEP.toString());
        Boolean approveMove = (Boolean) props.get(ApplicationModel.PROP_APPROVE_MOVE.toString());
        Boolean rejectMove = (Boolean) props.get(ApplicationModel.PROP_REJECT_MOVE.toString());
        NodeRef approveFolder = (NodeRef) props.get(ApplicationModel.PROP_APPROVE_FOLDER.toString());
        NodeRef rejectFolder = (NodeRef) props.get(ApplicationModel.PROP_REJECT_FOLDER.toString());
        // put the workflow properties in a separate map for use by the JSP
        this.workflowProperties = new HashMap<String, Serializable>(7);
        this.workflowProperties.put(SimpleWorkflowHandler.PROP_APPROVE_STEP_NAME, approveStepName);
        this.workflowProperties.put(SimpleWorkflowHandler.PROP_APPROVE_ACTION, approveMove ? "move" : "copy");
        this.workflowProperties.put(SimpleWorkflowHandler.PROP_APPROVE_FOLDER, approveFolder);
        if (rejectStepName == null || rejectMove == null || rejectFolder == null) {
            this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_STEP_PRESENT, "no");
        } else {
            this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_STEP_PRESENT, "yes");
            this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_STEP_NAME, rejectStepName);
            this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_ACTION, rejectMove ? "move" : "copy");
            this.workflowProperties.put(SimpleWorkflowHandler.PROP_REJECT_FOLDER, rejectFolder);
        }
    }
    return this.workflowProperties;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable)

Example 5 with NodeRef

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

the class BaseDetailsBean method reject.

/**
 * Event handler called to handle the approve step of the simple workflow
 *
 * @param event The event that was triggered
 */
public void reject(ActionEvent event) {
    UIActionLink link = (UIActionLink) event.getComponent();
    Map<String, String> params = link.getParameterMap();
    String id = params.get("id");
    if (id == null || id.length() == 0) {
        throw new AlfrescoRuntimeException("reject called without an id");
    }
    final NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id);
    try {
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // call the service to perform the reject
                WorkflowUtil.reject(docNodeRef, getNodeService(), getCopyService());
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // if this was called via the node details dialog we need to reset the node
        if (getNode() != null) {
            getNode().reset();
        }
        // also make sure the UI will get refreshed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
    } catch (Throwable e) {
        // rollback the transaction
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_REJECT), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1263 HashMap (java.util.HashMap)250 QName (org.alfresco.service.namespace.QName)247 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)212 Test (org.junit.Test)203 ArrayList (java.util.ArrayList)164 Serializable (java.io.Serializable)139 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 JSONObject (org.json.JSONObject)84 Map (java.util.Map)83 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Node (org.alfresco.web.bean.repository.Node)81 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)75 List (java.util.List)61 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 IOException (java.io.IOException)55 Date (java.util.Date)52 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52