use of org.activiti.engine.history.HistoricProcessInstanceQuery in project alfresco-repository by Alfresco.
the class ActivitiWorkflowEngine method createQuery.
@SuppressWarnings("unchecked")
private HistoricProcessInstanceQuery createQuery(WorkflowInstanceQuery workflowInstanceQuery, boolean isActive) {
// MNT-9074 My Tasks fails to render if tasks quantity is excessive
String processDefId = workflowInstanceQuery.getWorkflowDefinitionId() == null ? null : createLocalId(workflowInstanceQuery.getWorkflowDefinitionId());
HistoricProcessInstanceQuery query;
if (isActive) {
// Don't use ProcessInstanceQuery here because in any case they will be converted to WorkflowInstance thro HistoricProcessInstance.
query = historyService.createHistoricProcessInstanceQuery().unfinished();
} else {
query = historyService.createHistoricProcessInstanceQuery().finished();
}
if (activitiUtil.isMultiTenantWorkflowDeploymentEnabled() && tenantService.isEnabled() && !TenantUtil.isCurrentDomainDefault() && !StringUtils.isEmpty(TenantUtil.getCurrentDomain())) {
// Process definition keys are prefixed with the tenant ID, in case MT is enabled and
// deployments are done in tenant-context
query.processDefinitionKey("@" + TenantUtil.getCurrentDomain() + "@%");
}
if (processDefId != null) {
query = query.processDefinitionId(processDefId);
}
if (workflowInstanceQuery.getExcludedDefinitions() != null) {
List<String> exDefIds = new ArrayList<String>();
for (String excludedDef : workflowInstanceQuery.getExcludedDefinitions()) {
String exDef = createLocalId(excludedDef);
exDef = exDef.replaceAll("\\*", "%");
exDefIds.add(exDef);
}
if (exDefIds.size() > 0) {
query.processDefinitionKeyNotIn(exDefIds);
}
}
// Check start range
if (workflowInstanceQuery.getStartBefore() != null) {
query.startedBefore(workflowInstanceQuery.getStartBefore());
}
if (workflowInstanceQuery.getStartAfter() != null) {
query.startedAfter(workflowInstanceQuery.getStartAfter());
}
// check end range
if (workflowInstanceQuery.getEndBefore() != null) {
query.finishedBefore(workflowInstanceQuery.getEndBefore());
}
if (workflowInstanceQuery.getEndAfter() != null) {
query.finishedAfter(workflowInstanceQuery.getEndAfter());
}
if (workflowInstanceQuery.getCustomProps() != null) {
Map<QName, Object> customProps = workflowInstanceQuery.getCustomProps();
// CLOUD-667: Extract initiator-property and use 'startedBy' instead
Object initiatorObject = customProps.get(QNAME_INITIATOR);
if (initiatorObject != null && initiatorObject instanceof NodeRef) {
// Extract username from person-node
NodeRef initiator = (NodeRef) initiatorObject;
if (this.nodeService.exists(initiator)) {
String initiatorUserName = (String) nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
query.startedBy(initiatorUserName);
// Clone properties map and remove initiator
customProps = new HashMap<QName, Object>();
customProps.putAll(workflowInstanceQuery.getCustomProps());
customProps.remove(QNAME_INITIATOR);
}
}
for (Map.Entry<QName, Object> prop : customProps.entrySet()) {
String propertyName = factory.mapQNameToName(prop.getKey());
if (prop.getValue() == null) {
query.variableValueEquals(propertyName, null);
} else {
PropertyDefinition propertyDefinition = dictionaryService.getProperty(prop.getKey());
if (propertyDefinition == null) {
Object converted = propertyConverter.convertPropertyToValue(prop.getValue());
query.variableValueEquals(propertyName, converted);
} else {
String propertyType = propertyDefinition.getDataType().getJavaClassName();
if (propertyType.equals("java.util.Date")) {
Map<DatePosition, Date> dateProps = (Map<DatePosition, Date>) prop.getValue();
for (Map.Entry<DatePosition, Date> dateProp : dateProps.entrySet()) {
if (dateProp.getValue() != null) {
if (dateProp.getKey() == DatePosition.BEFORE) {
query.variableValueLessThanOrEqual(propertyName, dateProp.getValue());
}
if (dateProp.getKey() == DatePosition.AFTER) {
query.variableValueGreaterThanOrEqual(propertyName, dateProp.getValue());
}
}
}
} else {
Object convertedValue = DefaultTypeConverter.INSTANCE.convert(propertyDefinition.getDataType(), prop.getValue());
query.variableValueEquals(propertyName, convertedValue);
}
}
}
}
}
return query;
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project midpoint by Evolveum.
the class ProcessInstanceManager method getActivitiToMidpoint.
private Map<String, String> getActivitiToMidpoint(Set<String> activeProcessInstances, OperationResult result) {
Map<String, String> rv = new HashMap<>();
int processWithoutTaskOidCount = 0;
HistoricProcessInstanceQuery query = activitiEngine.getHistoryService().createHistoricProcessInstanceQuery().includeProcessVariables().excludeSubprocesses(true);
List<HistoricProcessInstance> processes = query.list();
for (HistoricProcessInstance process : processes) {
String taskOid = (String) process.getProcessVariables().get(CommonProcessVariableNames.VARIABLE_MIDPOINT_TASK_OID);
rv.put(process.getId(), taskOid);
if (taskOid == null) {
processWithoutTaskOidCount++;
}
if (process.getEndTime() == null) {
activeProcessInstances.add(process.getId());
}
}
LOGGER.info("Found {} processes; among these, {} have no task OID. Active processes: {}", rv.size(), processWithoutTaskOidCount, activeProcessInstances.size());
return rv;
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project herd by FINRAOS.
the class ActivitiServiceTest method testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStatusCompleted.
@Test
public void testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenStatusCompleted() {
JobStatusEnum jobStatus = JobStatusEnum.COMPLETED;
Collection<String> processDefinitionKeys = new ArrayList<>();
DateTime startTime = new DateTime();
DateTime endTime = new DateTime();
HistoricProcessInstanceQuery historicProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
when(activitiHistoryService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys))).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.unfinished()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.startedAfter(startTime.toDate())).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.finishedBefore(endTime.toDate())).thenReturn(historicProcessInstanceQuery);
List<HistoricProcessInstance> expectedHistoricProcessInstances = new ArrayList<>();
when(historicProcessInstanceQuery.list()).thenReturn(expectedHistoricProcessInstances);
List<HistoricProcessInstance> actualHistoricProcessInstance = activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime);
assertSame(expectedHistoricProcessInstances, actualHistoricProcessInstance);
InOrder inOrder = inOrder(historicProcessInstanceQuery);
inOrder.verify(historicProcessInstanceQuery).processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys));
inOrder.verify(historicProcessInstanceQuery).finished();
inOrder.verify(historicProcessInstanceQuery).startedAfter(startTime.toDate());
inOrder.verify(historicProcessInstanceQuery).finishedBefore(endTime.toDate());
inOrder.verify(historicProcessInstanceQuery).list();
inOrder.verifyNoMoreInteractions();
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project herd by FINRAOS.
the class ActivitiServiceTest method testGetHistoricProcessInstanceByProcessInstanceId.
@Test
public void testGetHistoricProcessInstanceByProcessInstanceId() {
String processInstanceId = "processInstanceId";
HistoricProcessInstanceQuery historicProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
when(activitiHistoryService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.processInstanceId(processInstanceId)).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.includeProcessVariables()).thenReturn(historicProcessInstanceQuery);
HistoricProcessInstance expectedHistoricProcessInstance = mock(HistoricProcessInstance.class);
when(historicProcessInstanceQuery.singleResult()).thenReturn(expectedHistoricProcessInstance);
HistoricProcessInstance actualHistoricProcessInstance = activitiService.getHistoricProcessInstanceByProcessInstanceId(processInstanceId);
assertSame(expectedHistoricProcessInstance, actualHistoricProcessInstance);
InOrder inOrder = inOrder(historicProcessInstanceQuery);
inOrder.verify(historicProcessInstanceQuery).processInstanceId(processInstanceId);
inOrder.verify(historicProcessInstanceQuery).includeProcessVariables();
inOrder.verify(historicProcessInstanceQuery).singleResult();
inOrder.verifyNoMoreInteractions();
}
use of org.activiti.engine.history.HistoricProcessInstanceQuery in project herd by FINRAOS.
the class ActivitiServiceTest method testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenEndTimeNotSpecified.
@Test
public void testGetHistoricProcessInstancesByStatusAndProcessDefinitionKeysWhenEndTimeNotSpecified() {
JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
Collection<String> processDefinitionKeys = new ArrayList<>();
DateTime startTime = new DateTime();
DateTime endTime = null;
HistoricProcessInstanceQuery historicProcessInstanceQuery = mock(HistoricProcessInstanceQuery.class);
when(activitiHistoryService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys))).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.unfinished()).thenReturn(historicProcessInstanceQuery);
when(historicProcessInstanceQuery.startedAfter(startTime.toDate())).thenReturn(historicProcessInstanceQuery);
List<HistoricProcessInstance> expectedHistoricProcessInstances = new ArrayList<>();
when(historicProcessInstanceQuery.list()).thenReturn(expectedHistoricProcessInstances);
List<HistoricProcessInstance> actualHistoricProcessInstance = activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(jobStatus, processDefinitionKeys, startTime, endTime);
assertSame(expectedHistoricProcessInstances, actualHistoricProcessInstance);
InOrder inOrder = inOrder(historicProcessInstanceQuery);
inOrder.verify(historicProcessInstanceQuery).processDefinitionKeyIn(new ArrayList<>(processDefinitionKeys));
inOrder.verify(historicProcessInstanceQuery).unfinished();
inOrder.verify(historicProcessInstanceQuery).startedAfter(startTime.toDate());
inOrder.verify(historicProcessInstanceQuery).list();
inOrder.verifyNoMoreInteractions();
}
Aggregations