public void salvar() { List<Classe> list = new ArrayList<Classe>(); Classe classe; try { BufferedReader reader = new BufferedReader(new InputStreamReader(uploadedFile.getInputstream())); String values[] = null; String colName[] = null; String aux = reader.readLine(); values = aux.split(";"); HashMap<String, Integer> mapMetricsCSV = new HashMap<String, Integer>(); mapMetricsCSV.put( "numberOfLinesOfCode", Util.searchBruteForce(values, "numberOfLinesOfCode")); mapMetricsCSV.put("numberOfMethods", Util.searchBruteForce(values, "numberOfMethods")); mapMetricsCSV.put( "numberOfPublicMethods", Util.searchBruteForce(values, "numberOfPublicMethods")); mapMetricsCSV.put( "numberOfPrivateMethods", Util.searchBruteForce(values, "numberOfPrivateMethods")); mapMetricsCSV.put( "numberOfMethodsInherited", Util.searchBruteForce(values, "numberOfMethodsInherited")); mapMetricsCSV.put("numberOfAttributes", Util.searchBruteForce(values, "numberOfAttributes")); mapMetricsCSV.put( "numberOfPrivateAttributes", Util.searchBruteForce(values, "numberOfPrivateAttributes")); mapMetricsCSV.put( "numberOfAttributesInherited", Util.searchBruteForce(values, "numberOfAttributesInherited")); mapMetricsCSV.put( "numberOfPublicAttributes", Util.searchBruteForce(values, "numberOfPublicAttributes")); mapMetricsCSV.put("numberOfChildren", Util.searchBruteForce(values, "numberOfChildren")); mapMetricsCSV.put("fanOut", Util.searchBruteForce(values, "fanOut")); mapMetricsCSV.put("fanIn", Util.searchBruteForce(values, "fanIn")); mapMetricsCSV.put( "numberOfMethodsOverriden", Util.searchBruteForce(values, "numberOfMethodsOverriden")); mapMetricsCSV.put( "totalNumberOfChildren", Util.searchBruteForce(values, "totalNumberOfChildren")); mapMetricsCSV.put("weightOfAClass", Util.searchBruteForce(values, "weightOfAClass")); mapMetricsCSV.put( "weightedMethodCount", Util.searchBruteForce(values, "weightedMethodCount")); mapMetricsCSV.put("inheritedMethods", Util.searchBruteForce(values, "inheritedMethods")); mapMetricsCSV.put( "couplingBetweenClasses", Util.searchBruteForce(values, "couplingBetweenClasses")); mapMetricsCSV.put( "lackOfCohesionInMethods", Util.searchBruteForce(values, "lackOfCohesionInMethods")); mapMetricsCSV.put("responseForClass", Util.searchBruteForce(values, "responseForClass")); mapMetricsCSV.put( "hierarchyNestingLevel", Util.searchBruteForce(values, "hierarchyNestingLevel")); while ((aux = reader.readLine()) != null) { try { values = aux.split(";"); colName = values[0].split(","); classe = new Classe(); classe.setName(colName[0].length() < 254 ? colName[0] : colName[0].substring(0, 253)); classe.setSuperEntity( colName[1].length() < 254 ? colName[1] : colName[1].substring(0, 253)); classe.setLoc(Integer.valueOf(values[mapMetricsCSV.get("numberOfLinesOfCode")].trim())); classe.setNom(Integer.valueOf(values[mapMetricsCSV.get("numberOfMethods")].trim())); classe.setNopubm( Integer.valueOf(values[mapMetricsCSV.get("numberOfPublicMethods")].trim())); classe.setNoprim( Integer.valueOf(values[mapMetricsCSV.get("numberOfPrivateMethods")].trim())); classe.setNoih( Integer.valueOf(values[mapMetricsCSV.get("numberOfMethodsInherited")].trim())); classe.setNoa(Integer.valueOf(values[mapMetricsCSV.get("numberOfAttributes")].trim())); classe.setNopria( Integer.valueOf(values[mapMetricsCSV.get("numberOfPrivateAttributes")].trim())); classe.setNoia( Integer.valueOf(values[mapMetricsCSV.get("numberOfAttributesInherited")].trim())); classe.setNopuba( Integer.valueOf(values[mapMetricsCSV.get("numberOfPublicAttributes")].trim())); classe.setNoc(Integer.valueOf(values[mapMetricsCSV.get("numberOfChildren")].trim())); classe.setFin(Integer.valueOf(values[mapMetricsCSV.get("fanIn")].trim())); classe.setFout(Integer.valueOf(values[mapMetricsCSV.get("fanOut")].trim())); classe.setNomo( Integer.valueOf(values[mapMetricsCSV.get("numberOfMethodsOverriden")].trim())); classe.setTnoc( Integer.valueOf(values[mapMetricsCSV.get("totalNumberOfChildren")].trim())); classe.setWoc(Integer.valueOf(values[mapMetricsCSV.get("weightOfAClass")].trim())); classe.setWmc(Integer.valueOf(values[mapMetricsCSV.get("weightedMethodCount")].trim())); classe.setIm( values[mapMetricsCSV.get("inheritedMethods")].length() < 254 ? values[mapMetricsCSV.get("inheritedMethods")].trim() : values[mapMetricsCSV.get("inheritedMethods")].substring(0, 253)); classe.setCbc( Integer.valueOf(values[mapMetricsCSV.get("couplingBetweenClasses")].trim())); classe.setLcm( Integer.valueOf(values[mapMetricsCSV.get("lackOfCohesionInMethods")].trim())); classe.setRfc(Integer.valueOf(values[mapMetricsCSV.get("responseForClass")].trim())); classe.setHnl(Integer.valueOf(values[mapMetricsCSV.get("hierarchyNestingLevel")].trim())); list.add(classe); } catch (Exception e) { FacesMessage msg = new FacesMessage( FacesMessage.SEVERITY_ERROR, "Erro!", "O arquivo nao correspondeu ao esperado"); FacesContext.getCurrentInstance().addMessage(null, msg); msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro!", e.getLocalizedMessage()); FacesContext.getCurrentInstance().addMessage(null, msg); create(); return; } } reader.close(); } catch (IOException e) { FacesMessage msg = new FacesMessage( FacesMessage.SEVERITY_ERROR, "Erro!", "O arquivo nao correspondeu ao esperado"); FacesContext.getCurrentInstance().addMessage(null, msg); msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro!", e.getLocalizedMessage()); FacesContext.getCurrentInstance().addMessage(null, msg); create(); return; } try { if (list != null && !list.isEmpty()) { this.sistema.setClasses(list); this.sistema.setData(new Timestamp(System.currentTimeMillis())); this.sistema.setUsuario(usuario); this.sistema.setDisponivel(true); this.sistemaDAO.persist(this.sistema); create(); FacesMessage msg = new FacesMessage("O sistema foi cadastrado com sucesso!"); FacesContext.getCurrentInstance().addMessage(null, msg); } else { FacesMessage msg = new FacesMessage( FacesMessage.SEVERITY_ERROR, "Erro!", "O arquivo nao correspondeu ao esperado"); FacesContext.getCurrentInstance().addMessage(null, msg); } } catch (Exception e) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro!", e.getLocalizedMessage()); FacesContext.getCurrentInstance().addMessage(null, msg); create(); return; } }