use of org.finra.herd.model.api.xml.Attribute 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;
}
use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoHelper method createBusinessObjectDefinitionEntity.
/**
* Create Business Object Definition Entity
* @param request business object definition create request
* @return Business Object Definition Entity
*/
public BusinessObjectDefinitionEntity createBusinessObjectDefinitionEntity(BusinessObjectDefinitionCreateRequest request) {
// Perform the validation.
validateBusinessObjectDefinitionCreateRequest(request);
// Get the namespace and ensure it exists.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
// Get the data provider and ensure it exists.
DataProviderEntity dataProviderEntity = dataProviderDaoHelper.getDataProviderEntity(request.getDataProviderName());
// Get business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(request.getNamespace(), request.getBusinessObjectDefinitionName());
// Ensure a business object definition with the specified key doesn't already exist.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
if (businessObjectDefinitionEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create business object definition with name \"%s\" because it already exists for namespace \"%s\".", businessObjectDefinitionKey.getBusinessObjectDefinitionName(), businessObjectDefinitionKey.getNamespace()));
}
// Create a new entity.
businessObjectDefinitionEntity = new BusinessObjectDefinitionEntity();
businessObjectDefinitionEntity.setNamespace(namespaceEntity);
businessObjectDefinitionEntity.setName(request.getBusinessObjectDefinitionName());
businessObjectDefinitionEntity.setDescription(request.getDescription());
businessObjectDefinitionEntity.setDataProvider(dataProviderEntity);
businessObjectDefinitionEntity.setDisplayName(request.getDisplayName());
// Create the attributes if they are specified.
if (!CollectionUtils.isEmpty(request.getAttributes())) {
List<BusinessObjectDefinitionAttributeEntity> attributeEntities = new ArrayList<>();
businessObjectDefinitionEntity.setAttributes(attributeEntities);
for (Attribute attribute : request.getAttributes()) {
BusinessObjectDefinitionAttributeEntity attributeEntity = new BusinessObjectDefinitionAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
// Persist the change event entity
saveBusinessObjectDefinitionChangeEvents(businessObjectDefinitionEntity);
// Persist and return the new entity.
return businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
use of org.finra.herd.model.api.xml.Attribute 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.api.xml.Attribute in project herd by FINRAOS.
the class AttributeHelper method validateAttributes.
/**
* Validates the attributes.
*
* @param attributes the attributes to validate. Null shouldn't be specified.
* @return the validated attribute map
* @throws IllegalArgumentException if any invalid attributes were found.
*/
public Map<String, String> validateAttributes(List<Attribute> attributes) throws IllegalArgumentException {
// Validate attributes if they are specified.
Map<String, String> attributeNameValidationMap = new HashMap<>();
if (!CollectionUtils.isEmpty(attributes)) {
for (Attribute attribute : attributes) {
attribute.setName(alternateKeyHelper.validateStringParameter("An", "attribute name", attribute.getName()));
// Ensure the attribute key isn't a duplicate by using a map with a "lowercase" name as the key for case insensitivity.
String validationMapKey = attribute.getName().toLowerCase();
if (attributeNameValidationMap.containsKey(validationMapKey)) {
throw new IllegalArgumentException("Duplicate attribute name found: " + attribute.getName());
}
attributeNameValidationMap.put(validationMapKey, attribute.getValue());
}
}
return attributeNameValidationMap;
}
use of org.finra.herd.model.api.xml.Attribute 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);
}
Aggregations