Search in sources :

Example 1 with JobDefinition

use of org.finra.herd.model.api.xml.JobDefinition in project herd by FINRAOS.

the class JobDefinitionServiceImpl method createJobDefinitionFromEntity.

/**
 * Creates the job definition from the persisted entity.
 *
 * @param jobDefinitionEntity the newly persisted job definition entity.
 *
 * @return the job definition.
 */
private JobDefinition createJobDefinitionFromEntity(JobDefinitionEntity jobDefinitionEntity) throws IOException {
    // Create the business object definition information.
    JobDefinition jobDefinition = new JobDefinition();
    jobDefinition.setId(jobDefinitionEntity.getId());
    jobDefinition.setNamespace(jobDefinitionEntity.getNamespace().getCode());
    jobDefinition.setJobName(jobDefinitionEntity.getName());
    jobDefinition.setDescription(jobDefinitionEntity.getDescription());
    String s3BucketName = jobDefinitionEntity.getS3BucketName();
    String s3ObjectKey = jobDefinitionEntity.getS3ObjectKey();
    if (s3BucketName != null && s3ObjectKey != null) {
        S3PropertiesLocation s3PropertiesLocation = new S3PropertiesLocation();
        s3PropertiesLocation.setBucketName(s3BucketName);
        s3PropertiesLocation.setKey(s3ObjectKey);
        jobDefinition.setS3PropertiesLocation(s3PropertiesLocation);
    }
    // Retrieve Activiti XML from activiti.
    ProcessDefinition processDefinition = activitiRepositoryService.createProcessDefinitionQuery().processDefinitionId(jobDefinitionEntity.getActivitiId()).singleResult();
    InputStream xmlStream = activitiRepositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
    jobDefinition.setActivitiJobXml(IOUtils.toString(xmlStream));
    // Add in the parameters.
    List<Parameter> parameters = new ArrayList<>();
    jobDefinition.setParameters(parameters);
    for (JobDefinitionParameterEntity parameterEntity : jobDefinitionEntity.getParameters()) {
        Parameter parameter = new Parameter(parameterEntity.getName(), parameterEntity.getValue());
        jobDefinitionHelper.maskPassword(parameter);
        parameters.add(parameter);
    }
    // Populate the "last updated by" user ID.
    jobDefinition.setLastUpdatedByUserId(jobDefinitionEntity.getUpdatedBy());
    return jobDefinition;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) InputStream(java.io.InputStream) JobDefinitionParameterEntity(org.finra.herd.model.jpa.JobDefinitionParameterEntity) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobDefinition(org.finra.herd.model.api.xml.JobDefinition)

Example 2 with JobDefinition

use of org.finra.herd.model.api.xml.JobDefinition in project herd by FINRAOS.

the class BusinessObjectDataNotificationJobActionServiceTest method testGetIdentifyingInformation.

@Test
public void testGetIdentifyingInformation() throws Exception {
    // Create a job definition.
    JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_LOG_VARIABLES_NO_REGEX_WITH_CLASSPATH);
    // Create a job action.
    List<JobAction> jobActions = new ArrayList<>();
    jobActions.add(new JobAction(jobDefinition.getNamespace(), jobDefinition.getJobName(), CORRELATION_DATA));
    // Create and persist a business object data notification registration entity.
    BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = notificationRegistrationDaoTestHelper.createBusinessObjectDataNotificationRegistrationEntity(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME), NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME, null, null, jobActions, NotificationRegistrationStatusEntity.ENABLED);
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS);
    // Create and initiate an instance of the business object data notification event parameters DTO.
    BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams = new BusinessObjectDataNotificationEventParamsDto();
    businessObjectDataNotificationEventParams.setBusinessObjectData(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity));
    businessObjectDataNotificationEventParams.setBusinessObjectDataNotificationRegistration(businessObjectDataNotificationRegistrationEntity);
    businessObjectDataNotificationEventParams.setEventType(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name());
    businessObjectDataNotificationEventParams.setNotificationJobAction((NotificationJobActionEntity) businessObjectDataNotificationRegistrationEntity.getNotificationActions().toArray()[0]);
    businessObjectDataNotificationEventParams.setStorageName(STORAGE_NAME);
    // Get the notification action service for the business object data registration event.
    NotificationActionService notificationActionService = notificationActionFactory.getNotificationActionHandler(NotificationTypeEntity.NOTIFICATION_TYPE_BDATA, NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name());
    // Validate the identifying information for the notification event.
    String expectedValue = String.format("namespace: \"%s\", actionId: \"%s\" with " + businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey) + ", storageName: \"%s\"", businessObjectDataNotificationRegistrationEntity.getNamespace().getCode(), ((NotificationJobActionEntity) businessObjectDataNotificationRegistrationEntity.getNotificationActions().toArray()[0]).getId(), STORAGE_NAME);
    assertEquals(expectedValue, notificationActionService.getIdentifyingInformation(businessObjectDataNotificationEventParams, businessObjectDataHelper));
}
Also used : JobAction(org.finra.herd.model.api.xml.JobAction) ArrayList(java.util.ArrayList) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) Test(org.junit.Test)

