Search in sources :

Example 41 with JobAction

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

the class NotificationEventServiceTest method testProcessBusinessObjectDataRegistrationNotificationEventSync.

@Test
public void testProcessBusinessObjectDataRegistrationNotificationEventSync() throws Exception {
    // Create job definition
    JobDefinition jobDefinition = jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_LOG_VARIABLES_NO_REGEX_WITH_CLASSPATH);
    List<JobAction> jobActions = new ArrayList<>();
    jobActions.add(new JobAction(jobDefinition.getNamespace(), jobDefinition.getJobName(), CORRELATION_DATA));
    // Create a business object format with a schema.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, FIRST_PARTITION_COLUMN_NAME, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), schemaColumnDaoTestHelper.getTestPartitionColumns());
    // Create business object data with storage units.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, true, BDATA_STATUS);
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3);
    storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Create and persist a business object data notification registration entity.
    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, BDATA_STATUS, null, jobActions, NotificationRegistrationStatusEntity.ENABLED);
    // Create and persist a business object data notification registration entity.
    notificationRegistrationDaoTestHelper.createBusinessObjectDataNotificationRegistrationEntity(new NotificationRegistrationKey(NAMESPACE, NOTIFICATION_NAME_2), NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, STORAGE_NAME_2, BDATA_STATUS, null, jobActions, NotificationRegistrationStatusEntity.ENABLED);
    // Trigger the notification
    List<Object> notificationActions = notificationEventService.processBusinessObjectDataNotificationEventSync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), BDATA_STATUS, null);
    // Validate the result job.
    Job job = (Job) notificationActions.get(0);
    assertEquals(new Job(job.getId(), null, TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, null, null, null, null, Arrays.asList(new Parameter("notification_businessObjectDefinitionName", BDEF_NAME), new Parameter("notification_partitionValues", PARTITION_VALUE + "|" + StringUtils.join(SUBPARTITION_VALUES, "|")), new Parameter("notification_namespace", NAMESPACE), new Parameter("notification_businessObjectData", jsonHelper.objectToJson(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity))), new Parameter("notification_businessObjectFormatUsage", FORMAT_USAGE_CODE), new Parameter(HERD_WORKFLOW_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT)), new Parameter("notification_businessObjectDefinitionNamespace", BDEF_NAMESPACE), new Parameter("notification_newBusinessObjectDataStatus", BDATA_STATUS), new Parameter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1), new Parameter("notification_businessObjectDataVersion", DATA_VERSION.toString()), new Parameter("notification_name", NOTIFICATION_NAME), new Parameter("notification_oldBusinessObjectDataStatus", null), new Parameter("notification_partitionColumnNames", "PRTN_CLMN001|PRTN_CLMN002|PRTN_CLMN003|PRTN_CLMN004|PRTN_CLMN005"), new Parameter("notification_businessObjectDataEventType", NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN.name()), new Parameter("notification_businessObjectFormatVersion", FORMAT_VERSION.toString()), new Parameter("notification_businessObjectFormatFileType", FORMAT_FILE_TYPE_CODE), new Parameter("notification_correlationData", CORRELATION_DATA)), null, null, null), job);
}
Also used : ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) JobAction(org.finra.herd.model.api.xml.JobAction) Parameter(org.finra.herd.model.api.xml.Parameter) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) Job(org.finra.herd.model.api.xml.Job) JobDefinition(org.finra.herd.model.api.xml.JobDefinition) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) Test(org.junit.Test)

Example 42 with JobAction

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

the class NamespaceSecurityAdviceTest method checkPermissionAssertNoExceptionWhenComplexCaseAndUserHasAllPermissions.

