public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { WorkflowData workflowData = item.getWorkflowData(); log.info("==================== <> ======================"); Iterator props = args.entrySet().iterator(); String pathToArchive = args.get("PROCESS_ARGS", String.class); if (pathToArchive != null) if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) { String path = workflowData.getPayload().toString(); try { Node node = (Node) session.getSession().getItem(path + "/jcr:content"); String orderBy = node.getProperty("orderby").getString(); log.info("----------orderby: " + orderBy); Node nodeToOrder = (Node) session.getSession().getItem(pathToArchive); Iterator<Node> iterator = nodeToOrder.getNodes(); List<Node> nodes = copyIterator(iterator); Collections.sort(nodes, new NodeComparator(orderBy)); for (Node orderNode : nodes) { session .getSession() .getWorkspace() .move( pathToArchive + "/" + orderNode.getName(), pathToArchive + "/" + orderNode.getName()); } } catch (RepositoryException e) { throw new WorkflowException(e.getMessage(), e); } } }
@Override public void execute(WorkItem workItem, WorkflowSession workflowSession, String[] strings) throws Exception { log.info("executing workflow"); WorkflowData workflowData = workItem.getWorkflowData(); String payload = workflowData.getPayload().toString(); log.info("payload " + payload); // find agent id if (strings.length == 0) { throw new Exception("Agent name is not set in arguments for workflow process step"); } final String agentId = StringUtils.trim(strings[0]); log.info("agent id " + agentId); // filter agent ReplicationOptions opts = new ReplicationOptions(); opts.setFilter( new AgentFilter() { public boolean isIncluded(final Agent agent) { return agentId.equals(agent.getId()); } }); // activate page Session session = null; try { session = repository.loginAdministrative(null); replicator.replicate(session, ReplicationActionType.ACTIVATE, payload, opts); } finally { if (session != null) { session.logout(); } } }
/** @see WorkflowProcess#execute(WorkItem, WorkflowSession, MetaDataMap) */ public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException { final Session session = workflowSession.getSession(); final WorkflowData data = workItem.getWorkflowData(); String path = null; String type = data.getPayloadType(); try { if (type.equals(TYPE_JCR_PATH) && data.getPayload() != null) { String payloadData = (String) data.getPayload(); if (session.itemExists(payloadData)) { path = payloadData; } } if (path != null) { final Node userGeneratedNode = (Node) session.getItem(path); if (userGeneratedNode.hasProperty(SLING_RESOURCE_TYPE) && userGeneratedNode .getProperty(SLING_RESOURCE_TYPE) .getString() .equals(COMMENT_RESOURCE_TYPE)) { logger.debug("Spam check for comment node at " + userGeneratedNode.getPath()); String ipAddress = null; if (userGeneratedNode.hasProperty("ip")) { ipAddress = userGeneratedNode.getProperty("ip").getString(); logger.debug("Spam check for comment node with ip " + ipAddress); } else { setIsSpam(userGeneratedNode, false, session); logger.info("Comment has no IP address, setting isSpam to false"); return; } // if the ip is localhost we set isspam to false as well if (ipAddress.equalsIgnoreCase("127.0.0.1") || ipAddress.equalsIgnoreCase("localhost") || ipAddress.equalsIgnoreCase("0:0:0:0:0:0:0:1")) { setIsSpam(userGeneratedNode, false, session); logger.info("Comment IP address is localhost, setting isSpam to false"); return; } String userAgent = null; if (userGeneratedNode.hasProperty("userAgent")) { userAgent = userGeneratedNode.getProperty("userAgent").getString(); logger.debug("Spam check for comment node with userAgent " + userAgent); } else { setIsSpam(userGeneratedNode, false, session); logger.info("Comment has no user agent, setting isSpam to false"); return; } String referrer = null; if (userGeneratedNode.hasProperty("referer")) { referrer = userGeneratedNode.getProperty("referer").getString(); logger.debug("Spam check for comment node with referrer " + referrer); } String permalink = null; try { ResourceResolver resourceResolver = jcrResourceResolverFactory.getResourceResolver(session); Resource resource = resourceResolver.getResource(path); BlogManager blogManager = resource.getResourceResolver().adaptTo(BlogManager.class); Blog entry = blogManager.getBlog(path); permalink = entry.getFullUrl(); logger.debug("Spam check for comment node with permalink " + permalink); } catch (Exception e) { logger.error("Exception " + e.toString() + " getting permalink"); } String author = null; if (userGeneratedNode.hasProperty("userIdentifier")) { author = userGeneratedNode.getProperty("userIdentifier").getString(); logger.debug("Spam check for comment node with permalink " + author); } String authorEmail = null; if (userGeneratedNode.hasProperty("email")) { authorEmail = userGeneratedNode.getProperty("email").getString(); logger.debug("Spam check for comment node with author " + authorEmail); } String authorURL = null; if (userGeneratedNode.hasProperty("url")) { authorURL = userGeneratedNode.getProperty("url").getString(); logger.debug("Spam check for comment node with authorURL " + authorURL); } String commentText = null; if (userGeneratedNode.hasProperty("jcr:description")) { commentText = userGeneratedNode.getProperty("jcr:description").getString(); logger.debug("Spam check for comment node with commentText " + commentText); } boolean isSpam = akismetService.commentCheck( ipAddress, userAgent, referrer, permalink, "comment", author, authorEmail, authorURL, commentText, null); setIsSpam(userGeneratedNode, isSpam, session); logger.info("Spam check result " + isSpam + " for comment: " + workItem.toString()); } else if (userGeneratedNode.hasProperty(SLING_RESOURCE_TYPE) && userGeneratedNode .getProperty(SLING_RESOURCE_TYPE) .getString() .equals(TRACKBACK_RESOURCE_TYPE)) { // for // trackbacks String ipAddress = null; if (userGeneratedNode.hasProperty("ip")) { ipAddress = userGeneratedNode.getProperty("ip").getString(); logger.debug("Spam check for trackback node with ip " + ipAddress); } String authorURL = null; if (userGeneratedNode.hasProperty("url")) { authorURL = userGeneratedNode.getProperty("url").getString(); logger.debug("Spam check for trackback node with authorURL " + authorURL); } String permalink = null; try { ResourceResolver resourceResolver = jcrResourceResolverFactory.getResourceResolver(session); Resource resource = resourceResolver.getResource(path); BlogManager blogManager = resource.getResourceResolver().adaptTo(BlogManager.class); Blog entry = blogManager.getBlog(path); permalink = entry.getFullUrl(); logger.debug("Spam check for trackback node with permalink " + permalink); } catch (Exception e) { logger.error("Exception " + e.toString() + " getting permalink"); } /* * it is not really clear from the akismet api how to map * the trackback's title and blog-name to the api call. will * try with the code below. */ String author = null; if (userGeneratedNode.hasProperty("blogName")) { author = userGeneratedNode.getProperty("blogName").getString(); logger.debug("Spam check for trackback node with blogName " + author); } // prepending the title to the excerpt String excerpt = ""; if (userGeneratedNode.hasProperty("excerpt")) { excerpt = userGeneratedNode.getProperty("excerpt").getString(); logger.debug("Spam check for trackback node with excerpt " + excerpt); } if (userGeneratedNode.hasProperty("jcr:title")) { excerpt = userGeneratedNode.getProperty("jcr:title").getString() + " " + excerpt; logger.debug( "Spam check for trackback node with title " + userGeneratedNode.hasProperty("jcr:title")); } boolean isSpam = akismetService.commentCheck( ipAddress, null, null, permalink, "trackback", author, null, authorURL, excerpt, null); setIsSpam(userGeneratedNode, isSpam, session); logger.info("Spam check result " + isSpam + " for trackback: " + workItem.toString()); } else { logger.warn( "Cannot check for spam because item is not a comment or a trackback. Workitem: " + workItem.toString()); } } else { logger.warn( "Cannot check for spam because path is null for this workitem: " + workItem.toString()); } } catch (RepositoryException e) { throw new WorkflowException(e); } }
public void execute(final WorkItem item, final WorkflowSession session, final MetaDataMap args) throws SocialModerationException { log.debug("In the workflow... (Flagged in JCR) "); try { validate(item); final JSONArray arr = new JSONArray((String) item.getWorkflowData().getPayload()); final ResourceResolver resolver = getResourceResolver(session.getSession()); for (int i = 0; i < arr.length(); i++) { final JSONObject obj = (JSONObject) arr.get(i); final String path = obj.getString(ModerationConstants.PATH); if (!obj.has(ModerationConstants.ACTION_FLAG)) { throw new SocialModerationException( FLAG_VERB_NOT_PRESENT_IN_PAYLOAD, ModerationConstants.ERR_FLAG_VERB_NOT_PRESENT_IN_PAYLOAD); } final boolean isFlagged = obj.getBoolean(ModerationConstants.ACTION_FLAG); final Resource resource = resolver.getResource(path); if (resource == null) { throw new SocialModerationException( ERR_SPECIFIED_RESOURCE_DOES_NOT_EXIST + path, ModerationConstants.ERR_SPECIFIED_RESOURCE_DOES_NOT_EXIST); } else { final Comment comment = resource.adaptTo(Comment.class); if (comment != null) { final Node node = resource.adaptTo(Node.class); node.setProperty(ModerationConstants.PROP_IS_FLAGGED, isFlagged); node.setProperty(ModerationConstants.PROP_IS_READ, true); addModHistory( profileMgr, resolver, node, ModerationConstants.PROP_IS_FLAGGED, String.valueOf(isFlagged), item.getWorkflow().getInitiator()); node.getSession().save(); replicator.replicate( session.getSession(), com.day.cq.replication.ReplicationActionType.ACTIVATE, path.substring(0, path.lastIndexOf('/')), null); // msgs[i] = "Comment " + verb + ": " + path; } else { throw new SocialModerationException( "Not a comment: " + path, ModerationConstants.ERR_NOT_A_COMMENT); } } } } catch (final JSONException je) { log.error(je.getLocalizedMessage(), je.getCause()); throw new SocialModerationException( je.getLocalizedMessage(), ModerationConstants.ERR_FLAGGED_ACTION, je.getCause()); } catch (final Exception e) { log.error(e.getLocalizedMessage(), e.getCause()); throw new SocialModerationException( e.getLocalizedMessage(), ModerationConstants.ERR_FLAGGED_ACTION, e.getCause()); } }