use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method updateStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#notificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration updateStorageUnitNotificationRegistration(NotificationRegistrationKey notificationRegistrationKey, StorageUnitNotificationRegistrationUpdateRequest request) {
// Validate and trim the key.
validateStorageUnitNotificationRegistrationKey(notificationRegistrationKey);
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationUpdateRequest(request);
// Retrieve and ensure that a storage unit notification exists with the specified key.
StorageUnitNotificationRegistrationEntity oldStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDaoHelper.getStorageUnitNotificationRegistrationEntity(notificationRegistrationKey);
String oldStorageUnitNotificationRegistrationName = oldStorageUnitNotificationRegistrationEntity.getName();
// Retrieve the namespace with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists. Since namespace is specified, retrieve a business object definition by it's key.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// 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).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// Retrieve and validate the notification registration status entity.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(request.getNotificationRegistrationStatus());
// Delete the storage unit notification.
storageUnitNotificationRegistrationDao.delete(oldStorageUnitNotificationRegistrationEntity);
// Create a storage unit notification registration entity from the request information.
StorageUnitNotificationRegistrationEntity newStorageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldStorageUnitNotificationRegistrationName), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
newStorageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(newStorageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(newStorageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class StorageUnitNotificationRegistrationServiceImpl method createStorageUnitNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#request?.storageUnitNotificationRegistrationKey?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.storageUnitNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public StorageUnitNotificationRegistration createStorageUnitNotificationRegistration(StorageUnitNotificationRegistrationCreateRequest request) {
// Validate and trim the request parameters.
validateStorageUnitNotificationRegistrationCreateRequest(request);
// Get the notification registration key.
NotificationRegistrationKey notificationRegistrationKey = request.getStorageUnitNotificationRegistrationKey();
// Retrieve and ensure that notification registration namespace exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(notificationRegistrationKey.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getStorageUnitEventType());
// Validate the notification event type.
Assert.isTrue(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG.name().equalsIgnoreCase(request.getStorageUnitEventType()), String.format("Notification event type \"%s\" is not supported for storage unit notification registration.", request.getStorageUnitEventType()));
// Get the storage unit notification filter.
StorageUnitNotificationFilter filter = request.getStorageUnitNotificationFilter();
// Retrieve and ensure that business object definition exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// Retrieve and ensure that storage exists.
StorageEntity storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
// If specified, retrieve and ensure that new storage unit status exists.
StorageUnitStatusEntity newStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getNewStorageUnitStatus())) {
newStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getNewStorageUnitStatus());
}
// If specified, retrieve and ensure that old storage unit status exists.
StorageUnitStatusEntity oldStorageUnitStatus = null;
if (StringUtils.isNotBlank(filter.getOldStorageUnitStatus())) {
oldStorageUnitStatus = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(filter.getOldStorageUnitStatus());
}
// 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).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// If specified, retrieve and validate the notification registration status entity. Otherwise, default it to ENABLED.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(StringUtils.isNotBlank(request.getNotificationRegistrationStatus()) ? request.getNotificationRegistrationStatus() : NotificationRegistrationStatusEntity.ENABLED);
// Ensure a storage unit notification with the specified name doesn't already exist for the specified namespace.
StorageUnitNotificationRegistrationEntity storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.getStorageUnitNotificationRegistrationByAltKey(notificationRegistrationKey);
if (storageUnitNotificationRegistrationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create storage unit notification with name \"%s\" because it already exists for namespace \"%s\".", notificationRegistrationKey.getNotificationName(), notificationRegistrationKey.getNamespace()));
}
// Create a storage unit notification registration entity from the request information.
storageUnitNotificationRegistrationEntity = createStorageUnitNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newStorageUnitStatus, oldStorageUnitStatus, request.getStorageUnitNotificationRegistrationKey(), request.getStorageUnitNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
storageUnitNotificationRegistrationEntity = storageUnitNotificationRegistrationDao.saveAndRefresh(storageUnitNotificationRegistrationEntity);
// Create and return the storage unit notification object from the persisted entity.
return createStorageUnitNotificationFromEntity(storageUnitNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method createBusinessObjectFormat.
@PublishNotificationMessages
@NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat createBusinessObjectFormat(BusinessObjectFormatCreateRequest request) {
// Perform the validation of the request parameters, except for the alternate key.
validateBusinessObjectFormatCreateRequest(request);
// Get business object format key from the request.
BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
// Get the business object definition and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName()));
// Get business object format file type and ensure it exists.
FileTypeEntity fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(request.getBusinessObjectFormatFileType());
// Get the latest format version for this business format, if it exists.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
// If the latest version exists, perform the additive schema validation and update the latest entity.
if (latestVersionBusinessObjectFormatEntity != null) {
// Get the latest version business object format model object.
BusinessObjectFormat latestVersionBusinessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(latestVersionBusinessObjectFormatEntity);
// If the latest version format has schema, check the new format version schema is "additive" to the previous format version.
if (latestVersionBusinessObjectFormat.getSchema() != null) {
validateNewSchemaIsAdditiveToOldSchema(request.getSchema(), latestVersionBusinessObjectFormat.getSchema());
}
// Update the latest entity.
latestVersionBusinessObjectFormatEntity.setLatestVersion(false);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Create a business object format entity from the request information.
Integer businessObjectFormatVersion = latestVersionBusinessObjectFormatEntity == null ? 0 : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion() + 1;
BusinessObjectFormatEntity newBusinessObjectFormatEntity = createBusinessObjectFormatEntity(request, businessObjectDefinitionEntity, fileTypeEntity, businessObjectFormatVersion, null);
// latest version format is the descriptive format for the bdef, update the bdef descriptive format to the newly created one
if (latestVersionBusinessObjectFormatEntity != null && latestVersionBusinessObjectFormatEntity.equals(businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat())) {
businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(newBusinessObjectFormatEntity);
businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
// latest version business object exists, carry the retention information to the new entity
if (latestVersionBusinessObjectFormatEntity != null) {
// for each of the previous version's child, remove the parent link to the previous version and set the parent to the new version
for (BusinessObjectFormatEntity childFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatChildren()) {
childFormatEntity.getBusinessObjectFormatParents().remove(latestVersionBusinessObjectFormatEntity);
childFormatEntity.getBusinessObjectFormatParents().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatChildren().add(childFormatEntity);
businessObjectFormatDao.saveAndRefresh(childFormatEntity);
}
// for each of the previous version's parent, remove the child link to the previous version and set the child link to the new version
for (BusinessObjectFormatEntity parentFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatParents()) {
parentFormatEntity.getBusinessObjectFormatChildren().remove(latestVersionBusinessObjectFormatEntity);
parentFormatEntity.getBusinessObjectFormatChildren().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatParents().add(parentFormatEntity);
businessObjectFormatDao.saveAndRefresh(parentFormatEntity);
}
// mark the latest version business object format
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatParents(null);
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatChildren(null);
// carry the retention information from the latest entity to the new entity
newBusinessObjectFormatEntity.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays());
newBusinessObjectFormatEntity.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag());
newBusinessObjectFormatEntity.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType());
businessObjectFormatDao.saveAndRefresh(newBusinessObjectFormatEntity);
// reset the retention information of the latest version business object format
latestVersionBusinessObjectFormatEntity.setRetentionType(null);
latestVersionBusinessObjectFormatEntity.setRecordFlag(null);
latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(null);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create a version change notification to be sent on create business object format event.
messageNotificationEventService.processBusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatHelper.getBusinessObjectFormatKey(newBusinessObjectFormatEntity), latestVersionBusinessObjectFormatEntity != null ? latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion().toString() : "");
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(newBusinessObjectFormatEntity);
}
use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataNotificationRegistrationServiceImpl method updateBusinessObjectDataNotificationRegistration.
@NamespacePermissions({ @NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#request?.businessObjectDataNotificationFilter?.namespace", permissions = NamespacePermissionEnum.READ), @NamespacePermission(fields = "#request?.jobActions?.![namespace]", permissions = NamespacePermissionEnum.EXECUTE) })
@Override
public BusinessObjectDataNotificationRegistration updateBusinessObjectDataNotificationRegistration(NotificationRegistrationKey key, BusinessObjectDataNotificationRegistrationUpdateRequest request) {
// Validate and trim the key.
validateBusinessObjectDataNotificationRegistrationKey(key);
// Validate and trim the request parameters.
validateBusinessObjectDataNotificationRegistrationUpdateRequest(request);
// Retrieve and ensure that a business object data notification exists with the specified key.
BusinessObjectDataNotificationRegistrationEntity oldBusinessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDaoHelper.getBusinessObjectDataNotificationRegistrationEntity(key);
String oldBusinessObjectDataNotificationRegistrationName = oldBusinessObjectDataNotificationRegistrationEntity.getName();
// Retrieve the namespace with the specified namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(key.getNamespace());
// Retrieve and validate the notification event type entity.
NotificationEventTypeEntity notificationEventTypeEntity = getAndValidateNotificationEventTypeEntity(request.getBusinessObjectDataEventType());
// Get the business object data notification filter.
BusinessObjectDataNotificationFilter filter = request.getBusinessObjectDataNotificationFilter();
// Retrieve and ensure that business object definition exists. Since namespace is specified, retrieve a business object definition by it's key.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(filter.getNamespace(), filter.getBusinessObjectDefinitionName()));
// If specified, retrieve and ensure that file type exists.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(filter.getBusinessObjectFormatFileType())) {
fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(filter.getBusinessObjectFormatFileType());
}
// If specified, retrieve and ensure that storage exists.
StorageEntity storageEntity = null;
if (StringUtils.isNotBlank(filter.getStorageName())) {
storageEntity = storageDaoHelper.getStorageEntity(filter.getStorageName());
}
// If specified, retrieve and ensure that new business object data status exists.
BusinessObjectDataStatusEntity newBusinessObjectDataStatus = null;
if (StringUtils.isNotBlank(filter.getNewBusinessObjectDataStatus())) {
newBusinessObjectDataStatus = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(filter.getNewBusinessObjectDataStatus());
}
// If specified, retrieve and ensure that old business object data status exists.
BusinessObjectDataStatusEntity oldBusinessObjectDataStatus = null;
if (StringUtils.isNotBlank(filter.getOldBusinessObjectDataStatus())) {
oldBusinessObjectDataStatus = businessObjectDataStatusDaoHelper.getBusinessObjectDataStatusEntity(filter.getOldBusinessObjectDataStatus());
}
// 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).
for (JobAction jobAction : request.getJobActions()) {
// Ensure that job definition exists.
jobDefinitionDaoHelper.getJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName());
}
// Retrieve and validate the notification registration status entity.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDaoHelper.getNotificationRegistrationStatusEntity(request.getNotificationRegistrationStatus());
// Delete the business object data notification.
businessObjectDataNotificationRegistrationDao.delete(oldBusinessObjectDataNotificationRegistrationEntity);
// Create a business object data notification registration entity from the request information.
BusinessObjectDataNotificationRegistrationEntity newBusinessObjectDataNotificationRegistrationEntity = createBusinessObjectDataNotificationEntity(namespaceEntity, notificationEventTypeEntity, businessObjectDefinitionEntity, fileTypeEntity, storageEntity, newBusinessObjectDataStatus, oldBusinessObjectDataStatus, new NotificationRegistrationKey(namespaceEntity.getCode(), oldBusinessObjectDataNotificationRegistrationName), request.getBusinessObjectDataNotificationFilter(), request.getJobActions(), notificationRegistrationStatusEntity);
// Persist the new entity.
newBusinessObjectDataNotificationRegistrationEntity = businessObjectDataNotificationRegistrationDao.saveAndRefresh(newBusinessObjectDataNotificationRegistrationEntity);
// Create and return the business object data notification object from the persisted entity.
return createBusinessObjectDataNotificationFromEntity(newBusinessObjectDataNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.FileTypeEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoImpl method getBusinessObjectDataByAltKeyAndStatus.
@Override
public BusinessObjectDataEntity getBusinessObjectDataByAltKeyAndStatus(BusinessObjectDataKey businessObjectDataKey, String businessObjectDataStatus) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectDataEntity> criteria = builder.createQuery(BusinessObjectDataEntity.class);
// The criteria root is the business object data.
Root<BusinessObjectDataEntity> businessObjectDataEntity = criteria.from(BusinessObjectDataEntity.class);
// Join to other tables that we need to filter on.
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = businessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
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).
Predicate mainQueryRestriction = getQueryRestriction(builder, businessObjectDataEntity, businessObjectFormatEntity, fileTypeEntity, businessObjectDefinitionEntity, businessObjectDataKey);
// If a format version was specified, use the latest available for this partition value.
if (businessObjectDataKey.getBusinessObjectFormatVersion() == null) {
// Business object format version is not specified, so just use the latest available for this set of partition values.
Subquery<Integer> subQuery = criteria.subquery(Integer.class);
// The criteria root is the business object data.
Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery.from(BusinessObjectDataEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> subBusinessObjectDefinitionEntity = subBusinessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
Join<BusinessObjectFormatEntity, FileTypeEntity> subBusinessObjectFormatFileTypeEntity = subBusinessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.status);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate subQueryRestriction = builder.equal(subBusinessObjectDefinitionEntity, businessObjectDefinitionEntity);
subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage), businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)));
subQueryRestriction = builder.and(subQueryRestriction, builder.equal(subBusinessObjectFormatFileTypeEntity, fileTypeEntity));
// Create and add standard restrictions on primary and sub-partition values.
subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity));
// Add restrictions on business object data version and business object data status.
Predicate subQueryRestrictionOnBusinessObjectDataVersionAndStatus = getQueryRestrictionOnBusinessObjectDataVersionAndStatus(builder, subBusinessObjectDataEntity, subBusinessObjectDataStatusEntity, businessObjectDataKey.getBusinessObjectDataVersion(), businessObjectDataStatus);
if (subQueryRestrictionOnBusinessObjectDataVersionAndStatus != null) {
subQueryRestriction = builder.and(subQueryRestriction, subQueryRestrictionOnBusinessObjectDataVersionAndStatus);
}
subQuery.select(builder.max(subBusinessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion))).where(subQueryRestriction);
mainQueryRestriction = builder.and(mainQueryRestriction, builder.in(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion)).value(subQuery));
}
// If a data version was not specified, use the latest one as per specified business object data status.
if (businessObjectDataKey.getBusinessObjectDataVersion() == null) {
// Since business object data version is not specified, just use the latest one as per specified business object data status.
if (businessObjectDataStatus != null) {
// Business object data version is not specified, so get the latest one as per specified business object data status.
Subquery<Integer> subQuery = criteria.subquery(Integer.class);
// The criteria root is the business object data.
Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery.from(BusinessObjectDataEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.status);
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate subQueryRestriction = builder.equal(subBusinessObjectFormatEntity, businessObjectFormatEntity);
// Create and add standard restrictions on primary and sub-partition values.
subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity));
// Create and add standard restrictions on business object data status.
subQueryRestriction = builder.and(subQueryRestriction, builder.equal(builder.upper(subBusinessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase()));
subQuery.select(builder.max(subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.version))).where(subQueryRestriction);
mainQueryRestriction = builder.and(mainQueryRestriction, builder.in(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)).value(subQuery));
} else {
// Both business object data version and business object data status are not specified, so just use the latest business object data version.
mainQueryRestriction = builder.and(mainQueryRestriction, builder.equal(businessObjectDataEntity.get(BusinessObjectDataEntity_.latestVersion), true));
}
}
criteria.select(businessObjectDataEntity).where(mainQueryRestriction);
return executeSingleResultQuery(criteria, String.format("Found more than one business object data instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " businessObjectFormatUsage=\"%s\", businessObjectFormatFileType=\"%s\", businessObjectFormatVersion=\"%d\"," + " businessObjectDataPartitionValue=\"%s\", businessObjectDataSubPartitionValues=\"%s\", businessObjectDataVersion=\"%d\"," + " businessObjectDataStatus=\"%s\"}.", businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), businessObjectDataKey.getBusinessObjectFormatVersion(), businessObjectDataKey.getPartitionValue(), CollectionUtils.isEmpty(businessObjectDataKey.getSubPartitionValues()) ? "" : StringUtils.join(businessObjectDataKey.getSubPartitionValues(), ","), businessObjectDataKey.getBusinessObjectDataVersion(), businessObjectDataStatus));
}
Aggregations