/**
   * Seta informacoes importantes para a gravacao dados. As informacoes serao preenchidas nas
   * collections: colCamposPK, colCamposTodos
   *
   * @param colGrupos
   * @param colCamposPK
   * @param colCamposTodos
   * @throws Exception
   */
  @Override
  public void setInfoSave(
      final Integer idVisao, final Collection colCamposPK, final Collection colCamposTodos)
      throws Exception {
    final GrupoVisaoCamposNegocioDao grupoVisaoCamposNegocioDao = new GrupoVisaoCamposNegocioDao();
    final CamposObjetoNegocioDao camposObjetoNegocioDao = new CamposObjetoNegocioDao();
    final GrupoVisaoDao grupoVisaoDao = new GrupoVisaoDao();

    final Collection colGrupos = grupoVisaoDao.findByIdVisaoAtivos(idVisao);
    if (colGrupos != null) {
      for (final Iterator it = colGrupos.iterator(); it.hasNext(); ) {
        final GrupoVisaoDTO grupoVisaoDTO = (GrupoVisaoDTO) it.next();
        grupoVisaoDTO.setColCamposVisao(
            grupoVisaoCamposNegocioDao.findByIdGrupoVisaoAtivos(grupoVisaoDTO.getIdGrupoVisao()));

        if (grupoVisaoDTO.getColCamposVisao() != null) {
          for (final Iterator it2 = grupoVisaoDTO.getColCamposVisao().iterator(); it2.hasNext(); ) {
            final GrupoVisaoCamposNegocioDTO grupoVisaoCamposNegocioDTO =
                (GrupoVisaoCamposNegocioDTO) it2.next();

            CamposObjetoNegocioDTO camposObjetoNegocioDTO = new CamposObjetoNegocioDTO();
            camposObjetoNegocioDTO.setIdCamposObjetoNegocio(
                grupoVisaoCamposNegocioDTO.getIdCamposObjetoNegocio());
            camposObjetoNegocioDTO =
                (CamposObjetoNegocioDTO) camposObjetoNegocioDao.restore(camposObjetoNegocioDTO);

            if (camposObjetoNegocioDTO != null) {
              camposObjetoNegocioDTO.setFormula(grupoVisaoCamposNegocioDTO.getFormula());
              camposObjetoNegocioDTO.setTipoNegocio(grupoVisaoCamposNegocioDTO.getTipoNegocio());
              if (camposObjetoNegocioDTO.getPk().equalsIgnoreCase("S")) {
                colCamposPK.add(camposObjetoNegocioDTO);
              }
              colCamposTodos.add(camposObjetoNegocioDTO);
            }
          }
        }
      }
    }
  }
  @Override
  public Collection restoreVisao(final Integer idVisao, final Collection colFilter)
      throws Exception {
    final GrupoVisaoDao grupoVisaoDao = new GrupoVisaoDao();
    final GrupoVisaoCamposNegocioDao grupoVisaoCamposNegocioDao = new GrupoVisaoCamposNegocioDao();
    final CamposObjetoNegocioDao camposObjetoNegocioDao = new CamposObjetoNegocioDao();
    final Collection colGrupos = grupoVisaoDao.findByIdVisaoAtivos(idVisao);

    final LookupServiceEjb lookupService = new LookupServiceEjb();

    final Collection colCamposTodos = new ArrayList<>();
    if (colGrupos != null) {
      for (final Iterator it = colGrupos.iterator(); it.hasNext(); ) {
        final GrupoVisaoDTO grupoVisaoDTO = (GrupoVisaoDTO) it.next();
        grupoVisaoDTO.setColCamposVisao(
            grupoVisaoCamposNegocioDao.findByIdGrupoVisaoAtivos(grupoVisaoDTO.getIdGrupoVisao()));

        if (grupoVisaoDTO.getColCamposVisao() != null) {
          for (final Iterator it2 = grupoVisaoDTO.getColCamposVisao().iterator(); it2.hasNext(); ) {
            final GrupoVisaoCamposNegocioDTO grupoVisaoCamposNegocioDTO =
                (GrupoVisaoCamposNegocioDTO) it2.next();

            CamposObjetoNegocioDTO camposObjetoNegocioDTO = new CamposObjetoNegocioDTO();
            camposObjetoNegocioDTO.setIdCamposObjetoNegocio(
                grupoVisaoCamposNegocioDTO.getIdCamposObjetoNegocio());
            camposObjetoNegocioDTO =
                (CamposObjetoNegocioDTO) camposObjetoNegocioDao.restore(camposObjetoNegocioDTO);

            if (camposObjetoNegocioDTO != null) {
              grupoVisaoCamposNegocioDTO.setCamposObjetoNegocioDto(camposObjetoNegocioDTO);
              camposObjetoNegocioDTO.setFormula(grupoVisaoCamposNegocioDTO.getFormula());
              colCamposTodos.add(grupoVisaoCamposNegocioDTO);
            }
          }
        }
      }
    }

    final String sql = this.generateSQLRestore(colCamposTodos, colFilter);

    final Collection colRetorno = this.getDao().execSQL(sql, null);
    if (colRetorno != null) {
      for (final Iterator it = colRetorno.iterator(); it.hasNext(); ) {
        final Object[] objs = (Object[]) it.next();
        int i = 0;
        for (final Iterator it2 = colCamposTodos.iterator(); it2.hasNext(); ) {
          final GrupoVisaoCamposNegocioDTO grupoVisaoCamposNegocioDTO =
              (GrupoVisaoCamposNegocioDTO) it2.next();
          final CamposObjetoNegocioDTO camposObjetoNegocioDTO =
              grupoVisaoCamposNegocioDTO.getCamposObjetoNegocioDto();
          camposObjetoNegocioDTO.setValue(objs[i]);

          if (grupoVisaoCamposNegocioDTO.getTipoNegocio().equalsIgnoreCase(MetaUtil.RELATION)) {
            if (grupoVisaoCamposNegocioDTO.getTipoLigacao() == null) {
              grupoVisaoCamposNegocioDTO.setTipoLigacao(GrupoVisaoCamposNegocioDTO.RELATION_SIMPLE);
            }
            if (grupoVisaoCamposNegocioDTO
                .getTipoLigacao()
                .equalsIgnoreCase(GrupoVisaoCamposNegocioDTO.RELATION_SIMPLE)) {
              final LookupDTO lookupDto = new LookupDTO();
              lookupDto.setTermoPesquisa("");
              if (objs[i] != null) {
                lookupDto.setTermoPesquisa(objs[i].toString());
                lookupDto.setIdGrupoVisao(grupoVisaoCamposNegocioDTO.getIdGrupoVisao());
                lookupDto.setIdCamposObjetoNegocio(
                    camposObjetoNegocioDTO.getIdCamposObjetoNegocio());

                final ReturnLookupDTO returnLookupAux = lookupService.restoreSimple(lookupDto);
                camposObjetoNegocioDTO.setReturnLookupDTO(returnLookupAux);
              } else {
                camposObjetoNegocioDTO.setReturnLookupDTO(null);
              }
            }
          }

          i++;
        }
        break; // Como é restore, pega só o 1.o
      }
    }
    return colCamposTodos;
  }