package gw.rating.impact
uses gw.api.database.Query
uses gw.api.productmodel.Product
uses gw.lang.reflect.IPropertyInfo
uses gw.lang.reflect.ReflectUtil
uses gw.xml.XMLNode
uses java.lang.IllegalArgumentException
uses java.lang.StringBuilder
uses java.util.Date
uses java.util.HashMap
uses java.util.Map
uses gw.api.productmodel.ProductLookup
uses java.text.SimpleDateFormat
uses java.util.List
@Export
class ImpactTestingSearchCriteriaImportExport {
var _itsc : ImpactTestingSearchCriteria
construct(itsc : ImpactTestingSearchCriteria) {
_itsc = itsc
}
// ======================================================================================== //
// EXPORT related
// ======================================================================================== //
// XML TOKEN NAMES
static var SEARCH_CRITERIA_NAME = "ImpactTestingSearchCriteria"
static var CHILD_ELEMENT_NAME = "ArrayElement"
static var NEWLINE = "\n"
static var INDENT = " "
function toXML(formatted : boolean = false) : String {
var xmlOutput = new StringBuilder()
var typeInfo = ImpactTestingSearchCriteria.Type.TypeInfo
xmlOutput.append("<").append(SEARCH_CRITERIA_NAME).append(">")
if (formatted) xmlOutput.append(NEWLINE)
typeInfo.DeclaredProperties.where(\ p -> p.Name != "ChangedSinceLastQuery" && p.Public)
.each(\p ->{
var val = p.Accessor.getValue(_itsc)
if (val != null) {
if (p.FeatureType.Array) {
var arrayLength = p.FeatureType.getArrayLength(val)
if (arrayLength > 0) {
if (formatted) xmlOutput.append(INDENT)
appendStartOfElement(xmlOutput, p)
if (formatted) xmlOutput.append(NEWLINE)
for (i in 0..|arrayLength) {
if (formatted) xmlOutput.append(INDENT).append(INDENT)
xmlOutput.append("<").append(CHILD_ELEMENT_NAME).append(">")
var arrayElement = p.FeatureType.getArrayComponent(val,i)
var outputValue : String
if (arrayElement typeis gw.entity.TypeKey) {
outputValue = arrayElement.Code
} else if (arrayElement typeis Product) {
outputValue = arrayElement.PublicID
} else {
outputValue = arrayElement.toString()
}
xmlOutput.append(outputValue)
xmlOutput.append("").append(CHILD_ELEMENT_NAME).append(">")
if (formatted) xmlOutput.append(NEWLINE)
}
if (formatted) xmlOutput.append(INDENT)
appendEndOfElement(xmlOutput,p)
if (formatted) xmlOutput.append(NEWLINE)
}
} else {
if (formatted) xmlOutput.append(INDENT)
appendStartOfElement(xmlOutput, p)
xmlOutput.append(val)
appendEndOfElement(xmlOutput,p)
if (formatted) xmlOutput.append(NEWLINE)
}
}
})
xmlOutput.append("").append(SEARCH_CRITERIA_NAME).append(">")
return xmlOutput.toString()
}
static private function appendStartOfElement(sb : StringBuilder, p : IPropertyInfo) : StringBuilder {
// \t
sb.append("<").append(p.Name).append(" type=\"").append(p.FeatureType).append("\">")
return sb
}
static private function appendEndOfElement(sb : StringBuilder, p : IPropertyInfo) : StringBuilder {
// \t
sb.append("").append(p.Name).append(">")
return sb
}
// ======================================================================================== //
// IMPORT related
// ======================================================================================== //
// Lazily loaded map of ProducerCode.Code -> ProducerCode
static var _producerCodeMap = new gw.util.concurrent.LockingLazyVar