Search in sources :

Example 1 with BusinessObjectDataNotificationEventParamsDto

use of org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto in project herd by FINRAOS.

the class NotificationEventServiceImpl method processBusinessObjectDataNotifications.

private List<Object> processBusinessObjectDataNotifications(String notificationEventType, List<BusinessObjectDataNotificationRegistrationEntity> businessObjectDataNotificationRegistrationEntities, BusinessObjectData businessObjectData, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus) {
    List<Object> notificationActions = new ArrayList<>();
    // Build a list of partition value that includes primary and sub-partition values, if any are specified in the business object data key.
    List<String> partitionValues = businessObjectDataHelper.getPrimaryAndSubPartitionValues(businessObjectData);
    // Get a list of partition columns from the associated business object format.
    List<String> partitionColumnNames = null;
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(businessObjectData.getNamespace(), businessObjectData.getBusinessObjectDefinitionName(), businessObjectData.getBusinessObjectFormatUsage(), businessObjectData.getBusinessObjectFormatFileType(), businessObjectData.getBusinessObjectFormatVersion()));
    if (businessObjectFormatEntity != null) {
        // Get business object format model object to directly access schema columns and partitions.
        BusinessObjectFormat businessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
        // Proceed only if this format has schema with partition columns specified.
        if (businessObjectFormat.getSchema() != null && !CollectionUtils.isEmpty(businessObjectFormat.getSchema().getPartitions())) {
            // Do not provide more partition column names than there are primary and
            // sub-partition values that this business object data is registered with.
            partitionColumnNames = new ArrayList<>();
            List<SchemaColumn> partitionColumns = businessObjectFormat.getSchema().getPartitions();
            for (int i = 0; i < Math.min(partitionValues.size(), partitionColumns.size()); i++) {
                partitionColumnNames.add(partitionColumns.get(i).getName());
            }
        }
    }
    for (BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistration : businessObjectDataNotificationRegistrationEntities) {
        // Retrieve the job notification actions needed to be triggered.
        for (NotificationActionEntity notificationActionEntity : businessObjectDataNotificationRegistration.getNotificationActions()) {
            // Trigger the job action.
            if (notificationActionEntity instanceof NotificationJobActionEntity) {
                NotificationJobActionEntity notificationJobActionEntity = (NotificationJobActionEntity) notificationActionEntity;
                BusinessObjectDataNotificationEventParamsDto notificationEventParams = new BusinessObjectDataNotificationEventParamsDto();
                notificationEventParams.setBusinessObjectDataNotificationRegistration(businessObjectDataNotificationRegistration);
                notificationEventParams.setNotificationJobAction(notificationJobActionEntity);
                notificationEventParams.setEventType(notificationEventType);
                notificationEventParams.setBusinessObjectData(businessObjectData);
                notificationEventParams.setPartitionColumnNames(partitionColumnNames);
                notificationEventParams.setStorageName(businessObjectDataNotificationRegistration.getStorage() == null ? null : businessObjectDataNotificationRegistration.getStorage().getName());
                notificationEventParams.setPartitionValues(partitionValues);
                notificationEventParams.setNewBusinessObjectDataStatus(newBusinessObjectDataStatus);
                notificationEventParams.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatus);
                notificationActions.add(triggerNotificationAction(NotificationTypeEntity.NOTIFICATION_TYPE_BDATA, notificationEventType, notificationEventParams));
            }
        }
    }
    return notificationActions;
}
Also used : ArrayList(java.util.ArrayList) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 2 with BusinessObjectDataNotificationEventParamsDto

use of org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto 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 BusinessObjectDataNotificationEventParamsDto

use of org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto in project herd by FINRAOS.

the class StorageUnitStatusChangeNotificationJobActionServiceTest method testPerformNotificationActionInvalidParamsDto.