Example 3 with JobDefinition

use of org.finra.herd.model.api.xml.JobDefinition in project herd by FINRAOS.

the class ActivitiDelegateTest method testCreateProcessCommandProcessSuspended.

/**
 * This method tests the scenario where a process definition is suspended in Activiti.
 */
@Test(expected = IllegalArgumentException.class)
public void testCreateProcessCommandProcessSuspended() throws Exception {
    // Define the job definition
    JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_HERD_WORKFLOW);
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobDefinition.getNamespace(), jobDefinition.getJobName());
    // Suspend the job definition with activiti api
    activitiRepositoryService.suspendProcessDefinitionById(jobDefinitionEntity.getActivitiId());
    jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) Test(org.junit.Test) HerdActivitiServiceTaskTest(org.finra.herd.service.activiti.task.HerdActivitiServiceTaskTest)

Example 4 with JobDefinition

use of org.finra.herd.model.api.xml.JobDefinition in project herd by FINRAOS.

the class JobDefinitionRestControllerTest method testCreateJobDefinition.

@Test
public void testCreateJobDefinition() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    String activitiJobXml = getActivitiJobXml(namespace, jobName);
    JobDefinitionCreateRequest request = new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null);
    JobDefinition jobDefinition = getJobDefinition(NAMESPACE, JOB_NAME);
    when(jobDefinitionService.createJobDefinition(request, true)).thenReturn(jobDefinition);
    JobDefinition resultJobDefinition = jobDefinitionRestController.createJobDefinition(new JobDefinitionCreateRequest(namespace, jobName, null, activitiJobXml, null, null));
    // Verify the external calls.
    verify(jobDefinitionService).createJobDefinition(request, true);
    verifyNoMoreInteractions(jobDefinitionService);
    // Validate the returned object.
    assertEquals(jobDefinition, resultJobDefinition);
}
Also used : JobDefinitionCreateRequest(org.finra.herd.model.api.xml.JobDefinitionCreateRequest) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) Test(org.junit.Test)

Example 5 with JobDefinition

use of org.finra.herd.model.api.xml.JobDefinition in project herd by FINRAOS.

the class JobDefinitionRestControllerTest method testUpdateJobDefinition.

@Test
public void testUpdateJobDefinition() throws Exception {
    String namespace = NAMESPACE;
    String jobName = JOB_NAME;
    String activitiJobXml = getActivitiJobXml(NAMESPACE, JOB_NAME);
    JobDefinitionUpdateRequest request = new JobDefinitionUpdateRequest(null, activitiJobXml, null, null);
    JobDefinition jobDefinition = getJobDefinition(NAMESPACE, JOB_NAME);
    when(jobDefinitionService.updateJobDefinition(namespace, jobName, request, true)).thenReturn(jobDefinition);
    JobDefinition resultJobDefinition = jobDefinitionRestController.updateJobDefinition(namespace, jobName, new JobDefinitionUpdateRequest(null, activitiJobXml, null, null));
    // Verify the external calls.
    verify(jobDefinitionService).updateJobDefinition(namespace, jobName, request, true);
    verifyNoMoreInteractions(jobDefinitionService);
    // Validate the returned object.
    assertEquals(jobDefinition, resultJobDefinition);
}
Also used : JobDefinition(org.finra.herd.model.api.xml.JobDefinition) JobDefinitionUpdateRequest(org.finra.herd.model.api.xml.JobDefinitionUpdateRequest) Test(org.junit.Test)

Aggregations

JobDefinition (org.finra.herd.model.api.xml.JobDefinition)24 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)9 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 JobAction (org.finra.herd.model.api.xml.JobAction)9 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)9 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)9 Parameter (org.finra.herd.model.api.xml.Parameter)9 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)8 Job (org.finra.herd.model.api.xml.Job)7 StorageEntity (org.finra.herd.model.jpa.StorageEntity)6 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)5 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)5 JobDefinitionUpdateRequest (org.finra.herd.model.api.xml.JobDefinitionUpdateRequest)4 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)4 InputStream (java.io.InputStream)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)1 BusinessObjectDataNotificationEventParamsDto (org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto)1 StorageUnitNotificationEventParamsDto (org.finra.herd.model.dto.StorageUnitNotificationEventParamsDto)1