use of org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectFormatHelper method createBusinessObjectFormatFromEntity.
/**
* Creates the business object format from the persisted entity.
*
* @param businessObjectFormatEntity the newly persisted business object format entity.
*
* @param checkLatestVersion need to check latest version
*
* @return the business object format.
*/
public BusinessObjectFormat createBusinessObjectFormatFromEntity(BusinessObjectFormatEntity businessObjectFormatEntity, Boolean checkLatestVersion) {
BusinessObjectFormat businessObjectFormat = new BusinessObjectFormat();
businessObjectFormat.setId(businessObjectFormatEntity.getId());
businessObjectFormat.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
businessObjectFormat.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
businessObjectFormat.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
businessObjectFormat.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
businessObjectFormat.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
businessObjectFormat.setLatestVersion(businessObjectFormatEntity.getLatestVersion());
businessObjectFormat.setPartitionKey(businessObjectFormatEntity.getPartitionKey());
businessObjectFormat.setDescription(businessObjectFormatEntity.getDescription());
// Add in the attributes.
List<Attribute> attributes = new ArrayList<>();
businessObjectFormat.setAttributes(attributes);
for (BusinessObjectFormatAttributeEntity attributeEntity : businessObjectFormatEntity.getAttributes()) {
Attribute attribute = new Attribute();
attributes.add(attribute);
attribute.setName(attributeEntity.getName());
attribute.setValue(attributeEntity.getValue());
}
// Add in the attribute definitions.
List<AttributeDefinition> attributeDefinitions = new ArrayList<>();
businessObjectFormat.setAttributeDefinitions(attributeDefinitions);
for (BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity : businessObjectFormatEntity.getAttributeDefinitions()) {
AttributeDefinition attributeDefinition = new AttributeDefinition();
attributeDefinitions.add(attributeDefinition);
attributeDefinition.setName(attributeDefinitionEntity.getName());
attributeDefinition.setPublish(attributeDefinitionEntity.getPublish());
}
// Only add schema information if this format has any schema columns defined.
if (!businessObjectFormatEntity.getSchemaColumns().isEmpty()) {
Schema schema = new Schema();
businessObjectFormat.setSchema(schema);
schema.setNullValue(businessObjectFormatEntity.getNullValue());
schema.setDelimiter(businessObjectFormatEntity.getDelimiter());
schema.setEscapeCharacter(businessObjectFormatEntity.getEscapeCharacter());
schema.setPartitionKeyGroup(businessObjectFormatEntity.getPartitionKeyGroup() != null ? businessObjectFormatEntity.getPartitionKeyGroup().getPartitionKeyGroupName() : null);
// Create two lists of schema column entities: one for the data columns and one for the partition columns.
List<SchemaColumnEntity> dataSchemaColumns = new ArrayList<>();
List<SchemaColumnEntity> partitionSchemaColumns = new ArrayList<>();
for (SchemaColumnEntity schemaColumnEntity : businessObjectFormatEntity.getSchemaColumns()) {
// We can determine which list (or both) a column entity belongs to depending on whether it has a position and/or partition level set.
if (schemaColumnEntity.getPosition() != null) {
dataSchemaColumns.add(schemaColumnEntity);
}
if (schemaColumnEntity.getPartitionLevel() != null) {
partitionSchemaColumns.add(schemaColumnEntity);
}
}
// Sort the data schema columns on the position.
Collections.sort(dataSchemaColumns, new SchemaColumnPositionComparator());
// Sort the partition schema columns on the partition level.
Collections.sort(partitionSchemaColumns, new SchemaColumnPartitionLevelComparator());
// Add in the data schema columns.
List<SchemaColumn> schemaColumns = new ArrayList<>();
schema.setColumns(schemaColumns);
for (SchemaColumnEntity schemaColumnEntity : dataSchemaColumns) {
schemaColumns.add(createSchemaColumn(schemaColumnEntity));
}
// columns which isn't valid from an XSD standpoint.
if (partitionSchemaColumns.size() > 0) {
schemaColumns = new ArrayList<>();
schema.setPartitions(schemaColumns);
for (SchemaColumnEntity schemaColumnEntity : partitionSchemaColumns) {
schemaColumns.add(createSchemaColumn(schemaColumnEntity));
}
}
}
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatEntity;
// use the latest version if it is not
if (checkLatestVersion) {
BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(businessObjectFormatEntity);
businessObjectFormatKey.setBusinessObjectFormatVersion(null);
latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
}
// add business object format parent
List<BusinessObjectFormatKey> businessObjectFormatParents = new ArrayList();
businessObjectFormat.setBusinessObjectFormatParents(businessObjectFormatParents);
for (BusinessObjectFormatEntity businessObjectFormatEntityParent : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatParents()) {
BusinessObjectFormatKey businessObjectFormatParent = getBusinessObjectFormatKey(businessObjectFormatEntityParent);
businessObjectFormatParent.setBusinessObjectFormatVersion(null);
businessObjectFormatParents.add(businessObjectFormatParent);
}
// add business object format children
List<BusinessObjectFormatKey> businessObjectFormatChildren = new ArrayList();
businessObjectFormat.setBusinessObjectFormatChildren(businessObjectFormatChildren);
for (BusinessObjectFormatEntity businessObjectFormatEntityChild : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatChildren()) {
BusinessObjectFormatKey businessObjectFormatChild = getBusinessObjectFormatKey(businessObjectFormatEntityChild);
businessObjectFormatChild.setBusinessObjectFormatVersion(null);
businessObjectFormatChildren.add(businessObjectFormatChild);
}
// add retention information
businessObjectFormat.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag());
businessObjectFormat.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays());
if (latestVersionBusinessObjectFormatEntity.getRetentionType() != null) {
businessObjectFormat.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType().getCode());
}
return businessObjectFormat;
}
use of org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity 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.BusinessObjectDataAttributeDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTestHelper method createBusinessObjectFormatEntity.
/**
* Creates and persists a new business object format entity.
*
* @return the newly created business object format entity.
*/
public BusinessObjectFormatEntity createBusinessObjectFormatEntity(boolean includeAttributeDefinition) {
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setBusinessObjectDefinition(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinition());
businessObjectFormatEntity.setDescription("test");
businessObjectFormatEntity.setFileType(fileTypeDaoTestHelper.createFileTypeEntity());
businessObjectFormatEntity.setBusinessObjectFormatVersion(0);
businessObjectFormatEntity.setLatestVersion(true);
businessObjectFormatEntity.setUsage("PRC");
businessObjectFormatEntity.setPartitionKey("testPartitionKey");
if (includeAttributeDefinition) {
List<BusinessObjectDataAttributeDefinitionEntity> attributeDefinitionEntities = new ArrayList<>();
businessObjectFormatEntity.setAttributeDefinitions(attributeDefinitionEntities);
BusinessObjectDataAttributeDefinitionEntity attributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
attributeDefinitionEntities.add(attributeDefinitionEntity);
attributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
attributeDefinitionEntity.setName(AbstractDaoTest.ATTRIBUTE_NAME_1_MIXED_CASE);
}
return businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTestHelper method createBusinessObjectDataAttributeDefinitionEntity.
/**
* Creates and persists a new business object data attribute definition entity.
*
* @param businessObjectFormatEntity the business object format entity
* @param businessObjectDataAttributeName the business object data attribute name
* @param publishBusinessObjectDataAttribute specifies if this business object data attribute should be published in notification messages
*
* @return the newly created business object data attribute definition entity.
*/
public BusinessObjectDataAttributeDefinitionEntity createBusinessObjectDataAttributeDefinitionEntity(BusinessObjectFormatEntity businessObjectFormatEntity, String businessObjectDataAttributeName, boolean publishBusinessObjectDataAttribute) {
// Create a new business object data attribute definition entity.
BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
businessObjectDataAttributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataAttributeDefinitionEntity.setName(businessObjectDataAttributeName);
businessObjectDataAttributeDefinitionEntity.setPublish(publishBusinessObjectDataAttribute);
// Update the parent entity.
businessObjectFormatEntity.getAttributeDefinitions().add(businessObjectDataAttributeDefinitionEntity);
businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
return businessObjectDataAttributeDefinitionEntity;
}
use of org.finra.herd.model.jpa.BusinessObjectDataAttributeDefinitionEntity in project herd by FINRAOS.
the class AttributeDaoHelperTest method testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsAttributeNamesEqualIgnoreCase.
@Test
public void testValidateAttributesAgainstBusinessObjectDataAttributeDefinitionsAttributeNamesEqualIgnoreCase() {
// Create a business object data attribute definition for a required attribute with attribute name in upper case.
BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
businessObjectDataAttributeDefinitionEntity.setName(ATTRIBUTE_NAME.toUpperCase());
// Call the method under test with the attribute name specified in lowercase.
attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(Arrays.asList(new Attribute(ATTRIBUTE_NAME.toLowerCase(), ATTRIBUTE_VALUE)), Arrays.asList(businessObjectDataAttributeDefinitionEntity));
// Verify the external calls.
verifyNoMoreInteractionsHelper();
}
Aggregations