示例#1
0
  @Override
  public String getEditHtml(
      FieldLayoutItem fieldLayoutItem,
      OperationContext operationContext,
      Action action,
      Issue issue,
      Map displayParameters) {
    Map<String, Object> velocityParams =
        getVelocityParams(fieldLayoutItem, action, issue, displayParameters);
    populateVelocityParams(
        fieldLayoutItem,
        (operationContext != null) ? operationContext.getFieldValuesHolder() : null,
        velocityParams);

    CommentHelper.CommentHelperBuilder helperBuilder = CommentHelper.builder().issue(issue);

    if (operationContext != null
        && operationContext.getFieldValuesHolder() != null
        && operationContext.getFieldValuesHolder().containsKey(getId())) {
      Map commentParams = (Map) operationContext.getFieldValuesHolder().get(getId());
      if (commentParams != null) {
        velocityParams.put(getId(), commentParams.get(getId()));
        // put the selected value into the params if it exists so we can handle errors
        populateParamsWithSelectedValue(commentParams, velocityParams);
        helperBuilder.comment((Comment) commentParams.get(PARAM_COMMENT_OBJECT));
      }
    }

    return commentFieldRenderer.getFieldEditHtml(velocityParams, helperBuilder.build());
  }
  public void validateParams(
      OperationContext operationContext,
      ErrorCollection errorCollection,
      I18nHelper i18n,
      Issue issue,
      FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem) {
    IssueLinkingValue value =
        (IssueLinkingValue) operationContext.getFieldValuesHolder().get(getId());

    if (isIssueLinkingEnabled() && value != null && !value.getLinkedIssues().isEmpty()) {
      IssueLinkService.AddIssueLinkValidationResult issueLinkValidationResult =
          issueLinkService.validateAddIssueLinks(
              authenticationContext.getLoggedInUser(),
              issue,
              value.getLinkDescription(),
              value.getLinkedIssues());

      // if we were returned an updated value, that signifies that we must update the
      // TimeTrackingValue in the FieldValuesHolder
      if (issueLinkValidationResult.isValid()) {
        //noinspection unchecked
        operationContext
            .getFieldValuesHolder()
            .put(getId(), new IssueLinkingValue.Builder(issueLinkValidationResult).build());
      } else {
        transferErrorMessages(
            errorCollection, issueLinkValidationResult.getErrorCollection().getErrorMessages());
        transferErrorMessages(
            errorCollection, issueLinkValidationResult.getErrorCollection().getErrors().values());
      }
    }
  }
示例#3
0
  @Override
  public void validateParams(
      OperationContext operationContext,
      ErrorCollection errorCollectionToAddTo,
      I18nHelper i18n,
      Issue issue,
      FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem) {
    Map fieldValuesHolder = operationContext.getFieldValuesHolder();
    Map<String, Object> commentParams = (Map<String, Object>) fieldValuesHolder.get(getId());
    String body = (String) commentParams.get(getId());

    String groupLevel = (String) commentParams.get(PARAM_GROUP_LEVEL);
    String roleLevel = (String) commentParams.get(PARAM_ROLE_LEVEL);
    Visibility visibility = Visibilities.fromGroupAndStrRoleId(groupLevel, roleLevel);

    ApplicationUser user = authenticationContext.getUser();

    if (commentParams.containsKey(EDIT_COMMENT)) {
      validateEditComment(errorCollectionToAddTo, issue, commentParams, body, visibility, user);
    } else if (commentParams.containsKey(REMOVE_COMMENT)) {
      validateRemoveComment(errorCollectionToAddTo, commentParams, user);
    } else {
      validateCreateComment(errorCollectionToAddTo, issue, commentParams, body, visibility, user);
    }
  }
示例#4
0
 /**
  * validate the field value
  *
  * @param operationContext OperationContext
  * @param errorCollectionToAddTo ErrorCollection
  * @param i18n I18nHelper
  * @param issue Issue
  * @param fieldScreenRenderLayoutItem FieldScreenRenderLayoutItem
  */
 public void validateParams(
     OperationContext operationContext,
     ErrorCollection errorCollectionToAddTo,
     I18nHelper i18n,
     Issue issue,
     FieldScreenRenderLayoutItem fieldScreenRenderLayoutItem) {
   Map fieldValuesHolder = operationContext.getFieldValuesHolder();
   String summary = (String) getValueFromParams(fieldValuesHolder);
   if (summary == null) {
     errorCollectionToAddTo.addError(getId(), i18n.getText("createissue.error.specify.a.summary"));
     return;
   }
   // JRADEV-1867 User can create summary with "  "
   summary = summary.trim();
   if (!TextUtils.stringSet(summary)) {
     errorCollectionToAddTo.addError(getId(), i18n.getText("createissue.error.specify.a.summary"));
   }
   if (summary.contains("\n") || summary.contains("\r")) {
     errorCollectionToAddTo.addError(getId(), i18n.getText("createissue.invalidsummary.newlines"));
   }
   if (summary.length() > MAX_LEN) {
     errorCollectionToAddTo.addError(
         getId(), i18n.getText("createissue.error.summary.less.than", MAX_LEN.toString()));
   }
 }
  private String getCreateOrEditHtml(
      FieldLayoutItem fieldLayoutItem,
      OperationContext operationContext,
      Action action,
      Issue issue,
      Map displayParameters,
      final Boolean create) {
    IssueLinkDisplayHelper issueLinkDisplayHelper =
        new IssueLinkDisplayHelper(userHistoryManager, authenticationContext.getLoggedInUser());

    Map<String, Object> velocityParams =
        getVelocityParams(fieldLayoutItem, action, issue, displayParameters);
    velocityParams.put(PARAMS_ISCREATEISSUE, create);
    final Object value = operationContext.getFieldValuesHolder().get(getId());
    velocityParams.put("value", value);
    velocityParams.put(
        "linkTypes",
        issueLinkDisplayHelper.getSortedIssueLinkTypes(issueLinkService.getIssueLinkTypes()));

    velocityParams.put("selectedLinkType", issueLinkDisplayHelper.getLastUsedLinkType());
    if (value != null && value instanceof IssueLinkingValue) {
      // JRADEV-7325: if the fieldvaluesholder contains a value and it contains a linkdescription
      // set that as the
      // currently selected value!
      final IssueLinkingValue ilv = (IssueLinkingValue) value;
      if (StringUtils.isNotBlank(ilv.getLinkDescription())) {
        velocityParams.put("selectedLinkType", ilv.getLinkDescription());
      }
    }

    return renderTemplate("issuelinks-edit.vm", velocityParams);
  }