コード例 #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());
  }
コード例 #2
0
  @Override
  public String getViewHtml(
      FieldLayoutItem fieldLayoutItem,
      Action action,
      Issue issue,
      Object value,
      Map displayParameters) {
    Map<String, Object> velocityParams =
        getVelocityParams(fieldLayoutItem, action, issue, displayParameters);

    // get the rendered value without specifying an issue for context
    IssueRenderContext context;
    if (issue != null) {
      context = issue.getIssueRenderContext();
    } else {
      context = new IssueRenderContext(null);
    }
    String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null;

    Map<String, Object> valueMap = (Map<String, Object>) value;

    velocityParams.put(
        "value",
        rendererManager.getRenderedContent(rendererType, (String) valueMap.get(getId()), context));
    if (valueMap.containsKey(PARAM_GROUP_LEVEL)) {
      velocityParams.put(PARAM_GROUP_LEVEL, valueMap.get(PARAM_GROUP_LEVEL));
    }
    if (valueMap.containsKey(PARAM_ROLE_LEVEL)) {
      String roleId = (String) valueMap.get(PARAM_ROLE_LEVEL);
      // We need the display name of the role
      if (roleId != null) {
        ProjectRole projectRole = projectRoleManager.getProjectRole(new Long(roleId));
        if (projectRole != null) {
          velocityParams.put("selectedRoleName", projectRole.getName());
        }
      }
      velocityParams.put(PARAM_ROLE_LEVEL, roleId);
    }
    if (valueMap.containsKey(PARAM_COMMENT_PROPERTY)) {
      velocityParams.put(PARAM_COMMENT_PROPERTY, valueMap.get(PARAM_COMMENT_PROPERTY));
    }
    return commentFieldRenderer.getFieldViewHtml(
        velocityParams, CommentHelper.builder().issue(issue).build());
  }