Search in sources :

Example 26 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class JobDefinitionDaoTest method testGetJobDefinitionByAltKey.

@Test
public void testGetJobDefinitionByAltKey() {
    // Create a namespace database entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create and persist a job definition entity.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoTestHelper.createJobDefinitionEntity(namespaceEntity, JOB_NAME, JOB_DESCRIPTION, ACTIVITI_ID);
    // Retrieve the job definition by its key.
    assertEquals(jobDefinitionEntity, jobDefinitionDao.getJobDefinitionByAltKey(NAMESPACE, JOB_NAME));
    // Retrieve the job definition by its key in uppercase.
    assertEquals(jobDefinitionEntity, jobDefinitionDao.getJobDefinitionByAltKey(NAMESPACE.toUpperCase(), JOB_NAME.toUpperCase()));
    // Retrieve the job definition by its key in lowercase.
    assertEquals(jobDefinitionEntity, jobDefinitionDao.getJobDefinitionByAltKey(NAMESPACE.toLowerCase(), JOB_NAME.toLowerCase()));
    // Try to retrieve a job definition for a non-existing namespace.
    assertNull(jobDefinitionDao.getJobDefinitionByAltKey("I_DO_NOT_EXIST", JOB_NAME));
    // Try to retrieve a job definition for a non-existing job name.
    assertNull(jobDefinitionDao.getJobDefinitionByAltKey(NAMESPACE, "I_DO_NOT_EXIST"));
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) Test(org.junit.Test)

Example 27 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class NamespaceDaoTest method testGetNamespaceByKey.

@Test
public void testGetNamespaceByKey() {
    // Create a namespace entity.
    namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Retrieve the namespace entity.
    NamespaceEntity resultNamespaceEntity = namespaceDao.getNamespaceByKey(new NamespaceKey(NAMESPACE));
    // Validate the results.
    assertEquals(NAMESPACE, resultNamespaceEntity.getCode());
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceKey(org.finra.herd.model.api.xml.NamespaceKey) Test(org.junit.Test)

Example 28 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationDaoTest method getNamespaceIamRoleAuthorizationsAssertFilterByNamespaceWhenGiven.

@Test
public void getNamespaceIamRoleAuthorizationsAssertFilterByNamespaceWhenGiven() {
    NamespaceEntity namespaceEntity1 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    NamespaceEntity namespaceEntity2 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
    {
        List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity1);
        assertNotNull(namespaceIamRoleAuthorizations);
        assertEquals(0, namespaceIamRoleAuthorizations.size());
    }
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity2);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity3 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity3.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity3.setIamRoleName("iamRoleName3");
    namespaceIamRoleAuthorizationEntity3.setDescription("description3");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity3);
    {
        List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(namespaceEntity1);
        assertNotNull(namespaceIamRoleAuthorizations);
        assertEquals(2, namespaceIamRoleAuthorizations.size());
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(0);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(1);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) List(java.util.List) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test)

Example 29 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationDaoTest method getNamespaceIamRoleAuthorizationsAssertGetAllWhenNamespaceIsNotGiven.

@Test
public void getNamespaceIamRoleAuthorizationsAssertGetAllWhenNamespaceIsNotGiven() {
    NamespaceEntity namespaceEntity1 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    NamespaceEntity namespaceEntity2 = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(namespaceEntity2);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity2);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity3 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity3.setNamespace(namespaceEntity1);
    namespaceIamRoleAuthorizationEntity3.setIamRoleName("iamRoleName3");
    namespaceIamRoleAuthorizationEntity3.setDescription("description3");
    namespaceIamRoleAuthorizationDao.saveAndRefresh(namespaceIamRoleAuthorizationEntity3);
    {
        List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizations = namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(null);
        assertNotNull(namespaceIamRoleAuthorizations);
        assertEquals(3, namespaceIamRoleAuthorizations.size());
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(0);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(1);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity1.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity3.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
        {
            NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity = namespaceIamRoleAuthorizations.get(2);
            assertNotNull(namespaceIamRoleAuthorizationEntity);
            assertEquals(namespaceEntity2.getCode(), namespaceIamRoleAuthorizationEntity.getNamespace().getCode());
            assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), namespaceIamRoleAuthorizationEntity.getIamRoleName());
            assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), namespaceIamRoleAuthorizationEntity.getDescription());
        }
    }
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) List(java.util.List) Test(org.junit.Test)

Example 30 with NamespaceEntity

use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.

the class NotificationRegistrationDaoTestHelper method createStorageUnitNotificationRegistrationEntity.

/**
 * Creates and persists a storage unit notification registration entity.
 *
 * @param notificationRegistrationKey the business object data notification registration key
 * @param notificationEventTypeCode the notification event type
 * @param businessObjectDefinitionNamespace the business object definition namespace
 * @param businessObjectDefinitionName the business object definition name
 * @param businessObjectFormatUsage the business object usage
 * @param businessObjectFormatFileType the business object format file type
 * @param businessObjectFormatVersion the business object format version
 * @param storageName the storage name
 * @param newStorageUnitStatus the new storage unit status
 * @param oldStorageUnitStatus the old storage unit status
 * @param jobActions the list of job actions
 * @param notificationRegistrationStatus the notification registration status
 *
 * @return the newly created storage unit notification registration entity
 */
