Static type checking The variable jiraHelper/issue is undeclared - jira

I am using a condition in my script in the REST endpoint and I am receiving the following errors:
Anyone knows what the problem is and what needs to be fixed?
Here is the code:
package CreateMultipleSubtasks
import org.apache.log4j.Logger
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import com.atlassian.jira.component.ComponentAccessor
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA BEFORE")
Configuration_CreateMultipleSubtasks conf = new Configuration_CreateMultipleSubtasks()
def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()
String projectKey = subTaskCreatorHashMap["projectKey"];
String issueTypeName = subTaskCreatorHashMap["issueTypeName"];
log.warn("MOUNA PROJECT KEY "+ projectKey+" issuetypename "+issueTypeName)
def val=jiraHelper.project?.key==projectKey && issue.issueType.name==issueTypeName
return val

Related

12200 - Schema validation warning twilio

Hi team i need to fix the 12200 - Schema validation warning twilio.
everything is working but i dont receive the whatsapp respond back .
enter image description here
here is the app.py code:
from helper.openai_api import text_complition
from helper.twilio_api import send_message
from twilio.twiml.messaging_response import MessagingResponse
from flask import Flask, request
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
#app.route('/')
def home():
return 'All is well...'
#app.route('/twilio/receiveMessage', methods=['POST'])
def receiveMessage():
try:
message = request.form['Body']
sender_id = request.form['From']
# Placeholder code
result = {}
result['status'] = 1
result['response'] = "Hi, I'm CODAI, I have received your message."
send_message(sender_id, result['response'])
except:
pass
return 'OK', 200
here is the openai.py code:
import os
import openai
from dotenv import load_dotenv
from twilio.twiml.messaging_response import MessagingResponse
load_dotenv()
openai.api_key = os.getenv('OPENAI_API_KEY')
def text_complition(prompt: str) -> dict:
'''
Call Openai API for text completion
Parameters:
- prompt: user query (str)
Returns:
- dict
'''
try:
response = openai.Completion.create(
model='text-davinci-003',
prompt=f'Human: {prompt}\nAI: ',
temperature=0.9,
max_tokens=150,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=['Human:', 'AI:']
)
return {
'status': 1,
'response': response['choices'][0]['text']
}
except:
return {
'status': 0,
'response': ''
}
here is the twilio.py code:
import os
from twilio.twiml.messaging_response import MessagingResponse
from twilio.rest import Client
from dotenv import load_dotenv
load_dotenv()
account_sid = os.getenv('TWILIO_ACCOUNT_SID')
auth_token = os.getenv('TWILIO_AUTH_TOKEN')
client = Client(account_sid, auth_token)
def send_message(to: str, message: str) -> None:
'''
Send message through Twilio's WhatsApp API.
Parameters:
- to(str): recipient's phone number in the format of "whatsapp:+[country code][phone number]"
- message(str): text message to send
Returns:
- None
'''
_ = client.messages.create(
from_=os.getenv('FROM'),
body=message,
to="whatsapp:" + to
)
i need help to fix the error 12200 - Schema validation warning twilio

How to pass parameter to groovy post build in jenkins?

I have the following Groovy Postbuild script in a jenkins job:
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.net.URL
import java.net.URLConnection
def sendPostRequest(urlString, paramString) {
def url = new URL(urlString)
def conn = url.openConnection()
conn.setDoOutput(true)
def writer = new OutputStreamWriter(conn.getOutputStream())
writer.write(paramString)
writer.flush()
String line
def reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))
while ((line = reader.readLine()) != null) {
println line
}
writer.close()
reader.close()
}
def result =" Project: *Autotests* \n Version *manager.build.buildVariables.get("VERSION_CURR")* \n"
sendPostRequest("https://api.telegram.org/bot{token}/sendMessage", "parse_mode=Markdown&chat_id={id_Chat}&reply_to_message_id=&text=${result}")
But I am getting an error: "groovy.lang.MissingPropertyException: No such property: VERSION_CURR for class: Script1"
However, I have a string parameter:
i also tried: def result =' Project: *Autotests* \n Version *${VERSION_CURR}* \n'

REST endpoint works as in line script and doesn't work when mentioned as file-Cannot open URL: bundle://200.0:1/rest_CreateMultipleSubtasks.groovy

I am using this REST endpoint for a fragment and it works perfectly as an inline script. 
Here is my code below and here is a screenshot of the page where I am redirected after clicking on the button. 
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks
import com.atlassian.jira.project.Project
#BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA CAMELIA223");
Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()
def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;
log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);
 def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
  def issueId = queryParams.getFirst("issueId") as Long
  Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
  def issueKey = myissue.getKey()
  def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)
  def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
  log1.warn("The rest endpoint has been executed by the user " +user)
  Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
 
}
When I specify a file for the code that I refer to in my script editor. Everything fails when I click on the button and I am redirected to an error page as you can see below. 
anyone knows what the problem is?
We need a package declatation at the top of the code so we need package BulkSplitter at the top of the code. We need to go to REST endpoint and execute an update. Otherwise, Jira doesn't recognize our changes.
package BulkSplitter
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks
import com.atlassian.jira.project.Project
#BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {MultivaluedMap queryParams, String body ->
def log1 = Logger.getLogger("atlassian-jira.log")
log1.warn("MOUNA CAMELIA223");
Configuration_CreateMultipleSubtasks conf =new Configuration_CreateMultipleSubtasks()
def MultipleSubtasksHashMap= conf.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = MultipleSubtasksHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"] as String;
log1.warn("MOUNA CAMELIA223 "+itracCreatemultiplesubtasksProjectCategoriesURL);
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
def issueId = queryParams.getFirst("issueId") as Long
Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
def issueKey = myissue.getKey()
def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issueKey)
def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
log1.warn("The rest endpoint has been executed by the user " +user)
Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
}

