package com.onresolve.jira.groovy.jql
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.LuceneQueryBuilder
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.permission.ProjectPermissions
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
import java.text.SimpleDateFormat
import com.atlassian.jira.component.ComponentAccessor
import groovy.json.*
import org.apache.lucene.search.Query
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
class CurrentUserTeams_34 extends AbstractScriptedJqlFunction implements JqlQueryFunction {
public static final String TEMPLATE_QUERY(){
def JIRA_REST_URL = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl");
def date = new Date();
def sdf = new SimpleDateFormat("yyyy-MM-dd");
def User = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name;
def JIRA_API_URL = JIRA_REST_URL + "/rest/tempo-teams/2/user/" + User + "/membership?from="+ sdf.format(date) +"&to=" + sdf.format(date);
def authString = "user:password".bytes.encodeBase64().toString();
def connection = JIRA_API_URL.toURL().openConnection();
connection.addRequestProperty("Authorization", "Basic " + authString);
connection.addRequestProperty("Content-Type", "application/json");
connection.setRequestMethod("GET");
connection.doOutput = false;
connection.connect();
def json = connection.content.text;
def jsonSlurper = new JsonSlurper();
def object = jsonSlurper.parseText(json);
def vals = object.teamId.toString().replace('[','"').replace(']','"');
return vals;
}
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
def luceneQueryBuilder = ComponentAccessor.getComponent(LuceneQueryBuilder)
def searchService = ComponentAccessor.getComponent(SearchService)
@Override
String getDescription() {
"Get current Users Teams"
}
@Override
List<Map> getArguments() {
Collections.EMPTY_LIST
}
@Override
JiraDataType getDataType() {
JiraDataTypes.TEXT
}
@Override
String getFunctionName() {
"currentUserTeams"
}
@Override
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
def query = mergeQuery(operand)
luceneQueryBuilder.createLuceneQuery(queryCreationContext, query.whereClause)
}
private com.atlassian.query.Query mergeQuery(FunctionOperand operand) {
def queryStr = MessageFormat.format(TEMPLATE_QUERY, operand.args.first())
queryParser.parseQuery(queryStr)
}
}
I'm not really clear what you are trying to do here. Could you explain? At a guess you want to use this like:
someCustomField in currentUserTeams()
and the function retrieves the teams as strings from tempo's rest API.
Is that what you're doing? What kind of custom field are you querying?
PS, unless that's a throwaway instance you should change your password...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you want something like the following, but it depends on the answers to my questions, and how the field is indexed:
This system is ridiculous for pasting code so find it here: https://gist.github.com/jechlin/11927d14ab4ce344eb2083f4c22432d8
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is just my local box. but good looking out about the password.
Holy Cr@p, way better than my scripting skills. Much Appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No worries ;-) I did it with reflection rather than our WithPlugin annotation for simplicity...
For future reference, I advise against using rest APIs to the same instance, from within a plugin... because you need to authenticate, which means hard-coded passwords somewhere, and won't work for instances that use single sign-on, or client SSL certificates etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Travis Alexander @Elias Alexander
FYI Thought you guys might appreciated this also. Jamie made a lifesaver of a JQL script.
Works wonders for Tempo Teams and SD Queues.
Team in currentUserTeams()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.