Search in sources :

Example 1 with BusinessObjectDataAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoHelper method createBusinessObjectDataEntity.

/**
 * Creates a new business object data entity from the request information.
 *
 * @param request the request.
 * @param businessObjectFormatEntity the business object format entity.
 * @param businessObjectDataVersion the business object data version.
 *
 * @return the newly created business object data entity.
 */
private BusinessObjectDataEntity createBusinessObjectDataEntity(BusinessObjectDataCreateRequest request, BusinessObjectFormatEntity businessObjectFormatEntity, Integer businessObjectDataVersion, BusinessObjectDataStatusEntity businessObjectDataStatusEntity) {
    // Create a new entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setPartitionValue(request.getPartitionValue());
    int subPartitionValuesCount = CollectionUtils.size(request.getSubPartitionValues());
    businessObjectDataEntity.setPartitionValue2(subPartitionValuesCount > 0 ? request.getSubPartitionValues().get(0) : null);
    businessObjectDataEntity.setPartitionValue3(subPartitionValuesCount > 1 ? request.getSubPartitionValues().get(1) : null);
    businessObjectDataEntity.setPartitionValue4(subPartitionValuesCount > 2 ? request.getSubPartitionValues().get(2) : null);
    businessObjectDataEntity.setPartitionValue5(subPartitionValuesCount > 3 ? request.getSubPartitionValues().get(3) : null);
    businessObjectDataEntity.setVersion(businessObjectDataVersion);
    businessObjectDataEntity.setLatestVersion(true);
    businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
    // Create the storage unit entities.
    businessObjectDataEntity.setStorageUnits(createStorageUnitEntitiesFromStorageUnits(request.getStorageUnits(), businessObjectDataEntity));
    // Create the attributes.
    List<BusinessObjectDataAttributeEntity> attributeEntities = new ArrayList<>();
    businessObjectDataEntity.setAttributes(attributeEntities);
    if (CollectionUtils.isNotEmpty(request.getAttributes())) {
        for (Attribute attribute : request.getAttributes()) {
            BusinessObjectDataAttributeEntity attributeEntity = new BusinessObjectDataAttributeEntity();
            attributeEntities.add(attributeEntity);
            attributeEntity.setBusinessObjectData(businessObjectDataEntity);
            attributeEntity.setName(attribute.getName());
            attributeEntity.setValue(attribute.getValue());
        }
    }
    // Create the parents.
    List<BusinessObjectDataEntity> businessObjectDataParents = new ArrayList<>();
    businessObjectDataEntity.setBusinessObjectDataParents(businessObjectDataParents);
    // Loop through all the business object data parents.
    if (request.getBusinessObjectDataParents() != null) {
        for (BusinessObjectDataKey businessObjectDataKey : request.getBusinessObjectDataParents()) {
            // Look up the business object data for each parent.
            BusinessObjectDataEntity businessObjectDataParent = getBusinessObjectDataEntity(businessObjectDataKey);
            // Add our newly created entity as a dependent (i.e. child) of the looked up parent.
            businessObjectDataParent.getBusinessObjectDataChildren().add(businessObjectDataEntity);
            // Add the looked up parent as a parent of our newly created entity.
            businessObjectDataParents.add(businessObjectDataParent);
        }
    }
    // Return the newly created entity.
    return businessObjectDataEntity;
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) Attribute(org.finra.herd.model.api.xml.Attribute) ArrayList(java.util.ArrayList) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 2 with BusinessObjectDataAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDataAttributeDaoHelper method getBusinessObjectDataAttributeEntity.

/**
 * Gets a business object data attribute entity on the key and makes sure that it exists.
 *
 * @param businessObjectDataAttributeKey the business object data attribute key
 *
 * @return the business object data attribute entity
 * @throws ObjectNotFoundException if the business object data or the business object data attribute don't exist
 */
