use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method getBusinessObjectFormatImpl.
/**
* Gets a business object format for the specified key.
*
* @param businessObjectFormatKey the business object format key
*
* @return the business object format
*/
protected BusinessObjectFormat getBusinessObjectFormatImpl(BusinessObjectFormatKey businessObjectFormatKey) {
// Perform validation and trim the alternate key parameters.
businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false);
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
boolean checkLatestVersion = false;
// need to check latest version if the format key does not have the version
if (businessObjectFormatKey.getBusinessObjectFormatVersion() != null) {
checkLatestVersion = true;
}
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity, checkLatestVersion);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatAttributeDefinitionsHelper.
/**
* Updates business object format attribute definitions
*
* @param businessObjectFormatEntity the business object format entity
* @param attributeDefinitions the attributes
*/
private void updateBusinessObjectFormatAttributeDefinitionsHelper(BusinessObjectFormatEntity businessObjectFormatEntity, List<AttributeDefinition> attributeDefinitions) {
// Update the attribute definitions.
// Load all existing attribute definition entities in a map with a "lowercase" attribute definition name as the key for case insensitivity.
Map<String, BusinessObjectDataAttributeDefinitionEntity> existingAttributeDefinitionEntities = businessObjectFormatEntity.getAttributeDefinitions().stream().collect(Collectors.toMap(attributeDefinition -> attributeDefinition.getName().toLowerCase(), attributeDefinition -> attributeDefinition));
// Process the list of attribute definitions to determine that business object definition attribute entities should be created, updated, or deleted.
List<BusinessObjectDataAttributeDefinitionEntity> createdAttributeDefinitionEntities = new ArrayList<>();
List<BusinessObjectDataAttributeDefinitionEntity> retainedAttributeDefinitionEntities = new ArrayList<>();
for (AttributeDefinition attributeDefinition : attributeDefinitions) {
// Use a "lowercase" attribute name for case insensitivity.
String lowercaseAttributeName = attributeDefinition.getName().toLowerCase();
if (existingAttributeDefinitionEntities.containsKey(lowercaseAttributeName)) {
// Check if the attribute definition value needs to be updated.
BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = existingAttributeDefinitionEntities.get(lowercaseAttributeName);
if (!attributeDefinition.isPublish().equals(businessObjectDataAttributeDefinitionEntity.getPublish())) {
// Update the business object attribute entity.
businessObjectDataAttributeDefinitionEntity.setPublish(attributeDefinition.isPublish());
}
// Add this entity to the list of business object definition attribute entities to be retained.
retainedAttributeDefinitionEntities.add(businessObjectDataAttributeDefinitionEntity);
} else {
// Create a new business object attribute entity.
BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
businessObjectFormatEntity.getAttributeDefinitions().add(businessObjectDataAttributeDefinitionEntity);
businessObjectDataAttributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataAttributeDefinitionEntity.setName(attributeDefinition.getName());
businessObjectDataAttributeDefinitionEntity.setPublish(BooleanUtils.isTrue(attributeDefinition.isPublish()));
// Add this entity to the list of the newly created business object definition attribute entities.
createdAttributeDefinitionEntities.add(businessObjectDataAttributeDefinitionEntity);
}
}
// Remove any of the currently existing attribute entities that did not get onto the retained entities list.
businessObjectFormatEntity.getAttributeDefinitions().retainAll(retainedAttributeDefinitionEntities);
// Add all of the newly created business object definition attribute entities.
businessObjectFormatEntity.getAttributeDefinitions().addAll(createdAttributeDefinitionEntities);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatAttributes.
@NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat updateBusinessObjectFormatAttributes(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatAttributesUpdateRequest businessObjectFormatAttributesUpdateRequest) {
// Perform validation and trim the alternate key parameters.
businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey);
Assert.notNull(businessObjectFormatAttributesUpdateRequest, "A business object format attributes update request is required.");
Assert.notNull(businessObjectFormatAttributesUpdateRequest.getAttributes(), "A business object format attributes list is required.");
List<Attribute> attributes = businessObjectFormatAttributesUpdateRequest.getAttributes();
// Validate optional attributes. This is also going to trim the attribute names.
attributeHelper.validateFormatAttributes(attributes);
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
// Update the business object format attributes
updateBusinessObjectFormatAttributesHelper(businessObjectFormatEntity, attributes);
// Persist and refresh the entity.
businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatAttributeDefinitions.
@NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat updateBusinessObjectFormatAttributeDefinitions(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatAttributeDefinitionsUpdateRequest businessObjectFormatAttributeDefinitionsUpdateRequest) {
// Perform validation and trim the alternate key parameters.
businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey);
Assert.notNull(businessObjectFormatAttributeDefinitionsUpdateRequest, "A business object format attribute definitions update request is required.");
List<AttributeDefinition> attributeDefinitions = businessObjectFormatAttributeDefinitionsUpdateRequest.getAttributeDefinitions();
// Validate and trim optional attribute definitions. This is also going to trim the attribute definition names.
validateAndTrimBusinessObjectFormatAttributeDefinitionsHelper(attributeDefinitions);
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
// Update the business object format attributes
updateBusinessObjectFormatAttributeDefinitionsHelper(businessObjectFormatEntity, attributeDefinitions);
// Persist and refresh the entity.
businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImpl method validateBusinessObjectData.
/**
* Validate that business object data is supported by the business object data destroy feature.
*
* @param businessObjectDataEntity the business object data entity
* @param businessObjectDataKey the business object data key
*/
protected void validateBusinessObjectData(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) {
// Get business object format for this business object data.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat();
// Create a version-less key for the business object format.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), null);
// Get the latest version of the format to retrieve retention information.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatEntity.getLatestVersion() ? businessObjectFormatEntity : businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
// Get retention information.
String retentionType = latestVersionBusinessObjectFormatEntity.getRetentionType() != null ? latestVersionBusinessObjectFormatEntity.getRetentionType().getCode() : null;
Integer retentionPeriodInDays = latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays();
// Validate that retention information is specified for this business object format.
if (StringUtils.isBlank(retentionType) || retentionPeriodInDays == null) {
throw new IllegalArgumentException(String.format("Retention information is not configured for the business object format. Business object format: {%s}", businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey)));
}
// Validate the retention type.
if (!RetentionTypeEntity.PARTITION_VALUE.equals(retentionType)) {
throw new IllegalArgumentException(String.format("Retention type \"%s\" is not supported by the business object data destroy feature. Business object format: {%s}", retentionType, businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey)));
}
// Try to convert business object data primary partition value to a timestamp. If conversion is not successful, the method returns a null value.
Date primaryPartitionValue = businessObjectDataHelper.getDateFromString(businessObjectDataEntity.getPartitionValue());
// If primary partition values is not a date, this business object data is not supported by the business object data destroy feature.
if (primaryPartitionValue == null) {
throw new IllegalArgumentException(String.format("Primary partition value \"%s\" cannot get converted to a valid date. Business object data: {%s}", businessObjectDataEntity.getPartitionValue(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
}
// Get the current timestamp from the database.
Timestamp currentTimestamp = herdDao.getCurrentTimestamp();
// Compute the relative primary partition value threshold date based on the current timestamp and retention period value.
Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -retentionPeriodInDays).getTime());
// Validate that this business object data has it's primary partition value before or equal to the threshold date.
if (primaryPartitionValue.compareTo(primaryPartitionValueThreshold) > 0) {
throw new IllegalArgumentException(String.format("Business object data fails retention threshold check for retention type \"%s\" with retention period of %d days. Business object data: {%s}", retentionType, retentionPeriodInDays, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
}
}
Aggregations