Script Runner Custom Scripted JQL not showing up in issue navigator?

Joel Chuah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2015

Hi

The script works and was detected when i click scan. However, it does not show up in the auto complete dropdown. I thought typing "project in p"  should give me "projectsSharingWorkflowScheme" in the suggestions dropdown.

I need to know the exact query name for me to use it  sad. Am I missing some configuration?

Thanks

 

package com.onresolve.jira.groovy.jql
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.plugin.jql.function.JqlFunctionModuleDescriptor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.util.MessageSetImpl;
import com.atlassian.jira.workflow.WorkflowScheme;
import com.atlassian.jira.workflow.WorkflowSchemeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.JiraDataType;
import com.atlassian.jira.JiraDataTypes;
import com.atlassian.jira.jql.operand.QueryLiteral;
import com.atlassian.jira.jql.query.QueryCreationContext;
import com.atlassian.jira.plugin.jql.function.AbstractJqlFunction;
import com.atlassian.jira.util.MessageSet;
import com.atlassian.jira.util.NotNull;
import com.atlassian.query.clause.TerminalClause;
import com.atlassian.query.operand.FunctionOperand;
import com.google.common.collect.Iterables;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.user.UserHistoryItem;
import com.atlassian.jira.user.UserProjectHistoryManager;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class projectsSharingWorkflowScheme extends AbstractScriptedJqlFunction implements JqlFunction
{
	@Override
    String getDescription() {"returns projects sharing the same workflow scheme"}
    @Override
    List<Map> getArguments() {
		[
            ["description": "project key", "optional": false]
        ]
	}
    @Override
    String getFunctionName() {"projectsSharingWorkflowScheme"}
	
	@Override
	JiraDataType getDataType(){JiraDataType.PROJECT}
	
	@Override
	boolean isList(){true}
	
	
	@Override
    public MessageSet validate(User searcher, FunctionOperand operand, TerminalClause terminalClause)
    {
        MessageSet messages = new MessageSetImpl();
        final List<String> arguments = operand.getArgs();
        if (arguments.isEmpty())
        {
            messages.addErrorMessage("You need to specify at least one project key");
            return messages;
        }
        else
        {
            for(String pKey : arguments)
            {
                if(ComponentAccessor.getProjectManager().getProjectObjByKey(pKey)==null)
                {
                    messages.addErrorMessage("Project key, " + pKey + " is not valid");
                }
            }
        }
        return messages;
    }

    public List<QueryLiteral> getValues(QueryCreationContext queryCreationContext,FunctionOperand operand, TerminalClause terminalClause)
    {
        WorkflowSchemeManager wfsm = ComponentAccessor.getWorkflowSchemeManager();
        ProjectManager prjm = ComponentAccessor.getProjectManager();
        final List<String> arguments = operand.getArgs();
        final List <Project> projects = ComponentAccessor.getProjectManager().getProjectObjects();
        final List <QueryLiteral> literals = new LinkedList<QueryLiteral>();
        for(final String pKey : arguments)
        {
            final WorkflowScheme wfs = wfsm.getWorkflowSchemeObj(prjm.getProjectObjByKey(pKey));
            for(final Project project : projects)
            {
               if( wfsm.getWorkflowSchemeObj(project).getId() == wfs.getId())
               {
                    literals.add(new QueryLiteral(operand,project.getId()));
               }
            }
        }
        return literals;
    }
}

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2015

It is JiraDataTypes.PROJECT, not JiraDataType.PROJECT.

You should be getting a compile error...?

 

Joel Chuah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2015

Ah that was silly of me.. Didnt take a closer look at the logs and it wouldnt have happened if I used an IDE. Thanks. Works now.

0 votes
Joel Chuah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 27, 2015

I am on JIRA 6.3.15 and scriptrunner 3.1.3. Script is place in scriptroot

TAGS
AUG Leaders

Atlassian Community Events