Search in sources :

Example 6 with BusinessObjectDataAttributeDefinitionEntity

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

the class BusinessObjectFormatServiceImpl method createAttributeDefinitionEntities.

/**
 * Creates a list of attribute definition entities.
 *
 * @param attributeDefinitions the list of attribute definitions
 * @param businessObjectFormatEntity the business object format entity
 *
 * @return the newly created list of attribute definition entities
 */
private List<BusinessObjectDataAttributeDefinitionEntity> createAttributeDefinitionEntities(List<AttributeDefinition> attributeDefinitions, BusinessObjectFormatEntity businessObjectFormatEntity) {
    List<BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntities = new ArrayList<>();
    if (!CollectionUtils.isEmpty(attributeDefinitions)) {
        for (AttributeDefinition attributeDefinition : attributeDefinitions) {
            // Create a new business object data attribute definition entity.
            BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
            attributeDefinitionEntities.add(attributeDefinitionEntity);
            attributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
            attributeDefinitionEntity.setName(attributeDefinition.getName());
            // For the "publish" option, default a Boolean null value to "false".
            attributeDefinitionEntity.setPublish(BooleanUtils.isTrue(attributeDefinition.isPublish()));
        }
    }
    return attributeDefinitionEntities;
}
Also used : BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) ArrayList(java.util.ArrayList) AttributeDefinition(org.finra.herd.model.api.xml.AttributeDefinition)

Example 7 with BusinessObjectDataAttributeDefinitionEntity

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

the class DefaultNotificationMessageBuilder method getBusinessObjectDataStatusChangeMessageVelocityContextMap.

/**
 * Returns Velocity context map of additional keys and values to place in the velocity context.
 *
 * @param businessObjectDataKey the business object data key
 * @param newBusinessObjectDataStatus the new business object data status
 * @param oldBusinessObjectDataStatus the old business object data status
 *
 * @return the Velocity context map
 */
private Map<String, Object> getBusinessObjectDataStatusChangeMessageVelocityContextMap(BusinessObjectDataKey businessObjectDataKey, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus) {
    // Create a context map of values that can be used when building the message.
    Map<String, Object> velocityContextMap = new HashMap<>();
    velocityContextMap.put("businessObjectDataKey", businessObjectDataKey);
    velocityContextMap.put("newBusinessObjectDataStatus", newBusinessObjectDataStatus);
    velocityContextMap.put("oldBusinessObjectDataStatus", oldBusinessObjectDataStatus);
    // Retrieve business object data entity and business object data id to the context.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
    velocityContextMap.put("businessObjectDataId", businessObjectDataEntity.getId());
    // Load all attribute definitions for this business object data in a map for easy access.
    Map<String, BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntityMap = businessObjectFormatHelper.getAttributeDefinitionEntities(businessObjectDataEntity.getBusinessObjectFormat());
    // Build an ordered map of business object data attributes that are flagged to be published in notification messages.
    Map<String, String> businessObjectDataAttributes = new LinkedHashMap<>();
    if (!attributeDefinitionEntityMap.isEmpty()) {
        for (BusinessObjectDataAttributeEntity attributeEntity : businessObjectDataEntity.getAttributes()) {
            if (attributeDefinitionEntityMap.containsKey(attributeEntity.getName().toUpperCase())) {
                BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity = attributeDefinitionEntityMap.get(attributeEntity.getName().toUpperCase());
                if (BooleanUtils.isTrue(attributeDefinitionEntity.getPublish())) {
                    businessObjectDataAttributes.put(attributeEntity.getName(), attributeEntity.getValue());
                }
            }
        }
    }
    // Add the map of business object data attributes to the context.
    velocityContextMap.put("businessObjectDataAttributes", businessObjectDataAttributes);
    // Add the namespace to the header.
    velocityContextMap.put("namespace", businessObjectDataKey.getNamespace());
    return velocityContextMap;
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with BusinessObjectDataAttributeDefinitionEntity

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

the class AttributeDaoHelperTest method testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeHasBlankValue.

@Test
public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeHasBlankValue() {
    // Create a business object data attribute definition for a required attribute.
    BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
    businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME);
    // Try to call the method under test.
    try {
        attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(Arrays.asList(new Attribute(ATTRIBUTE_NAME, BLANK_TEXT)), Arrays.asList(businessObjectDataAttributeDefinitionEntity));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", ATTRIBUTE_NAME), e.getMessage());
    }
    // Verify the external calls.
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) Attribute(org.finra.herd.model.api.xml.Attribute) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 9 with BusinessObjectDataAttributeDefinitionEntity

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

the class AttributeDaoHelperTest method testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeIsMissing.

@Test
public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsRequiredAttributeIsMissing() {
    // Create a business object data attribute definition for a required attribute.
    BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
    businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME);
    // Try to call the method under test.
    try {
        attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(NO_ATTRIBUTES, Arrays.asList(businessObjectDataAttributeDefinitionEntity));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("The business object format has a required attribute \"%s\" which was not specified or has a value which is blank.", ATTRIBUTE_NAME), e.getMessage());
    }
    // Verify the external calls.
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 10 with BusinessObjectDataAttributeDefinitionEntity

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

the class BusinessObjectDataServiceImplTest method testUpdateBusinessObjectDataAttributes.

@Test
public void testUpdateBusinessObjectDataAttributes() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create a list of attributes.
    List<Attribute> attributes = Arrays.asList(new Attribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE));
    // Create a business object data attributes update request.
    BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest = new BusinessObjectDataAttributesUpdateRequest(attributes);
    // Create a list of attribute definitions.
    List<BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntities = Arrays.asList(new BusinessObjectDataAttributeDefinitionEntity());
    // Create a business object format definition.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    businessObjectFormatEntity.setAttributeDefinitions(attributeDefinitionEntities);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    // Create a business object data.
    BusinessObjectData businessObjectData = new BusinessObjectData();
    businessObjectData.setId(ID);
    // Mock the external calls.
    when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
    when(businessObjectDataDao.saveAndRefresh(businessObjectDataEntity)).thenReturn(businessObjectDataEntity);
    when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity)).thenReturn(businessObjectData);
    // Call the method under test.
    BusinessObjectData result = businessObjectDataServiceImpl.updateBusinessObjectDataAttributes(businessObjectDataKey, businessObjectDataAttributesUpdateRequest);
    // Verify the external calls.
    verify(businessObjectDataHelper).validateBusinessObjectDataKey(businessObjectDataKey, true, true);
    verify(attributeHelper).validateAttributes(attributes);
    verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
    verify(attributeDaoHelper).validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, attributeDefinitionEntities);
    verify(attributeDaoHelper).updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes);
    verify(businessObjectDataDao).saveAndRefresh(businessObjectDataEntity);
    verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataEntity);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertEquals(businessObjectData, result);
}
Also used : BusinessObjectDataAttributeDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) BusinessObjectDataAttributesUpdateRequest(org.finra.herd.model.api.xml.BusinessObjectDataAttributesUpdateRequest) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

BusinessObjectDataAttributeDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity)10 Attribute (org.finra.herd.model.api.xml.Attribute)5 ArrayList (java.util.ArrayList)4 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)4 AttributeDefinition (org.finra.herd.model.api.xml.AttributeDefinition)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)2 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)2 Schema (org.finra.herd.model.api.xml.Schema)2 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)2 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)2 BusinessObjectFormatAttributeEntity (org.finra.herd.model.jpa.BusinessObjectFormatAttributeEntity)2 SchemaColumnEntity (org.finra.herd.model.jpa.SchemaColumnEntity)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1