import groovy.json.*;

def path1 = 'C:/Users/yljimenez/Desktop/json.json'
def path2 = 'C:/Users/yljimenez/Desktop/json2.txt'
def file = new File(path1)

String fileContents = new File('C:/Users/yljimenez/Desktop/json.json').getText('UTF-8')
println(fileContents)
//def reader = is.newReader();
//PrintWriter pw = new PrintWriter(file2)



println(file)

def input = '''
   {
      "articles":[
         {
            "basicInfo":{
               "coreInfo":{
                  "idArticle":2392898,
                  "model":6429,
                  "quality":644,
                  "idProduct":1,
                  "codProduct":0,
                  "idCampaign":27,
                  "idPurchaseCenter":4,
                  "codPurchaseCenter":"01",
                  "idBranch":4
               },
               "extendedInfo":{
                  "idSizingSystem":10004,
                  "idLabelTypeRFID":1,
                  "idArticleType":2,
                  "idArticleDesign":2737218,
                  "idAlarm":1001,
                  "idOriginCountry":676,
                  "originCountryISO":"MM",
                  "idFamily":167,
                  "codFamily":7,
                  "idExportFamily":167,
                  "idSubFamily":739,
                  "codSubFamily":107,
                  "idSectionType":1,
                  "idSection":14,
                  "idSubSection":58,
                  "packUnits":0,
                  "idDenim":0,
                  "idManufacturer":854855,
                  "idTariffGroup":3,
                  "isWoman":true,
                  "commercialDescription":{
                     "defaultDescription":"A2A (BASBER) ABRIGO SOFT PU"
                  },
                  "idRealSectionType":1,
                  "idPurchaser":632,
                  "idCommercialAttributeValue":3538,
                  "idsCommercialClassifica":[
                     7,
                     12
                  ],
                  "creationInfo":{
                     "creationDate":"2020-04-30T14:08:16.000+02:00",
                     "creationUser":"rosaliapb"
                  },
                  "commercialClassificationAttributes":[
                     {
                        "id":1539
                     },
                     {
                        "id":1707
                     }
                  ]
               }
            },
            "joinLife":{
               "isJoinLife":false
            },
            "colorsInfo":[
               {
                  "idColor":1458
               },
               {
                  "idColor":1576,
                  "joinLife":{
                     "idStatus":66,
                     "idLabel":140,
                     "creationDate":"2020-06-04T14:20:11.000+02:00"
                  }
               },
               {
                  "idColor":1111
               },
                {
                  "idColor":1900,
                  "joinLife":{
                     "idStatus":32,
                     "idLabel":156,
                     "creationDate":"2020-04-22T17:50:55.000+02:00"
                  }
                }
            ]
         },
         		{
			"basicInfo": {
				"coreInfo": {
					"idArticle": 2389223,
					"model": 5601,
					"quality": 303,
					"idProduct": 1,
					"codProduct": 0,
					"idCampaign": 27,
					"idPurchaseCenter": 33,
					"codPurchaseCenter": "K",
					"idBranch": 8
				},
				"extendedInfo": {
					"idSizingSystem": 12551,
					"idLabelTypeRFID": 1,
					"idArticleType": 1,
					"idArticleDesign": 2733539,
					"idAlarm": 955,
					"idOriginCountry": 666,
					"originCountryISO": "BD",
					"idFamily": 2458,
					"codFamily": 10,
					"idExportFamily": 2458,
					"idSubFamily": 8909,
					"codSubFamily": 248,
					"idSectionType": 1,
					"idSection": 11,
					"idSubSection": 409,
					"packUnits": 0,
					"idDenim": 0,
					"idManufacturer": 747422,
					"idTariffGroup": 3,
					"isWoman": true,
					"commercialDescription": {
						"defaultDescription": "JERSEY BSC CUELLO VUELTO JL"
					},
					"articleStates": [
						47,
						13,
						27
					],
					"idRealSectionType": 1,
					"idPurchaser": 17851,
					"idsCommercialClassifica": [
						11,
						8
					],
					"creationInfo": {
						"creationDate": "2020-04-23T16:21:11.000+02:00",
						"creationUser": "saramsae"
					},
					"commercialClassificationAttributes": [
						{
							"id": 1096
						}
					]
				}
			},
			"joinLife": {
				"isJoinLife": true,
				"creationDate": "2020-04-23T16:21:15.000+02:00"
			},
			"colorsInfo": [
				{
					"idColor": 18048,
					"joinLife": {
						"idStatus": 66,
						"idLabel": 160,
						"creationDate": "2020-07-06T17:32:59.000+02:00"
					},
					"documentsInfo": [
						{
							"idDocumentType": 1135,
							"documents": [
								{
									"idArticleDocument": 47688,
									"name": "2839_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						},
						{
							"documents": [
								{
									"idArticleDocument": 47682,
									"name": "1996_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 206782815,
									"creationDate": "2020-09-08T11:09:59.000+02:00"
								}
							]
						}
					]
				},
				{
					"idColor": 17591,
					"joinLife": {
						"idStatus": 47,
						"creationDate": "2020-09-08T11:09:59.000+02:00"
					},
					"documentsInfo": [
						{
							"idDocumentType": 1288,
							"documents": [
								{
									"idArticleDocument": 47692,
									"name": "2839_001.pdf",
									"idDocumentState": 1,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						}
					]
				},
				{
					"idColor": 18014,
					"joinLife": {
						"idStatus": 66,
						"idLabel": 161,
						"creationDate": "2020-10-10T17:32:59.000+02:00"
					},
					"documentsInfo": [
						{
							"documents": [
								{
									"idArticleDocument": 47686,
									"name": "2839_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						},
						{
							"idDocumentType": 1189,
							"documents": [
								{
									"idArticleDocument": 47680,
									"name": "1996_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 206782815,
									"creationDate": "2020-09-08T11:09:59.000+02:00"
								}
							]
						}
					]
				},
				{
					"idColor": 18018,
					"joinLife": {
						"idStatus": 66,
						"idLabel": 163
					},
					"documentsInfo": [
						{
							"idDocumentType": 1190,
							"documents": [
								{
									"idArticleDocument": 47689,
									"name": "2839_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						},
						{
							"idDocumentType": 1191,
							"documents": [
								{
									"idArticleDocument": 47683,
									"name": "1996_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 206782815,
									"creationDate": "2020-09-08T11:09:59.000+02:00"
								}
							]
						}
					]
				},
				{
					"idColor": 17968,
					"joinLife": {
						"idStatus": 66,
						"idLabel": 160,
						"creationDate": "2020-10-12T17:32:59.000+02:00"
					},
					"documentsInfo": [
						{
							"documents": [
								{
									"idArticleDocument": 47687,
									"name": "2839_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						},
						{
							"documents": [
								{
									"idArticleDocument": 47681,
									"name": "1996_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 206782815,
									"creationDate": "2020-09-08T11:09:59.000+02:00"
								}
							]
						}
					]
				},
				{
					"idColor": 17830,
					"joinLife": {
						"idStatus": 66,
						"idLabel": 160,
						"creationDate": "2020-07-06T17:32:59.000+02:00"
					},
					"documentsInfo": [
						{
							"idDocumentType": 1135,
							"documents": [
								{
									"idArticleDocument": 47691,
									"name": "2839_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						},
						{
							"idDocumentType": 1152,
							"documents": [
								{
									"idArticleDocument": 47685,
									"name": "1996_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 206782815,
									"creationDate": "2020-09-08T11:09:59.000+02:00"
								}
							]
						}
					]
				},
				{
					"idColor": 17764,
					"joinLife": {
						"idStatus": 66,
						"idLabel": 160,
						"creationDate": "2020-07-06T17:32:59.000+02:00"
					},
					"documentsInfo": [
						{
							"idDocumentType": 1098,
							"documents": [
								{
									"idArticleDocument": 47690,
									"name": "2839_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 211909804,
									"creationDate": "2020-09-08T11:10:00.000+02:00"
								}
							]
						},
						{
							"idDocumentType": 1152,
							"documents": [
								{
									"idArticleDocument": 47684,
									"name": "1996_001.pdf",
									"idDocumentState": 2,
									"idDocDownload": 206782815,
									"creationDate": "2020-09-08T11:09:59.000+02:00"
								}
							]
						}
					]
				}
			]
		},
         {
            "basicInfo":{
               "coreInfo":{
                  "idArticle":2563343,
                  "model":6429,
                  "quality":644,
                  "idProduct":1,
                  "codProduct":0,
                  "idCampaign":27,
                  "idPurchaseCenter":4,
                  "codPurchaseCenter":"01",
                  "idBranch":4
               },
               "extendedInfo":{
                  "idSizingSystem":10004,
                  "idLabelTypeRFID":1,
                  "idArticleType":2,
                  "idArticleDesign":2737218,
                  "idAlarm":1001,
                  "idOriginCountry":676,
                  "originCountryISO":"MM",
                  "idFamily":167,
                  "codFamily":7,
                  "idExportFamily":167,
                  "idSubFamily":739,
                  "codSubFamily":107,
                  "idSectionType":1,
                  "idSection":14,
                  "idSubSection":58,
                  "packUnits":0,
                  "idDenim":0,
                  "idManufacturer":854855,
                  "idTariffGroup":3,
                  "isWoman":true,
                  "commercialDescription":{
                     "defaultDescription":"A2A (BASBER) ABRIGO SOFT PU"
                  },
                  "articleStates":[
                     6
                  ],
                  "idRealSectionType":1,
                  "idPurchaser":632,
                  "idCommercialAttributeValue":3538,
                  "idsCommercialClassifica":[
                     7,
                     12
                  ],
                  "creationInfo":{
                     "creationDate":"2020-04-30T14:08:16.000+02:00",
                     "creationUser":"rosaliapb"
                  },
                  "commercialClassificationAttributes":[
                     {
                        "id":1539
                     },
                     {
                        "id":1707
                     }
                  ]
               }
            },
            "joinLife":{
               "isJoinLife":false
            }
         },         
         {
            "basicInfo":{
               "coreInfo":{
                  "idArticle":2392914,
                  "model":11,
                  "quality":645,
                  "idProduct":1,
                  "codProduct":0,
                  "idCampaign":27,
                  "idPurchaseCenter":4,
                  "codPurchaseCenter":"01",
                  "idBranch":4
               },
               "extendedInfo":{
                  "idSizingSystem":10026,
                  "idLabelTypeRFID":1,
                  "idArticleType":1,
                  "idArticleDesign":2737234,
                  "idAlarm":1001,
                  "idOriginCountry":666,
                  "originCountryISO":"BD",
                  "idFamily":169,
                  "codFamily":10,
                  "idExportFamily":169,
                  "idSubFamily":807,
                  "codSubFamily":510,
                  "idSectionType":2,
                  "idSection":33,
                  "idSubSection":61,
                  "packUnits":0,
                  "idDenim":0,
                  "idManufacturer":0,
                  "idTariffGroup":3,
                  "isWoman":false,
                  "commercialDescription":{
                     "defaultDescription":"B.O ECOVERO MAN"
                  },
                  "articleStates":[
                     37
                  ],
                  "idRealSectionType":2,
                  "idPurchaser":10977,
                  "idsCommercialClassifica":[
                     11,
                     9,
                     7
                  ],
                  "creationInfo":{
                     "creationDate":"2020-04-30T15:03:55.000+02:00",
                     "creationUser":"nataliaheg"
                  },
                  "commercialClassificationAttributes":[
                     {
                        "id":1710
                     }
                  ]
               }
            },
            "joinLife":{
               "isJoinLife":false
            }
         },
         {
            "basicInfo":{
               "coreInfo":{
                  "idArticle":2392897,
                  "model":7540,
                  "quality":33,
                  "idProduct":1,
                  "codProduct":0,
                  "idCampaign":27,
                  "idPurchaseCenter":4,
                  "codPurchaseCenter":"01",
                  "idBranch":4
               },
               "extendedInfo":{
                  "idSizingSystem":10004,
                  "idLabelTypeRFID":1,
                  "idArticleType":1,
                  "idArticleDesign":2737217,
                  "idAlarm":1001,
                  "idOriginCountry":10,
                  "originCountryISO":"PT",
                  "idFamily":170,
                  "codFamily":11,
                  "idExportFamily":170,
                  "idSubFamily":872,
                  "codSubFamily":311,
                  "idSectionType":1,
                  "idSection":14,
                  "idSubSection":59,
                  "packUnits":0,
                  "idDenim":0,
                  "idManufacturer":762680,
                  "idTariffGroup":3,
                  "isWoman":true,
                  "commercialDescription":{
                     "defaultDescription":"(BLOBSK)(MIX)JL CMTA M/C BRATZ"
                  },
                  "articleStates":[
                     47,
                     13,
                     27
                  ],
                  "idRealSectionType":1,
                  "idPurchaser":647,
                  "idCommercialAttributeValue":3280,
                  "idsCommercialClassifica":[
                     12,
                     9,
                     7
                  ],
                  "creationInfo":{
                     "creationDate":"2020-04-30T14:03:51.000+02:00",
                     "creationUser":"montserratpbu"
                  },
                  "commercialClassificationAttributes":[
                     {
                        "id":2008
                     },
                     {
                        "id":1708
                     }
                  ]
               }
            },
            "joinLife":{
               "isJoinLife":true,
               "creationDate":"2020-04-30T14:04:15.000+02:00"
            },
            "colorsInfo":[
               {
                  "idColor":1489,
                  "joinLife":{
                     "idStatus":66,
                     "idLabel":140,
                     "creationDate":"2020-06-04T14:20:11.000+02:00"
                  },
                  "documentsInfo":[
                     {
                        "idDocumentType":1135,
                        "documents":[
                           {
                              "idArticleDocument":26710,
                              "name":"FIBERTC_1000463-00508756.pdf",
                              "idDocumentState":8,
                              "idDocDownload":207740748,
                              "creationDate":"2020-07-17T09:57:37.000+02:00"
                           }
                        ]
                     },
                     {
                        "idDocumentType":1152,
                        "documents":[
                           {
                              "idArticleDocument":10573,
                              "name":"YARNTC_809673_00437061.pdf",
                              "idDocumentState":9,
                              "idDocDownload":203907687,
                              "creationDate":"2020-06-04T14:20:11.000+02:00"
                           }
                        ]
                     }
                  ]
               },
               {
                  "idColor":1255,
                  "joinLife":{
                     "idStatus":66,
                     "idLabel":140,
                     "creationDate":"2020-06-04T14:20:11.000+02:00"
                  },
                  "documentsInfo":[
                     {
                        "idDocumentType":1135,
                        "documents":[
                           {
                              "idArticleDocument":26709,
                              "name":"FIBERTC_1000463-00508756.pdf",
                              "idDocumentState":2,
                              "idDocDownload":207740748,
                              "creationDate":"2020-06-04T14:20:11.000+02:00"
                           }
                        ]
                     }
                  ]
               }
            ]
         },
               {
         "basicInfo":{
            "coreInfo":{
               "idArticle":2440083,
               "model":9247,
               "quality":348,
               "idProduct":1,
               "codProduct":0,
               "idCampaign":27,
               "idPurchaseCenter":3,
               "codPurchaseCenter":"W",
               "idBranch":2
            },
            "extendedInfo":{
               "idSizingSystem":10009,
               "idLabelTypeRFID":1,
               "idArticleType":1,
               "idArticleDesign":2784408,
               "idAlarm":981,
               "idOriginCountry":10,
               "originCountryISO":"PT",
               "idFamily":1295,
               "codFamily":11,
               "idExportFamily":1295,
               "idSubFamily":3497,
               "codSubFamily":358,
               "idSectionType":1,
               "idSection":18,
               "idSubSection":18,
               "packUnits":0,
               "idDenim":0,
               "idManufacturer":746876,
               "idTariffGroup":3,
               "isWoman":true,
               "commercialDescription":{
                  "defaultDescription":"CIR CAM LICENCIAS MICKEY & PLUTO FOTO (*Z)"
               },
               "articleStates":[
                  47,
                  6,
                  27
               ],
               "idRealSectionType":1,
               "idPurchaser":14456,
               "idCommercialAttribute":1443,
               "idCommercialAttributeValue":1451,
               "idsCommercialClassifica":[
                  3,
                  12,
                  8
               ],
               "creationInfo":{
                  "creationDate":"2020-06-22T18:07:04.000+02:00",
                  "creationUser":"carolinabm"
               }
            }
         },
         "joinLife":{
            "isJoinLife":true,
            "creationDate":"2020-06-22T18:07:07.000+02:00"
         },
         "colorsInfo":[
            {
               "idColor":11178,
               "joinLife":{
                  "idStatus":66,
                  "idLabel":109,
                  "creationDate":"2020-09-07T16:15:02.000+02:00"
               },
               "documentsInfo":[
                  {
                     "idDocumentType":1136,
                     "documents":[
                        {
                           "idArticleDocument":47150,
                           "name":"TC_MICKEY PLUTO.pdf",
                           "idDocumentState":1,
                           "idDocDownload":211825531,
                           "creationDate":"2020-09-07T16:15:02.000+02:00"
                        },
                        {
                           "idArticleDocument":47151,
                           "name":"(mickey pluto )TC_.pdf",
                           "idDocumentState":2,
                           "idDocDownload":211831420,
                           "creationDate":"2020-09-07T16:15:02.000+02:00"
                        },
                        {
                           "idArticleDocument":47152,
                           "name":"AD MICKEY PLUTO.JPG",
                           "idDocumentState":7,
                           "idDocDownload":211820078,
                           "creationDate":"2020-09-07T16:15:02.000+02:00"
                        }
                     ]
                  },
                  {
                    "idDocumentType":1152,
                    "documents":[
                              {
                                 "idArticleDocument":16803,
                                 "name":"Yarn TC_00352211.pdf",
                                 "idDocumentState":3,
                                 "idDocDownload":204387697,
                                 "creationDate":"2020-06-25T12:28:27.000+02:00"
                              },
                              {
                                 "idArticleDocument":32744,
                                 "name":"Yarn TC-00389024.pdf",
                                 "idDocumentState":2,
                                 "idDocDownload":208705760,
                                 "creationDate":"2020-07-30T10:16:58.000+02:00"
                              }
                           ]
                  }
               ]
            }
         ]
      }
      ],
                "syncActiveInfo": {
        "syncDate": "2020-09-23T14:30:48.000+02:00",
        "previousActivationDate": "2020-10-02T01:57:55.522+02:00"
    }
   }
''';

