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;
}
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));
}
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());
}
}
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());
}
}
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.");
}
}
Aggregations