Groovy web console

subscribe to the feed Subscribe
to this
site
EmpresaBeanUtil (via #groovywebconsole)
tweet this snippet Tweet
this
script

EmpresaBeanUtil

Published 6 months ago by Ulisses
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Bean {
   def cnpjCliente
   def cnpjRequisitante
}

class PedidoProgramacao {
   def cliente
   def requisitante
}

class EmpresaQuery {
  public findByCnpj(def cnpj) {
    if('111'== cnpj) return 'Login'
    if('222' == cnpj) return 'OWSE'
    return 'Empresa not found'
  }
}

class EmpresaBeanUtil {
   public void defineEmpresa(Bean bean, PedidoProgramacao pedidoProgramacao, String tipoCliente) {
      EmpresaQuery eQuery = new EmpresaQuery()
      pedidoProgramacao."${tipoCliente}" = eQuery.findByCnpj(bean."cnpj${tipoCliente.capitalize()}")
   }
}

Bean myBean = new Bean()
myBean.cnpjCliente = '111'
myBean.cnpjRequisitante = '222'

PedidoProgramacao myPP = new PedidoProgramacao()

EmpresaBeanUtil eBeanUtil = new EmpresaBeanUtil()

eBeanUtil.defineEmpresa(myBean, myPP, 'cliente')
println myPP.cliente

eBeanUtil.defineEmpresa(myBean, myPP, 'requisitante')
println myPP.requisitante