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;
}
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;
}
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();
}
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();
}
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);
}
Aggregations