コード例 #1
0
  @Put
  @Path("/reports/{reportId}")
  @LoggedIn
  public void updateErrorReport(
      Long reportId,
      String type,
      String badintIndex,
      String badintType,
      List<String> badintStart,
      List<String> badintEnd,
      List<String> badintRule,
      String omissionCategory,
      String omissionCustom,
      String omissionReplaceBy,
      String omissionStart,
      String omissionEnd) {

    LOG.debug(
        "reportId: "
            + reportId
            + "\n"
            + "type: "
            + type
            + "\n"
            + "badintIndex: "
            + badintIndex
            + "\n"
            + "badintType: "
            + badintType
            + "\n"
            + "badintStart: "
            + badintStart
            + "\n"
            + "badintEnd: "
            + badintEnd
            + "\n"
            + "badintRule: "
            + badintRule
            + "\n"
            + "omissionCategory: "
            + omissionCategory
            + "\n"
            + "omissionCustom: "
            + omissionCustom
            + "\n"
            + "omissionReplaceBy: "
            + omissionReplaceBy
            + "\n"
            + "omissionStart: "
            + omissionStart
            + "\n"
            + "omissionEnd: "
            + omissionEnd);

    ErrorEntry errorEntryFromDB = this.errorEntryDAO.retrieve(reportId);
    ErrorEntry originalErrorEntry = null;
    try {
      originalErrorEntry = (ErrorEntry) errorEntryFromDB.clone();

    } catch (CloneNotSupportedException e) {
      LOG.error("Error cloning ErrorEntry object: ", e);
    }
    if (type == null) {
      if (errorEntryFromDB.getBadIntervention() != null) {
        type = "BADINT";
      } else {
        type = "OMISSION";
      }
    }
    if (type.equals("BADINT")) {
      GrammarCheckerBadIntervention newBadIntervention = null;
      if (errorEntryFromDB.getBadIntervention() == null) {
        newBadIntervention = new GrammarCheckerBadIntervention();
        errorEntryFromDB.setBadIntervention(newBadIntervention);
      } else {
        newBadIntervention = errorEntryFromDB.getBadIntervention();
      }

      newBadIntervention.setClassification(
          Enum.valueOf(BadInterventionClassification.class, badintType));
      newBadIntervention.setErrorEntry(errorEntryFromDB);
      newBadIntervention.setRule(badintRule.get(Integer.valueOf(badintIndex) - 1));

      errorEntryFromDB.setSpanStart(
          Integer.valueOf(badintStart.get(Integer.valueOf(badintIndex) - 1)));
      errorEntryFromDB.setSpanEnd(Integer.valueOf(badintEnd.get(Integer.valueOf(badintIndex) - 1)));

      this.errorEntryLogic.updateBadIntervention(errorEntryFromDB, originalErrorEntry);
    } else {
      int start = -1;
      int end = -1;

      if (omissionStart != null && omissionEnd != null) {
        start = Integer.parseInt(omissionStart);
        end = Integer.parseInt(omissionEnd);
      }

      GrammarCheckerOmission o = null;
      if (errorEntryFromDB.getOmission() == null) {
        o = new GrammarCheckerOmission();
        errorEntryFromDB.setOmission(o);
      } else {
        o = errorEntryFromDB.getOmission();
      }

      o.setCategory(omissionCategory);
      if (omissionCategory.equals(ErrorEntryLogic.CUSTOM)) {
        o.setCustomCategory(sanitizer.sanitize(omissionCustom, false));
      } else {
        o.setCustomCategory(null);
      }
      o.setErrorEntry(errorEntryFromDB);
      o.setReplaceBy(sanitizer.sanitize(omissionReplaceBy, false));

      errorEntryFromDB.setSpanStart(start);
      errorEntryFromDB.setSpanEnd(end);

      if (!(end > 0 && end > start)) {
        validator.add(
            new ValidationMessage(
                ExceptionMessages.ERROR_REPORT_OMISSION_INVALID_SELECTION,
                ExceptionMessages.ERROR));
      }
      if (omissionCategory.equals("custom")
          && (omissionCustom == null || omissionCustom.length() == 0)) {
        validator.add(
            new ValidationMessage(
                ExceptionMessages.ERROR_REPORT_OMISSION_MISSING_CUSTOM_CATEGORY,
                ExceptionMessages.ERROR));
      }
      if ((omissionReplaceBy == null || omissionReplaceBy.length() == 0)) {
        validator.add(
            new ValidationMessage(
                ExceptionMessages.ERROR_REPORT_OMISSION_MISSING_REPLACE, ExceptionMessages.ERROR));
      }
      if (validator.hasErrors()) {
        validator
            .onErrorUse(Results.logic())
            .redirectTo(ErrorReportController.class)
            .editDetails(errorEntryFromDB);
        return;
      }
      this.errorEntryLogic.updateOmission(errorEntryFromDB, originalErrorEntry);
    }

    result.include("gaEventErrorChanged", true);
    result.redirectTo(getClass()).details(errorEntryFromDB);
  }