Search in sources :

Example 41 with NamespaceEntity

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

the class BusinessObjectDefinitionSubjectMatterExpertDaoImpl method getBusinessObjectDefinitionSubjectMatterExpertByKey.

@Override
public BusinessObjectDefinitionSubjectMatterExpertEntity getBusinessObjectDefinitionSubjectMatterExpertByKey(BusinessObjectDefinitionSubjectMatterExpertKey key) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionSubjectMatterExpertEntity> criteria = builder.createQuery(BusinessObjectDefinitionSubjectMatterExpertEntity.class);
    // The criteria root is the business object definition subject matter expert.
    Root<BusinessObjectDefinitionSubjectMatterExpertEntity> businessObjectDefinitionSubjectMatterExpertEntityRoot = criteria.from(BusinessObjectDefinitionSubjectMatterExpertEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionSubjectMatterExpertEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDefinitionSubjectMatterExpertEntityRoot.join(BusinessObjectDefinitionSubjectMatterExpertEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), key.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name)), key.getBusinessObjectDefinitionName().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionSubjectMatterExpertEntityRoot.get(BusinessObjectDefinitionSubjectMatterExpertEntity_.userId)), key.getUserId().toUpperCase()));
    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionSubjectMatterExpertEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    // Execute the query and return the results.
    return executeSingleResultQuery(criteria, String.format("Found more than one business object definition subject matter expert instance with parameters {namespace=\"%s\", " + "businessObjectDefinitionName=\"%s\", userId=\"%s\"}.", key.getNamespace(), key.getBusinessObjectDefinitionName(), key.getUserId()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) ArrayList(java.util.ArrayList) BusinessObjectDefinitionSubjectMatterExpertEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionSubjectMatterExpertEntity) Predicate(javax.persistence.criteria.Predicate)

Example 42 with NamespaceEntity

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

the class EmrClusterDefinitionDaoImpl method getEmrClusterDefinitionByAltKey.

@Override
public EmrClusterDefinitionEntity getEmrClusterDefinitionByAltKey(String namespaceCd, String definitionName) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<EmrClusterDefinitionEntity> criteria = builder.createQuery(EmrClusterDefinitionEntity.class);
    // The criteria root is the EMR cluster definition.
    Root<EmrClusterDefinitionEntity> emrClusterDefinition = criteria.from(EmrClusterDefinitionEntity.class);
    // Join to the other tables we can filter on.
    Join<EmrClusterDefinitionEntity, NamespaceEntity> namespace = emrClusterDefinition.join(EmrClusterDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate namespaceRestriction = builder.equal(builder.upper(namespace.get(NamespaceEntity_.code)), namespaceCd.toUpperCase());
    Predicate definitionNameRestriction = builder.equal(builder.upper(emrClusterDefinition.get(EmrClusterDefinitionEntity_.name)), definitionName.toUpperCase());
    criteria.select(emrClusterDefinition).where(builder.and(namespaceRestriction, definitionNameRestriction));
    return executeSingleResultQuery(criteria, String.format("Found more than one EMR cluster definition with parameters {namespace=\"%s\", clusterDefinitionName=\"%s\"}.", namespace, definitionName));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity) Predicate(javax.persistence.criteria.Predicate)

Example 43 with NamespaceEntity

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

the class EmrClusterDefinitionDaoImpl method getEmrClusterDefinitionsByNamespace.

@Override
public List<EmrClusterDefinitionKey> getEmrClusterDefinitionsByNamespace(String namespace) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the EMR cluster definition.
    Root<EmrClusterDefinitionEntity> emrClusterDefinitionEntityRoot = criteria.from(EmrClusterDefinitionEntity.class);
    // Join to the other tables we can filter on.
    Join<EmrClusterDefinitionEntity, NamespaceEntity> namespaceEntityJoin = emrClusterDefinitionEntityRoot.join(EmrClusterDefinitionEntity_.namespace);
    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> emrClusterDefinitionNameColumn = emrClusterDefinitionEntityRoot.get(EmrClusterDefinitionEntity_.name);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), namespace.toUpperCase());
    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, emrClusterDefinitionNameColumn);
    // Add the where clause.
    criteria.where(queryRestriction);
    // Add the order by clause.
    criteria.orderBy(builder.asc(emrClusterDefinitionNameColumn));
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<EmrClusterDefinitionKey> emrClusterDefinitionKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey();
        emrClusterDefinitionKeys.add(emrClusterDefinitionKey);
        emrClusterDefinitionKey.setNamespace(tuple.get(namespaceCodeColumn));
        emrClusterDefinitionKey.setEmrClusterDefinitionName(tuple.get(emrClusterDefinitionNameColumn));
    }
    return emrClusterDefinitionKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) EmrClusterDefinitionKey(org.finra.herd.model.api.xml.EmrClusterDefinitionKey) Tuple(javax.persistence.Tuple) EmrClusterDefinitionEntity(org.finra.herd.model.jpa.EmrClusterDefinitionEntity)

