Groovy web console

subscribe to the feed Subscribe
to this
site

app_event_holds_transformation_expression

Published 3 weeks ago by utelemaco
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.JsonOutput
import groovy.json.JsonBuilder
import java.util.List;

def _entity = [:]
_entity.cargaServicos = []
_entity.cargaServicos << [:]
_entity.cargaServicos[0].carga = [:]
_entity.cargaServicos[0].carga.identificador = 'AAAA123456'

_entity.cargaServicos << [:]
_entity.cargaServicos[1].carga = [:]
_entity.cargaServicos[1].carga.identificador = 'BBBBB98765'

def serviceInstance = _entity

List<String> cargas = new ArrayList<String>();

serviceInstance.cargaServicos.each { cargaServicos ->
    cargas.add(cargaServicos.carga.identificador);
}

def holds = [[action : "RELEASE_HOLD", holdPermId : "BLOQUEIO_NFE_PORTAL"]]

def jsonObj = [:]
jsonObj.hpu = [:]
jsonObj.hpu.entities = [:]
jsonObj.hpu.entities.units = [:]
jsonObj.hpu.flags = [:]
jsonObj.hpu.flags.flag = [:]

jsonObj.hpu.entities.units = [:]
jsonObj.hpu.entities.units.unitIdentity = cargas.collect { [id: "${it}"] }


def flags = new groovy.json.JsonBuilder(holds)

jsonObj.hpu.flags = flags.content

return JsonOutput.prettyPrint(JsonOutput.toJson(jsonObj))