public StorageUnitNotificationRegistrationEntity createStorageUnitNotificationRegistrationEntity(NotificationRegistrationKey notificationRegistrationKey, String notificationEventTypeCode, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String storageName, String newStorageUnitStatus, String oldStorageUnitStatus, List<JobAction> jobActions, String notificationRegistrationStatus) {
    // Create a namespace entity if needed.
    NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(notificationRegistrationKey.getNamespace());
    if (namespaceEntity == null) {
        namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(notificationRegistrationKey.getNamespace());
    }
    // Create a notification event type entity if needed.
    NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDao.getNotificationEventTypeByCode(notificationEventTypeCode);
    if (notificationEventTypeEntity == null) {
        notificationEventTypeEntity = createNotificationEventTypeEntity(notificationEventTypeCode);
    }
    // Create a business object definition entity if needed.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
    if (businessObjectDefinitionEntity == null) {
        businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionNamespace, businessObjectDefinitionName, AbstractDaoTest.DATA_PROVIDER_NAME, AbstractDaoTest.BDEF_DESCRIPTION);
    }
    // Create a business object format file type entity if needed.
    FileTypeEntity fileTypeEntity = null;
    if (StringUtils.isNotBlank(businessObjectFormatFileType)) {
        fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType);
        if (fileTypeEntity == null) {
            fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(businessObjectFormatFileType);
        }
    }
    // Create a storage entity.
    StorageEntity storageEntity = storageDao.getStorageByName(storageName);
    if (storageEntity == null) {
        storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
    }
    // Create a business object status entity for new status if needed.
    StorageUnitStatusEntity newStorageUnitStatusEntity = null;
    if (StringUtils.isNotBlank(newStorageUnitStatus)) {
        newStorageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(newStorageUnitStatus);
        if (newStorageUnitStatusEntity == null) {
            newStorageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(newStorageUnitStatus);
        }
    }
    // Create a business object status entity for new status if needed.
    StorageUnitStatusEntity oldStorageUnitStatusEntity = null;
    if (StringUtils.isNotBlank(oldStorageUnitStatus)) {
        oldStorageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(oldStorageUnitStatus);
        if (oldStorageUnitStatusEntity == null) {
            oldStorageUnitStatusEntity = storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(oldStorageUnitStatus);
        }
    }
    // Create a notification registration status entity if needed.
    NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDao.getNotificationRegistrationStatus(notificationRegistrationStatus);
    if (notificationRegistrationStatusEntity == null) {
        notificationRegistrationStatusEntity = createNotificationRegistrationStatusEntity(notificationRegistrationStatus);
    }
    // Create a business object data notification registration entity.
    StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = new StorageUnitNotificationRegistrationEntity();
    storageUnitNotificationRegistrationEntity.setNamespace(namespaceEntity);
    storageUnitNotificationRegistrationEntity.setName(notificationRegistrationKey.getNotificationName());
    storageUnitNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
    storageUnitNotificationRegistrationEntity.setUsage(businessObjectFormatUsage);
    storageUnitNotificationRegistrationEntity.setFileType(fileTypeEntity);
    storageUnitNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
    storageUnitNotificationRegistrationEntity.setStorage(storageEntity);
    storageUnitNotificationRegistrationEntity.setNewStorageUnitStatus(newStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setOldStorageUnitStatus(oldStorageUnitStatusEntity);
    storageUnitNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
    if (!CollectionUtils.isEmpty(jobActions)) {
        List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
        storageUnitNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
        for (JobAction jobAction : jobActions) {
            // Create a job definition entity if needed.
            JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobAction.getNamespace(), jobAction.getJobName());
            if (jobDefinitionEntity == null) {
                jobDefinitionEntity = jobDefinitionDaoTestHelper.createJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName(), String.format("Description of \"%s.%s\" job definition.", jobAction.getNamespace(), jobAction.getJobName()), String.format("%s.%s.%s", jobAction.getNamespace(), jobAction.getJobName(), AbstractDaoTest.ACTIVITI_ID));
            }
            NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
            notificationActionEntities.add(notificationJobActionEntity);
            notificationJobActionEntity.setNotificationRegistration(storageUnitNotificationRegistrationEntity);
            notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
            notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
        }
    }
    return storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) StorageUnitNotificationRegistrationEntity(org.finra.herd.model.jpa.StorageUnitNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Aggregations

NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)225 Test (org.junit.Test)139 ArrayList (java.util.ArrayList)63 EmrClusterCreateRequest (org.finra.herd.model.api.xml.EmrClusterCreateRequest)59 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)43 EmrClusterDefinition (org.finra.herd.model.api.xml.EmrClusterDefinition)40 Predicate (javax.persistence.criteria.Predicate)39 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)38 EmrCluster (org.finra.herd.model.api.xml.EmrCluster)32 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)25 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)24 NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)24 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)18 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)16 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)14 EmrClusterDefinitionKey (org.finra.herd.model.api.xml.EmrClusterDefinitionKey)13 AttributeValueListEntity (org.finra.herd.model.jpa.AttributeValueListEntity)13 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)13 StorageEntity (org.finra.herd.model.jpa.StorageEntity)13 EmrClusterDefinitionInformation (org.finra.herd.model.api.xml.EmrClusterDefinitionInformation)12