Example 44 with NamespaceEntity

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

the class BusinessObjectFormatDaoImpl method getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition.

@Override
public List<BusinessObjectFormatEntity> getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition(BusinessObjectDefinitionKey businessObjectDefinitionKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectFormatEntity> criteria = builder.createQuery(BusinessObjectFormatEntity.class);
    // The criteria root is the business object format.
    Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectDefinitionKey.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase()));
    // Add the order by clause.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)));
    orderBy.add(builder.asc(fileTypeEntity.get(FileTypeEntity_.code)));
    queryRestriction = builder.and(queryRestriction, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.latestVersion), true));
    criteria.orderBy(orderBy);
    // Add the where clause.
    criteria.where(queryRestriction);
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)

Example 45 with NamespaceEntity

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

the class NotificationRegistrationServiceTestHelper method createDatabaseEntitiesForStorageUnitNotificationRegistrationTesting.

/**
 * Create and persist database entities required for testing.
 *
 * @param namespace the namespace of the storage unit notification registration
 * @param notificationEventTypes the list of notification event types
 * @param businessObjectDefinitionNamespace the namespace of the business object definition
 * @param businessObjectDefinitionName the name of the business object definition
 * @param fileTypes the list of file types
 * @param storageNames the list of storage names
 * @param storageUnitStatuses the list of storage unit statuses
 * @param jobActions the list of job actions
 */
public void createDatabaseEntitiesForStorageUnitNotificationRegistrationTesting(String namespace, List<String> notificationEventTypes, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, List<String> fileTypes, List<String> storageNames, List<String> storageUnitStatuses, List<JobAction> jobActions) {
    // Create a namespace entity, if not exists.
    NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(namespace);
    if (namespaceEntity == null) {
        namespaceDaoTestHelper.createNamespaceEntity(namespace);
    }
    // Create specified notification event types, if not exist.
    if (!CollectionUtils.isEmpty(notificationEventTypes)) {
        for (String notificationEventType : notificationEventTypes) {
            NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDao.getNotificationEventTypeByCode(notificationEventType);
            if (notificationEventTypeEntity == null) {
                notificationRegistrationDaoTestHelper.createNotificationEventTypeEntity(notificationEventType);
            }
        }
    }
    // Create specified business object definition, if not exists.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
    if (businessObjectDefinitionEntity == null) {
        // Create and persist a business object definition entity.
        businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionNamespace, businessObjectDefinitionName, AbstractServiceTest.DATA_PROVIDER_NAME, AbstractServiceTest.BDEF_DESCRIPTION);
    }
    // Create specified file type entities, if not exist.
    if (!CollectionUtils.isEmpty(fileTypes)) {
        for (String businessObjectFormatFileType : fileTypes) {
            fileTypeDaoTestHelper.createFileTypeEntity(businessObjectFormatFileType);
        }
    }
    // Create specified storage entities, if not exist.
    if (!CollectionUtils.isEmpty(storageNames)) {
        for (String storageName : storageNames) {
            storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
        }
    }
    // Create specified business object data status entities, if not exist.
    if (!CollectionUtils.isEmpty(storageUnitStatuses)) {
        for (String storageUnitStatus : storageUnitStatuses) {
            StorageUnitStatusEntity storageUnitStatusEntity = storageUnitStatusDao.getStorageUnitStatusByCode(storageUnitStatus);
            if (storageUnitStatusEntity == null) {
                storageUnitStatusDaoTestHelper.createStorageUnitStatusEntity(storageUnitStatus);
            }
        }
    }
    // Create specified job definition entities.
    if (!CollectionUtils.isEmpty(jobActions)) {
        for (JobAction jobAction : jobActions) {
            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(), AbstractServiceTest.ACTIVITI_ID));
        }
    }
}
Also used : NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) StorageUnitStatusEntity(org.finra.herd.model.jpa.StorageUnitStatusEntity)

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