Search in sources :

Example 1 with WorkflowModel

use of com.day.cq.workflow.model.WorkflowModel in project acs-aem-commons by Adobe-Consulting-Services.

the class InitFormServlet method doGet.

@Override
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    final JsonObject json = new JsonObject();
    // Runners
    accumulate(json, KEY_RUNNER_TYPES, withLabelValue("AEM Workflow", AEMWorkflowRunnerImpl.class.getName()));
    accumulate(json, KEY_RUNNER_TYPES, withLabelValue("Synthetic Workflow (Single-threaded)", SyntheticWorkflowRunnerImpl.class.getName()));
    accumulate(json, KEY_RUNNER_TYPES, withLabelValue("Synthetic Workflow (Multi-threaded)", FastActionManagerRunnerImpl.class.getName()));
    // Query Types
    accumulate(json, KEY_QUERY_TYPES, withLabelValue("QueryBuilder", "queryBuilder"));
    accumulate(json, KEY_QUERY_TYPES, withLabelValue("List", "list"));
    accumulate(json, KEY_QUERY_TYPES, withLabelValue("xPath", "xpath"));
    accumulate(json, KEY_QUERY_TYPES, withLabelValue("JCR-SQL2", "JCR-SQL2"));
    accumulate(json, KEY_QUERY_TYPES, withLabelValue("JCR-SQL", "JCR-SQL"));
    // User Event Data
    accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("Custom user-event-data", ""));
    accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("changedByWorkflowProcess", "changedByWorkflowProcess"));
    accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("acs-aem-commons.bulk-workflow-manager", "acs-aem-commons.bulk-workflow-manager"));
    // Workflow Models
    final WorkflowSession workflowSession = workflowService.getWorkflowSession(request.getResourceResolver().adaptTo(Session.class));
    try {
        final WorkflowModel[] workflowModels = workflowSession.getModels();
        for (final WorkflowModel workflowModel : workflowModels) {
            boolean transientWorkflow = TransientWorkflowUtil.isTransient(request.getResourceResolver(), workflowModel.getId());
            String workflowLabel = workflowModel.getTitle();
            if (transientWorkflow) {
                workflowLabel += " ( Transient )";
            }
            JsonObject jsonWorkflow = withLabelValue(workflowLabel, workflowModel.getId());
            jsonWorkflow.addProperty("transient", transientWorkflow);
            accumulate(json, "workflowModels", jsonWorkflow);
        }
        response.getWriter().write(json.toString());
    } catch (WorkflowException e) {
        log.error("Could not create workflow model drop-down.", e);
        JSONErrorUtil.sendJSONError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not collect workflows", e.getMessage());
    }
}
Also used : WorkflowSession(com.day.cq.workflow.WorkflowSession) WorkflowException(com.day.cq.workflow.WorkflowException) JsonObject(com.google.gson.JsonObject) WorkflowModel(com.day.cq.workflow.model.WorkflowModel) WorkflowSession(com.day.cq.workflow.WorkflowSession) Session(javax.jcr.Session)

Example 2 with WorkflowModel

use of com.day.cq.workflow.model.WorkflowModel in project acs-aem-commons by Adobe-Consulting-Services.

the class InitServlet method getFormJSONObject.

/**
 * Get the JSON data to populate the Workflow Removal form.
 *
 * @param resourceResolver
 * @return
 * @throws WorkflowException
 * @throws JSONException
 */
private JSONObject getFormJSONObject(final ResourceResolver resourceResolver) throws WorkflowException, JSONException {
    final JSONObject json = new JSONObject();
    final WorkflowSession workflowSession = workflowService.getWorkflowSession(resourceResolver.adaptTo(Session.class));
    final WorkflowModel[] workflowModels = workflowSession.getModels();
    for (final WorkflowModel workflowModel : workflowModels) {
        final JSONObject jsonWorkflow = new JSONObject();
        jsonWorkflow.put("title", workflowModel.getTitle());
        jsonWorkflow.put("id", workflowModel.getId());
        json.accumulate("workflowModels", jsonWorkflow);
    }
    json.put("statuses", new JSONArray(Arrays.asList(WORKFLOW_STATUSES)));
    return json;
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) WorkflowSession(com.day.cq.workflow.WorkflowSession) JSONArray(org.apache.sling.commons.json.JSONArray) WorkflowModel(com.day.cq.workflow.model.WorkflowModel) Session(javax.jcr.Session) WorkflowSession(com.day.cq.workflow.WorkflowSession)

