public IssueRenderContext getIssueRenderContext() { return issue.getIssueRenderContext(); }
public IssueRenderContext getIssueRenderContext() { return issue.getIssueRenderContext(); }
private Object getRendererCustomFieldValue(FieldLayoutItem fieldLayoutItem, Issue issue, Object value) { Object customFieldValue; if (isRenderable() && value instanceof String) { String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null; customFieldValue = rendererManager.getRenderedContent(rendererType, (String) value, issue.getIssueRenderContext()); } else { customFieldValue = value; } return customFieldValue; }
public String getPreviewHtml(final String rendererType, final String unrenderedMarkup, final String issueKey, final String projectId, final String issueType) { final Issue issue = issueManager.getIssueObject(issueKey); if (issue != null) { return doGetPreviewHtml(rendererType, unrenderedMarkup, issue.getIssueRenderContext()); } if (StringUtils.isEmpty(projectId) || StringUtils.isEmpty(issueType)) { return doGetPreviewHtml(rendererType, unrenderedMarkup, null); } final IssueRenderContext renderContext = generateRenderContext(projectId, issueType); return doGetPreviewHtml(rendererType, unrenderedMarkup, renderContext); }
protected void populateVelocityParams(Map params) { params.put("action", this); params.put("worklog", this.getWorklog()); params.put("content", worklog.getComment()); params.put("userformats", userFormats); try { final FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(IssueFieldConstants.WORKLOG); if (fieldLayoutItem != null) { params.put("content", rendererManager.getRenderedContent(fieldLayoutItem.getRendererType(), worklog.getComment(), issue.getIssueRenderContext())); } } catch (DataAccessException e) { log.error(e.getMessage(), e); } }
public String getRenderedContent(FieldLayoutItem fieldConfig, Issue issue) { if (!(fieldConfig.getOrderableField() instanceof RenderableField)) { log.warn("Attempting to get renderered content from a field that is not of type RendererableField, offending field is: " + fieldConfig.getOrderableField().getId()); throw new IllegalArgumentException("Attempting to get renderered content from a field that is not of type RendererableField, offending field is: " + fieldConfig.getOrderableField().getId()); } IssueRenderContext renderContext = issue.getIssueRenderContext(); RenderableField renderField = (RenderableField) fieldConfig.getOrderableField(); JiraRendererPlugin rendererPlugin = getRendererForField(fieldConfig); return rendererPlugin.render(renderField.getValueFromIssue(issue), renderContext); }
public String getViewHtml(FieldLayoutItem fieldLayoutItem, Action action, Issue issue, String value, Map displayParameters) { Map velocityParams = getVelocityParams(fieldLayoutItem, action, issue, displayParameters); if (isRenderable()) { IssueRenderContext context; if (issue != null) { context = issue.getIssueRenderContext(); } else { context = new IssueRenderContext(null); } // get the rendered value without specifying an issue for context String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null; velocityParams.put("value", rendererManager.getRenderedContent(rendererType, (String) value, context)); } else { velocityParams.put("value", value); } return getViewHtml(velocityParams); }
@Override public Response apply(final CommentService.CommentParameters commentParameters) { Comment comment = commentService.create(user, commentValidationResult, true); CommentJsonBean entity; if (expand != null) { entity = CommentJsonBean.expandedShortBean(comment, jiraBaseUrls, projectRoleManager, dateTimeFormatterFactory, rendererManager, getCommentFieldRendererType(issue), issue.getIssueRenderContext(), expand, authContext.getUser(), emailFormatter); } else { entity = CommentJsonBean.shortBean(comment, jiraBaseUrls, projectRoleManager, authContext.getUser(), emailFormatter); } return Response.status(Response.Status.CREATED).location(getUri(entity)).entity(entity).cacheControl(never()).build(); } });
return rendererManager.getRenderedContent(fieldLayoutItem.getRendererType(), value, issue.getIssueRenderContext());
@Override public String call() { final Map<String, Object> combinedMap = getCombinedMap(field.getCustomFieldType().getVelocityParameters(issue, field, fieldLayoutItem), MapBuilder.build(VELOCITY_VALUE_PARAM, field.getValue(issue))); if (field.isRenderable() && !raw) { String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null; combinedMap.put("renderedValue", rendererManager.getRenderedContent(rendererType, (String) field.getValue(issue), issue.getIssueRenderContext())); } return getHtml(TEMPLATE_NAME_XML, combinedMap); } });
/** * Retrieves the html formatted environment. * <p/> * A simple string (with linked bug keys displayed) is returned if a rendered version cannot be generated. * * @return String the html formatted environment. */ public String getHtmlEnvironment() { // Try to generate rendered values for environment try { FieldLayout fieldLayout = fieldLayoutManager.getFieldLayout(issue); FieldLayoutItem fieldLayoutItem = fieldLayout.getFieldLayoutItem(IssueFieldConstants.ENVIRONMENT); String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null; String renderedContent = rendererManager.getRenderedContent(rendererType, issue.getEnvironment(), issue.getIssueRenderContext()); return renderedContent.replaceAll("<p>", "<p style='margin-top:0;margin-bottom:10px;'>"); } catch (Exception e) { log.warn("Unable to produce rendered version of the environment for the issue " + issue.getKey(), e); return JiraKeyUtils.linkBugKeys(issue.getEnvironment()); } }
/** * This will populate the passed in map with this object referenced as "action" and the rendered comment body as * "renderedContent". * @param params map of params to populate */ protected void populateVelocityParams(Map params) { params.put("action", this); params.put("velocityhelper", new JiraVelocityHelper(ComponentAccessor.getFieldManager())); params.put("requestContext", new DefaultVelocityRequestContextFactory(ComponentAccessor.getApplicationProperties()).getJiraVelocityRequestContext()); params.put("userformat", ComponentAccessor.getComponent(UserFormatManager.class)); params.put("textutils", new TextUtils()); try { FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue.getProjectObject(), issue.getIssueTypeId()).getFieldLayoutItem(IssueFieldConstants.COMMENT); if (fieldLayoutItem != null) { params.put("renderedContent", rendererManager.getRenderedContent(fieldLayoutItem.getRendererType(), comment.getBody(), issue.getIssueRenderContext())); } } catch (DataAccessException e) { log.error(e.getMessage(), e); } }
/** * Retrieves the html formatted description. * <p/> * A simple string (with linked bug keys displayed) is returned if a rendered version cannot be generated. * * @return String the html formatted description. */ public String getHtmlDescription() { // Try to generate rendered values for description try { FieldLayout fieldLayout = fieldLayoutManager.getFieldLayout(issue); FieldLayoutItem fieldLayoutItem = fieldLayout.getFieldLayoutItem(IssueFieldConstants.DESCRIPTION); String rendererType = (fieldLayoutItem != null) ? fieldLayoutItem.getRendererType() : null; String renderedContent = rendererManager.getRenderedContent(rendererType, issue.getDescription(), issue.getIssueRenderContext()); return renderedContent.replaceAll("<p>", "<p style='margin-top:0;margin-bottom:10px;'>"); } catch (Exception e) { log.warn("Unable to produce rendered version of the description for the issue " + issue.getKey(), e); return JiraKeyUtils.linkBugKeys(issue.getDescription()); } }
@Override public Response apply(final Map<String, JSONObject> properties) { Comment updatedComment = commentValidationResult.getComment().get(); commentService.update(user, commentValidationResult, true); CommentJsonBean bean; if (expand != null) { bean = CommentJsonBean.expandedShortBean(updatedComment, jiraBaseUrls, projectRoleManager, dateTimeFormatterFactory, rendererManager, getCommentFieldRendererType(issue), issue.getIssueRenderContext(), expand, authContext.getUser(), emailFormatter); } else { bean = CommentJsonBean.shortBean(updatedComment, jiraBaseUrls, projectRoleManager, authContext.getUser(), emailFormatter); } return Response.ok(bean).location(getUri(bean)).cacheControl(never()).build(); } });
@EventListener public void execute(final MentionIssueEvent mentionIssueEvent) { if (mailServerManager.isDefaultSMTPMailServerDefined()) { final ApplicationUser from = mentionIssueEvent.getFromUser(); for (ApplicationUser toUser : mentionIssueEvent.getToUsers()) { if (toUser.getEmailAddress() == null) { log.warn("User " + toUser.getName() + " does not have a registered email address. No mentioned notification will be sent."); continue; } final NotificationRecipient recipient = new NotificationRecipient(toUser); if (shouldSendMention(mentionIssueEvent, recipient)) { Map<String, Object> params = Maps.newHashMap(); params.put("comment", mentionIssueEvent.getMentionText()); params.put("issue", mentionIssueEvent.getIssue()); IssueRenderContext issueRenderContext = mentionIssueEvent.getIssue().getIssueRenderContext(); MailQueueItem item = new MentionMailQueueItem(from, recipient, params, issueRenderContext, rendererManager, mailQueue); mailQueue.addItem(item); } } } }
@Override public CommentJsonBean createRenderedBean(Comment comment, final ApplicationUser loggedInUser, final EmailFormatter emailFormatter) { Assertions.notNull("comment", comment); final IssueRenderContext issueRenderContext = comment.getIssue().getIssueRenderContext(); final FieldLayout layout = fieldLayoutManager.getFieldLayout(comment.getIssue()); final FieldLayoutItem fieldLayoutItem = layout.getFieldLayoutItem(IssueFieldConstants.COMMENT); final String rendererType = fieldLayoutItem == null ? null : fieldLayoutItem.getRendererType(); return CommentJsonBean.renderedShortBean( comment, jiraBaseUrls, projectRoleManager, dateTimeFormatterFactory, rendererManager, rendererType, issueRenderContext, loggedInUser, emailFormatter ); } }
public Html renderIssueFieldValue(Issue issue, String fieldId, String value) { FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue.getProjectObject(), issue.getIssueTypeObject().getId()).getFieldLayoutItem(fieldId); if (fieldLayoutItem == null) { return new Html(value); } return new Html(rendererManager.getRenderedContent(fieldLayoutItem.getRendererType(), value, issue.getIssueRenderContext())); }
public String getRenderedContent(FieldRenderContext fieldRenderContext) { Issue issue = fieldRenderContext.getIssue(); String fieldId = fieldRenderContext.getFieldId(); FieldLayoutManager fieldLayoutManager = ComponentAccessor.getComponentOfType(FieldLayoutManager.class); // can't put into constructor due to cyclic dependency FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue.getProjectObject(), issue.getIssueTypeId()).getFieldLayoutItem(fieldId); if (fieldLayoutItem != null) { return getRenderedContent(fieldLayoutItem.getRendererType(), fieldRenderContext.getBody(), issue.getIssueRenderContext()); } return null; }
renderedBean.setStartAt(0); renderedBean.setComments(CommentJsonBean.renderedShortBeans(comments, jiraBaseUrls, projectRoleManager, dateTimeFormatterFactory, rendererManager, fieldLayoutItem == null ? null : fieldLayoutItem.getRendererType(), issue.getIssueRenderContext(), authenticationContext.getUser(), emailFormatter)); fieldJsonRepresentation.setRenderedData(new JsonData(renderedBean));
@Override public FieldJsonRepresentation getJsonFromIssue(Issue issue, boolean renderedVersionRequested, final @Nullable FieldLayoutItem fieldLayoutItem) { final JiraServiceContextImpl serviceContext = new JiraServiceContextImpl(authenticationContext.getUser()); final PagedList<Worklog> worklogs = getWorklogService().getByIssueVisibleToUser(serviceContext, issue, 20); if (!serviceContext.getErrorCollection().hasAnyErrors()) { WorklogWithPaginationBean worklogWithPaginationBean = new WorklogWithPaginationBean(); worklogWithPaginationBean.setMaxResults(worklogs.getPageSize()); worklogWithPaginationBean.setTotal(worklogs.getSize()); worklogWithPaginationBean.setStartAt(0); worklogWithPaginationBean.setWorklogs(WorklogJsonBean.asBeans(worklogs.getPage(0), jiraBaseUrls, ComponentAccessor.getUserManager(), ComponentAccessor.getComponent(TimeTrackingConfiguration.class), authenticationContext.getUser(), emailFormatter)); FieldJsonRepresentation fieldJsonRepresentation = new FieldJsonRepresentation(new JsonData(worklogWithPaginationBean)); if (renderedVersionRequested) { WorklogWithPaginationBean renderedWorklogBean = new WorklogWithPaginationBean(); renderedWorklogBean.setMaxResults(worklogs.getPageSize()); renderedWorklogBean.setTotal(worklogs.getSize()); renderedWorklogBean.setStartAt(0); renderedWorklogBean.setWorklogs(WorklogJsonBean.asRenderedBeans(worklogs.getPage(0), jiraBaseUrls, fieldLayoutItem != null ? fieldLayoutItem.getRendererType() : null, issue.getIssueRenderContext(), authenticationContext.getUser(), emailFormatter)); fieldJsonRepresentation.setRenderedData(new JsonData(renderedWorklogBean)); } return fieldJsonRepresentation; } return null; }