@Test
public void checkPermissionAssertNoExceptionWhenComplexCaseAndUserHasAllPermissions() throws Exception {
    // Mock a join point of the method call
    // mockMethod(request);
    JoinPoint joinPoint = mock(JoinPoint.class);
    MethodSignature methodSignature = mock(MethodSignature.class);
    Method method = NamespaceSecurityAdviceTest.class.getDeclaredMethod("mockMethod", BusinessObjectDataNotificationRegistrationCreateRequest.class);
    when(methodSignature.getParameterNames()).thenReturn(new String[] { "request" });
    when(methodSignature.getMethod()).thenReturn(method);
    when(joinPoint.getSignature()).thenReturn(methodSignature);
    BusinessObjectDataNotificationRegistrationCreateRequest request = new BusinessObjectDataNotificationRegistrationCreateRequest();
    request.setBusinessObjectDataNotificationRegistrationKey(new NotificationRegistrationKey("ns1", null));
    request.setBusinessObjectDataNotificationFilter(new BusinessObjectDataNotificationFilter("ns2", null, null, null, null, null, null, null));
    request.setJobActions(Arrays.asList(new JobAction("ns3", null, null), new JobAction("ns4", null, null)));
    when(joinPoint.getArgs()).thenReturn(new Object[] { request });
    String userId = "userId";
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(userId);
    applicationUser.setNamespaceAuthorizations(new HashSet<>());
    applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns1", Arrays.asList(NamespacePermissionEnum.WRITE)));
    applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns2", Arrays.asList(NamespacePermissionEnum.READ)));
    applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns3", Arrays.asList(NamespacePermissionEnum.EXECUTE)));
    applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization("ns4", Arrays.asList(NamespacePermissionEnum.EXECUTE)));
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(userId, "", false, false, false, false, Arrays.asList(), applicationUser), null));
    try {
        namespaceSecurityAdvice.checkPermission(joinPoint);
    } catch (AccessDeniedException e) {
        fail();
    }
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) AccessDeniedException(org.springframework.security.access.AccessDeniedException) MethodSignature(org.aspectj.lang.reflect.MethodSignature) BusinessObjectDataNotificationRegistrationCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDataNotificationRegistrationCreateRequest) BusinessObjectDataNotificationFilter(org.finra.herd.model.api.xml.BusinessObjectDataNotificationFilter) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization) Method(java.lang.reflect.Method) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) JoinPoint(org.aspectj.lang.JoinPoint) JobAction(org.finra.herd.model.api.xml.JobAction) NotificationRegistrationKey(org.finra.herd.model.api.xml.NotificationRegistrationKey) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 43 with JobAction

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

the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationEntity.

/**
 * Creates a new storage unit notification registration entity from the request information.
 *
 * @param namespaceEntity the namespace entity
 * @param notificationEventTypeEntity the notification event type entity
 * @param businessObjectDefinitionEntity the business object definition entity
 * @param fileTypeEntity the file type entity
 * @param storageEntity the storage entity
 * @param newStorageUnitStatusEntity the new storage unit status entity
 * @param oldStorageUnitStatusEntity the old storage unit status entity
 * @param key the storage unit notification registration key
 * @param storageUnitNotificationFilter the storage unit notification filter
 * @param jobActions the list of notification job actions
 * @param notificationRegistrationStatusEntity the notification registration status entity
 *
 * @return the newly created storage unit notification registration entity
 */
