use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowInstanceDetailed.
@SuppressWarnings("unchecked")
public void testBuildWorkflowInstanceDetailed() throws Exception {
WorkflowTaskDefinition workflowTaskDefinition = makeTaskDefinition();
QName taskTypeName = WorkflowModel.TYPE_WORKFLOW_TASK;
when(workflowTaskDefinition.getMetadata().getName()).thenReturn(taskTypeName);
when(workflowTaskDefinition.getMetadata().getTitle(dictionaryService)).thenReturn("The Type Title");
when(workflowTaskDefinition.getMetadata().getDescription(dictionaryService)).thenReturn("The Type Description");
WorkflowInstance workflowInstance = makeWorkflowInstance(workflowTaskDefinition);
Map<String, Object> model = builder.buildDetailed(workflowInstance, true);
assertEquals(workflowInstance.getId(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertEquals(workflowInstance.getDefinition().getName(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME));
assertEquals(workflowInstance.getDefinition().getTitle(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE));
assertEquals(workflowInstance.getDefinition().getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION));
assertEquals(workflowInstance.isActive(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDateStr = ISO8601DateFormat.format(workflowInstance.getStartDate());
String endDateStr = ISO8601DateFormat.format(workflowInstance.getEndDate());
String startDateBuilderStr = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
String endDateBuilderStr = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_END_DATE));
assertEquals(startDateStr, startDateBuilderStr);
assertEquals(endDateStr, endDateBuilderStr);
Map<String, Object> initiator = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_INITIATOR);
if (initiator != null) {
assertEquals(userName, initiator.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, initiator.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, initiator.get(WorkflowModelBuilder.PERSON_LAST_NAME));
}
assertEquals(workflowInstance.getContext().toString(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_CONTEXT));
assertEquals(workflowInstance.getWorkflowPackage().toString(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_PACKAGE));
Map<String, Object> taskInstanceModel = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DEFINITION);
assertEquals(workflowInstance.getDefinition().getVersion(), taskInstanceModel.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_VERSION));
assertEquals(workflowInstance.getDefinition().getStartTaskDefinition().getMetadata().getName(), taskInstanceModel.get(WorkflowModelBuilder.WORKFLOW_DEFINITION_START_TASK_DEFINITION_TYPE));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowInstance.
@SuppressWarnings("unchecked")
public void testBuildWorkflowInstance() throws Exception {
WorkflowInstance workflowInstance = makeWorkflowInstance(null);
Map<String, Object> model = builder.buildSimple(workflowInstance);
assertEquals(workflowInstance.getId(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertTrue(model.containsKey(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_URL));
assertEquals(workflowInstance.getDefinition().getName(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_NAME));
assertEquals(workflowInstance.getDefinition().getTitle(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_TITLE));
assertEquals(workflowInstance.getDefinition().getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DESCRIPTION));
assertEquals(workflowInstance.getDescription(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_MESSAGE));
assertEquals(workflowInstance.isActive(), model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDate = ISO8601DateFormat.format(workflowInstance.getStartDate());
String endDate = ISO8601DateFormat.format(workflowInstance.getEndDate());
String startDateBuilder = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE));
String endDateBuilder = ISO8601DateFormat.formatToZulu((String) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_END_DATE));
assertEquals(startDate, startDateBuilder);
assertEquals(endDate, endDateBuilder);
Map<String, Object> initiator = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_INITIATOR);
if (initiator != null) {
assertEquals(userName, initiator.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, initiator.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, initiator.get(WorkflowModelBuilder.PERSON_LAST_NAME));
}
assertTrue(model.containsKey(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_DEFINITION_URL));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilderTest method testBuildWorkflowTask.
@SuppressWarnings("unchecked")
public void testBuildWorkflowTask() throws Exception {
Date date = new Date();
WorkflowTask task = makeTask(date);
Map<String, Object> model = builder.buildSimple(task, null);
Object id = model.get(WorkflowModelBuilder.TASK_ID);
assertEquals(task.getId(), id);
Object url = model.get(WorkflowModelBuilder.TASK_URL);
assertEquals("api/task-instances/" + task.getId(), url);
assertEquals(task.getName(), model.get(WorkflowModelBuilder.TASK_NAME));
assertEquals(task.getTitle(), model.get(WorkflowModelBuilder.TASK_TITLE));
assertEquals(task.getDescription(), model.get(WorkflowModelBuilder.TASK_DESCRIPTION));
assertEquals(task.getState().name(), model.get(WorkflowModelBuilder.TASK_STATE));
assertNull(model.get(WorkflowModelBuilder.TASK_OUTCOME));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_EDITABLE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_REASSIGNABLE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_CLAIMABLE));
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_RELEASABLE));
Map<String, Object> owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
assertEquals(firstName, owner.get(WorkflowModelBuilder.PERSON_FIRST_NAME));
assertEquals(lastName, owner.get(WorkflowModelBuilder.PERSON_LAST_NAME));
Map<String, Object> props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
assertEquals(task.getProperties().size() + 1, props.size());
assertEquals(5, props.get("test_int"));
assertEquals(false, props.get("test_boolean"));
assertEquals("foo bar", props.get("test_string"));
String dateStr = (String) props.get("test_date");
assertEquals(date, ISO8601DateFormat.parse(dateStr));
Map<String, Object> workflowInstance = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE);
assertNotNull(workflowInstance);
WorkflowInstance instance = task.getPath().getInstance();
assertEquals(instance.getId(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_ID));
assertEquals(instance.isActive(), workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_IS_ACTIVE));
String startDateStr = ISO8601DateFormat.format(instance.getStartDate());
String workFlowStartDateStr = (String) workflowInstance.get(WorkflowModelBuilder.TASK_WORKFLOW_INSTANCE_START_DATE);
assertEquals(startDateStr, ISO8601DateFormat.formatToZulu(workFlowStartDateStr));
task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, new ArrayList<NodeRef>(0));
model = builder.buildSimple(task, null);
assertEquals(false, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
ArrayList<NodeRef> actors = new ArrayList<NodeRef>(1);
actors.add(person);
task.getProperties().put(WorkflowModel.ASSOC_POOLED_ACTORS, actors);
model = builder.buildSimple(task, null);
assertEquals(true, model.get(WorkflowModelBuilder.TASK_IS_POOLED));
model = builder.buildSimple(task, Arrays.asList("test_int", "test_string"));
// Check task owner still created properly.
owner = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_OWNER);
assertEquals(userName, owner.get(WorkflowModelBuilder.PERSON_USER_NAME));
// Check properties populated correctly
props = (Map<String, Object>) model.get(WorkflowModelBuilder.TASK_PROPERTIES);
assertEquals(2, props.size());
assertEquals(5, props.get("test_int"));
assertEquals("foo bar", props.get("test_string"));
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project acs-community-packaging by Alfresco.
the class UIWorkflowHistory method encodeBegin.
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (!isRendered())
return;
WorkflowInstance wi = getValue();
if (wi != null) {
ResponseWriter out = context.getResponseWriter();
ResourceBundle bundle = Application.getBundle(context);
if (logger.isDebugEnabled())
logger.debug("Retrieving workflow history for workflow instance: " + wi);
WorkflowTaskQuery query = new WorkflowTaskQuery();
query.setActive(null);
query.setProcessId(wi.id);
query.setTaskState(WorkflowTaskState.COMPLETED);
query.setOrderBy(new WorkflowTaskQuery.OrderBy[] { WorkflowTaskQuery.OrderBy.TaskCreated_Desc, WorkflowTaskQuery.OrderBy.TaskActor_Asc });
List<WorkflowTask> tasks = Repository.getServiceRegistry(context).getWorkflowService().queryTasks(query);
if (tasks.size() == 0) {
out.write("<div style='margin-left:18px;margin-top: 6px;'>");
out.write(bundle.getString(MSG_NO_HISTORY));
out.write("</div>");
} else {
// output surrounding table and style if necessary
out.write("<table cellspacing='2' cellpadding='1' border='0'");
if (this.getAttributes().get("style") != null) {
out.write(" style=\"");
out.write((String) this.getAttributes().get("style"));
out.write("\"");
}
if (this.getAttributes().get("styleClass") != null) {
out.write(" class=\"");
out.write((String) this.getAttributes().get("styleClass"));
out.write("\"");
}
out.write(">");
// output a header row
out.write("<tr align=left><th>");
out.write(bundle.getString(MSG_DESCRIPTION));
out.write("</th><th>");
out.write(bundle.getString(MSG_TASK));
out.write("</th><th>");
out.write(bundle.getString(MSG_ID));
out.write("</th><th>");
out.write(bundle.getString(MSG_CREATED));
out.write("</th><th>");
out.write(bundle.getString(MSG_ASSIGNEE));
out.write("</th><th>");
out.write(bundle.getString(MSG_COMMENT));
out.write("</th><th>");
out.write(bundle.getString(MSG_DATE_COMPLETED));
out.write("</th><th>");
out.write(bundle.getString(MSG_OUTCOME));
out.write("</th></tr>");
// output a row for each previous completed task
for (WorkflowTask task : tasks) {
String id = null;
Serializable idObject = task.properties.get(WorkflowModel.PROP_TASK_ID);
if (idObject instanceof Long) {
id = ((Long) idObject).toString();
} else {
id = idObject.toString();
}
String desc = (String) task.properties.get(WorkflowModel.PROP_DESCRIPTION);
Date createdDate = (Date) task.properties.get(ContentModel.PROP_CREATED);
String owner = (String) task.properties.get(ContentModel.PROP_OWNER);
String comment = (String) task.properties.get(WorkflowModel.PROP_COMMENT);
Date completedDate = (Date) task.properties.get(WorkflowModel.PROP_COMPLETION_DATE);
String transition = (String) task.properties.get(WorkflowModel.PROP_OUTCOME);
String outcome = "";
if (transition != null) {
WorkflowTransition[] transitions = task.definition.node.transitions;
for (WorkflowTransition trans : transitions) {
if (trans.id.equals(transition)) {
outcome = trans.title;
break;
}
}
}
if ((outcome == null || outcome.equals("")) && transition != null) {
// it's possible in Activiti to have tasks without an outcome set,
// in this case default to the transition, if there is one.
outcome = transition;
}
// ACE-1154
if (outcome.equals("")) {
outcome = I18NUtil.getMessage(DEFAULT_TRANSITION_TITLE);
}
out.write("<tr><td>");
out.write(desc == null ? "" : Utils.encode(desc));
out.write("</td><td>");
out.write(Utils.encode(task.title));
out.write("</td><td>");
out.write(id);
out.write("</td><td>");
out.write(Utils.getDateTimeFormat(context).format(createdDate));
out.write("</td><td>");
out.write(owner == null ? "" : owner);
out.write("</td><td>");
out.write(comment == null ? "" : Utils.encode(comment));
out.write("</td><td>");
out.write(Utils.getDateTimeFormat(context).format(completedDate));
out.write("</td><td>");
out.write(outcome);
out.write("</td></tr>");
}
// output the end of the table
out.write("</table>");
}
}
}
use of org.alfresco.service.cmr.workflow.WorkflowInstance in project acs-community-packaging by Alfresco.
the class UIWorkflowSummary method encodeBegin.
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
if (!isRendered())
return;
WorkflowInstance wi = getValue();
if (wi != null) {
ResponseWriter out = context.getResponseWriter();
ResourceBundle bundle = Application.getBundle(context);
// output surrounding table and style if necessary
out.write("<table");
if (this.getAttributes().get("style") != null) {
out.write(" style=\"");
out.write((String) this.getAttributes().get("style"));
out.write("\"");
}
if (this.getAttributes().get("styleClass") != null) {
out.write(" class=\"");
out.write((String) this.getAttributes().get("styleClass"));
out.write("\"");
}
out.write(">");
// output the title and description
out.write("<tr><td>");
out.write(bundle.getString("title"));
out.write(":</td><td>");
out.write(wi.definition.title);
if (wi.definition.description != null && wi.definition.description.length() > 0) {
out.write(" (");
out.write(Utils.encode(wi.definition.description));
out.write(")");
}
out.write("</td></tr><tr><td>");
out.write(bundle.getString("initiated_by"));
out.write(":</td><td>");
NodeService nodeService = getNodeService(context);
if (wi.initiator != null) {
if (nodeService.exists(wi.initiator)) {
out.write(Utils.encode(User.getFullName(Repository.getServiceRegistry(context).getNodeService(), wi.initiator)));
} else {
out.write("<");
out.write(bundle.getString("unknown"));
out.write(">");
}
}
out.write("</td></tr><tr><td>");
out.write(bundle.getString("started_on"));
out.write(":</td><td>");
if (wi.startDate != null) {
out.write(Utils.getDateFormat(context).format(wi.startDate));
}
out.write("</td></tr><tr><td>");
out.write(bundle.getString("completed_on"));
out.write(":</td><td>");
if (wi.endDate != null) {
out.write(Utils.getDateFormat(context).format(wi.endDate));
} else {
out.write("<");
out.write(bundle.getString("in_progress"));
out.write(">");
}
out.write("</td></tr></table>");
}
}
Aggregations