use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.
the class JobServiceImpl method createJobFromRequest.
/**
* Creates a new job object from request.
*
* @param namespaceCd, the namespace Code
* @param jobName, the job name
* @param mergedParameters parameters that were submitted with the job
* @param processInstanceId process instance ID of the submitted job
*
* @return the created job object
*/
private Job createJobFromRequest(String namespaceCd, String jobName, Map<String, Object> mergedParameters, String processInstanceId) {
// Create the job.
Job job = new Job();
job.setId(processInstanceId);
job.setNamespace(namespaceCd);
job.setJobName(jobName);
// Populate parameters from process instance.
if (!mergedParameters.isEmpty()) {
List<Parameter> jobParameters = new ArrayList<>();
job.setParameters(jobParameters);
for (Map.Entry<String, Object> entry : mergedParameters.entrySet()) {
Parameter parameter = new Parameter(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null);
jobDefinitionHelper.maskPassword(parameter);
jobParameters.add(parameter);
}
}
return job;
}
use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.
the class JobServiceImpl method signalJob.
@Override
public Job signalJob(JobSignalRequest request) throws Exception {
// Perform the validation.
validateJobSignalRequest(request);
Execution execution = activitiService.getExecutionByProcessInstanceIdAndActivitiId(request.getId(), request.getReceiveTaskId());
if (execution == null) {
throw new ObjectNotFoundException(String.format("No job found for matching job id: \"%s\" and receive task id: \"%s\".", request.getId(), request.getReceiveTaskId()));
}
String processDefinitionKey = activitiService.getProcessInstanceById(execution.getProcessInstanceId()).getProcessDefinitionKey();
checkPermissions(processDefinitionKey, new NamespacePermissionEnum[] { NamespacePermissionEnum.EXECUTE });
// Retrieve the job before signaling.
Job job = getJob(request.getId(), false, false);
// Build the parameters map
Map<String, Object> signalParameters = getParameters(request);
// Signal the workflow.
activitiService.signal(execution.getId(), signalParameters);
// Build the parameters map merged with job and signal parameters.
Map<String, Object> mergedParameters = new HashMap<>();
for (Parameter jobParam : job.getParameters()) {
mergedParameters.put(jobParam.getName(), jobParam.getValue());
}
mergedParameters.putAll(signalParameters);
// Update the parameters in job
populateWorkflowParameters(job, mergedParameters);
return job;
}
use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.
the class JobRestControllerTest method testCreateJob.
@Test
public void testCreateJob() throws Exception {
// Create a job create request.
JobCreateRequest jobCreateRequest = new JobCreateRequest();
jobCreateRequest.setNamespace(JOB_NAMESPACE);
jobCreateRequest.setJobName(JOB_NAME);
// Create a job.
Job job = new Job();
job.setId(JOB_ID);
// Mock the external calls.
when(jobService.createAndStartJob(jobCreateRequest)).thenReturn(job);
// Call the method under test.
Job result = jobRestController.createJob(jobCreateRequest);
// Verify the external calls.
verify(jobService).createAndStartJob(jobCreateRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(job, result);
}
use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.
the class JobRestControllerTest method testDeleteJob.
@Test
public void testDeleteJob() throws Exception {
// Create a job delete request.
JobDeleteRequest jobDeleteRequest = new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON);
// Create a job.
Job job = new Job();
job.setId(JOB_ID);
// Mock the external calls.
when(jobService.deleteJob(JOB_ID, jobDeleteRequest)).thenReturn(job);
// Call the method under test.
Job result = jobRestController.deleteJob(JOB_ID, jobDeleteRequest);
// Verify the external calls.
verify(jobService).deleteJob(JOB_ID, jobDeleteRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(job, result);
}
use of org.finra.herd.model.api.xml.Job in project herd by FINRAOS.
the class JobRestControllerTest method testUpdateJob.
@Test
public void testUpdateJob() throws Exception {
// Create a job update request.
JobUpdateRequest jobUpdateRequest = new JobUpdateRequest(JobActionEnum.RESUME);
// Create a job.
Job job = new Job();
job.setId(JOB_ID);
// Mock the external calls.
when(jobService.updateJob(JOB_ID, jobUpdateRequest)).thenReturn(job);
// Call the method under test.
Job result = jobRestController.updateJob(JOB_ID, jobUpdateRequest);
// Verify the external calls.
verify(jobService).updateJob(JOB_ID, jobUpdateRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(job, result);
}
Aggregations