use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataAttributeServiceImpl method createBusinessObjectDataAttributeImpl.
/**
* Creates a new business object data attribute.
*
* @param request the information needed to create a business object data attribute
*
* @return the newly created business object data attribute
*/
protected BusinessObjectDataAttribute createBusinessObjectDataAttributeImpl(BusinessObjectDataAttributeCreateRequest request) {
// Validate and trim the key.
businessObjectDataAttributeHelper.validateBusinessObjectDataAttributeKey(request.getBusinessObjectDataAttributeKey());
// Get the business object format and ensure it exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion()));
// Validate the attribute value.
if (businessObjectDataAttributeHelper.isBusinessObjectDataAttributeRequired(request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatEntity)) {
Assert.hasText(request.getBusinessObjectDataAttributeValue(), String.format("A business object data attribute value must be specified since \"%s\" is a required attribute for business object format {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
}
// Get the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(new BusinessObjectDataKey(request.getBusinessObjectDataAttributeKey().getNamespace(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDefinitionName(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatUsage(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatFileType(), request.getBusinessObjectDataAttributeKey().getBusinessObjectFormatVersion(), request.getBusinessObjectDataAttributeKey().getPartitionValue(), request.getBusinessObjectDataAttributeKey().getSubPartitionValues(), request.getBusinessObjectDataAttributeKey().getBusinessObjectDataVersion()));
// Load all existing business object data attribute entities into a map for quick access using lowercase attribute names.
Map<String, BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntityMap = businessObjectDataAttributeDaoHelper.getBusinessObjectDataAttributeEntityMap(businessObjectDataEntity.getAttributes());
// Ensure a business object data attribute with the specified name doesn't already exist for the specified business object data.
if (businessObjectDataAttributeEntityMap.containsKey(request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName().toLowerCase())) {
throw new AlreadyExistsException(String.format("Unable to create business object data attribute with name \"%s\" because it already exists for the business object data {%s}.", request.getBusinessObjectDataAttributeKey().getBusinessObjectDataAttributeName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
}
// Create a business object data attribute entity from the request information.
BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = createBusinessObjectDataAttributeEntity(businessObjectDataEntity, request);
// Persist the new entity.
businessObjectDataAttributeEntity = businessObjectDataAttributeDao.saveAndRefresh(businessObjectDataAttributeEntity);
// Create and return the business object data attribute object from the persisted entity.
return createBusinessObjectDataAttributeFromEntity(businessObjectDataAttributeEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataAttributeServiceImpl method getBusinessObjectDataAttributesImpl.
/**
* Gets a list of keys for all existing business object data attributes.
*
* @param businessObjectDataKey the business object data key
*
* @return the list of business object data attribute keys
*/
protected BusinessObjectDataAttributeKeys getBusinessObjectDataAttributesImpl(BusinessObjectDataKey businessObjectDataKey) {
// Validate and trim the business object data key.
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Retrieve the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Create and populate a list of business object data attribute keys.
BusinessObjectDataAttributeKeys businessObjectDataAttributeKeys = new BusinessObjectDataAttributeKeys();
for (BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity : businessObjectDataEntity.getAttributes()) {
businessObjectDataAttributeKeys.getBusinessObjectDataAttributeKeys().add(getBusinessObjectDataAttributeKey(businessObjectDataAttributeEntity));
}
return businessObjectDataAttributeKeys;
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoImpl method getPredict.
/**
* Create search restrictions
*
* @param builder criteria builder
* @param criteria criteria
* @param businessObjectDataEntity root business object data entity
* @param businessDataSearchKey business object data search key
* @param isCountQuery is the query a count query
*
* @return search restrictions
*/
private Predicate getPredict(CriteriaBuilder builder, CriteriaQuery<?> criteria, Root<BusinessObjectDataEntity> businessObjectDataEntity, BusinessObjectDataSearchKey businessDataSearchKey, boolean isCountQuery) {
// Join to the other tables we can filter on.
Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity = businessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
if (!isCountQuery) {
List<Order> orderList = new ArrayList<>();
orderList.add(builder.asc(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace)));
orderList.add(builder.asc(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)));
orderList.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)));
orderList.add(builder.asc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.fileType)));
orderList.add(builder.desc(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion)));
orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue)));
orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2)));
orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3)));
orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4)));
orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5)));
orderList.add(builder.desc(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)));
criteria.orderBy(orderList);
}
// Create the standard restrictions based on the business object search key values (i.e. the standard where clauses).
// Create a restriction on namespace code.
Predicate predicate = builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.namespace).get(NamespaceEntity_.code)), businessDataSearchKey.getNamespace().toUpperCase());
// Create and append a restriction on business object definition name.
predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)), businessDataSearchKey.getBusinessObjectDefinitionName().toUpperCase()));
// Create and append a restriction on business object format usage.
if (!StringUtils.isEmpty(businessDataSearchKey.getBusinessObjectFormatUsage())) {
predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessDataSearchKey.getBusinessObjectFormatUsage().toUpperCase()));
}
if (!StringUtils.isEmpty(businessDataSearchKey.getBusinessObjectFormatFileType())) {
// Create and append a restriction on business object format file type.
predicate = builder.and(predicate, builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.fileType).get(FileTypeEntity_.code)), businessDataSearchKey.getBusinessObjectFormatFileType().toUpperCase()));
}
// If specified, create and append a restriction on business object format version.
if (businessDataSearchKey.getBusinessObjectFormatVersion() != null) {
predicate = builder.and(predicate, builder.equal(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion), businessDataSearchKey.getBusinessObjectFormatVersion()));
}
predicate = createPartitionValueFilters(businessDataSearchKey, businessObjectDataEntity, businessObjectFormatEntity, builder, predicate);
List<AttributeValueFilter> attributeValueFilters = businessDataSearchKey.getAttributeValueFilters();
if (attributeValueFilters != null && !attributeValueFilters.isEmpty()) {
predicate = createAttributeValueFilters(businessDataSearchKey, businessObjectDataEntity, builder, predicate);
}
if (BooleanUtils.isTrue(businessDataSearchKey.isFilterOnLatestValidVersion())) {
String validStatus = BusinessObjectDataStatusEntity.VALID;
Subquery<Integer> subQuery = getMaximumBusinessObjectDataVersionSubQuery(builder, criteria, businessObjectDataEntity, businessObjectFormatEntity, validStatus);
predicate = builder.and(predicate, builder.in(businessObjectDataEntity.get(BusinessObjectDataEntity_.version)).value(subQuery));
}
if (BooleanUtils.isTrue(businessDataSearchKey.isFilterOnRetentionExpiration())) {
predicate = createRetentionExpirationFilter(businessDataSearchKey, businessObjectDataEntity, businessObjectFormatEntity, builder, predicate);
}
return predicate;
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoImpl method getQueryResultListFromEntityList.
/**
* Gets a query result list from an entity list.
*
* @param entityArray entity array from query
* @param attributeValueList attribute value list
*
* @return the list of business object data
*/
private List<BusinessObjectData> getQueryResultListFromEntityList(List<BusinessObjectDataEntity> entityArray, List<AttributeValueFilter> attributeValueList) {
List<BusinessObjectData> businessObjectDataList = new ArrayList<>();
Set<Integer> businessObjectIdSet = new HashSet<>();
for (BusinessObjectDataEntity dataEntity : entityArray) {
// need to skip the same data entity
if (businessObjectIdSet.contains(dataEntity.getId())) {
continue;
}
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectIdSet.add(dataEntity.getId());
businessObjectData.setId(dataEntity.getId());
businessObjectData.setPartitionValue(dataEntity.getPartitionValue());
businessObjectData.setVersion(dataEntity.getVersion());
businessObjectData.setLatestVersion(dataEntity.getLatestVersion());
BusinessObjectFormatEntity formatEntity = dataEntity.getBusinessObjectFormat();
businessObjectData.setNamespace(formatEntity.getBusinessObjectDefinition().getNamespace().getCode());
businessObjectData.setBusinessObjectDefinitionName(formatEntity.getBusinessObjectDefinition().getName());
businessObjectData.setBusinessObjectFormatUsage(formatEntity.getUsage());
businessObjectData.setBusinessObjectFormatFileType(formatEntity.getFileType().getCode());
businessObjectData.setBusinessObjectFormatVersion(formatEntity.getBusinessObjectFormatVersion());
businessObjectData.setPartitionKey(formatEntity.getPartitionKey());
businessObjectData.setStatus(dataEntity.getStatus().getCode());
List<String> subpartitions = new ArrayList<>();
if (dataEntity.getPartitionValue2() != null) {
subpartitions.add(dataEntity.getPartitionValue2());
}
if (dataEntity.getPartitionValue3() != null) {
subpartitions.add(dataEntity.getPartitionValue3());
}
if (dataEntity.getPartitionValue4() != null) {
subpartitions.add(dataEntity.getPartitionValue4());
}
if (dataEntity.getPartitionValue5() != null) {
subpartitions.add(dataEntity.getPartitionValue5());
}
if (subpartitions.size() > 0) {
businessObjectData.setSubPartitionValues(subpartitions);
}
// add attribute name and values in the request to the response
if (attributeValueList != null && !attributeValueList.isEmpty()) {
Collection<BusinessObjectDataAttributeEntity> dataAttributeCollection = dataEntity.getAttributes();
List<Attribute> attributeList = new ArrayList<>();
for (BusinessObjectDataAttributeEntity attributeEntity : dataAttributeCollection) {
Attribute attribute = new Attribute(attributeEntity.getName(), attributeEntity.getValue());
if (shouldIncludeAttributeInResponse(attributeEntity, attributeValueList) && !attributeList.contains(attribute)) {
attributeList.add(attribute);
}
}
businessObjectData.setAttributes(attributeList);
}
businessObjectDataList.add(businessObjectData);
}
return businessObjectDataList;
}
use of org.finra.herd.model.jpa.BusinessObjectDataEntity 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