def json = new groovy.json.JsonSlurper().parseText(input)


def id_art_ls0 = json.articles.basicInfo.coreInfo.idArticle.toString().split(',');

//////////////////////////////////////// Test ////////////////////////////////////////////

def id_art_ls = json.articles.basicInfo.coreInfo.idArticle.toString().split(',');
def ls_id_art = [];
def art_states_ls = json.articles.basicInfo.extendedInfo.articleStates.toString().split('\\],');
def ls_art_st = [];
//def id_col_ls = json.articles.colorsInfo.idColor.toString().split('\\],');
//println(id_col_ls)
def ls_id_col = [];
def creation_date_ls = json.articles.colorsInfo.joinLife.creationDate.toString().split('\\],');
def ls_cd_col = [];
def ls_id_lbl = [];
def ls_doc_typ = [];
def ls_doc_st = [];
def ls_doc_cd = [];

// No todos los artículos tienen articleStates por tanto hay que llenar el vector buscando nulos
// Para cada idArticle hay 1 colors_info y 1 articleStates --> 1 idArticle (Not Null) 1 articleStates (Puede ser nulo)
// En cada colors_info hay n idColor --> 1 idArticle N idColor (Not Null)
// Por cada idColor hay 1 idLabel (Puede ser nulo) y 1 creationDate (Puede ser nulo)
// En cada colors_info hay 1 documentsInfo (Puede ser nulo) por cada idColor --> 1 idColor 1 documentsInfo
// En cada colors_info hay 1 documentsInfo (Puede ser nulo) por cada idColor --> 1 idColor 1 documentsInfo
// En cada documentsInfo puede haber n idDocumentType (Not Null si Existe) -->  1 --> N idDocumentType
// En cada idDocumentType puede haber n idArticleDocument (Not Null si Existe) que equivale a 1 idDocumentState y1 creationDate



