package ibase.client;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

public class MetaDataDtl
{
	private String getDbDataSource = "";

	public String getGetDbDataSource()
	{
		return getDbDataSource;
	}

	public void setGetDbDataSource(String getDbDataSource)
	{
		this.getDbDataSource = getDbDataSource;
	}

	@SuppressWarnings("unchecked")
	public HashMap<String, HashMap> getGridNMapMetData(JSONObject jsonObjMetadata,String viewOptionSelectd)
	{
		Document document = null;
		ArrayList<String> metaDataList = null;
		LinkedHashMap<JSONString, JSONString> metaDataMap = new LinkedHashMap<JSONString, JSONString>();
		LinkedHashMap<JSONString, JSONString> colorDataMap = null;
		ArrayList<String> xAxisColunList = null;
		ArrayList<String> xAxisColumnName = null;
		ArrayList<String> yAxisColumnName = null;
		ArrayList<String> yAxisColunList = null;
		ArrayList<String> datsSourceDtlList = null;
		ArrayList<String> renderInfoList = null;
		ArrayList<String> showValList = null;
		ArrayList<String> lineVisibleList = null;
		ArrayList<String> dotThicknessList = null;

		ArrayList<String> colorInfoList = null;
		ArrayList<FilterInfo> fltrDtlList = null;
		NodeList gridNodeList = null;
		Node viewNode = null;
		NodeList viewNodeList = null;
		
		Node graphDataNode = null;
		NodeList xAxsisNodeList = null;
		Node xAxsisNode = null;
		NodeList yAaxixNodeList = null;
		Node yAxsisNode = null;
		String childNodeName = "";
		JSONString jsnStringKey = null;
		JSONString dataStringValue = null;
		String xmlMetadata = null;
		LinkedHashMap<String, ArrayList<String>> gridMeataDataMap = null;
		LinkedHashMap<String, ArrayList<String>> gridNameDataMap  = null;
		LinkedHashMap<String, String> gridSizeDataMap 			  = null;
		LinkedHashMap<String, String> gridCaptionDataMap 		  = null;
		LinkedHashMap<String, String> gridAlignDataMap 			  = null;
		LinkedHashMap<String, String> typeGridMap				  = null;
		LinkedHashMap<String, String> typeGraphMap				  = null;
		LinkedHashMap<String, String> gridDataSourceMap 		  = null;
		LinkedHashMap<String, String> graphDataSourceMap 		  = null;
		LinkedHashMap<String, String> divIdGrpMap				  = null;
		LinkedHashMap<String, String> gridCompTypeMap 			  = null;
		LinkedHashMap<String, String> gridLinkFormatMap 		  = null;
		//Added By Prashant Chavan 09-Mar-15 [for Link On Grid] Start
		LinkedHashMap<String, String> gridMetaLinkDataMap 		  = null;
		//Added By Prashant Chavan 09-Mar-15 [for Link On Grid] End
		LinkedHashMap<String, String> componentTypeMap 			  = null;
		LinkedHashMap<String, ArrayList<String>> datsSourceDtlMap = null;
		LinkedHashMap<String, ArrayList<FilterInfo>> filterDtlMap = null;
		HashMap<String, ArrayList<Object>> graphMeataDataMap 	  = null;
		HashMap<String, HashMap> gridNGraphMeataDataMap 		  = null;
		Node columnGrpNode = null;
		NodeList columnGrpNodeList = null;
		ArrayList<String> columnIDList = null;
		ArrayList<String> chartTypeList = null;
		ArrayList<String> columnNameList = null;
		NodeList columsNodeList = null;
		Node columnNode = null;
		String title = "";
		Node colGrpTitlNode = null;
		String columnID = null;
		String columnName = null;
		Node rootNode = null;
		NodeList rootNodeList = null;
		ArrayList graphDtlList = null;
		NodeList graphNodeList = null;
		String attributeName = "";
		String graphID = "";
		String type = "";
		int conuter = 0;
		String columnGrpId = "";
		String renderDtl = "";
		String showValDtl = "";
		String colorDtl = "";
		String lineVisibleDtl = "";
		String dotThicknessDtl = "";
	//add on 20dec2014 by swati linkedchart
		NodeList pupUpOptNodeList=null;
		Node popUpNode=null;
		ArrayList<String> linkedMetadataList=null;
		ArrayList<String> linkTypeList=null;
		String linkedProperties="";
		String linkedMetadataName="";
		String linkTypeName="";
	//end on 20dec2014 by swati for linkedchart 
		//add on dated 9 july 201041
		Node chartPropertyNode = null;
		NodeList chartPropertyNodeList = null;
		ArrayList<String> rowIdList = new ArrayList<String>();
		ArrayList<String> rowNameList = new ArrayList<String>();
		ArrayList<String> columnIdList = new ArrayList<String>();
		ArrayList<String> colorRangeList = new ArrayList<String>();
		ArrayList<String> colorList = new ArrayList<String>();
		//added on 16 jan 2015 for hat map
		
		NodeList rowNodeList = null;
		Node rowNode = null;
		NodeList columnNodeList = null;
		
		// ended for heat map
		/*Start For countrymap maxvalue dynamic pass throw query  24/04/2015*/
		ArrayList<NodeList> colorNodeList= null;
		/*End For countrymap maxvalue dynamic pass throw query  24/04/2015*/

		if (jsonObjMetadata != null)
		{
			gridNGraphMeataDataMap 	= 	new HashMap<String, HashMap>();
			gridMeataDataMap 		= 	new LinkedHashMap<String, ArrayList<String>>();
			gridNameDataMap 		= 	new LinkedHashMap<String, ArrayList<String>>();
			gridSizeDataMap 		= 	new LinkedHashMap<String, String>();
			gridLinkFormatMap		=   new LinkedHashMap<String, String>();
			gridCaptionDataMap		= 	new LinkedHashMap<String, String>();
			gridAlignDataMap 		= 	new LinkedHashMap<String, String>();
			divIdGrpMap				= 	new LinkedHashMap<String, String>();
			componentTypeMap 		= 	new LinkedHashMap<String, String>();
			gridCompTypeMap 		= 	new LinkedHashMap<String, String>();			
			datsSourceDtlMap 		= 	new LinkedHashMap<String, ArrayList<String>>();
			filterDtlMap 			= 	new LinkedHashMap<String, ArrayList<FilterInfo>>();
			xmlMetadata 			= 	jsonObjMetadata.get("metaData").toString();
			xmlMetadata 			= 	jsonObjMetadata.get("metaData").toString().replace("\\", "").trim();
			xmlMetadata 			= 	xmlMetadata.replace('"', ' ').trim();
			String metDtName = Window.Location.getParameter("metadataname");
			try
			{
				document = XMLParser.parse(xmlMetadata);
				XMLParser.removeWhitespace(document);
				if (document != null)
				{
					rootNodeList = document.getElementsByTagName("Root").item(0).getChildNodes();
					for (int rootCtr = 0; rootCtr < rootNodeList.getLength(); rootCtr++)
					{
						rootNode = rootNodeList.item(rootCtr);
						
						if ("datasource".equals(rootNode.getNodeName()))
						{
							datsSourceDtlList = new ArrayList<String>();
							String id = rootNode.getAttributes().getNamedItem("id").getNodeValue();
							datsSourceDtlList.add(rootNode.getAttributes().getNamedItem("driverName").getNodeValue());
							datsSourceDtlList.add(rootNode.getChildNodes().item(0).getNodeValue());
							datsSourceDtlMap.put(id, datsSourceDtlList);
						}
						String columnsize = "";
						String columnAlign = "";
						String dataSource="";
						
						if ("view".equals(rootNode.getNodeName()))
						{
							viewNodeList = rootNode.getChildNodes();
							if(!viewOptionSelectd.equals(rootNode.getAttributes().getNamedItem("name").getNodeValue()))
							{
							}
							if( viewOptionSelectd !=null && viewOptionSelectd.equals(rootNode.getAttributes().getNamedItem("name").getNodeValue()))
							{
								for (int viewCtr = 0; viewCtr < viewNodeList.getLength(); viewCtr++)
								{
									viewNode = viewNodeList.item(viewCtr);
									if ("grid".equals(viewNode.getNodeName()))
									{
										gridNameDataMap=new LinkedHashMap<String, ArrayList<String>>();
										gridMeataDataMap=new LinkedHashMap<String, ArrayList<String>>();
										gridSizeDataMap=new LinkedHashMap<String, String>();
										gridCaptionDataMap=new LinkedHashMap<String, String>();
										gridAlignDataMap=new LinkedHashMap<String, String>();
										typeGridMap = 	new LinkedHashMap<String, String>();
										gridDataSourceMap= 	new LinkedHashMap<String, String>();	
										gridCompTypeMap 	= 	new LinkedHashMap<String, String>();
										//Added By Prashant Chavan 09-Mar-15 [for Link On Grid] Start
										gridMetaLinkDataMap = new LinkedHashMap<String, String>();;
										//Added By Prashant Chavan 09-Mar-15 [for Link On Grid] End
										
										gridLinkFormatMap=new LinkedHashMap<String, String>();
										graphID = viewNode.getAttributes().getNamedItem("id").getNodeValue();
										dataSource = viewNode.getAttributes().getNamedItem("datasource").getNodeValue();
										type= viewNode.getAttributes().getNamedItem("type").getNodeValue();									
										gridDataSourceMap.put("datasource"+graphID, dataSource);
										typeGridMap.put("type"+graphID, type);
										gridNodeList = viewNode.getChildNodes();
										String componentType = "";
										String componentCaption="";
										//Added By Prashant Chavan 09-Mar-15 [for Link On Grid] Start
										String linkMetadata="";
										//Added By Prashant Chavan 09-Mar-15 [for Link On Grid] End
										String linkFormat="";
										String filterDisplay="";
										for (int gridCtr = 0; gridCtr < gridNodeList.getLength(); gridCtr++)
										{
											columnGrpNode = gridNodeList.item(gridCtr);
											if (columnGrpNode.getNodeName().equals("component_type"))
											{
												componentType = columnGrpNode.getChildNodes().item(0).getNodeValue();
											}
											else if (columnGrpNode.getNodeName().equals("component_caption"))
											{
												componentCaption = columnGrpNode.getChildNodes().item(0).getNodeValue();
											} 
											else if (columnGrpNode.getNodeName().equals("link_format"))
											{
												linkFormat = columnGrpNode.getChildNodes().item(0).getNodeValue();
												filterDisplay = columnGrpNode.getAttributes().getNamedItem("filterdisplay").getNodeValue();
												//if(linkFormat.trim().length()>0 && filterDisplay.trim().length()>0)
												//{
													linkFormat = linkFormat+"@"+filterDisplay;
												//}
											} 
											else
											{
												columnGrpId = columnGrpNode.getAttributes().getNamedItem("id").getNodeValue();
												columnGrpNodeList = columnGrpNode.getChildNodes();
												columnIDList = new ArrayList<String>();
												columnNameList = new ArrayList<String>();
												
												for (int colmnCtr = 0; colmnCtr < columnGrpNodeList.getLength(); colmnCtr++)
												{
													colGrpTitlNode = columnGrpNodeList.item(colmnCtr);
													if ("col_group_title".equals(colGrpTitlNode.getNodeName()))
													{
														title = colGrpTitlNode.getChildNodes().item(0).getNodeValue();
													}
													if ("column_size".equals(colGrpTitlNode.getNodeName()))
													{
														columnsize = colGrpTitlNode.getChildNodes().item(0).getNodeValue();
													}
													if ("column_alignment".equals(colGrpTitlNode.getNodeName()))
													{
														columnAlign = colGrpTitlNode.getChildNodes().item(0).getNodeValue();
													}
													//Added By Prashant Chavan 09-Mar-15 [Link for Grid] Start
													if ("link_metadata".equals(colGrpTitlNode.getNodeName()))
													{
														String linkMetadataName = colGrpTitlNode.getChildNodes().item(0).getNodeValue();
														//Added By Prashant Chavan on 09-Mar-15 [For Link on Grid] Start
														gridMetaLinkDataMap.put(columnGrpId, linkMetadataName);
														//Added By Prashant Chavan on 09-Mar-15 [For Link on Grid] End
														gridLinkFormatMap.put(columnGrpId, linkFormat);
													}
													//Added By Prashant Chavan 09-Mar-15 [Link for Grid] Start
													if ("columns".equals(colGrpTitlNode.getNodeName()))
													{
														columsNodeList = colGrpTitlNode.getChildNodes();
														for (int colCtr = 0; colCtr < columsNodeList.getLength(); colCtr++)
														{
															columnNode = columsNodeList.item(colCtr);
															columnName = columnNode.getChildNodes().item(0).getNodeValue();
															columnID = columnNode.getAttributes().getNamedItem("id").getNodeValue();
															columnIDList.add(columnID);
															columnNameList.add(columnName);
														}
													}
												}
												//start modified code on 3 march 2015 by swati
												gridMeataDataMap.put(columnGrpId, columnIDList);
												gridNameDataMap.put(title, columnNameList);
												gridSizeDataMap.put(title, columnsize);
												gridAlignDataMap.put(title, columnAlign);
												//end modified code on 3 march 2015 by swati
											}
											
										}
										gridCaptionDataMap.put("componentCaption"+graphID,componentCaption );
										gridCompTypeMap.put("buildComponent"+graphID, componentType);
										gridNGraphMeataDataMap.put("componentType"+graphID, gridCompTypeMap);
										gridNGraphMeataDataMap.put(graphID, gridMeataDataMap);
										gridNGraphMeataDataMap.put("columnName"+graphID, gridNameDataMap);
										gridNGraphMeataDataMap.put("columnSize"+graphID, gridSizeDataMap);
										gridNGraphMeataDataMap.put("componentCaption"+graphID, gridCaptionDataMap);
										gridNGraphMeataDataMap.put("columnAlign"+graphID, gridAlignDataMap);
										gridNGraphMeataDataMap.put("type"+graphID, typeGridMap);
										gridNGraphMeataDataMap.put("datasource"+graphID, gridDataSourceMap);
										//Added By Prashant Chavan on 09-Mar-15 [Link Metadata for Grid] Start
										gridNGraphMeataDataMap.put("linkFormatType"+graphID, gridLinkFormatMap);
										gridNGraphMeataDataMap.put("metadataNameLink"+graphID, gridMetaLinkDataMap);
										//Added By Prashant Chavan on 09-Mar-15 [Link Metadata for Grid] Start
										columnIDList = new ArrayList<String>();
										columnNameList= new ArrayList<String>();
									}
									if ("graph".equals(viewNode.getNodeName()))
									{
										typeGraphMap= 	new LinkedHashMap<String, String>();
										graphDataSourceMap= 	new LinkedHashMap<String, String>();									
										graphID = viewNode.getAttributes().getNamedItem("id").getNodeValue();
										type= viewNode.getAttributes().getNamedItem("type").getNodeValue();
										dataSource = viewNode.getAttributes().getNamedItem("datasource").getNodeValue();
										graphDataSourceMap.put("datasource"+graphID, dataSource);
										typeGraphMap.put("type"+graphID, type);									
										graphDtlList = new ArrayList<String>();
										xAxisColunList = new ArrayList<String>();
										yAxisColunList = new ArrayList<String>();
										metaDataList = new ArrayList<String>();
										xAxisColumnName = new ArrayList<String>();
										yAxisColumnName = new ArrayList<String>();
										renderInfoList = new ArrayList<String>();
										showValList = new ArrayList<String>();
										lineVisibleList = new ArrayList<String>();
										dotThicknessList = new ArrayList<String>();
										colorInfoList = new ArrayList<String>();
										graphMeataDataMap = new HashMap<String, ArrayList<Object>>();
										graphNodeList = viewNode.getChildNodes();
									//added by swati 20dec2014 for linked chart
										linkedMetadataList= new ArrayList<String>();
										linkTypeList = new ArrayList<String>();	
									//ended by swati 20dec2014 for linked chart
										for (int i = 0; i < graphNodeList.getLength(); i++)
										{
											graphDataNode = graphNodeList.item(i);
											childNodeName = graphDataNode.getNodeName();
											if ("column_group".equalsIgnoreCase(childNodeName))
											{
												attributeName = graphDataNode.getAttributes().getNamedItem("id").getNodeValue();
												if ("x_axis".equalsIgnoreCase(attributeName))
												{
													xAxsisNodeList = graphDataNode.getChildNodes();
													for (int j = 0; j < xAxsisNodeList.getLength(); j++)
													{
														xAxsisNode = xAxsisNodeList.item(j);
														if ("col_group_title".equals(xAxsisNode.getNodeName()))
														{
															dataStringValue = new JSONString(xAxsisNode.getChildNodes().item(0).getNodeValue());
															jsnStringKey = new JSONString("xAxisName");
															metaDataMap.put(jsnStringKey, dataStringValue);
														}
														if ("columns".equals(xAxsisNode.getNodeName()))
														{
															xAxsisNodeList = xAxsisNode.getChildNodes();
															for (int colCtr = 0; colCtr < xAxsisNodeList.getLength(); colCtr++)
															{
																columnNode = xAxsisNodeList.item(colCtr);
																columnID = columnNode.getAttributes().getNamedItem("id").getNodeValue();
																xAxisColunList.add(columnID);
																xAxisColumnName.add(columnNode.getChildNodes().item(0).getNodeValue());
															}
														}
													}
												}
												if ("y_axis".equalsIgnoreCase(attributeName))
												{
													yAaxixNodeList = graphDataNode.getChildNodes();
													for (int j = 0; j < yAaxixNodeList.getLength(); j++)
													{
														yAxsisNode = yAaxixNodeList.item(j);
														if ("col_group_title".equals(yAxsisNode.getNodeName()))
														{
															dataStringValue = new JSONString(yAxsisNode.getChildNodes().item(0).getNodeValue());
															jsnStringKey = new JSONString("yAxisName");
															metaDataMap.put(jsnStringKey, dataStringValue);
														}
														String flag = null;
														if ("columns".equals(yAxsisNode.getNodeName()))
														{
															flag = "false";
															NodeList yAxsisNodeList = yAxsisNode.getChildNodes();
															for (int colCtr = 0; colCtr < yAxsisNodeList.getLength(); colCtr++)
															{
																columnNode = yAxsisNodeList.item(colCtr);
																columnID = columnNode.getAttributes().getNamedItem("id").getNodeValue();
																yAxisColunList.add(columnID);
																yAxisColumnName.add(columnNode.getChildNodes().item(0).getNodeValue());
																renderDtl = columnNode.getAttributes().getNamedItem("render").getNodeValue();
																renderInfoList.add(renderDtl);
	
																showValDtl = columnNode.getAttributes().getNamedItem("showvalue").getNodeValue();
																showValList.add(showValDtl);
	
																colorDtl = columnNode.getAttributes().getNamedItem("color").getNodeValue();
																colorInfoList.add(colorDtl);
																if (columnNode.getAttributes().getNamedItem("linevisibility") != null)
																{
																	lineVisibleDtl = columnNode.getAttributes().getNamedItem("linevisibility").getNodeValue();
																	if (!lineVisibleDtl.trim().equals("0"))
																	{
																		flag = "true";
																	}
																	lineVisibleList.add(lineVisibleDtl);
																}
																if (columnNode.getAttributes().getNamedItem("dotthickness") != null)
																{
																	dotThicknessDtl = columnNode.getAttributes().getNamedItem("dotthickness").getNodeValue();
																	metaDataMap.put(new JSONString("anchorRadius"), new JSONString(dotThicknessDtl));
																	dotThicknessList.add(dotThicknessDtl);
																}
															//added  linked chart metadata name to graphdetail list by swati on 24 Dec 2014
																linkedMetadataName = columnNode.getAttributes().getNamedItem("linkedmetadata").getNodeValue();
																linkedMetadataList.add(linkedMetadataName);
																linkTypeName = columnNode.getAttributes().getNamedItem("linktype").getNodeValue();
																linkTypeList.add(linkTypeName);
														//added  linked chart metadata name to graphdetail list by swati on 24 Dec 2014	
															}
															if (flag.equals("false"))
															{
																metaDataMap.put(new JSONString("lineAlpha"), new JSONString("1"));
																metaDataMap.put(new JSONString("anchorBorderThickness"), new JSONString("3"));
															}
														}
														//added by swati   "placevaluesinside": "1",rotatevalues
														if ("left_yaxis_title".equals(yAxsisNode.getNodeName()))
														{
															dataStringValue = new JSONString(yAxsisNode.getChildNodes().item(0).getNodeValue());
															jsnStringKey = new JSONString("pyaxisname");
															metaDataMap.put(jsnStringKey, dataStringValue);
														}
														if ("right_yaxis_title".equals(yAxsisNode.getNodeName()))
														{
															dataStringValue = new JSONString(yAxsisNode.getChildNodes().item(0).getNodeValue());
															jsnStringKey = new JSONString("syaxisname");
															metaDataMap.put(jsnStringKey, dataStringValue);
														}
														//end added by swati	
													}
												}
											}
											//Add on dated by swati for chart_properties
											if ("chart_properties".equalsIgnoreCase(childNodeName))
											{
												chartTypeList = new ArrayList<String>();
												chartPropertyNodeList = graphDataNode.getChildNodes();
												for (int k = 0; k < chartPropertyNodeList.getLength(); k++)
												{
													chartPropertyNode = chartPropertyNodeList.item(k);
													if ("caption".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("caption");
														if(metDtName=="halolmfgmonth")
														{
															//Window.alert(FilterCreator.parameterList.get(1));
															String temp = FilterCreator.parameterList.get(2);
															dataStringValue = new JSONString(temp+" "+chartPropertyNode.getChildNodes().item(0).getNodeValue()+" ("+getCurrentDate()+")");
														}
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
																										
													if ("slantlabels".equals(chartPropertyNode.getNodeName()))
													{
														if(("0").equals(chartPropertyNode.getChildNodes().item(0).getNodeValue()))
														{
															metaDataMap.put(new JSONString("labelDisplay"), new JSONString(""));
														}
														else if(("1").equals(chartPropertyNode.getChildNodes().item(0).getNodeValue()))
														{
															metaDataMap.put(new JSONString("labelDisplay"), new JSONString("Rotate"));
														}
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey    = new JSONString("slantLabels");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("bg_color".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("bgcolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("showlegend".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showLegend");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("useroundedges".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("useroundedges");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("rotatevalues".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("rotateValues");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("decimals".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("decimals");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("formatnumberscale".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("formatNumberScale");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("formatnumber".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("formatNumber");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("chart_type".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("chart_type");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														chartTypeList.add(chartPropertyNode.getAttributes().getNamedItem("id").getNodeValue());
													}
													if ("width".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("width");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														//metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("height".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("height");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														//metaDataMap.put(jsnStringKey, dataStringValue);
													}
												//added  linked chart metadata name to graphdetail list by swati on 22 Dec 2014
													if ("win_properties".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														linkedProperties = (chartPropertyNode.getChildNodes().item(0).getNodeValue());
													}
											    //ended  linked chart metadata name to graphdetail list by swati on 22 Dec 2014
													if ("exportenabled".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("exportEnabled");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("exportatclient".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("exportAtClient");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("exporthandler".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("exportHandler");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("exportaction".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("exportAction");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
												}
											}
											//end swati for chart properties
										}
										metaDataList.add(metaDataMap.toString().replace('=', ':'));
										graphDtlList.add(xAxisColunList);
										graphDtlList.add(yAxisColunList);
										graphDtlList.add(metaDataList);
										graphDtlList.add(xAxisColumnName);
										graphDtlList.add(yAxisColumnName);
										graphDtlList.add(renderInfoList);
										graphDtlList.add(colorInfoList);
										graphDtlList.add(lineVisibleList);
										graphDtlList.add(dotThicknessList);
										graphDtlList.add(showValList);
										graphDtlList.add(chartTypeList);
									//added  linked chart metadata name to graphdetail list by swati on 22 Dec 2014
										graphDtlList.add(linkedMetadataList);
										graphDtlList.add(linkedProperties);
										graphDtlList.add(linkTypeList);										
									//ended  linked chart metadata name to graphdetail list by swati on 22 Dec 2014
										conuter++;
										gridNGraphMeataDataMap.put("type"+graphID, typeGraphMap);
										graphMeataDataMap.put("graph" + conuter, graphDtlList);
										gridNGraphMeataDataMap.put(graphID, graphMeataDataMap);
										gridNGraphMeataDataMap.put("datasource"+graphID, graphDataSourceMap);
									}
									
									if ("heatmap".equals(viewNode.getNodeName()))
									{
										typeGraphMap= 	new LinkedHashMap<String, String>();
										graphDataSourceMap= 	new LinkedHashMap<String, String>();									
										graphID = viewNode.getAttributes().getNamedItem("id").getNodeValue();
										type= viewNode.getAttributes().getNamedItem("type").getNodeValue();
										dataSource = viewNode.getAttributes().getNamedItem("datasource").getNodeValue();
										graphDataSourceMap.put("datasource"+graphID, dataSource);
										typeGraphMap.put("type"+graphID, type);									
										graphDtlList = new ArrayList<String>();
										rowIdList = new ArrayList<String>();
										rowNameList = new ArrayList<String>();
										columnIdList = new ArrayList<String>();
										ArrayList<String> showValueList= new ArrayList<String>();
										
										ArrayList<String> tlLabelList= new ArrayList<String>();
										ArrayList<String> trLabelList= new ArrayList<String>();
										ArrayList<String> blLabelList= new ArrayList<String>();
										ArrayList<String> brLabelList= new ArrayList<String>();
										linkedMetadataList= new ArrayList<String>();
										colorRangeList = new ArrayList<String>();
									    columnNameList = new ArrayList<String>();										
										metaDataList = new ArrayList<String>();										
										graphMeataDataMap = new HashMap<String, ArrayList<Object>>();
										graphNodeList = viewNode.getChildNodes();
										for (int i = 0; i < graphNodeList.getLength(); i++)
										{
											graphDataNode = graphNodeList.item(i);
											childNodeName = graphDataNode.getNodeName();
											if ("chart_properties".equalsIgnoreCase(childNodeName))
											{
												chartTypeList = new ArrayList<String>();
	
												chartPropertyNodeList = graphDataNode.getChildNodes();
												for (int k = 0; k < chartPropertyNodeList.getLength(); k++)
												{
													chartPropertyNode = chartPropertyNodeList.item(k);
													
													if ("chart_type".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("chart_type");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														chartTypeList.add(chartPropertyNode.getAttributes().getNamedItem("id").getNodeValue());
													}
													if ("width".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("width");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
													}
													if ("height".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("height");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
													}												
													if ("caption".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("caption");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("subcaption".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("subcaption");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													if ("bgcolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("bgcolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}												
														if ("labelDisplay".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("labelDisplay");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
															
													if ("canvasborderthickness".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("canvasborderthickness");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
	
													if ("plotbordercolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("plotbordercolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													if ("outcnvbasefontcolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("outcnvbasefontcolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
														if ("showvalues".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showvalues");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													if ("captionpadding".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("captionpadding");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
												/*
												 	if ("legendpadding".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendpadding");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	*/
													if ("canvasborderalpha".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("canvasborderalpha");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("legendshadow".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendshadow");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("showBorder".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showBorder");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													if ("theme".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("theme");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("xAxisName".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("xAxisName");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													if ("yAxisName".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("yAxisName");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													
													if ("xAxisLabelsOnTop".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("xAxisLabelsOnTop");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													
													if ("showplotborder".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showplotborder");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													
													//add new code by Birendra Pandey on dated 22-jan-2015															
													
													if ("xAxisNameFontBold".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("yAxisNameFontBold");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("baseFontSize".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("baseFontSize");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legenddisplay".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showLegend");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}													
													
													//end new code by Birendra Pandey on dated 22-jan-2015
													
												}
											}
											if ("rows".equalsIgnoreCase(childNodeName))
											{
													rowNodeList = graphDataNode.getChildNodes();
													for (int j = 0; j < rowNodeList.getLength(); j++)
													{
														rowNode = rowNodeList.item(j);
														rowIdList.add(rowNode.getAttributes().getNamedItem("id").getNodeValue());
														rowNameList.add(rowNode.getChildNodes().item(0).getNodeValue());
													}
											}
											if ("columns".equalsIgnoreCase(childNodeName))
											{
													columnNodeList = graphDataNode.getChildNodes();
													for (int j = 0; j < columnNodeList.getLength(); j++)
													{
														columnNode = columnNodeList.item(j);
														columnIdList.add(columnNode.getAttributes().getNamedItem("id").getNodeValue());
														showValueList.add(columnNode.getAttributes().getNamedItem("showValue").getNodeValue());
														columnNameList.add(columnNode.getChildNodes().item(0).getNodeValue());
														tlLabelList.add(columnNode.getAttributes().getNamedItem("tllabel").getNodeValue());
														trLabelList.add(columnNode.getAttributes().getNamedItem("trlabel").getNodeValue());
														brLabelList.add(columnNode.getAttributes().getNamedItem("blLabel").getNodeValue());
														blLabelList.add(columnNode.getAttributes().getNamedItem("brLabel").getNodeValue());
														
														linkedMetadataName = columnNode.getAttributes().getNamedItem("linkedmetadata").getNodeValue();
														linkedMetadataList.add(linkedMetadataName);
														
													}
											}
											if ("colorrange".equalsIgnoreCase(childNodeName))
											{
												if (graphDataNode.getAttributes().getNamedItem("mapbypercent") != null)
												{
												colorRangeList.add(graphDataNode.getAttributes().getNamedItem("mapbypercent").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("gradient") != null)
												{
												colorRangeList.add(graphDataNode.getAttributes().getNamedItem("gradient").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("minvalue") != null)
												{
												colorRangeList.add(graphDataNode.getAttributes().getNamedItem("minvalue").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("code") != null)
												{
												colorRangeList.add(graphDataNode.getAttributes().getNamedItem("code").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("startlabel") != null)
												{
												colorRangeList.add(graphDataNode.getAttributes().getNamedItem("startlabel").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("endlabel") != null)
												{
												colorRangeList.add(graphDataNode.getAttributes().getNamedItem("endlabel").getNodeValue());
												}
												columnNodeList = graphDataNode.getChildNodes();
												for (int j = 0; j < columnNodeList.getLength(); j++)
												{
													colorDataMap = new LinkedHashMap<JSONString, JSONString>();
													columnNode = columnNodeList.item(j);
													if (columnNode.getAttributes().getNamedItem("code") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("code").getNodeValue());
														jsnStringKey = new JSONString("code");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													if (columnNode.getAttributes().getNamedItem("minvalue") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("minvalue").getNodeValue());
														jsnStringKey = new JSONString("minvalue");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													if (columnNode.getAttributes().getNamedItem("maxvalue") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("maxvalue").getNodeValue());
														jsnStringKey = new JSONString("maxvalue");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													if (columnNode.getAttributes().getNamedItem("label") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("label").getNodeValue());
														jsnStringKey = new JSONString("label");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													colorList.add(colorDataMap.toString().replace('=', ':'));
												}
											}
										}
										metaDataList.add(metaDataMap.toString().replace('=', ':'));
										graphDtlList.add(metaDataList);
										graphDtlList.add(rowIdList);
										graphDtlList.add(rowNameList);
										graphDtlList.add(columnIdList);
										graphDtlList.add(columnNameList);										
										graphDtlList.add(colorRangeList);
										graphDtlList.add(colorList);
										graphDtlList.add(showValueList);
										
										graphDtlList.add(tlLabelList);										
										graphDtlList.add(trLabelList);
										graphDtlList.add(brLabelList);
										graphDtlList.add(blLabelList);
										graphDtlList.add(linkedMetadataList);
										conuter++;
										gridNGraphMeataDataMap.put("type"+graphID, typeGraphMap);
										graphMeataDataMap.put("graph" + conuter, graphDtlList);
										gridNGraphMeataDataMap.put(graphID, graphMeataDataMap);
										gridNGraphMeataDataMap.put("datasource"+graphID, graphDataSourceMap);
									
									}
									/**Start of build metadata for country map chart by swati 16 April 2015**/
									if ("countrymap".equals(viewNode.getNodeName()))
									{
										typeGraphMap= 	new LinkedHashMap<String, String>();
										graphDataSourceMap= 	new LinkedHashMap<String, String>();									
										graphID = viewNode.getAttributes().getNamedItem("id").getNodeValue();
										type= viewNode.getAttributes().getNamedItem("type").getNodeValue();
										dataSource = viewNode.getAttributes().getNamedItem("datasource").getNodeValue();
										graphDataSourceMap.put("datasource"+graphID, dataSource);
										typeGraphMap.put("type"+graphID, type);									
										graphDtlList = new ArrayList<String>();
										columnIdList = new ArrayList<String>();
										columnNameList = new ArrayList<String>();										
										linkedMetadataList= new ArrayList<String>();
										linkTypeList = new ArrayList<String>();	
										ArrayList<String> toptoolTipList= new ArrayList<String>();
										ArrayList<String> bottomToolTipList= new ArrayList<String>();
										ArrayList<String> showLabelList= new ArrayList<String>();
										ArrayList<String> hovercolorList= new ArrayList<String>();
										ArrayList<String> tooltextList= new ArrayList<String>();
										colorRangeList = new ArrayList<String>();
										metaDataList = new ArrayList<String>();										
										graphMeataDataMap = new HashMap<String, ArrayList<Object>>();
										graphNodeList = viewNode.getChildNodes();
										StringBuffer brandNameStr = new StringBuffer();
										StringBuffer divisionNameStr = new StringBuffer();
										String brandName = "";
										String divisionName = "";
										String[] brandNameArr = null;
										String[] divisionNameArr = null;
										for (int i = 0; i < graphNodeList.getLength(); i++)
										{
											graphDataNode = graphNodeList.item(i);
											childNodeName = graphDataNode.getNodeName();
											if ("chart_properties".equalsIgnoreCase(childNodeName))
											{
												chartTypeList = new ArrayList<String>();
												chartPropertyNodeList = graphDataNode.getChildNodes();
												for (int k = 0; k < chartPropertyNodeList.getLength(); k++)
												{
													chartPropertyNode = chartPropertyNodeList.item(k);
													if ("chart_type".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("chart_type");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														chartTypeList.add(chartPropertyNode.getAttributes().getNamedItem("id").getNodeValue());
													}
													if ("width".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("width");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
													}
													if ("height".equalsIgnoreCase(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("height");
														graphDtlList.add(chartPropertyNode.getChildNodes().item(0).getNodeValue());
													}												
													if ("caption".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("caption");
														/*Start add code for india map Dhanendra 06/05/2015*/
														if(metDtName=="indiamap")
														{
															brandName = FilterCreator.parameterListDtl.get(2);
															divisionName = FilterCreator.parameterListDtl.get(3);
															
															if(brandName.length()==0 && brandName.equals(""))
															{
																brandName = "All";
															}
															if(divisionName.length()==0 && divisionName.equals(""))
															{
																divisionName = "All";
																
															}
															brandNameArr = brandName.split(",");
															divisionNameArr = divisionName.split(",");
															for(int cnt=0; cnt<brandNameArr.length; cnt++)
															{
																if(cnt<2)
																{
																	if(cnt==0)
																	{
																		brandNameStr.append(brandNameArr[cnt]);
																	}else{
																		brandNameStr.append(",");
																		brandNameStr.append(brandNameArr[cnt]);
																	}
																}
															}
															if(brandNameArr.length>2)
															{
																brandNameStr.append("...");
															}
															
															for(int cnt=0; cnt<divisionNameArr.length; cnt++)
															{
																if(cnt<2)
																{
																	if(cnt==0)
																	{
																		divisionNameStr.append(divisionNameArr[cnt]);
																	}else{
																		divisionNameStr.append(",");
																		divisionNameStr.append(divisionNameArr[cnt]);
																	}
																}
																
															}
															if(divisionNameArr.length>2)
															{
																divisionNameStr.append("...");
															}
														}
														if(brandName.length()==0 && divisionName.length()==0)
														{
															dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue()+" Brand : "+brandName + " And Division : "+ divisionName);
														}else{
															dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue()+" Brand : "+brandNameStr + " And Division : "+ divisionNameStr);
														}
														/*End add code for india map Dhanendra 06/05/2015*/
														metaDataMap.put(jsnStringKey, dataStringValue);
													}	
													if ("bgcolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("bgcolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("theme".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("theme");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("basefontsize".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("baseFontSize");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legendshadow".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendshadow");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legenddisplay".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showlegend");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legendposition".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendposition");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legendborderalpha".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendborderalpha");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legendbordercolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendbordercolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("legendallowdrag".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("legendallowdrag");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("animation".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("animation");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("hovercolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("hovercolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("usehovercolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("usehovercolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("fillalpha".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("fillalpha");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("connectorcolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("connectorcolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("showborder".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showborder");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("bordercolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("bordercolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("canvasbordercolor".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("canvasbordercolor");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("showbevel".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showbevel");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
													if ("showshadow".equals(chartPropertyNode.getNodeName()))
													{
														dataStringValue = new JSONString(chartPropertyNode.getChildNodes().item(0).getNodeValue());
														jsnStringKey = new JSONString("showshadow");
														metaDataMap.put(jsnStringKey, dataStringValue);
													}
												}
											}
											if ("data".equalsIgnoreCase(childNodeName))
											{
												columnNodeList = graphDataNode.getChildNodes();
												for (int j = 0; j < columnNodeList.getLength(); j++)
												{
													columnNode = columnNodeList.item(j);
													columnIdList.add(columnNode.getAttributes().getNamedItem("id").getNodeValue());
													linkedMetadataList.add(columnNode.getAttributes().getNamedItem("linkedmetadata").getNodeValue());
													linkTypeList.add(columnNode.getAttributes().getNamedItem("linktype").getNodeValue());
													toptoolTipList.add(columnNode.getAttributes().getNamedItem("toptooltip").getNodeValue());
													bottomToolTipList.add(columnNode.getAttributes().getNamedItem("bottomtooltip").getNodeValue());
													showLabelList.add(columnNode.getAttributes().getNamedItem("showlabel").getNodeValue());
													hovercolorList.add(columnNode.getAttributes().getNamedItem("usehovercolor").getNodeValue());
													tooltextList.add(columnNode.getAttributes().getNamedItem("tooltext").getNodeValue());
													
												}
											}
											if ("colorrange".equalsIgnoreCase(childNodeName))
											{
												if (graphDataNode.getAttributes().getNamedItem("startlabel") != null)
												{
												   colorRangeList.add(graphDataNode.getAttributes().getNamedItem("startlabel").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("endlabel") != null)
												{
												   colorRangeList.add(graphDataNode.getAttributes().getNamedItem("endlabel").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("gradient") != null)
												{
												   colorRangeList.add(graphDataNode.getAttributes().getNamedItem("gradient").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("minvalue") != null)
												{
												   colorRangeList.add(graphDataNode.getAttributes().getNamedItem("minvalue").getNodeValue());
												}
												if (graphDataNode.getAttributes().getNamedItem("code") != null)
												{
												   colorRangeList.add(graphDataNode.getAttributes().getNamedItem("code").getNodeValue());
												}
												colorNodeList = new ArrayList<NodeList>();
												columnNodeList = graphDataNode.getChildNodes();
												colorNodeList.add(columnNodeList);
												/*Start This code is write in Chart Creator for max value set from sql by dhanendra on 24/04/2015*/
												/*for (int j = 0; j < columnNodeList.getLength(); j++)
												{
													colorDataMap = new LinkedHashMap<JSONString, JSONString>();
													columnNode = columnNodeList.item(j);
													if (columnNode.getAttributes().getNamedItem("code") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("code").getNodeValue());
														jsnStringKey = new JSONString("code");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													if (columnNode.getAttributes().getNamedItem("maxvalue") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("maxvalue").getNodeValue());
														jsnStringKey = new JSONString("maxvalue");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													if (columnNode.getAttributes().getNamedItem("label") != null)
													{
														dataStringValue = new JSONString(columnNode.getAttributes().getNamedItem("label").getNodeValue());
														jsnStringKey = new JSONString("displayvalue");
														colorDataMap.put(jsnStringKey, dataStringValue);
													}
													colorList.add(colorDataMap.toString().replace('=', ':'));
												}*/
												
												/*End This code is write in Chart Creator for max value set from sql by dhanendra on 24/04/2015*/
											}
										}
										metaDataList.add(metaDataMap.toString().replace('=', ':'));
										graphDtlList.add(metaDataList);
										graphDtlList.add(columnIdList);
										graphDtlList.add(columnNameList);										
										graphDtlList.add(colorRangeList);
										/*graphDtlList.add(colorList);*/
										graphDtlList.add(colorNodeList);
										graphDtlList.add(toptoolTipList);
										graphDtlList.add(bottomToolTipList);
										graphDtlList.add(linkedMetadataList);
										graphDtlList.add(linkTypeList);
										graphDtlList.add(showLabelList);
										graphDtlList.add(hovercolorList);
										graphDtlList.add(tooltextList);
										
										
										
										conuter++;
										gridNGraphMeataDataMap.put("type"+graphID, typeGraphMap);
										graphMeataDataMap.put("graph" + conuter, graphDtlList);
										gridNGraphMeataDataMap.put(graphID, graphMeataDataMap);
										gridNGraphMeataDataMap.put("datasource"+graphID, graphDataSourceMap);
									}
									/**End of build metadata for country mao by swati 16 April 2015**/
								}
							}
						}
					}
				}
			} catch (Exception e)
			{
				Window.alert(" Exception :: getGridNMapMetData() :: MetaDataDtl [" + e.getMessage() + "]");
			}
		}
		gridNGraphMeataDataMap.put("datSrc", datsSourceDtlMap);
	//	Window.alert("gridNGraphMeataDataMap:"+gridNGraphMeataDataMap);
		return gridNGraphMeataDataMap;
	}

	public ArrayList<FilterInfo> getFilters(JSONObject jsonObjMetadata)
	{
		Document document = null;
		String xmlMetadata = null;
		Node rootNode = null;
		NodeList rootNodeList = null;
		NodeList filtrNodeList = null;
		NodeList fltrDtlNodeList = null;
		Node columNode = null;
		ArrayList<FilterInfo> fltrDtlList = new ArrayList<FilterInfo>();		;
		FilterInfo filterInfo = null;

		if (jsonObjMetadata != null)
		{
			xmlMetadata = jsonObjMetadata.get("metaData").toString();
			xmlMetadata = jsonObjMetadata.get("metaData").toString().replace("\\", "").trim();
			xmlMetadata = xmlMetadata.replace('"', ' ').trim();
			try
			{
				document = XMLParser.parse(xmlMetadata);
				XMLParser.removeWhitespace(document);
				if (document != null)
				{
					rootNodeList = document.getElementsByTagName("Root").item(0).getChildNodes();
					for (int rootCtr = 0; rootCtr < rootNodeList.getLength(); rootCtr++)
					{
						rootNode = rootNodeList.item(rootCtr);
						if ("filters".equals(rootNode.getNodeName()))
						{
							filtrNodeList = rootNode.getChildNodes();
							for (int fltrCtr = 0; fltrCtr < filtrNodeList.getLength(); fltrCtr++)
							{
								fltrDtlNodeList = filtrNodeList.item(fltrCtr).getChildNodes();
								filterInfo = new FilterInfo();

								filterInfo.setFiltertype(filtrNodeList.item(fltrCtr).getAttributes().getNamedItem("type").getNodeValue());
								for (int dtlCnt = 0; dtlCnt < fltrDtlNodeList.getLength(); dtlCnt++)
								{
									columNode = fltrDtlNodeList.item(dtlCnt);
									if ("col_title".equals(columNode.getNodeName()))
									{
										// fltrDtlList.add(columNode.getChildNodes().item(0).getNodeValue());
										filterInfo.setColTitle(columNode.getChildNodes().item(0).getNodeValue());
									}
									if ("col_name".equals(columNode.getNodeName()))
									{
										// fltrDtlList.add(columNode.getChildNodes().item(0).getNodeValue());

										filterInfo.setColName(columNode.getChildNodes().item(0).getNodeValue());
										filterInfo.setColNameId(columNode.getAttributes().getNamedItem("id").getNodeValue());
										filterInfo.setColModuleName(columNode.getAttributes().getNamedItem("moduleName").getNodeValue());
										/*Add Dhanendra For 2 Attribute in Metaxml 8Dec2014*/
										filterInfo.setName(columNode.getAttributes().getNamedItem("name").getNodeValue());
										filterInfo.setMandatory(columNode.getAttributes().getNamedItem("mandatory").getNodeValue());
										/*End Dhanendra For 2 Attribute in Metaxml 8Dec2014*/
										
									}
									if ("col_descr".equals(columNode.getNodeName()))
									{
										filterInfo.setColDescr(columNode.getChildNodes().item(0).getNodeValue());
										// fltrDtlList.add(columNode.getChildNodes().item(0).getNodeValue());
									}
								}
								fltrDtlList.add(filterInfo);
							}
						}
					}
				}
			} catch (Exception e)
			{
				Window.alert(" Exception :: :: getFilters() :: MetaDataDtl  [" + e.getMessage() + "]");
			}
		}
		return fltrDtlList;
	}

	public ArrayList<String> getTitle(JSONObject jsonObjMetadata)
	{
		Document document = null;
		String xmlMetadata = null;
		Node rootNode = null;
		NodeList rootNodeList = null;

		ArrayList<String> pageTitle = new ArrayList<String>();
		if (jsonObjMetadata != null)
		{
			xmlMetadata = jsonObjMetadata.get("metaData").toString();
			xmlMetadata = jsonObjMetadata.get("metaData").toString().replace("\\", "").trim();
			xmlMetadata = xmlMetadata.replace('"', ' ').trim();
			try
			{
				document = XMLParser.parse(xmlMetadata);
				XMLParser.removeWhitespace(document);
				if (document != null)
				{
					rootNodeList = document.getElementsByTagName("Root").item(0).getChildNodes();
					for (int rootCtr = 0; rootCtr < rootNodeList.getLength(); rootCtr++)
					{
						rootNode = rootNodeList.item(rootCtr);
						if ("page_title".equals(rootNode.getNodeName()))
						{
							pageTitle.add(rootNode.getChildNodes().item(0).getNodeValue());
						}
						if ("sub_title".equals(rootNode.getNodeName()))
						{
							pageTitle.add(rootNode.getChildNodes().item(0).getNodeValue());
						}
					}
				}
			} catch (Exception e)
			{
				Window.alert(" Exception :: getGridNMapMetData() :: MetaDataDtl [" + e.getMessage() + "]");
			}
		}
		return pageTitle;
	}
	
	
	
	
	public boolean isFiltrHide(JSONObject jsonObjMetadata)
	{
		boolean showFilter=false;
		Document document = null;
		String xmlMetadata = null;
		Node rootNode = null;
		NodeList rootNodeList = null;
		String fiterValue="";

		if (jsonObjMetadata != null)
		{
			xmlMetadata = jsonObjMetadata.get("metaData").toString();
			xmlMetadata = jsonObjMetadata.get("metaData").toString().replace("\\", "").trim();
			xmlMetadata = xmlMetadata.replace('"', ' ').trim();
			try
			{
				document = XMLParser.parse(xmlMetadata);
				XMLParser.removeWhitespace(document);
				if (document != null)
				{
					rootNodeList = document.getElementsByTagName("Root").item(0).getChildNodes();
					for (int rootCtr = 0; rootCtr < rootNodeList.getLength(); rootCtr++)
					{
						rootNode = rootNodeList.item(rootCtr);
						if ("filters".equals(rootNode.getNodeName()))
						{
							fiterValue=rootNode.getAttributes().getNamedItem("display").getNodeValue();
						}
					}
				}
			} catch (Exception e)
			{
				Window.alert(" Exception :: :: isFiltrHide() :: MetaDataDtl  [" + e.getMessage() + "]");
			}
		}
		if("Y".equalsIgnoreCase(fiterValue))
		{
			showFilter=true;
		}
		return showFilter;
	}
	
	public String getCurrentDate()
	{
		String currDate="";
		DateFormat dateFor = new SimpleDateFormat("dd/MM/yyyy");
		Date date = new Date();
		currDate = dateFor.format(date);
		return currDate;
	}
}