Example 3 with WorkflowModel

use of com.day.cq.workflow.model.WorkflowModel in project acs-aem-commons by Adobe-Consulting-Services.

the class SyntheticWorkflowSessionTest method setUp.

@Before
public void setUp() {
    session = new SyntheticWorkflowSession(new SyntheticWorkflowRunnerImpl(), resourceResolver.adaptTo(Session.class));
    workflowData = new SyntheticWorkflowData("JCR_PATH", "/content/test");
    workflowData.getMetaDataMap().put("cat", "meow");
    workflowData.getMetaDataMap().put("bird", "ka-kaw");
    syntheticWorkflow = new SyntheticWorkflow("test", workflowData);
    SyntheticWorkItem syntheticWorkItem = SyntheticWorkItem.createSyntheticWorkItem(syntheticWorkflow.getWorkflowData());
    wrappedWorkItem = (WorkItem) Proxy.newProxyInstance(WrappedSyntheticWorkItem.class.getClassLoader(), new Class[] { WorkItem.class, WrappedSyntheticWorkItem.class }, syntheticWorkItem);
    SyntheticRoute syntheticRoute = new SyntheticRoute(false);
    route = (Route) syntheticRoute;
    workItemFilter = new WorkItemFilter() {

        @Override
        public boolean doInclude(WorkItem workItem) {
            return false;
        }
    };
    workflowModelFilter = new WorkflowModelFilter() {

        @Override
        public boolean doInclude(WorkflowModel workflowModel) {
            return false;
        }
    };
}
Also used : WrappedSyntheticWorkItem(com.adobe.acs.commons.workflow.synthetic.cq.WrappedSyntheticWorkItem) SyntheticWorkflowData(com.adobe.acs.commons.workflow.synthetic.impl.SyntheticWorkflowData) WrappedSyntheticWorkItem(com.adobe.acs.commons.workflow.synthetic.cq.WrappedSyntheticWorkItem) SyntheticWorkflowRunnerImpl(com.adobe.acs.commons.workflow.synthetic.impl.SyntheticWorkflowRunnerImpl) WorkflowModelFilter(com.day.cq.workflow.model.WorkflowModelFilter) WorkflowModel(com.day.cq.workflow.model.WorkflowModel) WorkItemFilter(com.day.cq.workflow.exec.filter.WorkItemFilter) WorkItem(com.day.cq.workflow.exec.WorkItem) WrappedSyntheticWorkItem(com.adobe.acs.commons.workflow.synthetic.cq.WrappedSyntheticWorkItem) Before(org.junit.Before)

Aggregations

WorkflowModel (com.day.cq.workflow.model.WorkflowModel)3 WorkflowSession (com.day.cq.workflow.WorkflowSession)2 Session (javax.jcr.Session)2 WrappedSyntheticWorkItem (com.adobe.acs.commons.workflow.synthetic.cq.WrappedSyntheticWorkItem)1 SyntheticWorkflowData (com.adobe.acs.commons.workflow.synthetic.impl.SyntheticWorkflowData)1 SyntheticWorkflowRunnerImpl (com.adobe.acs.commons.workflow.synthetic.impl.SyntheticWorkflowRunnerImpl)1 WorkflowException (com.day.cq.workflow.WorkflowException)1 WorkItem (com.day.cq.workflow.exec.WorkItem)1 WorkItemFilter (com.day.cq.workflow.exec.filter.WorkItemFilter)1 WorkflowModelFilter (com.day.cq.workflow.model.WorkflowModelFilter)1 JsonObject (com.google.gson.JsonObject)1 JSONArray (org.apache.sling.commons.json.JSONArray)1 JSONObject (org.apache.sling.commons.json.JSONObject)1 Before (org.junit.Before)1