public VistaFuncionWrapper(
     long vista, EnumFormatoGuardar formato, EnumTipoInforme tipo, String select)
     throws ExcepcionAplicacion {
   _id = vista;
   _nombre = Global.PREFIJO_STRING_ID_RECURSO + vista;
   _formato = formato != null ? formato : EnumFormatoGuardar.INFORME;
   _tipo = tipo != null ? tipo : EnumTipoInforme.DETALLE;
   if (_formato.equals(EnumFormatoGuardar.ARCHIVO) && _tipo.equals(EnumTipoInforme.GRAFICO)) {
     throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.GRAFICO_NO_DISPONIBLE));
   }
   _select = StringUtils.trimToNull(select);
   if (_select == null) {
     throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT));
   }
   init();
 }
 private boolean write(VelocityContext context, String tempname, String filename)
     throws ExcepcionAplicacion {
   if (VelocityEngineer.init()) {
     try {
       VelocityEngineer.write(context, tempname, filename);
       return true;
     } catch (Exception ex) {
       throw new ExcepcionAplicacion(ex);
     }
   }
   throw new ExcepcionAplicacion(
       Bitacora.getTextoMensaje(CBM.RECURSO_NO_DISPONIBLE, Velocity.class.getName()));
 }
 public boolean generateJasperReport() throws ExcepcionAplicacion {
   check();
   File dir = Reporter.getUserDefinedReportsDir();
   if (dir == null) {
     throw new ExcepcionAplicacion(
         Bitacora.getTextoMensaje(CBM.RECURSO_NO_DISPONIBLE, EAC.REPORT_SOURCE_DIR));
   }
   String sep = System.getProperties().getProperty("file.separator");
   String informe = getReportSourceFileName();
   String tempname = "informe" + "-" + _tipo.name().toLowerCase() + "." + "jrxml" + "." + "vm";
   String filename = dir.getPath() + sep + informe + "." + "jrxml";
   Report report = new Report(this, _tipo);
   VelocityContext context = VelocityAid.newVelocityContext();
   context.put("report", report);
   context.put("eacode", EAB.ENTERPRISE_APPLICATION_CODE);
   return write(context, tempname, filename);
 }
 private void init() throws ExcepcionAplicacion {
   _vista = EJBL.getVistaFuncionFacade().find(_id, true);
   if (_vista == null) {
     throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.VISTA_NO_DISPONIBLE, _nombre));
   }
   _nombre = _vista.getNombre();
   _from = from(_select);
   if (StringUtils.isBlank(_from)) {
     // vista "{0}" no tiene origen
     throw new ExcepcionAplicacion(
         Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_1, _nombre));
   }
   _where = where(_select);
   _columnas = new ArrayList<>(_vista.getVistaFuncionColByVistaCollection());
   _columnasOcultas = new ArrayList<>();
   _grupos = new ArrayList<>();
   _agregaciones = new ArrayList<>();
   VistaFuncionColPorSecuencia c1 = new VistaFuncionColPorSecuencia();
   VistaFuncionColPorId c2 = new VistaFuncionColPorId();
   Comparator<VistaFuncionColBase> comparator =
       (Comparator<VistaFuncionColBase>) ComparatorUtils.chainedComparator(c1, c2);
   Collections.sort((List<VistaFuncionColBase>) _columnas, comparator);
   boolean parametrosRestringidos =
       TLC.getControlador().esFuncionConParametrosRestringidos(_vista.getFuncion().getIdFuncion());
   String codigoDominio = _vista.getFuncion().getIdDominio().getCodigoDominio();
   TipoAgregacionBase agregacion;
   TipoAgregacionEnumeration tipoAgregacion;
   VistaFuncionColBase grupo;
   String alias;
   String propertyColumn;
   Long propertySelect;
   boolean parametroAutorizado;
   for (VistaFuncionColBase vistaFuncionCol : _columnas) {
     agregacion = vistaFuncionCol.getAgregacion();
     tipoAgregacion =
         agregacion == null ? null : TipoAgregacionEnumeration.valueOf(agregacion.getNumero());
     grupo = vistaFuncionCol.getGrupo();
     alias = vistaFuncionCol.getAlias();
     if (parametrosRestringidos) {
       propertyColumn = BaseBundle.getPropertyColumn(codigoDominio, alias);
       propertySelect = BaseBundle.getPropertySelect(codigoDominio, alias);
       parametroAutorizado =
           propertyColumn == null
               || propertySelect == null
               || TLC.getControlador().esParametroAutorizado(propertyColumn, propertySelect);
     } else {
       parametroAutorizado = true;
     }
     if (parametroAutorizado) {
       if (tipoAgregacion != null) {
         if (TipoAgregacionEnumeration.GRUPO.equals(tipoAgregacion)) {
           if (grupo != null && vistaFuncionCol.getId().equals(grupo.getId())) {
             _grupos.add(vistaFuncionCol);
             _ultimo = vistaFuncionCol;
           }
         } else {
           _agregaciones.add(vistaFuncionCol);
         }
       }
       _orden |= BitUtils.valueOf(vistaFuncionCol.getOrden());
     } else {
       _columnasOcultas.add(vistaFuncionCol);
     }
   }
   if (_columnasOcultas.isEmpty()) {
     if (_columnas.isEmpty()) {
       // vista "{0}" no tiene columnas
       throw new ExcepcionAplicacion(
           Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_2, _nombre));
     }
     switch (_tipo) {
       case DETALLE:
         if (_grupos.isEmpty()) {
         } else if (_agregaciones.isEmpty()) {
           // vista "{0}" no tiene agregaciones
           throw new ExcepcionAplicacion(
               Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_4, _nombre));
         }
         break;
       case GRAFICO:
         if (_grupos.isEmpty()) {
           // vista "{0}" no tiene grupos
           throw new ExcepcionAplicacion(
               Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_3, _nombre));
         }
         if (_agregaciones.isEmpty()) {
           // vista "{0}" no tiene agregaciones
           throw new ExcepcionAplicacion(
               Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_4, _nombre));
         }
         agregacion = null;
         for (VistaFuncionColBase vistaFuncionCol : _agregaciones) {
           if (BitUtils.valueOf(vistaFuncionCol.getGraficable())) {
             continue;
           }
           agregacion = vistaFuncionCol.getAgregacion();
           tipoAgregacion = TipoAgregacionEnumeration.valueOf(agregacion.getNumero());
           TLC.getBitacora()
               .error(
                   CBM.COLUMNA_NO_GRAFICABLE,
                   vistaFuncionCol.getNombre(),
                   tipoAgregacion.getLabel());
         }
         if (agregacion != null) {
           throw new ExcepcionAplicacion(
               Bitacora.getTextoMensaje(CBM.VISTA_NO_GRAFICABLE, _nombre));
         }
         break;
       case RESUMEN:
         if (_agregaciones.isEmpty()) {
           // vista "{0}" no tiene agregaciones
           throw new ExcepcionAplicacion(
               Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT_VISTA_4, _nombre));
         }
         break;
     }
   } else {
     for (VistaFuncionColBase vistaFuncionCol : _columnasOcultas) {
       TLC.getBitacora().error(CBM.COLUMNA_NO_AUTORIZADA, vistaFuncionCol.getNombre());
     }
     throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.VISTA_NO_AUTORIZADA, _nombre));
   }
   if (_orden) {
   } else {
     // vista "{0}" no tiene orden
     TLC.getBitacora().warn(CBM.ERROR_COMANDO_SELECT_VISTA_5, _nombre);
   }
   _vistaValida = true;
 }
 private void check() throws ExcepcionAplicacion {
   if (!_vistaValida) {
     throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.VISTA_NO_DISPONIBLE, _nombre));
   }
 }