use of org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity in project herd by FINRAOS.
the class BusinessObjectDataHelper method createBusinessObjectDataFromEntity.
/**
* Creates the business object data from the persisted entity.
*
* @param businessObjectDataEntity the newly persisted business object data entity.
* @param includeBusinessObjectDataStatusHistory specifies to include business object data status history in the response
* @param includeStorageUnitStatusHistory specifies to include storage unit status history for each storage unit in the response
*
* @return the business object data.
*/
public BusinessObjectData createBusinessObjectDataFromEntity(BusinessObjectDataEntity businessObjectDataEntity, Boolean includeBusinessObjectDataStatusHistory, Boolean includeStorageUnitStatusHistory) {
// Make the business object format associated with this data easily accessible.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat();
// Create the core business object data information.
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectData.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
businessObjectData.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
businessObjectData.setId(businessObjectDataEntity.getId());
businessObjectData.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
businessObjectData.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
businessObjectData.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
businessObjectData.setPartitionKey(businessObjectDataEntity.getBusinessObjectFormat().getPartitionKey());
businessObjectData.setPartitionValue(businessObjectDataEntity.getPartitionValue());
businessObjectData.setSubPartitionValues(getSubPartitionValues(businessObjectDataEntity));
businessObjectData.setStatus(businessObjectDataEntity.getStatus().getCode());
businessObjectData.setVersion(businessObjectDataEntity.getVersion());
businessObjectData.setLatestVersion(businessObjectDataEntity.getLatestVersion());
// Add in the storage units.
businessObjectData.setStorageUnits(storageUnitHelper.createStorageUnitsFromEntities(businessObjectDataEntity.getStorageUnits(), includeStorageUnitStatusHistory));
// Add in the attributes.
List<Attribute> attributes = new ArrayList<>();
businessObjectData.setAttributes(attributes);
for (BusinessObjectDataAttributeEntity attributeEntity : businessObjectDataEntity.getAttributes()) {
Attribute attribute = new Attribute();
attributes.add(attribute);
attribute.setName(attributeEntity.getName());
attribute.setValue(attributeEntity.getValue());
}
// Add in the parents - sorted.
List<BusinessObjectDataKey> businessObjectDataKeys = new ArrayList<>();
businessObjectData.setBusinessObjectDataParents(businessObjectDataKeys);
for (BusinessObjectDataEntity parent : businessObjectDataEntity.getBusinessObjectDataParents()) {
businessObjectDataKeys.add(createBusinessObjectDataKeyFromEntity(parent));
}
Collections.sort(businessObjectDataKeys, new BusinessObjectDataKeyComparator());
// Add in the children - sorted.
businessObjectDataKeys = new ArrayList<>();
businessObjectData.setBusinessObjectDataChildren(businessObjectDataKeys);
for (BusinessObjectDataEntity parent : businessObjectDataEntity.getBusinessObjectDataChildren()) {
businessObjectDataKeys.add(createBusinessObjectDataKeyFromEntity(parent));
}
Collections.sort(businessObjectDataKeys, new BusinessObjectDataKeyComparator());
// If specified, add business object data status history.
if (BooleanUtils.isTrue(includeBusinessObjectDataStatusHistory)) {
List<BusinessObjectDataStatusChangeEvent> businessObjectDataStatusChangeEvents = new ArrayList<>();
businessObjectData.setBusinessObjectDataStatusHistory(businessObjectDataStatusChangeEvents);
for (BusinessObjectDataStatusHistoryEntity businessObjectDataStatusHistoryEntity : businessObjectDataEntity.getHistoricalStatuses()) {
businessObjectDataStatusChangeEvents.add(new BusinessObjectDataStatusChangeEvent(businessObjectDataStatusHistoryEntity.getStatus().getCode(), HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDataStatusHistoryEntity.getCreatedOn()), businessObjectDataStatusHistoryEntity.getCreatedBy()));
}
}
return businessObjectData;
}
Aggregations