use of org.finra.herd.model.api.xml.WorkflowStep in project herd by FINRAOS.
the class JobServiceImpl method populateCompletedActivitiSteps.
/**
* Populates the job Object with completed workflow steps.
*
* @param job, the Job object
* @param historicActivitiTasks, the completed activiti steps
*/
private void populateCompletedActivitiSteps(Job job, List<HistoricActivityInstance> historicActivitiTasks) {
// Set completed steps
List<WorkflowStep> completedWorkflowSteps = new ArrayList<>();
for (HistoricActivityInstance historicActivityInstance : historicActivitiTasks) {
completedWorkflowSteps.add(new WorkflowStep(historicActivityInstance.getActivityId(), historicActivityInstance.getActivityName(), HerdDateUtils.getXMLGregorianCalendarValue(historicActivityInstance.getStartTime()), HerdDateUtils.getXMLGregorianCalendarValue(historicActivityInstance.getEndTime())));
}
job.setCompletedWorkflowSteps(completedWorkflowSteps);
}
use of org.finra.herd.model.api.xml.WorkflowStep in project herd by FINRAOS.
the class JobServiceImpl method getJob.
/**
* Gets a job by the given jobId, and displays verbose information if verbose flag is true. Does namespace permission check if namespace permissions flag is
* true.
*
* @param jobId the job ID
* @param verbose specifies if verbose mode is enabled or not
* @param checkNamespacePermissions specifies whether to check namespace permissions or not
*
* @return the job information
*/
private Job getJob(String jobId, boolean verbose, boolean checkNamespacePermissions) {
String jobIdLocal = jobId;
// Validate and trim required elements
Assert.hasText(jobIdLocal, "A job Id must be specified.");
jobIdLocal = jobIdLocal.trim();
// Get process instance from Activiti runtime.
ProcessInstance processInstance = activitiService.getProcessInstanceById(jobIdLocal);
// Get historic process instance.
HistoricProcessInstance historicProcessInstance = activitiService.getHistoricProcessInstanceByProcessInstanceId(jobIdLocal);
/*
* Check permissions against namespace of the job.
* Cannot be done through the annotation because the namespace is not part of the request.
* TODO refactor this so it gets namespace from JobDefinitionEntity instead of parsing process definition key.
*/
if (checkNamespacePermissions) {
String processDefinitionKey = null;
if (processInstance != null) {
processDefinitionKey = processInstance.getProcessDefinitionKey();
} else if (historicProcessInstance != null) {
processDefinitionKey = activitiService.getProcessDefinitionById(historicProcessInstance.getProcessDefinitionId()).getKey();
}
if (processDefinitionKey != null) {
checkPermissions(processDefinitionKey, new NamespacePermissionEnum[] { NamespacePermissionEnum.READ });
}
}
Job job = new Job();
job.setId(jobIdLocal);
if (processInstance == null && historicProcessInstance == null) {
// Process not found
throw new ObjectNotFoundException(String.format("Job with Id: \"%s\" doesn't exist.", jobIdLocal));
} else if (processInstance != null) {
// Process is still running or suspended.
job.setStatus(processInstance.isSuspended() ? JobStatusEnum.SUSPENDED : JobStatusEnum.RUNNING);
// Check if there are errors.
List<org.activiti.engine.runtime.Job> erroredJobs = activitiService.getJobsWithExceptionByProcessInstanceId(processInstance.getProcessInstanceId());
if (!CollectionUtils.isEmpty(erroredJobs)) {
// Errors found.
List<WorkflowError> workflowErrors = new ArrayList<>();
for (org.activiti.engine.runtime.Job erroredJob : erroredJobs) {
WorkflowError workflowError = new WorkflowError();
workflowError.setErrorMessage(erroredJob.getExceptionMessage());
workflowError.setRetriesLeft(erroredJob.getRetries());
workflowError.setErrorStackTrace(activitiService.getJobExceptionStacktrace(erroredJob.getId()));
workflowErrors.add(workflowError);
}
job.setWorkflowErrors(workflowErrors);
}
if (processInstance.getActivityId() != null) {
// Set current workflow step.
WorkflowStep currentStep = new WorkflowStep();
currentStep.setId(processInstance.getActivityId());
job.setCurrentWorkflowStep(currentStep);
}
// Set the workflow variables.
populateWorkflowParameters(job, processInstance.getProcessVariables());
// If verbose, set activiti workflow xml.
if (verbose) {
populateActivitiXml(job, processInstance.getProcessDefinitionId());
}
} else {
// Process completed
job.setStatus(JobStatusEnum.COMPLETED);
// Set the workflow variables.
populateWorkflowParameters(job, historicProcessInstance.getProcessVariables());
job.setDeleteReason(historicProcessInstance.getDeleteReason());
// If verbose, set activiti workflow xml.
if (verbose) {
populateActivitiXml(job, historicProcessInstance.getProcessDefinitionId());
}
}
if (historicProcessInstance != null) {
// If verbose, set completed steps.
if (verbose) {
populateCompletedActivitiSteps(job, activitiService.getHistoricActivityInstancesByProcessInstanceId(jobIdLocal));
}
// Set the start time always since all jobs will have a start time.
job.setStartTime(HerdDateUtils.getXMLGregorianCalendarValue(historicProcessInstance.getStartTime()));
// Set the end time if the historic process instance has it set (the job is completed).
if (historicProcessInstance.getEndTime() != null) {
job.setEndTime(HerdDateUtils.getXMLGregorianCalendarValue(historicProcessInstance.getEndTime()));
}
}
return job;
}
Aggregations