コード例 #1
0
  @Get
  @Path("/reports/{errorEntry.id}/edit")
  @LoggedIn
  public void editDetails(ErrorEntry errorEntry) {
    if (errorEntry == null) {
      result.redirectTo(getClass()).list();
      return;
    }

    ErrorEntry errorEntryFromDB = errorEntryDAO.retrieve(new Long(errorEntry.getId()));
    LOG.debug("Details for: " + errorEntryFromDB);

    if (errorEntryFromDB == null) {
      validator.add(
          new ValidationMessage(ExceptionMessages.PAGE_NOT_FOUND, ExceptionMessages.ERROR));
      validator.onErrorUse(Results.logic()).redirectTo(ErrorReportController.class).list();
    } else if (!loggedUser.isLogged() || !loggedUser.getUser().getRole().getCanEditErrorReport()) {
      validator.add(
          new ValidationMessage(ExceptionMessages.USER_UNAUTHORIZED, ExceptionMessages.ERROR));
      validator
          .onErrorUse(Results.logic())
          .redirectTo(ErrorReportController.class)
          .details(errorEntryFromDB);
    } else {
      List<ProcessResult> procRes = cogrooFacade.processText(errorEntryFromDB.getText());

      boolean hasError = false;
      for (ProcessResult processResult : procRes) {
        if (processResult.getMistakes().size() > 0) {
          hasError = true;
          break;
        }
      }

      result
          .include("errorEntry", errorEntryFromDB)
          .include("hasError", hasError)
          .include("processResultList", procRes)
          .include(
              "singleGrammarErrorList",
              cogrooFacade.asSingleGrammarErrorList(errorEntryFromDB.getText(), procRes))
          .include("omissionCategoriesList", this.errorEntryLogic.getErrorCategoriesForUser());
    }
  }
コード例 #2
0
  @Post
  @Path("/reports/newtext")
  public void addReport(String text) {
    text = sanitizer.sanitize(text, false, true);
    try {
      if (text != null && text.length() >= 0) {
        if (text.length() > 255) {
          text = text.substring(0, 255);
        }

        if (!loggedUser.isLogged()) {
          // if not logged we save the text.
          if (LOG.isDebugEnabled()) {
            LOG.debug("Saving error report text before login: "******"Error text: " + text);
        }
        List<ProcessResult> pr = cogrooFacade.processText(text);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Text processed. Results:");
          for (ProcessResult processResult : pr) {
            LOG.debug("... " + processResult.getTextAnnotatedWithErrors());
          }
        }
        result
            .include("analyzed", true)
            .include("cleanText", text)
            .include("annotatedText", cogrooFacade.getAnnotatedText(text, pr))
            .include("singleGrammarErrorList", cogrooFacade.asSingleGrammarErrorList(text, pr))
            .include("omissionCategoriesList", this.errorEntryLogic.getErrorCategoriesForUser())
            .include("processResultList", pr)
            .redirectTo(getClass())
            .addReport();
      } else {
        result.redirectTo(getClass()).addReport();
      }
    } catch (Exception e) {
      LOG.error("Error processing text: " + text, e);
    }
  }
コード例 #3
0
  @Get
  @Path("/reports/{errorEntry.id}")
  public void details(ErrorEntry errorEntry) {
    if (errorEntry == null) {
      result.redirectTo(getClass()).list();
      return;
    }

    ErrorEntry errorEntryFromDB = errorEntryDAO.retrieve(new Long(errorEntry.getId()));
    LOG.debug("Details for: " + errorEntryFromDB);

    if (errorEntryFromDB == null) {
      result.notFound();
      return;
    }

    result
        .include("errorEntry", errorEntryFromDB)
        .include("processResultList", cogrooFacade.cachedProcessText(errorEntryFromDB.getText()))
        .include("priorities", Priority.values())
        .include("states", State.values());

    String title = "Problema Nº. " + errorEntryFromDB.getId() + ": " + errorEntryFromDB.getText();

    String sender = "Enviado por: " + errorEntryFromDB.getSubmitter().getName();
    String version = "Versão: " + errorEntryFromDB.getVersion().getVersion();
    String creationDate =
        "Criado em: "
            + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
                .format(errorEntryFromDB.getCreation());
    String changeDate =
        "Modificado em: "
            + DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
                .format(errorEntryFromDB.getModified());
    String type = "Tipo: ";
    String details = null;
    if (errorEntryFromDB.getOmission() == null) {
      type += "Intervenção indevida";
      String rule = "Regra: " + errorEntryFromDB.getBadIntervention().getRule();
      String classification =
          "Erro: "
              + messages.getString(
                  errorEntryFromDB.getBadIntervention().getClassification().toString());
      details = rule + "; " + classification;
    } else {
      type += "Omissão";
      String category =
          "Categoria"
              + (errorEntryFromDB.getOmission().getCategory() == null
                  ? " (personalizada): " + errorEntryFromDB.getOmission().getCustomCategory()
                  : ": " + errorEntryFromDB.getOmission().getCategory());
      String replaceBy = "Substituir por: " + errorEntryFromDB.getOmission().getReplaceBy();
      details = category + "; " + replaceBy;
    }
    String description =
        sender
            + "; "
            + version
            + "; "
            + type
            + "; "
            + details
            + "; "
            + creationDate
            + "; "
            + changeDate;

    result
        .include("headerTitle", StringEscapeUtils.escapeHtml(title))
        .include("headerDescription", StringEscapeUtils.escapeHtml(description));
  }