use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class AbstractHerdDao method getQueryRestriction.
/**
* TODO This method may be bformat specific. Consider creating new abstract class to group all bformat related DAO. Builds a query restriction predicate for
* the specified business object format entity as per business object format key values.
*
* @param builder the criteria builder
* @param businessObjectFormatEntity the business object format entity that appears in the from clause
* @param fileTypeEntity the file type entity that appears in the from clause
* @param businessObjectDefinitionEntity the business object definition entity that appears in the from clause
* @param businessObjectFormatKey the business object format key
* @param ignoreBusinessObjectFormatVersion specifies whether to ignore the business object format version when building the predicate
*
* @return the query restriction predicate
*/
protected Predicate getQueryRestriction(CriteriaBuilder builder, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, From<?, FileTypeEntity> fileTypeEntity, From<?, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity, BusinessObjectFormatKey businessObjectFormatKey, boolean ignoreBusinessObjectFormatVersion) {
// Join to the other tables we can filter on.
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
// Create the standard restrictions based on the business object format key values (i.e. the standard where clauses).
// Create a restriction on namespace code.
Predicate predicate = builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectFormatKey.getNamespace().toUpperCase());
// Create and append a restriction on business object definition name.
predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessObjectFormatKey.getBusinessObjectDefinitionName().toUpperCase()));
// Create and append a restriction on business object format usage.
predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatKey.getBusinessObjectFormatUsage().toUpperCase()));
// Create and append a restriction on business object format file type.
predicate = builder.and(predicate, builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)), businessObjectFormatKey.getBusinessObjectFormatFileType().toUpperCase()));
// If specified, create and append a restriction on business object format version.
if (!ignoreBusinessObjectFormatVersion && businessObjectFormatKey.getBusinessObjectFormatVersion() != null) {
predicate = builder.and(predicate, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessObjectFormatKey.getBusinessObjectFormatVersion()));
}
return predicate;
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity 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.BusinessObjectDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoImpl method getBusinessObjectFormatByAltKey.
@Override
public BusinessObjectFormatEntity getBusinessObjectFormatByAltKey(BusinessObjectFormatKey businessObjectFormatKey) {
// 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, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
// Create the standard restrictions (i.e. the standard where clauses).
// Please note that we specify not to ignore the business object format version.
Predicate queryRestriction = getQueryRestriction(builder, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectFormatKey, false);
// If a business format version was not specified, use the latest one.
if (businessObjectFormatKey.getBusinessObjectFormatVersion() == null) {
queryRestriction = builder.and(queryRestriction, builder.isTrue(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.latestVersion)));
}
criteria.select(businessObjectFormatEntity).where(queryRestriction);
return executeSingleResultQuery(criteria, String.format("Found more than one business object format instance with parameters " + "{namespace=\"%s\", businessObjectDefinitionName=\"%s\", businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", " + "businessObjectFormatVersion=\"%d\"}.", businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), businessObjectFormatKey.getBusinessObjectFormatVersion()));
}
use of org.finra.herd.model.jpa.BusinessObjectDefinitionEntity 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.BusinessObjectDefinitionEntity 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