Search in sources :

Example 1 with Action

use of org.alfresco.service.cmr.action.Action in project alfresco-remote-api by Alfresco.

the class AbstractExecuteActionWebscript method buildModel.

protected Map<String, Object> buildModel(RunningActionModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache) {
    try {
        // Have the action to run be identified
        Action action = identifyAction(req, status, cache);
        if (action == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "No Runnable Action found with the supplied details");
        }
        // Ask for it to be run in the background
        // It will be available to execute once the webscript finishes
        actionService.executeAction(action, null, false, true);
        // Return the details if we can
        ExecutionSummary summary = getSummaryFromAction(action);
        if (summary == null) {
            throw new WebScriptException(Status.STATUS_EXPECTATION_FAILED, "Action failed to be added to the pending queue");
        }
        return modelBuilder.buildSimpleModel(summary);
    } catch (Exception e) {
        // Transaction broke
        throw new RuntimeException(e);
    }
}
Also used : Action(org.alfresco.service.cmr.action.Action) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 2 with Action

use of org.alfresco.service.cmr.action.Action in project alfresco-remote-api by Alfresco.

the class RunningActionsPost method identifyAction.

@Override
protected Action identifyAction(WebScriptRequest req, Status status, Cache cache) {
    // Which action did they ask for?
    String nodeRef = req.getParameter("nodeRef");
    if (nodeRef == null) {
        try {
            JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
            if (!json.has("nodeRef")) {
                throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'nodeRef' parameter");
            }
            nodeRef = json.getString("nodeRef");
        } catch (IOException iox) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from request.", iox);
        } catch (JSONException je) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from request.", je);
        }
    }
    // Does it exist in the repo?
    NodeRef actionNodeRef = new NodeRef(nodeRef);
    if (!nodeService.exists(actionNodeRef)) {
        return null;
    }
    // Load the specified action
    Action action = runtimeActionService.createAction(actionNodeRef);
    return action;
}
Also used : JSONTokener(org.json.JSONTokener) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Action(org.alfresco.service.cmr.action.Action) JSONObject(org.json.JSONObject) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 3 with Action

use of org.alfresco.service.cmr.action.Action in project alfresco-remote-api by Alfresco.

the class RuleServiceTest method testGetRuleset.

public void testGetRuleset() throws Exception {
    JSONObject parentRule = createRule(testWorkNodeRef);
    String[] parentRuleIds = new String[] { parentRule.getJSONObject("data").getString("id") };
    JSONObject jsonRule = createRule(testNodeRef);
    String[] ruleIds = new String[] { jsonRule.getJSONObject("data").getString("id") };
    Action linkRulesAction = actionService.createAction(LinkRules.NAME);
    linkRulesAction.setParameterValue(LinkRules.PARAM_LINK_FROM_NODE, testNodeRef);
    actionService.executeAction(linkRulesAction, testNodeRef2);
    Response linkedFromResponse = sendRequest(new GetRequest(formatRulesetUrl(testNodeRef)), 200);
    JSONObject linkedFromResult = new JSONObject(linkedFromResponse.getContentAsString());
    checkRuleset(linkedFromResult, 1, ruleIds, 1, parentRuleIds, true, false);
    Response linkedToResponse = sendRequest(new GetRequest(formatRulesetUrl(testNodeRef2)), 200);
    JSONObject linkedToResult = new JSONObject(linkedToResponse.getContentAsString());
    checkRuleset(linkedToResult, 1, ruleIds, 1, parentRuleIds, false, true);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) Action(org.alfresco.service.cmr.action.Action) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 4 with Action

use of org.alfresco.service.cmr.action.Action in project alfresco-remote-api by Alfresco.

the class PutMethod method executeImpl.

/**
 * Execute the WebDAV request
 *
 * @exception WebDAVServerException
 */
