Search in sources :

Example 11 with BusinessObjectFormatEntity

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);
}
Also used : BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Example 12 with BusinessObjectFormatEntity

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);
}
Also used : Arrays(java.util.Arrays) CustomDdlKey(org.finra.herd.model.api.xml.CustomDdlKey) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormatRetentionInformationUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatRetentionInformationUpdateRequest) Autowired(org.springframework.beans.factory.annotation.Autowired) BusinessObjectFormatDdl(org.finra.herd.model.api.xml.BusinessObjectFormatDdl) BusinessObjectFormatAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatAttributesUpdateRequest) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.finra.herd.model.api.xml.Attribute) Map(java.util.Map) BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) FileTypeDaoHelper(org.finra.herd.service.helper.FileTypeDaoHelper) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) BusinessObjectFormatHelper(org.finra.herd.service.helper.BusinessObjectFormatHelper) Collection(java.util.Collection) PartitionKeyGroupDaoHelper(org.finra.herd.service.helper.PartitionKeyGroupDaoHelper) MessageNotificationEventService(org.finra.herd.service.MessageNotificationEventService) Set(java.util.Set) AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition) BusinessObjectFormatDaoHelper(org.finra.herd.service.helper.BusinessObjectFormatDaoHelper) Collectors(java.util.stream.Collectors) NamespacePermissions(org.finra.herd.model.annotation.NamespacePermissions) List(java.util.List) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) BusinessObjectFormatUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatUpdateRequest) BusinessObjectFormatCreateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatCreateRequest) CollectionUtils(org.springframework.util.CollectionUtils) BusinessObjectFormatDdlCollectionRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionRequest) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission) BusinessObjectDefinitionHelper(org.finra.herd.service.helper.BusinessObjectDefinitionHelper) NamespacePermissionEnum(org.finra.herd.model.api.xml.NamespacePermissionEnum) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) DaoSpringModuleConfig(org.finra.herd.dao.config.DaoSpringModuleConfig) BusinessObjectFormatDao(org.finra.herd.dao.BusinessObjectFormatDao) BusinessObjectFormatParentsUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatParentsUpdateRequest) SearchIndexUpdateHelper(org.finra.herd.service.helper.SearchIndexUpdateHelper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SEARCH_INDEX_UPDATE_TYPE_UPDATE(org.finra.herd.model.dto.SearchIndexUpdateDto.SEARCH_INDEX_UPDATE_TYPE_UPDATE) Propagation(org.springframework.transaction.annotation.Propagation) DdlGeneratorFactory(org.finra.herd.service.helper.DdlGeneratorFactory) Service(org.springframework.stereotype.Service) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) CustomDdlDaoHelper(org.finra.herd.service.helper.CustomDdlDaoHelper) BusinessObjectDefinitionDaoHelper(org.finra.herd.service.helper.BusinessObjectDefinitionDaoHelper) BusinessObjectFormatService(org.finra.herd.service.BusinessObjectFormatService) BusinessObjectDataDao(org.finra.herd.dao.BusinessObjectDataDao) BusinessObjectFormatAttributeEntity(org.finra.herd.model.jpa.BusinessObjectFormatAttributeEntity) AlternateKeyHelper(org.finra.herd.service.helper.AlternateKeyHelper) BusinessObjectFormatDdlCollectionResponse(org.finra.herd.model.api.xml.BusinessObjectFormatDdlCollectionResponse) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) BusinessObjectDefinitionDao(org.finra.herd.dao.BusinessObjectDefinitionDao) PublishNotificationMessages(org.finra.herd.model.annotation.PublishNotificationMessages) BusinessObjectFormatDdlRequest(org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest) BusinessObjectFormatAttributeDefinitionsUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectFormatAttributeDefinitionsUpdateRequest) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatKeys(org.finra.herd.model.api.xml.BusinessObjectFormatKeys) NumberUtils(org.apache.commons.lang3.math.NumberUtils) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) Schema(org.finra.herd.model.api.xml.Schema) DdlGenerator(org.finra.herd.service.helper.DdlGenerator) Collections(java.util.Collections) AttributeHelper(org.finra.herd.service.helper.AttributeHelper) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) CustomDdlEntity(org.finra.herd.model.jpa.CustomDdlEntity) BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) ArrayList(java.util.ArrayList) AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition)

Example 13 with BusinessObjectFormatEntity

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);
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 14 with 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);
}
Also used : AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 15 with 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)));
    }
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)181 Test (org.junit.Test)100 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)72 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)53 ArrayList (java.util.ArrayList)43 StorageEntity (org.finra.herd.model.jpa.StorageEntity)37 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)32 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)32 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)28 Predicate (javax.persistence.criteria.Predicate)25 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)25 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)25 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)23 Attribute (org.finra.herd.model.api.xml.Attribute)22 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)22 BusinessObjectDefinitionColumn (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumn)20 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)20 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)18 BusinessObjectDefinitionColumnEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity)18