// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/geoenrichment/ReportPlayer/core/conversion/portalToEditorUtils/MetadataParser",["esri/dijit/geoenrichment/utils/JsonXmlConverter","./variables/VariableUtil","../../../_devConfig"],function(d,k,n){var l={},h={getObjects:function(d,f){var c=h._getVariableInfo(d,f),b=h._getScriptObjects(d);return{variables:c.variables,variableObjects:c.variableObjects,scriptObjects:b}},_getVariableInfo:function(e,f){var c=[];d.queryJson(e,f?/RawFields|Fields/:"Fields").forEach(function(a){c=c.concat(d.queryJson(a,
/Field|PortalFiel/))});var b=[],m=[];c.forEach(function(a){b.push(a.attributes.MapTo);(a=k.fieldTagToVariable(a,e.attributes.Name))&&m.push(a)});return{variables:b,variableObjects:m}},_getScriptObjects:function(e){var f=d.queryJson(e,"CalculatedFields")[0];return(f&&d.queryJson(f,"Script")||[]).map(function(c){return k.scriptTagToVariable(c,e.attributes.Name)})}};l.parseMetadataXML=function(e,f,c){c.log&&c.log(e.data);var b=d.parseXml(e.data);b&&b.attributes&&(function(){d.queryJson(b,"SpecialTradeAreaFields").forEach(function(d){c.variableProvider.isDummy&&
h.getObjects(d,!0).variableObjects.forEach(function(a){c.variableProvider.addVariable(a)})})}(),function(){d.queryJson(b,"DataCollections").forEach(function(b){var a=d.queryJson(b,"ComparisonLevel");if(n.emulateErrors.metadataParseError)throw Error("Error test: something crashed during the parsing of the metadata!");var g;if(c.variableProvider.isDummy||a.length)g=h.getObjects(b);a.length&&(a={variables:g.variables,levels:a.map(function(a){return a.attributes.Name}),variableObjects:g.variableObjects},
f&&(f.metadata.comparisonCalculatorsHash[b.attributes.Name]=a));c.variableProvider.isDummy&&(g.variableObjects.forEach(function(a){c.variableProvider.addVariable(a)}),g.scriptObjects.forEach(function(a){c.variableProvider.addScriptVariable(a)}))})}(),function(){d.queryJson(b,"Maps").forEach(function(c){d.queryJson(c,"Map").forEach(function(a){var b=d.queryJson(a,"Layer").filter(function(a){return!!a.attributes.PortalItemId}),e;1<b.length&&(e=b.shift());b=b.shift();e={defaultBasemapId:e&&e.attributes.PortalItemId,
webMapId:b&&b.attributes.PortalItemId,mapScale:Number(a.attributes.Scale)||null,fieldName:a.attributes.Name};f&&(f.metadata.mapImageInfosHash[c.attributes.Name+"."+a.attributes.Name]=e)})})}())};return l});