println("Prueba")
println(json.articles[0].colorsInfo.idColor)
println(json.articles[0].colorsInfo.joinLife.idLabel)
println(json.articles[4].colorsInfo[0].documentsInfo[0].documents[0].idDocumentState)
//println(json.articles[1].colorsInfo[1].toString().contains('idLabel'))
println("End Prueba")
println("")

////////////// NUEVO TEST RAPIDO 2 /////////////////////////////////


for (i = 0; i < id_art_ls.size(); i++) {
  def color = 'null';
  def estado_composicion = 'null';
  def etiqueta = 'null';
  def fecha_grab_etiq_jl = 'null';
  def tipo_certificado = 'null';
  def estado_certificado = 'null';
  def fecha_doc_certificado = 'null';
  if(json.articles[i].colorsInfo==null){
      if(json.articles[i].basicInfo.extendedInfo.toString().contains('articleStates')){
      if(json.articles[i].basicInfo.extendedInfo.articleStates.contains(6) || json.articles[i].basicInfo.extendedInfo.articleStates.contains(13)){
        estado_composicion = 'Validada';}else{estado_composicion='null';}}else{estado_composicion='null';}
      println(id_art_ls[i].replaceAll('\\]','').replaceAll('\\[','').trim()+';'+estado_composicion+';'+color+';'+etiqueta+';'+fecha_grab_etiq_jl+';'+tipo_certificado+';'+estado_certificado+';'+fecha_doc_certificado)
  }else{
      if(json.articles[i].basicInfo.extendedInfo.toString().contains('articleStates')){
      if(json.articles[i].basicInfo.extendedInfo.articleStates.contains(6) || json.articles[i].basicInfo.extendedInfo.articleStates.contains(13)){
        estado_composicion = 'Validada';}}
      def cont_col_info = 0;
      json.articles[i].colorsInfo.each{
        //println("cont_col_info: "+cont_col_info);
        if(it.toString().contains('idLabel')){
          etiqueta = json.articles[i].colorsInfo[cont_col_info].joinLife.idLabel
            if(it.toString().contains('creationDate')){
              fecha_grab_etiq_jl = json.articles[i].colorsInfo[cont_col_info].joinLife.creationDate}
        } else{etiqueta='null'; fecha_grab_etiq_jl='null';}
        if(it.toString().contains('idColor')){
          color = json.articles.colorsInfo[i].idColor[cont_col_info];
        } else{color='null';}
        if(it.documentsInfo==null){
          println(id_art_ls[i].replaceAll('\\]','').replaceAll('\\[','').trim()+';'+estado_composicion+';'+color+';'+etiqueta+';'+fecha_grab_etiq_jl+';'+tipo_certificado+';'+estado_certificado+';'+fecha_doc_certificado)}
        else{
          def cont_docu_info = 0;
          it.documentsInfo.each{
            //println("cont_docu_info: "+cont_docu_info);
            if(it.toString().contains('idDocumentType')){
              tipo_certificado = json.articles[i].colorsInfo[cont_col_info].documentsInfo[cont_docu_info].idDocumentType;}
              else{tipo_certificado='null';}
              if(it.documents==null){
                println(id_art_ls[i].replaceAll('\\]','').replaceAll('\\[','').trim()+';'+estado_composicion+';'+color+';'+etiqueta+';'+fecha_grab_etiq_jl+';'+tipo_certificado+';'+estado_certificado+';'+fecha_doc_certificado)}
              else{
                def cont_documents = 0;
                it.documents.each{
                  //println("cont_documents: "+cont_documents)
                  if(it.toString().contains('idDocumentState')){
                    estado_certificado = json.articles[i].colorsInfo[cont_col_info].documentsInfo[cont_docu_info].documents[cont_documents].idDocumentState;}
                    else{estado_certificado='null';}
                  if(it.toString().contains('creationDate')){
                    fecha_doc_certificado = json.articles[i].colorsInfo[cont_col_info].documentsInfo[cont_docu_info].documents[cont_documents].creationDate;}
                    else{fecha_doc_certificado='null';}
                  println(id_art_ls[i].replaceAll('\\]','').replaceAll('\\[','').trim()+';'+estado_composicion+';'+color+';'+etiqueta+';'+fecha_grab_etiq_jl+';'+tipo_certificado+';'+estado_certificado+';'+fecha_doc_certificado)
                  cont_documents=cont_documents+1;
              } //each documents
            } //else documents is null
          cont_docu_info=cont_docu_info+1;
          } //each documentsInfo
        } // else documentsInfo is null
      cont_col_info=cont_col_info+1;
      } //each colorsInfo
   } // else colorsInfo is null
}


