Exemplo n.º 1
0
  private void printInformation(CharacteristicsGeneratorGenerator g) {

    BufferedWriter outcsv = null;
    try {
      Calendar cal = Calendar.getInstance();
      SimpleDateFormat sdf = new SimpleDateFormat("MMyyyy");
      String date = sdf.format(cal.getTime());

      // Should be an static route, because we need permisions on the path
      File file = new File(filepath + date + ".csv");
      if (!file.exists()) {
        outcsv = new BufferedWriter(new FileWriter(file, false));
        outcsv.write(g.getHeader());

      } else {
        outcsv = new BufferedWriter(new FileWriter(file, true));
      }
      outcsv.write("\r\n");
      outcsv.write(g.getCSV());
      outcsv.flush();
      outcsv.close();
      outcsv = null;
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    filepath.trim();
    String propertiesFilePath = getServletContext().getRealPath("WEB-INF/errors.properties");
    Properties prop = new Properties();
    prop.load(new FileInputStream(propertiesFilePath));

    CharacteristicsGeneratorGenerator chGen =
        new CharacteristicsGeneratorGenerator(
            request.getParameter("name"),
            request.getParameter("mail"),
            request.getParameter("organization"),
            request.getParameter("nmodels"),
            request.getParameter("nfeatures"),
            request.getParameter("pmandatory"),
            request.getParameter("poptional"),
            request.getParameter("palternative"),
            request.getParameter("por"),
            request.getParameter("pctc"),
            request.getParameter("mbf"),
            request.getParameter("mnc"),
            request.getParameter("attributes"),
            "integer",
            request.getParameter("numberOfAtts"),
            request.getParameter("sat"),
            request.getParameter("splx"),
            request.getParameter("famaxml"),
            request.getParameter("famatf"),
            request.getParameter("jpg"),
            request.getParameter("x3d"),
            prop);
    if (chGen.hasErrors()) {
      printInformation(chGen);
      request.setAttribute("message", chGen.getHtmlErrors());

      RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
      dispatcher.forward(request, response);
    } else {
      File directory = createTempDir();
      FMGenerator generator = new FMGenerator();
      OnlyValidModelSATGenerator genV = new OnlyValidModelSATGenerator(generator);
      IGenerator atGenerator = new AttributedFMGenerator(generator);
      Benchmark b;

      if (chGen.extended) {
        b = new FAMABenchmark(atGenerator);

      } else {
        if (chGen.sat) {

          b = new FAMABenchmark(genV);
        } else {
          b = new FAMABenchmark(generator);
        }
      }
      try {
        ArrayList<RandomExperiment> experiments =
            b.createSetRandomExperiment("FeatureModel", chGen.nmodels, chGen.getCharacteristics());
        for (Experiment e : experiments) {
          // STEP 3: Save the model and the products
          FMWriter writer = new FMWriter();

          if (chGen.famaxml) {
            writer.saveFM(
                e.getVariabilityModel(), directory.getPath() + "/" + e.getName() + ".xml");
          }
          if (chGen.jpg) {
            writer.saveFM(
                e.getVariabilityModel(), directory.getPath() + "/" + e.getName() + ".dot");
          }
          if (chGen.splx) {
            writer.saveFM(
                e.getVariabilityModel(), directory.getPath() + "/" + e.getName() + ".splx");
          }
          if (chGen.x3d) {
            writer.saveFM(
                e.getVariabilityModel(), directory.getPath() + "/" + e.getName() + ".x3d");
          }
          if (chGen.famatf) {
            writer.saveFM(
                e.getVariabilityModel(), directory.getPath() + "/" + e.getName() + ".afm");
          }
        }
        experiments = null;

      } catch (Exception e2) {

        request.setAttribute(
            "message",
            prop.getProperty("headclass") + e2.getMessage() + prop.getProperty("tailclass"));

        RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
        dispatcher.forward(request, response);
      }

      printInformation(chGen);
      // If all went ok, clear all error messages
      request.removeAttribute("message");

      // Compress and return the generated files
      compressAndReturn(response, directory);

      // force cleaning
      b = null;
      System.gc();
    }
  }