Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-19908

JiraVelocityUtils.java

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Answered
    • None
    • None
    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

    Description

      I have modified my JiraVelocityUtils.class and it run very good in my version 3.13.5
      But in my work we have the version is 3.13.2 and dont work the code in my custom filed VelocityMessage(for edit)is:

      #set ( $allowed = false )
      #set ( $inicia = 0 )
      #set ( $pid = $requestContext.getRequestParameter("pid") )

      #if ( $pid )

      #set ( $roles = ["Administrators","Developers","Release Managers","Users"] )

      #foreach ( $prj in $componentManager.getProjectManager().getProjects() )
      #if ( $prj.id == $prj.id.parseLong($pid) )
      #set ( $project = $componentManager.getProjectManager().getProjectObj($prj.id) )

      #end

      #end

      #foreach ( $rol in $roles )
      #set ( $role = $projectRoleManager.getProjectRole($rol) )
      $rol
      #set ( $allowed=$projectRoleManager.isUserInProjectRole($authcontext.user, $role, $project))
      #if ( $allowed )
      #set ( $inicia=1 )
      #end
      #end

      #end

      <div class="warningBox">
      $inicia
      </div>

      And My JiraVelocityUtils.java for 3.13.5 is:

      package com.atlassian.jira.util;

      import com.atlassian.core.util.DateUtils;
      import com.atlassian.core.util.XMLUtils;
      import com.atlassian.core.util.map.EasyMap;
      import com.atlassian.jira.ComponentManager;
      import com.atlassian.jira.mail.JiraMailQueueUtils;
      import com.atlassian.jira.plugin.profile.UserFormatManager;
      import com.atlassian.jira.security.JiraAuthenticationContext;
      import com.atlassian.jira.security.roles.ProjectRoleManager;
      import com.atlassian.jira.util.velocity.VelocityRequestContext;
      import com.atlassian.jira.util.velocity.VelocityRequestContextFactory;
      import com.atlassian.jira.web.bean.I18nBean;
      import com.atlassian.jira.web.bean.PermissionCheckBean;
      import com.atlassian.jira.web.util.ExternalLinkUtilImpl;
      import com.opensymphony.util.TextUtils;
      import java.util.HashMap;
      import java.util.Map;
      import org.apache.log4j.Logger;
      import webwork.action.ActionContext;

      // Referenced classes of package com.atlassian.jira.util:
      // JiraUrlCodec, JiraWebUtils

      public class JiraVelocityUtils
      {

      public JiraVelocityUtils()
      {
      }

      public static Map getDefaultVelocityParams(JiraAuthenticationContext authenticationContext)

      { return getDefaultVelocityParams(null, authenticationContext); }

      public static Map getDefaultVelocityParams(Map startingParams, JiraAuthenticationContext authenticationContext)
      {
      Map velocityParams = new HashMap();
      try
      {
      velocityParams.put("xmlutils", new XMLUtils());
      velocityParams.put("textutils", new TextUtils());
      velocityParams.put("urlcodec", new JiraUrlCodec());
      velocityParams.put("outlookdate", authenticationContext.getOutlookDate());
      velocityParams.put("authcontext", authenticationContext);
      velocityParams.put("dateutils", new DateUtils(authenticationContext.getI18nBean().getDefaultResourceBundle()));
      velocityParams.put("externalLinkUtil", ExternalLinkUtilImpl.getInstance());
      VelocityRequestContext velocityRequestContext = (new VelocityRequestContextFactory(ComponentManager.getInstance().getApplicationProperties())).getJiraVelocityRequestContext();
      velocityParams.put("requestContext", velocityRequestContext);
      velocityParams.put("baseurl", velocityRequestContext.getBaseUrl());
      velocityParams.put("webResourceManager", ComponentManager.getInstance().getWebResourceManager());

      *************************************************************
      *************************************************************
      *************************************************************

      here is where dont work in 3.13.2 : this line is added for me

      velocityParams.put("componentManager", ComponentManager.getInstance());
      velocityParams.put("projectRoleManager", ComponentManager.getComponentInstanceOfType(com/atlassian/jira/security/roles/ProjectRoleManager));

      ****************************************
      ****************************************
      ****************************************

      UserFormatManager userFormatManager = (UserFormatManager)ComponentManager.getComponentInstanceOfType(com/atlassian/jira/plugin/profile/UserFormatManager);
      velocityParams.put("userformat", userFormatManager);
      velocityParams.put("map", new EasyMap());
      velocityParams.put("permissionCheck", new PermissionCheckBean(authenticationContext, ComponentManager.getInstance().getPermissionManager()));
      if(ActionContext.getRequest() != null)

      { javax.servlet.http.HttpServletRequest httpRequest = JiraWebUtils.getHttpRequest(); velocityParams.put("req", httpRequest); }

      }
      catch(Exception e)

      { log.warn("Error occurred adding velocity params to template. All properties may not be available", e); }

      JiraMailQueueUtils.getContextParamsBody(velocityParams);
      if(startingParams != null)
      velocityParams.putAll(startingParams);
      return velocityParams;
      }

      public static final Logger log = Logger.getLogger(com/atlassian/jira/util/JiraVelocityUtils);

      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              e2dd3a80bf3f SoXmArT
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: