Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JMWE - Sending issues in batches using callRest function

Hugo Michelez
October 31, 2023

Hi all, 

 

I'm trying to create a post-function that posts all issues for which the status has changed to a dedicated endpoint on an hourly basis.

 

As such, I've created a Scheduled Action. 

Every hour, all issues matching the following JQL posted: project = MY_PROJECT and type in (Bug, Task, Review, Sub-task) AND status changed AFTER -1h

 

Here the post-function I have so far: 

{# Set the URL of the API endpoint #}
{% set url = "https://mycompany/endpoint" %},

{# Set the headers for the request, including the auth token #}
{% set headers = {
"Content-Type": "application/json",
"Authorization": "Token abcde"
} %}

{# Set the body of the request, using the issue data #} |
{% set body = {
"issue": issue
} %}

{# Make the POST request and store the response #}
{% set response = url | callRest( verb="POST", options = {headers : headers} , body=body) | dump(2) %}

 

However, I realized that the webhooks are sent individually (per updated issue), and not in batch. Is there a way to change this ?

 

Thanks in advance!

1 answer

1 accepted

0 votes
Answer accepted
Tom Lister
Community Champion
November 2, 2018

Hi @lpopek

Are you passing an instance of your class into velocity params with key action?

What kind of plugin are you developing?

lpopek
November 3, 2018

"Are you passing an instance of your class into velocity params with key action?"

What does it mean? 

In my velocity I use 

$webResourceManager.requireResourcesForContext

 
And I have a properly configuration in xml, I can invoke method without parameters, but in this case I want to in Velocity pass parameter and theres a problem

Tom Lister
Community Champion
November 4, 2018

Hi Steven

 

Forget my previous comments, I think the problem here is that you have issues without work logged against them. In those cases the getTimeSpent method will return null

 

If that's not the case, have you got more info?

Can you post a fuller stack trace that shows the error class and line number reported? That will tell me more.

What is your Java Class? Have you extended an action and expect that action class to be available in the template?

lpopek
November 5, 2018

Hello, 

For example, If I will use;


<td colspan="1" class="confluenceTd">$issue.getTimeSpent()</td>

 

I will get a result in miliseconds, so it seems that the parameter is passed. 

Now, I want to use method from my Java class, because I want get time in nice format hh:mm. 

In my Java class I have the following method. 

public String getCorrectFormatDate(Issue issue){
Long timespent = issue.getTimeSpent();

if(timespent>0){
int hours = (int) (timespent / 3600);
int remainder = (int) (timespent - hours * 3600);
int min = remainder / 60;
String result = hours + "h " + min +"min";
return result;
}
else{
return "0";
}

}

 

Also, In my template I pass variable 'issues' from my Java class from other method. 

 

Im sure, that This template see my Java class with this method 

public String getCorrectFormatDate(Issue issue)

 

Problem is, that in my Velocity template I want to pass parameters 

for exmaple 

#foreach ($issue in $issues)

<tr role="row">
<td colspan="1" class="confluenceTd">$action.getTimeSpent($issue)</td>

#end 


How to solve my problem and call function for each issue, 
Thanks a lot for Your helps, Best wishes

Tom Lister
Community Champion
November 5, 2018

Hi Stephen

Are you still getting the NullPointerException?

The only place I can deduce will return null in the code you've shown is the issue.getTimeSpent() call in your getCorrectFormatDate method. (I assume that is in your own action class that is preparing the velocity call)

Are you able to add logging or run in debug?

Tom Lister
Community Champion
November 5, 2018

 

I'm seeing now that you are in Confluence not JIRA. The $action object is the current webwork action. Is your method in your webwork action class?

If not, then you need to pass your class in the velocity context as per the example in your link

e.g.

Message mg = new Message(); 

    context.put("formatter", mg);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events