Package com.atlassian.jira.util

Examples of com.atlassian.jira.util.I18nHelper


   * @param messageParameters can be the same as {@link com.atlassian.jira.util.I18nHelper#getText(String, Object)}
   * */
  public static String getText(@Nullable Locale locale, @Nullable User user, String textKey, Object... messageParameters) {
    I18nHelper.BeanFactory factory = ComponentAccessor.getI18nHelperFactory();
    if (factory == null) return textKey + ' ' + Arrays.toString(messageParameters);
    I18nHelper i18nHelper = locale != null || user == null
      ? factory.getInstance(locale != null ? locale : getJiraDefaultLocale())
      : factory.getInstance(user);
    return i18nHelper.getText(textKey, messageParameters);
  }
View Full Code Here


   * @param messageParameters can be the same as {@link com.atlassian.jira.util.I18nHelper#getText(String, Object)}
   * */
  public static String getText(@Nullable Locale locale, @Nullable User user, String textKey, Object... messageParameters) {
    I18nHelper.BeanFactory factory = ComponentAccessor.getI18nHelperFactory();
    if (factory == null) return textKey + ' ' + Arrays.toString(messageParameters);
    I18nHelper i18nHelper = locale != null || user == null
      ? factory.getInstance(locale != null ? locale : getJiraDefaultLocale())
      : factory.getInstance(user);
    return i18nHelper.getText(textKey, messageParameters);
  }
View Full Code Here

   * */
   @NotNull
   public static String getText(@Nullable Locale locale, @Nullable User user, String textKey, Object... messageParameters) {
    I18nHelper.BeanFactory factory = ComponentAccessor.getI18nHelperFactory();
    if (factory == null) return textKey + ' ' + Arrays.toString(messageParameters);
    I18nHelper i18nHelper = locale != null || user == null
      ? factory.getInstance(locale != null ? locale : getJiraDefaultLocale())
      : factory.getInstance(user);
    return i18nHelper.getText(textKey, messageParameters);
  }
View Full Code Here

    @Path("/initjqldlg")
    @Produces({MediaType.APPLICATION_JSON})
    public Response initJqlDialog(@Context HttpServletRequest req)
    {
        JiraAuthenticationContext authCtx = ComponentManager.getInstance().getJiraAuthenticationContext();
        I18nHelper i18n = authCtx.getI18nHelper();
        User user = authCtx.getLoggedInUser();
        if (user == null)
        {
            log.error("QueryFieldsService::initJclDialog - User is not logged");
            return Response.ok(i18n.getText("queryfields.error.notlogged")).status(401).build();
        }

        String cfIdStr = req.getParameter("cfId");
        String prIdStr = req.getParameter("prId");
        String type = req.getParameter("type");
        if (!Utils.isValidStr(cfIdStr) || !Utils.isValidStr(prIdStr) || !Utils.isValidStr(type))
        {
            log.error("QueryFieldsService::initJclDialog - Required parameters are not set");
            return Response.ok(i18n.getText("queryfields.error.notrequiredparms")).status(500).build();
        }

        long cfId;
        long prId;
        try
        {
            cfId = Long.parseLong(cfIdStr);
            prId = Long.parseLong(prIdStr);
        }
        catch (NumberFormatException nex)
        {
            log.error("QueryFieldsService::initJclDialog - Parameters are not valid");
            return Response.ok(i18n.getText("queryfields.error.notvalidparms")).status(500).build();
        }

        XsrfTokenGenerator xsrfTokenGenerator = ComponentManager.getComponentInstanceOfType(XsrfTokenGenerator.class);
        String atl_token = xsrfTokenGenerator.generateToken(req);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("i18n", authCtx.getI18nHelper());
        params.put("baseUrl", Utils.getBaseUrl(req));
        params.put("atl_token", atl_token);
        params.put("cfId", cfId);
        params.put("prId", prId);
        params.put("type", type);
        params.put("jqlData", qfMgr.getQueryFieldData(cfId, prId));
        params.put("jqlnull", qfMgr.getAddNull(cfId, prId));
        params.put("autocompleteview", qfMgr.isAutocompleteView(cfId, prId));

        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put("key", "queryfields.opt.key");
        map.put("status", "queryfields.opt.status");
        map.put("assignee", "queryfields.opt.assignee");
        map.put("due", "queryfields.opt.due");
        map.put("priority", "queryfields.opt.priority");
        if (type.equals("1"))
        {
            map.put("editKey", "queryfields.opt.editKey");
            map.put("justDesc", "queryfields.opt.justDesc");
        }
        params.put("options", map);
        params.put("selectedOptions", qfMgr.getLinkeFieldsOptions(cfId, prId));

        try
        {
            String body = ComponentAccessor.getVelocityManager().getBody("templates/", "setjql.vm", params);
            return Response.ok(new HtmlEntity(body)).build();
        }
        catch (VelocityException vex)
        {
            log.error("QueryFieldsService::initJclDialog - Velocity parsing error", vex);
            return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
        }
    }
View Full Code Here

    @Path("/setjql")
    @Produces({MediaType.APPLICATION_JSON})
    public Response setJcl(@Context HttpServletRequest req)
    {
        JiraAuthenticationContext authCtx = ComponentManager.getInstance().getJiraAuthenticationContext();
        I18nHelper i18n = authCtx.getI18nHelper();
        User user = authCtx.getLoggedInUser();
        if (user == null)
        {
            log.error("QueryFieldsService::setJcl - User is not logged");
            return Response.ok(i18n.getText("queryfields.error.notlogged")).status(401).build();
        }

        XsrfTokenGenerator xsrfTokenGenerator = ComponentManager.getComponentInstanceOfType(XsrfTokenGenerator.class);
        String token = xsrfTokenGenerator.getToken(req);
        if (!xsrfTokenGenerator.generatedByAuthenticatedUser(token))
        {
            log.error("QueryFieldsService::setJcl - There is no token");
            return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
        }
        else
        {
            String atl_token = req.getParameter("atl_token");
            if (!atl_token.equals(token))
            {
                log.error("QueryFieldsService::setJcl - Token is invalid");
                return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
            }
        }

        String cfIdStr = req.getParameter("cfId");
        String prIdStr = req.getParameter("prId");
        String data = req.getParameter("jqlclause");
        String jqlnull = req.getParameter("jqlnull");
        String autocompleteView = req.getParameter("autocompleteview");
        String[] options = req.getParameterValues("options");
        if (!Utils.isValidStr(cfIdStr) || !Utils.isValidStr(prIdStr))
        {
            log.error("QueryFieldsService::setJcl - Required parameters are not set");
            return Response.ok(i18n.getText("queryfields.error.notrequiredparms")).status(500).build();
        }

        long cfId;
        long prId;
        try
        {
            cfId = Long.parseLong(cfIdStr);
            prId = Long.parseLong(prIdStr);
        }
        catch (NumberFormatException nex)
        {
            log.error("QueryFieldsService::setJcl - Parameters are not valid");
            return Response.ok(i18n.getText("queryfields.error.notvalidparms")).status(500).build();
        }

        if (Utils.isValidStr(data))
        {
            String jqlQuery = data;
            if (data.startsWith(Consts.REVERSE_LINK_PART))
            {
                String reserveData = data.substring(Consts.REVERSE_LINK_PART.length());
                int inx = reserveData.indexOf("|");
                if (inx < 0)
                {
                    Set<String> errs = new TreeSet<String>();
                    errs.add(i18n.getText("queryfields.error.rlinkerror"));
                    Map<String, Object> params = new HashMap<String, Object>();
                    params.put("errs", errs);
                    params.put("i18n", i18n);

                    try
                    {
                        String body = ComponentAccessor.getVelocityManager().getBody("templates/", "conferr.vm", params);
                        return Response.ok(new HtmlEntity(body)).status(500).build();
                    }
                    catch (VelocityException vex)
                    {
                        log.error("QueryFieldsService::setJcl - Velocity parsing error", vex);
                        return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
                    }
                }

                String proj = reserveData.substring(0, inx);
                String cfName = reserveData.substring(inx + 1);

                jqlQuery = String.format(Consts.TEST_QUERY_PATTERN, proj, cfName);
            }

            SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlQuery);
            if (parseResult.isValid())
            {
                qfMgr.setQueryFieldData(cfId, prId, data);
                if (Utils.isValidStr(jqlnull) && jqlnull.equals("on"))
                {
                    qfMgr.setAddNull(cfId, prId, true);
                }
                else
                {
                    qfMgr.setAddNull(cfId, prId, false);
                }
                if (Utils.isValidStr(autocompleteView) && autocompleteView.equals("on"))
                {
                    qfMgr.setAutocompleteView(cfId, prId, true);
                }
                else
                {
                    qfMgr.setAutocompleteView(cfId, prId, false);
                }
                List<String> optList = new ArrayList<String>();
                if (options != null)
                {
                    for (String option : options)
                    {
                        optList.add(option);
                    }
                }
                qfMgr.setLinkerFieldOptions(cfId, prId, optList);
            }
            else
            {
                MessageSet ms = parseResult.getErrors();
                Set<String> errs = ms.getErrorMessages();
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("errs", errs);
                params.put("i18n", i18n);

                try
                {
                    String body = ComponentAccessor.getVelocityManager().getBody("templates/", "conferr.vm", params);
                    return Response.ok(new HtmlEntity(body)).status(500).build();
                }
                catch (VelocityException vex)
                {
                    log.error("QueryFieldsService::setJcl - Velocity parsing error", vex);
                    return Response.ok(i18n.getText("queryfields.error.internalerror")).status(500).build();
                }
            }
        }
        else
        {
View Full Code Here

    @Produces({MediaType.APPLICATION_JSON})
    public Response getCfVals(@Context HttpServletRequest req)
    {
        JiraAuthenticationContext authCtx = ComponentManager.getInstance()
            .getJiraAuthenticationContext();
        I18nHelper i18n = authCtx.getI18nHelper();
        User user = authCtx.getLoggedInUser();
        if (user == null)
        {
            log.error("QueryAutocompleteService::getCfVals - User is not logged");
            return Response
                .ok(i18n.getText("queryfields.service.user.notlogged"))
                .status(401).build();
        }

        String cfId = req.getParameter("cf_id");

        AutocompleteUniversalData data;
        List<AutocompleteUniversalData> values = null;

        if (Utils.isValidStr(cfId))
        {
            CustomField cf = ComponentManager.getInstance()
                .getCustomFieldManager().getCustomFieldObject(cfId);
            if (cf == null)
            {
                log.error("QueryAutocompleteService::getCfVals - Custom field is null. Incorrect data in plugin settings");
                return Response
                    .ok(i18n.getText("queryfields.service.error.cfid.invalid"))
                    .status(400).build();
            }

            String jqlData;
            if (cf.isAllProjects())
            {
                jqlData = qfMgr.getQueryFieldData(cf.getIdAsLong(),
                    Consts.PROJECT_ID_FOR_GLOBAL_CF);
            }
            else
            {
                UserProjectHistoryManager userProjectHistoryManager = ComponentManager
                    .getComponentInstanceOfType(UserProjectHistoryManager.class);
                Project currentProject = userProjectHistoryManager
                    .getCurrentProject(Permissions.BROWSE,
                        authCtx.getLoggedInUser());
                if (currentProject == null)
                {
                    log.error("QueryAutocompleteService::getCfVals - Current project is null");
                    return Response
                        .ok(i18n.getText("queryfields.service.error.curproject"))
                        .status(400).build();
                }
                jqlData = qfMgr.getQueryFieldData(cf.getIdAsLong(),
                    currentProject.getId());
            }

            List<Issue> issues = Utils.executeJQLQuery(jqlData);
            values = new ArrayList<AutocompleteUniversalData>(issues.size());
            for (Issue issue : issues)
            {
                String icon;
                data = new AutocompleteUniversalData();
                data.setName(issue.getKey());
                data.setDescription(issue.getSummary());
                if (issue.getIssueTypeObject() != null)
                {
                    data.setType(issue.getIssueTypeObject().getName());
                    icon = issue.getIssueTypeObject().getIconUrl();
                    if (Utils.isValidStr(icon))
                    {
                        data.setTypeimage(icon);
                    }
                }

                if (issue.getStatusObject() != null)
                {
                    data.setState(issue.getStatusObject().getName());
                }

                values.add(data);
            }
        }
        else
        {
            log.error("QueryAutocompleteService::getCfVals - Incorrect parameters");
            return Response
                .ok(i18n
                    .getText("queryfields.service.error.parameters.invalid"))
                .status(400).build();
        }

        Response resp;
View Full Code Here

    @Produces({MediaType.APPLICATION_JSON})
    public Response getIssueTemplate(@Context HttpServletRequest req)
    {
        JiraAuthenticationContext authCtx = ComponentManager.getInstance()
            .getJiraAuthenticationContext();
        I18nHelper i18n = authCtx.getI18nHelper();
        User user = authCtx.getLoggedInUser();
        if (user == null)
        {
            log.error("QueryAutocompleteService::validateInput - User is not logged");
            return Response
                .ok(i18n.getText("queryfields.service.user.notlogged"))
                .status(401).build();
        }

        String cfId = req.getParameter("cf_id");
        String cfValue = req.getParameter("cf_value");

        if (!Utils.isValidStr(cfId) || !Utils.isValidStr(cfValue))
        {
            log.error("QueryAutocompleteService::validateInput - Invalid parameters");
            return Response
                .ok(i18n
                    .getText("queryfields.service.error.parameters.invalid"))
                .status(400).build();
        }

        CustomField cf = ComponentManager.getInstance().getCustomFieldManager()
            .getCustomFieldObject(cfId);
        if (cf == null)
        {
            log.error("QueryAutocompleteService::validateInput - Custom field is null. Incorrect data in plugin settings");
            return Response
                .ok(i18n.getText("queryfields.service.error.cfid.invalid"))
                .status(400).build();
        }

        AutocompleteUniversalData entity = new AutocompleteUniversalData();
        if (Utils.isOfQueryMultiSelectType(cf.getCustomFieldType().getKey()))
        {
            Issue issue = ComponentManager.getInstance().getIssueManager()
                .getIssueObject(cfValue);
            if (issue == null)
            {
                // nothing to do. Sending object with empty key
            }
            else
            {
                String icon;
                entity.setName(issue.getKey());
                if (issue.getIssueTypeObject() != null)
                {
                    entity.setType(issue.getIssueTypeObject().getName());
                    icon = issue.getIssueTypeObject().getIconUrl();
                    if (Utils.isValidStr(icon))
                    {
                        entity.setTypeimage(icon);
                    }
                }
                entity.setDescription(issue.getSummary());

                if (issue.getStatusObject() != null)
                {
                    entity.setState(issue.getStatusObject().getName());
                    icon = issue.getStatusObject().getIconUrl();
                    if (Utils.isValidStr(icon))
                    {
                        entity.setStateimage(icon);
                    }
                }

                if (issue.getPriorityObject() != null)
                {
                    entity.setPreference(issue.getPriorityObject().getName());
                    icon = issue.getPriorityObject().getIconUrl();
                    if (Utils.isValidStr(icon))
                    {
                        entity.setPreferenceimage(icon);
                    }
                }

                Map<String, Object> params = new HashMap<String, Object>();
                params.put("cfid", cfId);
                params.put("baseUrl", Utils.getBaseUrl(req));
                params.put("data", entity);
                params.put("i18n", i18n);

                try
                {
                    String body = ComponentAccessor.getVelocityManager()
                        .getBody("templates/", "edit-issue-representation.vm",
                            params);
                    return Response.ok(new HtmlEntity(body)).build();
                }
                catch (VelocityException vex)
                {
                    log.error(
                        "QueryAutocompleteService::manageInput - Velocity parsing error",
                        vex);
                    return Response
                        .ok(i18n
                            .getText("queryfields.service.velocity.parseerror"))
                        .status(500).build();
                }
            }
        }
View Full Code Here

        @SuppressWarnings("unchecked")
        final Collection<String> params = cfParams.getAllValues();
        CustomField cf = fieldConfig.getCustomField();
        JiraAuthenticationContext authCtx = ComponentManager.getInstance()
            .getJiraAuthenticationContext();
        I18nHelper i18n = authCtx.getI18nHelper();
        UserProjectHistoryManager userProjectHistoryManager = ComponentManager
            .getComponentInstanceOfType(UserProjectHistoryManager.class);
        Project currentProject = userProjectHistoryManager.getCurrentProject(
            Permissions.BROWSE, authCtx.getLoggedInUser());

        boolean isAutocompleteView;
        if (cf.isAllProjects())
        {
            isAutocompleteView = qfMgr.isAutocompleteView(cf.getIdAsLong(),
                Consts.PROJECT_ID_FOR_GLOBAL_CF);        }
        else
        {
            isAutocompleteView = qfMgr.isAutocompleteView(cf.getIdAsLong(),
                currentProject.getId());
        }
       
        if (isAutocompleteView)
        {
            if ((params == null) || params.isEmpty())
            {
                boolean addNull;
                if (cf.isAllProjects())
                {
                    addNull = qfMgr.getAddNull(cf.getIdAsLong(),
                        Consts.PROJECT_ID_FOR_GLOBAL_CF);
                }
                else
                {
                    addNull = qfMgr.getAddNull(cf.getIdAsLong(),
                        currentProject.getId());
                }

                if (!addNull)
                {
                    errorCollection.addError(fieldConfig.getFieldId(),
                        i18n.getText("queryfields.error.isnotnull"));
                }
            }
            else
            {
                if (params.size() > 1)
                {
                    errorCollection.addError(fieldConfig.getFieldId(),
                        i18n.getText("queryfields.error.invalid.params"));
                }
                else
                {
                    for (String param : params)
                    {
                        Issue issue = issueMgr.getIssueObject(param);
                        if (issue == null)
                        {
                            errorCollection.addError(fieldConfig.getFieldId(),
                                i18n.getText("queryfields.error.notissue", param));
                        }
                    }
                }
            }
        }
View Full Code Here

   * @param messageParameters can be the same as {@link com.atlassian.jira.util.I18nHelper#getText(String, Object)}
   * */
  public static String getText(@Nullable Locale locale, @Nullable User user, String textKey, Object... messageParameters) {
    I18nHelper.BeanFactory factory = ComponentAccessor.getI18nHelperFactory();
    if (factory == null) return textKey + ' ' + Arrays.toString(messageParameters);
    I18nHelper i18nHelper = locale != null || user == null
      ? factory.getInstance(locale != null ? locale : getJiraDefaultLocale())
      : factory.getInstance(user);
    return i18nHelper.getText(textKey, messageParameters);
  }
View Full Code Here

   * @param messageParameters can be the same as {@link com.atlassian.jira.util.I18nHelper#getText(String, Object)}
   * */
  public static String getText(@Nullable Locale locale, @Nullable User user, String textKey, Object... messageParameters) {
    I18nHelper.BeanFactory factory = ComponentAccessor.getI18nHelperFactory();
    if (factory == null) return textKey + ' ' + Arrays.toString(messageParameters);
    I18nHelper i18nHelper = locale != null || user == null
      ? factory.getInstance(locale != null ? locale : getJiraDefaultLocale())
      : factory.getInstance(user);
    return i18nHelper.getText(textKey, messageParameters);
  }
View Full Code Here

TOP

Related Classes of com.atlassian.jira.util.I18nHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.