Jira REST endpoint redirected to error page

I am using a REST endpoint and here is my code: and here are some screenshots. The first screenshot shows the declaration of the condition and the denclaration of the Link: /rest/scriptrunner/latest/custom/callSubTaskCreator?issueId=${issue.id}. The second screenshot shows the declaration of the REST endpoint. I am specifying the link of a file in the script editor. Finally, the last screenshot shows the error page where I am redirected after clicking on the link.
as you can see I am redirected to an error page after I click on the button. Anyone knows what is wrong?
package CreateMultipleSubtasks
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import org.apache.log4j.Logger
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.project.ProjectManager
#BaseScript CustomEndpointDelegate delegate
callSubTaskCreator(httpMethod: "GET", groups: ["jira-users"]) {
MultivaluedMap queryParams, String body ->
def log = Logger.getLogger("atlassian-jira.log")
log.warn("I AM HERE MOUNA 1");
ConfigurationCreateMultipleSubtasks conf = new ConfigurationCreateMultipleSubtasks()
def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()
String itracCreatemultiplesubtasksProjectCategoriesURL = subTaskCreatorHashMap["itracCreatemultiplesubtasksProjectCategoriesURL"];
def user = ComponentAccessor.jiraAuthenticationContext?.loggedInUser
Issue issue = ComponentAccessor.getIssueManager().getIssueObject(queryParams.getFirst("issueId") as Long)
def itracCreatemultiplesubtasksProjectCategoriesURL2 = itracCreatemultiplesubtasksProjectCategoriesURL.replaceAll(":1:", issue.getKey())
def itracCreatemultiplesubtasksProjectCategoriesURL3 = itracCreatemultiplesubtasksProjectCategoriesURL2.replaceAll(":2:", user.getUsername())
Response.temporaryRedirect(URI.create(itracCreatemultiplesubtasksProjectCategoriesURL3)).build()
 
}

Zeppelin Twitter Streaming Example Not Working

I am trying to run Twitter Streaming Example in Zeppelin. After I searched around, I added "org.apache.bahir:spark-streaming-twitter_2.11:2.0.0" into Spark Interpreter. So I can make the first part work, as in:
Apache Zeppelin 0.6.1: Run Spark 2.0 Twitter Stream App
Now I am trying to add the second half as:
case class Tweet(createdAt:Long, text:String, screenName:String)
twt.map(status=>
Tweet(status.getCreatedAt().getTime()/1000, status.getText(), status.getUser().getScreenName())
).foreachRDD(rdd=>
rdd.toDF().registerTempTable("tweets")
)
Now I got the error:
<console>:56: error: not found: type StreamingContext
val ssc = new StreamingContext(sc, Seconds(2))
^
<console>:56: error: not found: value Seconds
val ssc = new StreamingContext(sc, Seconds(2))
^
<console>:61: error: not found: value Seconds
val twt = tweets.window(Seconds(60))
Actually I added the case line, I got the above error. I really had no idea what happened here.
Any one has any clue here?
Here are details
Spark: 2.0.0
Zeppelin: 0.6.2
Thanks a lot.
=====================================================================
// All codes for your reference:
import org.apache.spark.streaming.twitter
import org.apache.spark.streaming._
import org.apache.spark.storage.StorageLevel
import scala.io.Source
import scala.collection.mutable.HashMap
import java.io.File
import org.apache.log4j.Logger
import org.apache.log4j.Level
import sys.process.stringSeqToProcess
import org.apache.spark.SparkConf
// ********************************* Configures the Oauth Credentials for accessing Twitter ****************************
def configureTwitterCredentials(apiKey: String, apiSecret: String, accessToken: String, accessTokenSecret: String) {...}
// ***************************************** Configure Twitter credentials ********************************************
val apiKey = ...
val apiSecret = ...
val accessToken = ...
val accessTokenSecret = ...
configureTwitterCredentials(apiKey, apiSecret, accessToken, accessTokenSecret)
// ************************************************* The logic itself *************************************************
val ssc = new StreamingContext(sc, Seconds(2))
val tweets = TwitterUtils.createStream(ssc, None)
val twt = tweets.window(Seconds(60))
twt.print
// above codes work correctly
// If added the following line, it failed with the above error
case class Tweet(createdAt:Long, text:String, screenName:String)
I had the same problem, and I have no idea why moving the import statements from the top to right before the new StreamingContext fixed it, but it did.
import org.apache.spark.streaming._ //moved here from top
import org.apache.spark.streaming.twitter._ //moved here from top
val ssc = new StreamingContext(sc, Seconds(2)) //existing
I had a similar issue. Using the FQCNs worked ok, so I ended up using that as a workaround.

Resources