Exemplo n.º 1
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());
  }
Exemplo n.º 2
0
  /**
   * Adds to the given velocity parameters using the given fieldValuesHolder and fieldLayoutItem (to
   * determine the renderer).
   *
   * @param fieldLayoutItem the FieldLayoutItem in play
   * @param fieldValuesHolder the fields values holder in play
   * @param velocityParams the velocity parameters to which values will be added
   */
  private void populateVelocityParams(
      FieldLayoutItem fieldLayoutItem, Map fieldValuesHolder, Map<String, Object> velocityParams) {
    if (fieldValuesHolder != null) {
      Map commentParams = (Map) fieldValuesHolder.get(getId());
      if (commentParams != null) {
        velocityParams.put(getId(), commentParams.get(getId()));
      }
    }

    velocityParams.put("rendererParams", new HashMap());
    String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null;
    velocityParams.put(
        "rendererDescriptor", rendererManager.getRendererForType(rendererType).getDescriptor());
    velocityParams.put("groupLevels", getGroupLevels());
    velocityParams.put(
        "mentionable", mentionService.isUserAbleToMention(authenticationContext.getLoggedInUser()));

    Issue issue = (Issue) velocityParams.get("issue");
    if (issue != null) {
      velocityParams.put("roleLevels", getRoleLevels(issue));
    } else {
      // We are possibly in a bulk screen
      Object action = velocityParams.get("action");
      if (action != null && action instanceof BulkWorkflowTransition) {
        BulkWorkflowTransition bulkWorkflowTransition = (BulkWorkflowTransition) action;
        BulkEditBean bulkEditBean = bulkWorkflowTransition.getBulkEditBean();
        if (bulkEditBean != null) {
          // TODO: what if there are multiple projects? We should get the intersection of all roles.
          GenericValue project = bulkEditBean.getProject();
          if (project != null) {
            velocityParams.put("roleLevels", getRoleLevels(project));
          }
        }
      }
    }
  }
Exemplo n.º 3
0
  @Override
  public void updateValue(
      FieldLayoutItem fieldLayoutItem,
      Issue issue,
      ModifiedValue modifiedValue,
      IssueChangeHolder issueChangeHolder) {
    // all comment creations are seen as an update
    Map<String, Object> commentParams = (Map<String, Object>) modifiedValue.getNewValue();
    String body = (String) commentParams.get(getId());

    // allow the renderer for this field a change to transform the value
    String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null;
    body = (String) rendererManager.getRendererForType(rendererType).transformFromEdit(body);

    if (commentParams.containsKey(EDIT_COMMENT)) {
      editComment(issueChangeHolder, commentParams, body);
    } else if (commentParams.containsKey(REMOVE_COMMENT)) {
      removeComment(issueChangeHolder, commentParams);
    } else {
      if (StringUtils.isNotBlank(body)) {
        createComment(issue, issueChangeHolder, commentParams, body);
      }
    }
  }