Search in sources :

Example 1 with Job

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;
}
Also used : ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with 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;
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job)

Example 3 with 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);
}
Also used : Job(org.finra.herd.model.api.xml.Job) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest) Test(org.junit.Test)

Example 4 with Job

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);
}
Also used : JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Example 5 with Job

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);
}
Also used : JobUpdateRequest(org.finra.herd.model.api.xml.JobUpdateRequest) Job(org.finra.herd.model.api.xml.Job) Test(org.junit.Test)

Aggregations

Job (org.finra.herd.model.api.xml.Job)71 Test (org.junit.Test)60 Parameter (org.finra.herd.model.api.xml.Parameter)30 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)21 ArrayList (java.util.ArrayList)20 FieldExtension (org.activiti.bpmn.model.FieldExtension)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)11 Task (org.activiti.engine.task.Task)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)8 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)7 JobDeleteRequest (org.finra.herd.model.api.xml.JobDeleteRequest)7 JobSignalRequest (org.finra.herd.model.api.xml.JobSignalRequest)7 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)7 AccessDeniedException (org.springframework.security.access.AccessDeniedException)7 JobAction (org.finra.herd.model.api.xml.JobAction)6 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)6 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)6 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)6 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)6