@Test
public void testPerformNotificationActionInvalidParamsDto() throws Exception {
    // Get the notification action service for the storage unit status change event.
    NotificationActionService notificationActionService = notificationActionFactory.getNotificationActionHandler(NotificationTypeEntity.NOTIFICATION_TYPE_STORAGE_UNIT, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name());
    // Try to perform a notification action for the storage unit status change event with an invalid type of the parameters DTO.
    try {
        notificationActionService.performNotificationAction(new BusinessObjectDataNotificationEventParamsDto());
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Notification event parameters DTO passed to the method must be an instance of StorageUnitNotificationEventParamsDto.", e.getMessage());
    }
}
Also used : BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) Test(org.junit.Test)

Example 4 with BusinessObjectDataNotificationEventParamsDto

use of org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto in project herd by FINRAOS.

the class StorageUnitStatusChangeNotificationJobActionServiceTest method testGetIdentifyingInformationInvalidParamsDto.

@Test
public void testGetIdentifyingInformationInvalidParamsDto() {
    // Get the notification action service for the storage unit status change event.
    NotificationActionService notificationActionService = notificationActionFactory.getNotificationActionHandler(NotificationTypeEntity.NOTIFICATION_TYPE_STORAGE_UNIT, NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name());
    // Try to retrieve the identifying information for the notification event using an invalid type of the parameters DTO.
    try {
        notificationActionService.getIdentifyingInformation(new BusinessObjectDataNotificationEventParamsDto(), businessObjectDataHelper);
        fail();
    } catch (IllegalStateException e) {
        assertEquals("Notification event parameters DTO passed to the method must be an instance of StorageUnitNotificationEventParamsDto.", e.getMessage());
    }
}
Also used : BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) Test(org.junit.Test)

Example 5 with BusinessObjectDataNotificationEventParamsDto

use of org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto in project herd by FINRAOS.

the class BusinessObjectDataNotificationJobActionServiceImpl method performNotificationAction.

@Override
public Object performNotificationAction(NotificationEventParamsDto notificationEventParams) throws Exception {
    if (notificationEventParams instanceof BusinessObjectDataNotificationEventParamsDto) {
        BusinessObjectDataNotificationEventParamsDto businessObjectDataNotificationEventParams = (BusinessObjectDataNotificationEventParamsDto) notificationEventParams;
        JobCreateRequest request = new JobCreateRequest();
        JobDefinitionEntity jobDefinitionEntity = businessObjectDataNotificationEventParams.getNotificationJobAction().getJobDefinition();
        request.setNamespace(jobDefinitionEntity.getNamespace().getCode());
        request.setJobName(jobDefinitionEntity.getName());
        request.setParameters(buildJobParameters(businessObjectDataNotificationEventParams));
        /*
             * Log enough information so we can trace back what notification registration triggered what workflow.
             * This also allows us to reproduce the workflow execution if needed by logging the entire jobCreateRequest in JSON format.
             */
        if (LOGGER.isInfoEnabled()) {
            BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistration = businessObjectDataNotificationEventParams.getBusinessObjectDataNotificationRegistration();
            LOGGER.info("Starting a job due to a notification. notificationRegistrationKey={} jobCreateRequest={}", jsonHelper.objectToJson(notificationRegistrationHelper.getNotificationRegistrationKey(businessObjectDataNotificationRegistration)), jsonHelper.objectToJson(request));
        }
        return jobService.createAndStartJob(request);
    } else {
        throw new IllegalStateException("Notification event parameters DTO passed to the method must be an instance of BusinessObjectDataNotificationEventParamsDto.");
    }
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) BusinessObjectDataNotificationEventParamsDto(org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) JobCreateRequest(org.finra.herd.model.api.xml.JobCreateRequest)

Aggregations

BusinessObjectDataNotificationEventParamsDto (org.finra.herd.model.dto.BusinessObjectDataNotificationEventParamsDto)5 BusinessObjectDataNotificationRegistrationEntity (org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)1 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 JobAction (org.finra.herd.model.api.xml.JobAction)1 JobCreateRequest (org.finra.herd.model.api.xml.JobCreateRequest)1 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)1 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)1 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)1 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)1 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)1 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)1 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)1 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)1