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