Example #1
0
  public void construirGrafico(String metrica) {

    if (metrica != null && getMetricas().contains(metrica)) {

      try {
        this.powerLow = new CartesianChartModel();
        ChartSeries cs = new ChartSeries();

        cs.setLabel(metrica);

        List<Object[]> o = new ArrayList<Object[]>();

        for (Classe c : sistema.getClasses()) {

          if (metrica.equals(Metricas.LOC)) {
            o.add(new Object[] {c.getId(), c.getLoc()});
          } else if (metrica.equals(Metricas.CBC)) {
            o.add(new Object[] {c.getId(), c.getCbc()});
          } else if (metrica.equals(Metricas.FIN)) {
            o.add(new Object[] {c.getId(), c.getFin()});
          } else if (metrica.equals(Metricas.FOUT)) {
            o.add(new Object[] {c.getId(), c.getFout()});
          } else if (metrica.equals(Metricas.HNL)) {
            o.add(new Object[] {c.getId(), c.getHnl()});
          } else if (metrica.equals(Metricas.LCM)) {
            o.add(new Object[] {c.getId(), c.getLcm()});
          } else if (metrica.equals(Metricas.NOA)) {
            o.add(new Object[] {c.getId(), c.getNoa()});
          } else if (metrica.equals(Metricas.NOAH)) {
            o.add(new Object[] {c.getId(), c.getNoia()});
          } else if (metrica.equals(Metricas.NOC)) {
            o.add(new Object[] {c.getId(), c.getNoc()});
          } else if (metrica.equals(Metricas.NOM)) {
            o.add(new Object[] {c.getId(), c.getNom()});
          } else if (metrica.equals(Metricas.NOMH)) {
            o.add(new Object[] {c.getId(), c.getNoih()});
          } else if (metrica.equals(Metricas.NOMO)) {
            o.add(new Object[] {c.getId(), c.getNomo()});
          } else if (metrica.equals(Metricas.PRIA)) {
            o.add(new Object[] {c.getId(), c.getNopria()});
          } else if (metrica.equals(Metricas.PRIM)) {
            o.add(new Object[] {c.getId(), c.getNoprim()});
          } else if (metrica.equals(Metricas.PUBA)) {
            o.add(new Object[] {c.getId(), c.getNopuba()});
          } else if (metrica.equals(Metricas.PUBM)) {
            o.add(new Object[] {c.getId(), c.getNopubm()});
          } else if (metrica.equals(Metricas.RFC)) {
            o.add(new Object[] {c.getId(), c.getRfc()});
          } else if (metrica.equals(Metricas.TNOC)) {
            o.add(new Object[] {c.getId(), c.getTnoc()});
          } else if (metrica.equals(Metricas.WMC)) {
            o.add(new Object[] {c.getId(), c.getWmc()});
          } else if (metrica.equals(Metricas.WOC)) {
            o.add(new Object[] {c.getId(), c.getWoc()});
          }
        }

        Collections.sort(
            o,
            new Comparator<Object[]>() {

              @Override
              public int compare(Object[] o1, Object[] o2) {
                if (Long.parseLong(o1[1].toString()) > Long.parseLong(o2[1].toString())) {
                  return 1;
                } else if (Long.parseLong(o1[1].toString()) < Long.parseLong(o2[1].toString())) {
                  return -1;
                } else {
                  return 0;
                }
              }
            });

        int sum = 0;
        Long maior = Long.parseLong(o.get(o.size() - 1)[1].toString());
        Long blocos = maior / 10;
        Long cont = blocos;

        for (Object[] o1 : o) {
          sum++;
          if (Long.parseLong(o1[1].toString()) >= cont) {
            cs.set("" + (cont), sum);
            cont += blocos;
            sum = 0;
          }
        }

        this.powerLow.addSeries(cs);

      } catch (Exception e) {
        FacesMessage msg =
            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro!", e.getLocalizedMessage());
        FacesContext.getCurrentInstance().addMessage(null, msg);
      }

      return;
    }

    FacesMessage msg =
        new FacesMessage(
            FacesMessage.SEVERITY_INFO,
            "Indisponível",
            "Grafico para metrica selecionada indisponível");
    FacesContext.getCurrentInstance().addMessage(null, msg);
  }
Example #2
0
  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;
    }
  }