////////////// END TEST + RAPIDO 2 /////////////////////////////////

println("")
println("")
/////////////// OK /////////////////
/*
//for (i = 0; i < id_art_ls.size(); i++) {
for (i = 1; i < 2; i++) {
  def id_lbl_array = [];
  def cd_col_array = [];
  def doc_typ_array = [];
  def doc_st_array = [];
  def doc_cd_array = [];
  if(json.articles[i].colorsInfo==null){
    id_lbl_array.add([null]);
    cd_col_array.add(null);
    doc_typ_array.add(null);
    doc_st_array.add(null);
    doc_cd_array.add(null);
    ls_id_col.add([null]);
    }else{
  def cont_col_info = 0;
  json.articles[i].colorsInfo.each{
    if(it.toString().contains('idLabel')){
      id_lbl_array.add(json.articles[i].colorsInfo[cont_col_info].joinLife.idLabel);
	  if(it.toString().contains('creationDate')){
		cd_col_array.add(json.articles[i].colorsInfo[cont_col_info].joinLife.creationDate);}}
    else{id_lbl_array.add(null);
	       cd_col_array.add(null);}
    cont_col_info=cont_col_info+1;
    }
  def cont_doc_typ = 0;
  def cont_doc_st = 0;
  def cont_doc_cd = 0;
  if(json.articles[i].colorsInfo.documentsInfo==null){
    doc_typ_array.add(null);
    doc_st_array.add(null);
    doc_cd_array.add(null);
  }else{
  json.articles[i].colorsInfo.documentsInfo.each{
    if(it.toString().contains('idDocumentType')){
      def arr1 = json.articles[i].colorsInfo.documentsInfo.idDocumentType[cont_doc_typ];
    doc_typ_array.add(arr1);}
    else{doc_typ_array.add(null);}
    if(it.toString().contains('idDocumentState')){
      def arr2 = json.articles[i].colorsInfo.documentsInfo.documents.idDocumentState[cont_doc_st];
    doc_st_array.add(arr2);}
    else{doc_st_array.add(null);}
    if(it.toString().contains('creationDate')){
      def arr3 = json.articles[i].colorsInfo.documentsInfo.documents.creationDate[cont_doc_cd];
    doc_cd_array.add(arr3);}
    else{doc_cd_array.add(null);}
    cont_doc_typ=cont_doc_typ+1;
    cont_doc_st=cont_doc_st+1;
    cont_doc_cd=cont_doc_cd+1;
  }}
  if(json.articles[i].colorsInfo.toString().contains('idColor')){
    def arr4 = json.articles.colorsInfo[i].idColor.toString().replaceAll('\\]','').replaceAll('\\[','').split(',').collect{it as int}
  ls_id_col.add(arr4);}
  else{ls_id_col.add(null)}
  }
  def ls_as = '';
  if(json.articles[i].basicInfo.extendedInfo.toString().contains('articleStates')){
      if(json.articles[i].basicInfo.extendedInfo.articleStates.contains(6) || json.articles[i].basicInfo.extendedInfo.articleStates.contains(13)){
      ls_as='Validada';} else{ls_as=null;}
      ls_art_st.add(ls_as);}
  else{ls_art_st.add(null)
  }     
  def k = id_art_ls[i].replaceAll('\\]','').replaceAll('\\[','').split(',').collect{it as int}
  ls_id_art.add(k);
  ls_id_lbl.add(id_lbl_array);
  ls_cd_col.add(cd_col_array);
  ls_doc_typ.add(doc_typ_array);
  ls_doc_st.add(doc_st_array);
  ls_doc_cd.add(doc_cd_array);
}

//Primer nivel i
//println(ls_id_art) // idArticle
//println(ls_art_st) // articleStates
//Segundo nivel j
//println(ls_id_col) // idColor
//println(ls_id_lbl) // idLabel
//println(ls_cd_col) // creationDate (idColor)
//Tercer nivel k
//println(ls_doc_typ) // idDocumentType
//Cuarto nivel l
//println(ls_doc_st) // idDocumentState
//println(ls_doc_cd) // creationDate (idColor)

//println("")
//println(new_array_art)
//println(ls_art_st0)
//println("")





for (i = 0; i < ls_id_art.size(); i++) {
    for (j = 0; j < ls_id_col[i].size(); j++) {
        if(ls_doc_typ[i][j]==null){inner_ls_doc_typ = [ls_doc_typ[i][j]];}else{inner_ls_doc_typ = ls_doc_typ[i][j];}
        //println(ls_doc_typ[i][j]);
        //println(inner_ls_doc_typ);
        //println(inner_ls_doc_typ.size());
        if(ls_doc_st[i][j]==null){inner_ls_doc_st = [ls_doc_st[i][j]];}else{inner_ls_doc_st = ls_doc_st[i][j];}
				//println(inner_ls_doc_st);
        if(ls_doc_cd[i][j]==null){inner_ls_doc_cd = [ls_doc_cd[i][j]];}else{inner_ls_doc_cd = ls_doc_cd[i][j];}
        //println(inner_ls_doc_st);
				for (k = 0; k < inner_ls_doc_typ.size(); k++) {
				  //println("ijk: "+i+j+k)
				  if(inner_ls_doc_st[k]==null){in_in_ls_doc_st = [inner_ls_doc_st[k]];}else{in_in_ls_doc_st = inner_ls_doc_st[k];}
				  if(inner_ls_doc_cd[k]==null){in_in_ls_doc_cd = [inner_ls_doc_cd[k]];}else{in_in_ls_doc_cd = inner_ls_doc_cd[k];}
				  for (l = 0; l < in_in_ls_doc_st.size(); l++) {
				      //println(ls_id_art[i].toString().replaceAll('\\W', '').trim());
				      //println(ls_art_st[i].toString().replaceAll('\\W', '').trim());
				      //println(ls_id_col[i][j].toString().replaceAll('\\W', '').trim());
				      //println(ls_id_lbl[i][j].toString().replaceAll('\\W', '').trim());
              //println(ls_cd_col[i][j].toString().replaceAll('\\]','').replaceAll('\\[','').trim().replaceAll('T',' '));
              //println(inner_ls_doc_typ[k].toString().replaceAll('\\W', '').trim());
              //println(in_in_ls_doc_st[l].toString().replaceAll('\\W', '').trim());
              //println(in_in_ls_doc_cd[l].toString().replaceAll('\\]','').replaceAll('\\[','').trim().replaceAll('T',' '));
              println(ls_id_art[i].toString().replaceAll('\\W', '').trim()+';'+ls_art_st[i].toString().replaceAll('\\W', '').trim()+';'+ls_id_col[i][j].toString().replaceAll('\\W', '').trim()+';'+ls_id_lbl[i][j].toString().replaceAll('\\W', '').trim()+';'+ls_cd_col[i][j].toString().replaceAll('\\]','').replaceAll('\\[','').trim().replaceAll('T',' ')+';'+inner_ls_doc_typ[k].toString().replaceAll('\\W', '').trim()+';'+in_in_ls_doc_st[l].toString().replaceAll('\\W', '').trim()+';'+in_in_ls_doc_cd[l].toString().replaceAll('\\]','').replaceAll('\\[','').trim().replaceAll('T',' '));
        }
    }
  }
}
*/

 
by

