package com.connor.erp.materialquery.ViewStockOfERP;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.text.html.parser.Entity;

import com.connor.erpintegration.entity.BOMLineEntity;
import com.connor.erpintegration.entity.BomCheckResult;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Test {

	public static void main(String[] args) {
		String json = "{\r\n" + 
				"    \"ret\": 88,\r\n" + 
				"    \"msg\": \"succ\",\r\n" + 
				"    \"cont\": {\r\n" + 
				"        \"canAllImport\": false,\r\n" + 
				"        \"checkResult\": [\r\n" + 
				"            {\r\n" + 
				"                \"assembly_item\": \"CAL1600A01\",\r\n" + 
				"                \"assembly_item_exist\": true,\r\n" + 
				"                \"locator_integrity\": false,\r\n" + 
				"                \"bom_exist\": true,\r\n" + 
				"                \"route_exist\": true,\r\n" + 
				"                \"BOMLine\": [\r\n" + 
				"                    {\r\n" + 
				"                        \"item\": \"15229504\",\r\n" + 
				"                        \"operation_seq_num\": 10,\r\n" + 
				"                        \"item_exist\": true,\r\n" + 
				"                        \"item_valid\": true,\r\n" + 
				"                        \"locator_integrity\": true,\r\n" + 
				"                        \"operation_seq_num_exist_in_route\": false\r\n" + 
				"                    },\r\n" + 
				"                    {\r\n" + 
				"                        \"item\": \"09015394\",\r\n" + 
				"                        \"operation_seq_num\": 20,\r\n" + 
				"                        \"item_exist\": true,\r\n" + 
				"                        \"item_valid\": true,\r\n" + 
				"                        \"locator_integrity\": true,\r\n" + 
				"                        \"operation_seq_num_exist_in_route\": false\r\n" + 
				"                    }\r\n" + 
				"                ],\r\n" + 
				"                \"canBOMImport\": false\r\n" + 
				"            }\r\n" + 
				"        ]\r\n" + 
				"    }\r\n" + 
				"}";
		JSONObject jsonObject = JSONObject.fromObject(json);
		JSONObject jsonObject2 = jsonObject.getJSONObject("cont");
		JSONArray jsonArray = jsonObject2.getJSONArray("checkResult");
		List<BomCheckResult> bomCheckResults = JSONArray.toList(jsonArray,BomCheckResult.class);
		
		for(BomCheckResult b:bomCheckResults) {
			Map<String, Class> classMap = new HashMap<String, Class>();
			classMap.put("BOMLine", BOMLineEntity.class);
			BomCheckResult r =(BomCheckResult)JSONObject.toBean(JSONObject.fromObject(b),BomCheckResult.class,classMap);
			System.out.println("-------------checkResult-------------");
			System.out.println("assembly_item============="+r.getAssembly_item());
			System.out.println("assembly_item_exist============="+r.getAssembly_item_exist());
			System.out.println("locator_integrity============="+r.getLocator_integrity());
			System.out.println("bom_exist============="+r.getBom_exist());
			System.out.println("route_exist============="+r.getRoute_exist());
			System.out.println("canBOMImport============="+r.getCanBOMImport());
			System.out.println("-------------checkResult-------------");
//			String bomLine = b.getBOMLine();
			
			List<BOMLineEntity> bomline = r.getBOMLine();
			for(BOMLineEntity boMline: bomline) {
				System.out.println("-------------bomline-------------");
				System.out.println("item============"+boMline.getItem());
				System.out.println("operation_seq_num============"+boMline.getOperation_seq_num());
				System.out.println("item_exist============"+boMline.getItem_exist());
				System.out.println("item_valid============"+boMline.getItem_valid());
				System.out.println("locator_integrity============"+boMline.getLocator_integrity());
				System.out.println("operation_seq_num_exist_in_route============"+boMline.getOperation_seq_num_exist_in_route());
				System.out.println("-------------bomline-------------");
			}
		}
//		Map<String, Object> itemMap = (Map<String, Object>) JSONObject.toBean(jsonObject2, Map.class);
//
//		for (Entry<String, Object> entry : itemMap.entrySet()) {
//			
//			System.out.println("key=============" + entry.getKey());
//			JSONObject jsonObject3 = JSONObject.fromObject(entry.getValue());
//			JSONObject jsonObject4 = jsonObject3.getJSONObject("itemQty");
//			JSONArray jsonArray1 = jsonObject4.getJSONArray("ORG_NHL");
//			JSONArray jsonArray2 = jsonObject4.getJSONArray("ORG_NSC");
//			JSONArray jsonArray3 = jsonObject4.getJSONArray("ORG_NBJ");
//			JSONArray jsonArray4 = jsonObject4.getJSONArray("ORG_NSJ");
//			System.out.println("ORG_NHL=========="+jsonArray1.isEmpty());
//			System.out.println("ORG_NSC=========="+jsonArray2.isEmpty());
//			System.out.println("ORG_NBJ=========="+jsonArray3.isEmpty());
//			System.out.println("ORG_NSJ=========="+jsonArray4.isEmpty());
//		}
	}
}
