Search in sources :

Example 56 with BusinessObjectDataAttributeEntity

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;
}
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

BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)56 Test (org.junit.Test)41 BusinessObjectDataAttribute (org.finra.herd.model.api.xml.BusinessObjectDataAttribute)27 ArrayList (java.util.ArrayList)24 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)23 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)23 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)15 HashMap (java.util.HashMap)11 FieldExtension (org.activiti.bpmn.model.FieldExtension)9 Parameter (org.finra.herd.model.api.xml.Parameter)9 Attribute (org.finra.herd.model.api.xml.Attribute)8 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)8 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)6 AttributeValueFilter (org.finra.herd.model.api.xml.AttributeValueFilter)6 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)6 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)3 HashSet (java.util.HashSet)2 Predicate (javax.persistence.criteria.Predicate)2