use of org.alfresco.repo.workflow.activiti.ActivitiScriptNode in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testCreateProcessInstanceWithItems.
@Test
public void testCreateProcessInstanceWithItems() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
final ProcessInfo processRest = startAdhocProcess(requestContext, docNodeRefs);
assertNotNull(processRest);
final Map<String, Object> variables = activitiProcessEngine.getRuntimeService().getVariables(processRest.getId());
assertEquals(1, variables.get("bpm_priority"));
final ActivitiScriptNode packageScriptNode = (ActivitiScriptNode) variables.get("bpm_package");
assertNotNull(packageScriptNode);
final Map<String, FavouriteDocument> documentMap = new HashMap<>();
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
for (ChildAssociationRef childAssociationRef : documentList) {
FavouriteDocument doc = getTestFixture().getRepoService().getDocument(requestContext.getNetworkId(), childAssociationRef.getChildRef());
documentMap.put(doc.getName(), doc);
}
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).singleResult();
assertEquals(requestContext.getRunAsUser(), task.getAssignee());
activitiProcessEngine.getTaskService().complete(task.getId());
final Task task2 = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processRest.getId()).singleResult();
assertEquals(requestContext.getRunAsUser(), task2.getAssignee());
activitiProcessEngine.getTaskService().complete(task2.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
assertEquals(2, documentMap.size());
assertTrue(documentMap.containsKey("Test Doc1"));
FavouriteDocument doc = documentMap.get("Test Doc1");
assertEquals("Test Doc1", doc.getName());
assertEquals("Test Doc1 Title", doc.getTitle());
assertTrue(documentMap.containsKey("Test Doc2"));
doc = documentMap.get("Test Doc2");
assertEquals("Test Doc2", doc.getName());
assertEquals("Test Doc2 Title", doc.getTitle());
cleanupProcessInstance(processRest.getId());
}
use of org.alfresco.repo.workflow.activiti.ActivitiScriptNode in project records-management by Alfresco.
the class RequestInfoAssignmentHandler method notify.
/**
* @see org.activiti.engine.delegate.TaskListener#notify(org.activiti.engine.delegate.DelegateTask)
*/
@Override
public void notify(DelegateTask delegateTask) {
ParameterCheck.mandatory("delegateTask", delegateTask);
// Set the workflow description for the task
delegateTask.setVariable("bpm_workflowDescription", getWorkflowDescription(RequestInfoUtils.getRecordName(delegateTask)));
// Get the list of user(s) and/or group(s)
ActivitiScriptNodeList usersAndGroups = (ActivitiScriptNodeList) delegateTask.getVariable("rmwf_mixedAssignees");
// Check if it was possible to extract the user(s) and/or group(s)
if (usersAndGroups == null) {
throw new AlfrescoRuntimeException("It was not possible to extract the user(s) and/or group(s)!!!");
}
// Define lists for candidate user(s)/group(s)
List<String> candidateUsers = new ArrayList<String>();
List<String> candidateGroups = new ArrayList<String>();
// Iterate through the list add user(s)/group(s) to the lists
for (ActivitiScriptNode activitiScriptNode : usersAndGroups) {
// Get the node type
String type = activitiScriptNode.getType();
// Get the properties
Map<String, Object> properties = activitiScriptNode.getProperties();
// Check if it is a user or a group
if (type.equalsIgnoreCase(ContentModel.TYPE_PERSON.toString())) {
// Add the user
candidateUsers.add((String) properties.get(ContentModel.PROP_USERNAME.toString()));
} else if (type.equalsIgnoreCase(ContentModel.TYPE_AUTHORITY_CONTAINER.toString())) {
// Add the group
candidateGroups.add((String) properties.get(ContentModel.PROP_AUTHORITY_NAME.toString()));
} else {
throw new AlfrescoRuntimeException("The type '" + type + "' is neither a user nor a group!!!");
}
}
// Check if there is at least one user or one group
if (candidateUsers.size() == 0 && candidateGroups.size() == 0) {
throw new AlfrescoRuntimeException("Neither a user nor a group was found!!!");
}
// Add the user(s) to the task
if (candidateUsers.size() > 0) {
delegateTask.addCandidateUsers(candidateUsers);
}
// Add the group(s) to the task
if (candidateGroups.size() > 0) {
delegateTask.addCandidateGroups(candidateGroups);
}
}
Aggregations