public String getNumber(String value) { if (value == null) { return null; } if (value.indexOf("[") > -1) { final String aux = value.substring(value.indexOf("[")); return UtilStrings.apenasNumeros(aux); } value = value.replaceAll(",00", ""); value = value.replaceAll(",000", ""); value = value.replaceAll("\\,", "."); return value; }
@Override public boolean isPKExists(final Collection colCamposPK, final Map hashValores) throws Exception { final ObjetoNegocioDao objetoNegocioDao = new ObjetoNegocioDao(); String sql = "SELECT "; String sqlFields = ""; String sqlFilter = ""; int i = 1; if (colCamposPK == null || colCamposPK.size() == 0) { return false; } for (final Iterator it = colCamposPK.iterator(); it.hasNext(); ) { final CamposObjetoNegocioDTO camposObjetoNegocioDTO = (CamposObjetoNegocioDTO) it.next(); ObjetoNegocioDTO objetoNegocioDTO = new ObjetoNegocioDTO(); objetoNegocioDTO.setIdObjetoNegocio(camposObjetoNegocioDTO.getIdObjetoNegocio()); objetoNegocioDTO = (ObjetoNegocioDTO) objetoNegocioDao.restore(objetoNegocioDTO); if (objetoNegocioDTO != null) { if (!sqlFields.equalsIgnoreCase("")) { sqlFields += ", "; } sqlFields += objetoNegocioDTO.getNomeTabelaDB() + "." + camposObjetoNegocioDTO.getNomeDB() + " Val_" + i; } if (!sqlFilter.equalsIgnoreCase("")) { sqlFilter += " AND "; } String pref = ""; String suf = ""; final String comp = "="; if (MetaUtil.isStringType(camposObjetoNegocioDTO.getTipoDB().trim())) { pref = "'"; suf = "'"; } String strVal = (String) hashValores.get(camposObjetoNegocioDTO.getNomeDB().toUpperCase()); if (strVal != null) { if (strVal.trim().equalsIgnoreCase("")) { // Se nao existir valor para a PK, eh que nao existe! return false; } if (MetaUtil.isNumericType(camposObjetoNegocioDTO.getTipoDB().trim())) { final int x = strVal.indexOf("["); // Vai ate este ponto, pois o codigo fica entre [x] if (x > -1) { strVal = strVal.substring(x); } strVal = UtilStrings.apenasNumeros(strVal); } strVal = strVal.replaceAll(",00", ""); strVal = strVal.replaceAll("\\,", "."); sqlFilter += objetoNegocioDTO.getNomeTabelaDB() + "." + camposObjetoNegocioDTO.getNomeDB() + " " + comp + " " + pref + strVal + suf; } else { // Se nao existir valor para a PK, eh que nao existe! return false; } i++; } sql += sqlFields + " FROM " + this.generateFrom(colCamposPK) + " WHERE " + sqlFilter; final Collection colRet = this.getDao().execSQL(sql, null); if (colRet == null) { return false; } if (colRet.size() > 0) { return true; } return false; }
@Override public void load(DocumentHTML document, HttpServletRequest request, HttpServletResponse response) throws Exception { HashMap hashValores = getFormFields(request); String idStr = (String) hashValores.get("ID"); int id = -1; try { if (idStr != null && !idStr.equalsIgnoreCase("-1")) { idStr = UtilStrings.apenasNumeros(idStr); } id = Integer.parseInt(idStr); } catch (Exception e) { // e.printStackTrace(); } BICategoriasService biCategoriasService = (BICategoriasService) ServiceLocator.getInstance().getService(BICategoriasService.class, null); BIConsultaService biConsultaService = (BIConsultaService) ServiceLocator.getInstance().getService(BIConsultaService.class, null); String strCab = ""; if (id == -1) { strCab += "[{"; strCab += "\"id\":-1,"; strCab += "\"text\":\"" + UtilI18N.internacionaliza(request, "listagemConsultas.consultas") + "\","; strCab += "\"children\":["; Collection colObjsNeg = biCategoriasService.findSemPai(); if (colObjsNeg != null) { boolean bPrim = true; for (Iterator it = colObjsNeg.iterator(); it.hasNext(); ) { BICategoriasDTO biCategoriasDTO = (BICategoriasDTO) it.next(); if (!bPrim) { strCab += ","; } strCab += "{"; strCab += "\"id\":\"G" + biCategoriasDTO.getIdCategoria() + "\","; strCab += "\"text\":\"" + biCategoriasDTO.getNomeCategoria() + "\","; strCab += "\"state\":\"closed\""; strCab += "}"; bPrim = false; } } strCab += "]"; strCab += "}]"; } else { Collection col = biCategoriasService.findByIdCategoriaPai(id); Collection col2 = biConsultaService.findByIdCategoria(id); if (col != null || col2 != null) { if (col == null) col = new ArrayList(); if (col2 == null) col2 = new ArrayList(); strCab += "["; boolean bPrim = true; for (Iterator it = col.iterator(); it.hasNext(); ) { if (!bPrim) { strCab += ","; } BICategoriasDTO biCategoriasDTO = (BICategoriasDTO) it.next(); // String strTam = ""; strCab += "{"; strCab += "\"id\":\"G" + biCategoriasDTO.getIdCategoria() + "\","; strCab += "\"text\":\"" + biCategoriasDTO.getNomeCategoria() + "\""; strCab += "}"; bPrim = false; } bPrim = true; for (Iterator it = col2.iterator(); it.hasNext(); ) { if (!bPrim) { strCab += ","; } BIConsultaDTO biConsultaDTO = (BIConsultaDTO) it.next(); // String strTam = ""; strCab += "{"; strCab += "\"id\":\"" + biConsultaDTO.getTipoConsulta() + biConsultaDTO.getIdConsulta() + "\","; strCab += "\"text\":\"" + biConsultaDTO.getNomeConsulta() + "\""; strCab += "}"; bPrim = false; } strCab += "]"; } } request.setAttribute("json_retorno", strCab); }