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