public BusinessObjectDataAttributeEntity getBusinessObjectDataAttributeEntity(BusinessObjectDataAttributeKey businessObjectDataAttributeKey) throws ObjectNotFoundException {
    // Get the business object data and ensure it exists.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(new BusinessObjectDataKey(businessObjectDataAttributeKey.getNamespace(), businessObjectDataAttributeKey.getBusinessObjectDefinitionName(), businessObjectDataAttributeKey.getBusinessObjectFormatUsage(), businessObjectDataAttributeKey.getBusinessObjectFormatFileType(), businessObjectDataAttributeKey.getBusinessObjectFormatVersion(), businessObjectDataAttributeKey.getPartitionValue(), businessObjectDataAttributeKey.getSubPartitionValues(), businessObjectDataAttributeKey.getBusinessObjectDataVersion()));
    // Load all existing business object data attribute entities into a map for quick access using lowercase attribute names.
    Map<String, BusinessObjectDataAttributeEntity> businessObjectDataAttributeEntityMap = getBusinessObjectDataAttributeEntityMap(businessObjectDataEntity.getAttributes());
    // Get the relative entity using the attribute name in lowercase.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeEntityMap.get(businessObjectDataAttributeKey.getBusinessObjectDataAttributeName().toLowerCase());
    if (businessObjectDataAttributeEntity == null) {
        throw new ObjectNotFoundException(String.format("Attribute with name \"%s\" does not exist for business object data {%s}.", businessObjectDataAttributeKey.getBusinessObjectDataAttributeName(), businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
    }
    return businessObjectDataAttributeEntity;
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey)

Example 3 with BusinessObjectDataAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity in project herd by FINRAOS.

the class AttributeDaoHelper method updateBusinessObjectDataAttributes.

/**
 * Updates business object data attributes.
 *
 * @param businessObjectDataEntity the business object data entity
 * @param attributes the attributes
 */
public void updateBusinessObjectDataAttributes(BusinessObjectDataEntity businessObjectDataEntity, final List<Attribute> attributes) {
    // Load all existing attribute entities in a map with a "lowercase" attribute name as the key for case insensitivity.
    Map<String, BusinessObjectDataAttributeEntity> existingAttributeEntities = new HashMap<>();
    for (BusinessObjectDataAttributeEntity attributeEntity : businessObjectDataEntity.getAttributes()) {
        String mapKey = attributeEntity.getName().toLowerCase();
        if (existingAttributeEntities.containsKey(mapKey)) {
            throw new IllegalStateException(String.format("Found duplicate attribute with name \"%s\" for business object data. Business object data: {%s}", mapKey, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
        }
        existingAttributeEntities.put(mapKey, attributeEntity);
    }
    // Process the list of attributes to determine that business object definition attribute entities should be created, updated, or deleted.
    List<BusinessObjectDataAttributeEntity> createdAttributeEntities = new ArrayList<>();
    List<BusinessObjectDataAttributeEntity> retainedAttributeEntities = new ArrayList<>();
    if (!CollectionUtils.isEmpty(attributes)) {
        for (Attribute attribute : attributes) {
            // Use a "lowercase" attribute name for case insensitivity.
            String lowercaseAttributeName = attribute.getName().toLowerCase();
            if (existingAttributeEntities.containsKey(lowercaseAttributeName)) {
                // Check if the attribute value needs to be updated.
                BusinessObjectDataAttributeEntity attributeEntity = existingAttributeEntities.get(lowercaseAttributeName);
                if (!StringUtils.equals(attribute.getValue(), attributeEntity.getValue())) {
                    // Update the business object attribute entity.
                    attributeEntity.setValue(attribute.getValue());
                }
                // Add this entity to the list of business object definition attribute entities to be retained.
                retainedAttributeEntities.add(attributeEntity);
            } else {
                // Create a new business object attribute entity.
                BusinessObjectDataAttributeEntity attributeEntity = new BusinessObjectDataAttributeEntity();
                businessObjectDataEntity.getAttributes().add(attributeEntity);
                attributeEntity.setBusinessObjectData(businessObjectDataEntity);
                attributeEntity.setName(attribute.getName());
                attributeEntity.setValue(attribute.getValue());
                // Add this entity to the list of the newly created business object definition attribute entities.
                createdAttributeEntities.add(attributeEntity);
            }
        }
    }
    // Remove any of the currently existing attribute entities that did not get onto the retained entities list.
    businessObjectDataEntity.getAttributes().retainAll(retainedAttributeEntities);
    // Add all of the newly created business object definition attribute entities.
    businessObjectDataEntity.getAttributes().addAll(createdAttributeEntities);
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) HashMap(java.util.HashMap) Attribute(org.finra.herd.model.api.xml.Attribute) ArrayList(java.util.ArrayList)

Example 4 with BusinessObjectDataAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDataAttributeServiceTest method testUpdateBusinessObjectDataAttributeRequiredAttribute.

@Test
public void testUpdateBusinessObjectDataAttributeRequiredAttribute() {
    // Create and persist a business object data attribute definition entity.
    businessObjectFormatDaoTestHelper.createBusinessObjectDataAttributeDefinitionEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE);
    // Create and persist a required business object data attribute entity.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1);
    // Update the required business object data attribute.
    BusinessObjectDataAttribute updatedBusinessObjectDataAttribute = businessObjectDataAttributeService.updateBusinessObjectDataAttribute(new BusinessObjectDataAttributeKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE), businessObjectDataAttributeServiceTestHelper.createBusinessObjectDataAttributeUpdateRequest(ATTRIBUTE_VALUE_2));
    // Validate the returned object.
    businessObjectDataAttributeServiceTestHelper.validateBusinessObjectDataAttribute(businessObjectDataAttributeEntity.getId(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_2, updatedBusinessObjectDataAttribute);
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataAttribute(org.finra.herd.model.api.xml.BusinessObjectDataAttribute) BusinessObjectDataAttributeKey(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey) Test(org.junit.Test)

Example 5 with BusinessObjectDataAttributeEntity

use of org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity in project herd by FINRAOS.

the class BusinessObjectDataAttributeServiceTest method testUpdateBusinessObjectDataAttributeUpperCaseParameters.

@Test
public void testUpdateBusinessObjectDataAttributeUpperCaseParameters() {
    // Create and persist a business object data attribute entity using lower case values.
    BusinessObjectDataAttributeEntity businessObjectDataAttributeEntity = businessObjectDataAttributeDaoTestHelper.createBusinessObjectDataAttributeEntity(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE.toLowerCase(), convertListToLowerCase(SUBPARTITION_VALUES), DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), ATTRIBUTE_VALUE_1.toLowerCase());
    // Update the business object data attribute using upper case input parameters (except for case-sensitive partition values).
    BusinessObjectDataAttribute updatedBusinessObjectDataAttribute = businessObjectDataAttributeService.updateBusinessObjectDataAttribute(new BusinessObjectDataAttributeKey(NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase(), FORMAT_USAGE_CODE.toUpperCase(), FORMAT_FILE_TYPE_CODE.toUpperCase(), FORMAT_VERSION, PARTITION_VALUE.toLowerCase(), convertListToLowerCase(SUBPARTITION_VALUES), DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase()), businessObjectDataAttributeServiceTestHelper.createBusinessObjectDataAttributeUpdateRequest(ATTRIBUTE_VALUE_2.toUpperCase()));
    // Validate the returned object.
    businessObjectDataAttributeServiceTestHelper.validateBusinessObjectDataAttribute(businessObjectDataAttributeEntity.getId(), NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), FORMAT_VERSION, PARTITION_VALUE.toLowerCase(), convertListToLowerCase(SUBPARTITION_VALUES), DATA_VERSION, ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), ATTRIBUTE_VALUE_2.toUpperCase(), updatedBusinessObjectDataAttribute);
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataAttribute(org.finra.herd.model.api.xml.BusinessObjectDataAttribute) BusinessObjectDataAttributeKey(org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey) Test(org.junit.Test)

Aggregations

BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)56 Test (org.junit.Test)41 BusinessObjectDataAttribute (org.finra.herd.model.api.xml.BusinessObjectDataAttribute)27 ArrayList (java.util.ArrayList)24 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)23 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)23 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)15 HashMap (java.util.HashMap)11 FieldExtension (org.activiti.bpmn.model.FieldExtension)9 Parameter (org.finra.herd.model.api.xml.Parameter)9 Attribute (org.finra.herd.model.api.xml.Attribute)8 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)8 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)6 AttributeValueFilter (org.finra.herd.model.api.xml.AttributeValueFilter)6 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)6 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)3 HashSet (java.util.HashSet)2 Predicate (javax.persistence.criteria.Predicate)2