Search in sources :

Example 6 with BusinessObjectDataStatusHistoryEntity

use of org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity 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;
}
Also used : BusinessObjectDataAttributeEntity(org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity) BusinessObjectDataStatusChangeEvent(org.finra.herd.model.api.xml.BusinessObjectDataStatusChangeEvent) BusinessObjectDataStatusHistoryEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity) BusinessObjectData(org.finra.herd.model.api.xml.BusinessObjectData) Attribute(org.finra.herd.model.api.xml.Attribute) ArrayList(java.util.ArrayList) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity)

Aggregations

BusinessObjectDataStatusHistoryEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusHistoryEntity)6 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)5 ArrayList (java.util.ArrayList)4 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)2 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)2 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)1 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)1 BusinessObjectDataStatusChangeEvent (org.finra.herd.model.api.xml.BusinessObjectDataStatusChangeEvent)1 BusinessObjectDataStorageUnitKey (org.finra.herd.model.api.xml.BusinessObjectDataStorageUnitKey)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)1 Test (org.junit.Test)1