コード例 #1
0
    // TODO: Check if this would be correct with multiple values and uris being passed back
    // First, need to order by uris in original and new values probably and
    // for literals, order by? Alphabetical or numeric value? Hard to say
    public static boolean hasFieldChanged(
        String fieldName, EditConfigurationVTwo editConfig, MultiValueEditSubmission submission) {
      List<String> orgValue = editConfig.getUrisInScope().get(fieldName);
      List<String> newValue = submission.getUrisFromForm().get(fieldName);
      // Sort both just in case
      if (orgValue != null) {
        Collections.sort(orgValue);
      }
      if (newValue != null) {
        Collections.sort(newValue);
      }
      if (orgValue != null && newValue != null) {
        if (orgValue.equals(newValue)) return false;
        else return true;
      }

      List<Literal> orgLit = editConfig.getLiteralsInScope().get(fieldName);
      List<Literal> newLit = submission.getLiteralsFromForm().get(fieldName);
      // TODO: Sort ? Need custom comparator
      // Collections.sort(orgLit);
      // Collections.sort(newLit);
      // for(Literal l: orgLit)
      // boolean fieldChanged = !EditLiteral.equalLiterals(orgLit, newLit);
      // TODO:Check if below acts as expected
      boolean fieldChanged = !orgLit.equals(newLit);
      if (!fieldChanged) {
        int orgLen = orgLit.size();
        int newLen = newLit.size();
        if (orgLen != newLen) {
          fieldChanged = true;
        } else {
          int i;
          for (i = 0; i < orgLen; i++) {
            if (!EditLiteral.equalLiterals(orgLit.get(i), newLit.get(i))) {
              fieldChanged = true;
              break;
            }
          }
        }
      }
      log.debug("field " + fieldName + " " + (fieldChanged ? "did Change" : "did NOT change"));
      return fieldChanged;
    }
コード例 #2
0
  private ResponseValues doValidationErrors(
      VitroRequest vreq,
      EditConfigurationVTwo editConfiguration,
      MultiValueEditSubmission submission) {

    Map<String, String> errors = submission.getValidationErrors();

    if (errors != null && !errors.isEmpty()) {
      String form = editConfiguration.getFormUrl();
      vreq.setAttribute("formUrl", form);
      vreq.setAttribute("view", vreq.getParameter("view"));
      // Need to ensure that edit key is set so that the correct
      // edit configuration and edit submission are retrieved
      // This can also be set as a parameter instead
      String formUrl = editConfiguration.getFormUrl();
      formUrl += "&editKey=" + editConfiguration.getEditKey();
      return new RedirectResponseValues(formUrl);
    }
    return null; // no errors
  }