Groovy online compiler

Write, Run & Share Groovy code online using OneCompiler's Groovy online compiler for free. It's one of the robust, feature-rich online compilers for Groovy language, running the latest Groovy version 2.6. Getting started with the OneCompiler's Groovy editor is easy and fast. The editor shows sample boilerplate code when you choose language as Groovy and start coding.

Read inputs from stdin

OneCompiler's Groovy online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample Groovy program which takes name as input and prints hello message with your name.

def name = System.in.newReader().readLine()
println "Hello " + name

About Groovy

Groovy is an object-oriented programming language based on java. Apache Groovy is a dynamic and agile language which is similar to Python, Ruby, Smalltalk etc.

Key Features

  • It's not a replacement for java but it's an enhancer to Java with extra features like DSL support, dynamic typing, closures etc.
  • Accepts Java code as it extends JDK
  • Greater flexibility
  • Concise and much simpler compared to Java
  • Can be used as both programming language and scripting language.

Syntax help

Data Types

Data typeDescriptionRange
StringTo represent text literalsNA
charTo represent single character literalNA
intTo represent whole numbers-2,147,483,648 to 2,147,483,647
shortTo represent short numbers-32,768 to 32,767
longTo represent long numbers-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
doubleTo represent 64 bit floating point numbers4.94065645841246544e-324d to 1.79769313486231570e+308d
floatTo represent 32 bit floating point numbers1.40129846432481707e-45 to 3.40282346638528860e+38
byteTo represent byte value-128 to 127
booleanTo represent boolean values either true or falseTrue or False

Variables

You can define variables in two ways

Syntax:

data-type variable-name;

[or]

def variable-name;

Loops

0.upto(n) {println "$it"}

or

n.times{println "$it"}

where n is the number of loops and 0 specifies the starting index

Decision-Making

1. If / Nested-If / If-Else:

When ever you want to perform a set of operations based on a condition or set of conditions, then If / Nested-If / If-Else is used.

if(conditional-expression) {
  // code
} else {
  // code
}

2. Switch:

Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 //code to be executed when all the above cases are not matched;    
} 

List

List allows you to store ordered collection of data values.

Example:

def mylist = [1,2,3,4,5];
List MethodsDescription
size()To find size of elements
sort()To sort the elements
add()To append new value at the end
contains()Returns true if this List contains requested value.
get()Returns the element of the list at the definite position
pop()To remove the last item from the List
isEmpty()Returns true if List contains no elements
minus()This allows you to exclude few specified elements from the elements of the original
plus()This allows you to add few specified elements to the elements of the original
remove()To remove the element present at the specific position
reverse()To reverse the elements of the original List and creates new list