protected void executeImpl() throws WebDAVServerException, Exception {
    if (logger.isDebugEnabled()) {
        String path = getPath();
        String userName = getDAVHelper().getAuthenticationService().getCurrentUserName();
        logger.debug("Put node: \n" + "     user: " + userName + "\n" + "     path: " + path + "\n" + "noContent: " + noContent);
    }
    FileFolderService fileFolderService = getFileFolderService();
    // Get the status for the request path
    LockInfo nodeLockInfo = null;
    try {
        contentNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
        // make sure that we are not trying to use a folder
        if (contentNodeInfo.isFolder()) {
            throw new WebDAVServerException(HttpServletResponse.SC_BAD_REQUEST);
        }
        nodeLockInfo = checkNode(contentNodeInfo);
        // 'Unhide' nodes hidden by us and behave as though we created them
        NodeRef contentNodeRef = contentNodeInfo.getNodeRef();
        if (fileFolderService.isHidden(contentNodeRef) && !getDAVHelper().isRenameShuffle(getPath())) {
            fileFolderService.setHidden(contentNodeRef, false);
            created = true;
        }
    } catch (FileNotFoundException e) {
        // the file doesn't exist - create it
        String[] paths = getDAVHelper().splitPath(getPath());
        try {
            FileInfo parentNodeInfo = getNodeForPath(getRootNodeRef(), paths[0]);
            // create file
            contentNodeInfo = getDAVHelper().createFile(parentNodeInfo, paths[1]);
            created = true;
        } catch (FileNotFoundException ee) {
            // bad path
            throw new WebDAVServerException(HttpServletResponse.SC_CONFLICT);
        } catch (FileExistsException ee) {
            // ALF-7079 fix, retry: it looks like concurrent access (file not found but file exists)
            throw new ConcurrencyFailureException("Concurrent access was detected.", ee);
        }
    }
    String userName = getDAVHelper().getAuthenticationService().getCurrentUserName();
    LockInfo lockInfo = getDAVLockService().getLockInfo(contentNodeInfo.getNodeRef());
    if (lockInfo != null) {
        if (lockInfo.isLocked() && !lockInfo.getOwner().equals(userName)) {
            if (logger.isDebugEnabled()) {
                String path = getPath();
                String owner = lockInfo.getOwner();
                logger.debug("Node locked: path=[" + path + "], owner=[" + owner + "], current user=[" + userName + "]");
            }
            // Indicate that the resource is locked
            throw new WebDAVServerException(WebDAV.WEBDAV_SC_LOCKED);
        }
    }
    // ALF-16808: We disable the versionable aspect if we are overwriting
    // empty content because it's probably part of a compound operation to
    // create a new single version
    boolean disabledVersioning = false;
    try {
        // Disable versioning if we are overwriting an empty file with content
        NodeRef nodeRef = contentNodeInfo.getNodeRef();
        ContentData contentData = (ContentData) getNodeService().getProperty(nodeRef, ContentModel.PROP_CONTENT);
        if ((contentData == null || contentData.getSize() == 0) && getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE)) {
            getDAVHelper().getPolicyBehaviourFilter().disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
            disabledVersioning = true;
        }
        // Access the content
        ContentWriter writer = fileFolderService.getWriter(contentNodeInfo.getNodeRef());
        // set content properties
        writer.guessMimetype(contentNodeInfo.getName());
        writer.guessEncoding();
        // Get the input stream from the request data
        InputStream is = m_request.getInputStream();
        // Write the new data to the content node
        writer.putContent(is);
        // - the node does not have any content (zero length binaries included)
        if (nodeLockInfo != null && nodeLockInfo.isExclusive() && !(ContentData.hasContent(contentData) && contentData.getSize() > 0)) {
            getNodeService().addAspect(contentNodeInfo.getNodeRef(), ContentModel.ASPECT_NO_CONTENT, null);
        }
        // Ask for the document metadata to be extracted
        Action extract = getActionService().createAction(ContentMetadataExtracter.EXECUTOR_NAME);
        if (extract != null) {
            extract.setExecuteAsynchronously(false);
            getActionService().executeAction(extract, contentNodeInfo.getNodeRef());
        }
        // from the original specified in the request, update it.
        if (m_strContentType == null || !m_strContentType.equals(writer.getMimetype())) {
            String oldMimeType = m_strContentType;
            m_strContentType = writer.getMimetype();
            if (logger.isDebugEnabled()) {
                logger.debug("Mimetype originally specified as " + oldMimeType + ", now guessed to be " + m_strContentType);
            }
        }
        // Record the uploaded file's size
        fileSize = writer.getSize();
        // Set the response status, depending if the node existed or not
        m_response.setStatus(created ? HttpServletResponse.SC_CREATED : HttpServletResponse.SC_NO_CONTENT);
    } catch (AccessDeniedException e) {
        throw new WebDAVServerException(HttpServletResponse.SC_FORBIDDEN, e);
    } catch (Throwable e) {
        // we are about to give up
        if (noContent && RetryingTransactionHelper.extractRetryCause(e) == null) {
            // remove the 0 bytes content if save operation failed or was cancelled
            final NodeRef nodeRef = contentNodeInfo.getNodeRef();
            getTransactionService().getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {

                public String execute() throws Throwable {
                    getNodeService().deleteNode(nodeRef);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Put failed. DELETE  " + getPath());
                    }
                    return null;
                }
            }, false, false);
        }
        throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    } finally {
        if (disabledVersioning) {
            getDAVHelper().getPolicyBehaviourFilter().enableBehaviour(contentNodeInfo.getNodeRef(), ContentModel.ASPECT_VERSIONABLE);
        }
    }
    postActivity();
}
Also used : Action(org.alfresco.service.cmr.action.Action) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) InputStream(java.io.InputStream) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentData(org.alfresco.service.cmr.repository.ContentData) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 5 with Action

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

Aggregations

Action (org.alfresco.service.cmr.action.Action)29 NodeRef (org.alfresco.service.cmr.repository.NodeRef)18 ArrayList (java.util.ArrayList)8 Rule (org.alfresco.service.cmr.rule.Rule)7 CreateRecordAction (org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction)6 JSONObject (org.json.JSONObject)6 Serializable (java.io.Serializable)5 FileToAction (org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction)5 HashMap (java.util.HashMap)4 List (java.util.List)4 JSONArray (org.json.JSONArray)4 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 ActionImpl (org.alfresco.repo.action.ActionImpl)2 CompositeActionImpl (org.alfresco.repo.action.CompositeActionImpl)2 ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)2 ThumbnailRegistry (org.alfresco.repo.thumbnail.ThumbnailRegistry)2 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 ActionDefinition (org.alfresco.service.cmr.action.ActionDefinition)2