private StorageUnitNotificationRegistrationEntity createStorageUnitNotificationEntity(NamespaceEntity namespaceEntity, NotificationEventTypeEntity notificationEventTypeEntity, BusinessObjectDefinitionEntity businessObjectDefinitionEntity, FileTypeEntity fileTypeEntity, StorageEntity storageEntity, StorageUnitStatusEntity newStorageUnitStatusEntity, StorageUnitStatusEntity oldStorageUnitStatusEntity, NotificationRegistrationKey key, StorageUnitNotificationFilter storageUnitNotificationFilter, List<JobAction> jobActions, NotificationRegistrationStatusEntity notificationRegistrationStatusEntity) {
    // Create a new entity.
    StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = new StorageUnitNotificationRegistrationEntity();
    storageUnitNotificationRegistrationEntity.setNamespace(namespaceEntity);
    storageUnitNotificationRegistrationEntity.setName(key.getNotificationName());
    storageUnitNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    if (StringUtils.isNotBlank(storageUnitNotificationFilter.getBusinessObjectFormatUsage())) {
        storageUnitNotificationRegistrationEntity.setUsage(storageUnitNotificationFilter.getBusinessObjectFormatUsage());
    }
    storageUnitNotificationRegistrationEntity.setFileType(fileTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectFormatVersion(storageUnitNotificationFilter.getBusinessObjectFormatVersion());
    storageUnitNotificationRegistrationEntity.setStorage(storageEntity);
    storageUnitNotificationRegistrationEntity.setNewStorageUnitStatus(newStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setOldStorageUnitStatus(oldStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    // Create the relative entities for job actions.
    // TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
    List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
    storageUnitNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
    for (JobAction jobAction : jobActions) {
        // Retrieve and ensure that job definition exists.
        JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
        // Create a new entity.
        NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
        notificationActionEntities.add(notificationJobActionEntity);
        notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
        notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
        notificationJobActionEntity.setNotificationRegistration(storageUnitNotificationRegistrationEntity);
    }
    return storageUnitNotificationRegistrationEntity;
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobAction(org.finra.herd.model.api.xml.JobAction) ArrayList(java.util.ArrayList) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 44 with JobAction

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

the class BusinessObjectDataNotificationRegistrationServiceImpl method createBusinessObjectDataNotificationEntity.

/**
 * Creates a new business object data notification registration entity from the request information.
 *
 * @param namespaceEntity the namespace entity
 * @param notificationEventTypeEntity the notification event type entity
 * @param businessObjectDefinitionEntity the business object definition entity
 * @param fileTypeEntity the file type entity
 * @param storageEntity the storage entity
 * @param newBusinessObjectDataStatusEntity the new business object data status entity
 * @param oldBusinessObjectDataStatusEntity the old business object data status entity
 * @param key the business object data notification registration key
 * @param businessObjectDataNotificationFilter the business object data notification filter
 * @param jobActions the list of notification job actions
 * @param notificationRegistrationStatusEntity the notification registration status entity
 *
 * @return the newly created business object data notification registration entity
 */
private BusinessObjectDataNotificationRegistrationEntity createBusinessObjectDataNotificationEntity(NamespaceEntity namespaceEntity, NotificationEventTypeEntity notificationEventTypeEntity, BusinessObjectDefinitionEntity businessObjectDefinitionEntity, FileTypeEntity fileTypeEntity, StorageEntity storageEntity, BusinessObjectDataStatusEntity newBusinessObjectDataStatusEntity, BusinessObjectDataStatusEntity oldBusinessObjectDataStatusEntity, NotificationRegistrationKey key, BusinessObjectDataNotificationFilter businessObjectDataNotificationFilter, List<JobAction> jobActions, NotificationRegistrationStatusEntity notificationRegistrationStatusEntity) {
    // Create a new entity.
    BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = new BusinessObjectDataNotificationRegistrationEntity();
    businessObjectDataNotificationRegistrationEntity.setNamespace(namespaceEntity);
    businessObjectDataNotificationRegistrationEntity.setName(key.getNotificationName());
    businessObjectDataNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    businessObjectDataNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage())) {
        businessObjectDataNotificationRegistrationEntity.setUsage(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage());
    }
    businessObjectDataNotificationRegistrationEntity.setFileType(fileTypeEntity);
    businessObjectDataNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectDataNotificationFilter.getBusinessObjectFormatVersion());
    businessObjectDataNotificationRegistrationEntity.setStorage(storageEntity);
    businessObjectDataNotificationRegistrationEntity.setNewBusinessObjectDataStatus(newBusinessObjectDataStatusEntity);
    businessObjectDataNotificationRegistrationEntity.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatusEntity);
    businessObjectDataNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    // Create the relative entities for job actions.
    // TODO: We need to add a null/empty list check here, if/when list of job actions will become optional (due to addition of other action types).
    List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
    businessObjectDataNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
    for (JobAction jobAction : jobActions) {
        // Retrieve and ensure that job definition exists.
        JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
        // Create a new entity.
        NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
        notificationActionEntities.add(notificationJobActionEntity);
        notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
        notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
        notificationJobActionEntity.setNotificationRegistration(businessObjectDataNotificationRegistrationEntity);
    }
    return businessObjectDataNotificationRegistrationEntity;
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobAction(org.finra.herd.model.api.xml.JobAction) ArrayList(java.util.ArrayList) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 45 with JobAction

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

the class BusinessObjectDataNotificationRegistrationServiceImpl method validateNotificationActions.

/**
 * Validates the business object data notification actions. This method also trims the notification action parameters.
 *
 * @param jobActions the list of notification job actions
 */
private void validateNotificationActions(List<JobAction> jobActions) {
    Assert.notEmpty(jobActions, "At least one notification action must be specified.");
    // Ensure job action isn't a duplicate by using a hash set with lowercase job definition key values for case insensitivity.
    Set<JobAction> validatedJobActionsSet = new LinkedHashSet<>();
    for (JobAction jobAction : jobActions) {
        Assert.hasText(jobAction.getNamespace(), "A job action namespace must be specified.");
        jobAction.setNamespace(jobAction.getNamespace().trim());
        Assert.hasText(jobAction.getJobName(), "A job action job name must be specified.");
        jobAction.setJobName(jobAction.getJobName().trim());
        // Create a special version of the job action with the relative job definition key values in lowercase.
        JobAction lowercaseJobDefinitionKey = new JobAction();
        lowercaseJobDefinitionKey.setNamespace(jobAction.getNamespace().toLowerCase());
        lowercaseJobDefinitionKey.setJobName(jobAction.getJobName().toLowerCase());
        if (validatedJobActionsSet.contains(lowercaseJobDefinitionKey)) {
            throw new IllegalArgumentException(String.format("Duplicate job action {namespace: \"%s\", jobName: \"%s\"} found.", jobAction.getNamespace(), jobAction.getJobName()));
        }
        validatedJobActionsSet.add(lowercaseJobDefinitionKey);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JobAction(org.finra.herd.model.api.xml.JobAction)

Aggregations

JobAction (org.finra.herd.model.api.xml.JobAction)59 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)49 Test (org.junit.Test)41 BusinessObjectDataNotificationFilter (org.finra.herd.model.api.xml.BusinessObjectDataNotificationFilter)23 StorageUnitNotificationFilter (org.finra.herd.model.api.xml.StorageUnitNotificationFilter)17 ArrayList (java.util.ArrayList)15 BusinessObjectDataNotificationRegistration (org.finra.herd.model.api.xml.BusinessObjectDataNotificationRegistration)15 StorageEntity (org.finra.herd.model.jpa.StorageEntity)12 BusinessObjectDataNotificationRegistrationCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDataNotificationRegistrationCreateRequest)11 StorageUnitNotificationRegistration (org.finra.herd.model.api.xml.StorageUnitNotificationRegistration)11 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)9 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)9 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 StorageUnitNotificationRegistrationCreateRequest (org.finra.herd.model.api.xml.StorageUnitNotificationRegistrationCreateRequest)8 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)8 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)8 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)8 NotificationEventTypeEntity (org.finra.herd.model.jpa.NotificationEventTypeEntity)8 BusinessObjectDataNotificationRegistrationUpdateRequest (org.finra.herd.model.api.xml.BusinessObjectDataNotificationRegistrationUpdateRequest)7 Job (org.finra.herd.model.api.xml.Job)6