Get Holiday List from Tempo Rest API and comparing it with field

Hi everyone, I have been working on trying to get the Holiday list from the Tempo plugin and I have been having difficulties. So far this is my good for that section:

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl;
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import java.lang.Object
import com.atlassian.jira.issue.worklog.WorklogImpl2
import java.text.SimpleDateFormat
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.DefaultWorklogManager
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.worklog.Worklog
import com.atlassian.jira.datetime.LocalDate
import groovy.xml.DOMBuilder
import javax.xml.parsers.*


*******************************************************************************************************
    
def URLflooting = "http://yourserver.yourserver/rest/tempo-core/1/holidayscheme/1/days/floating"
def URLfixed = "http://yourserver.yourserver/rest/tempo-core/1/holidayscheme/1/days/fixed"
    
******************************************************************************************************

def componentManager = ComponentManager.getInstance()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfend = customFieldManager.getCustomFieldObjectByName("End Date")
def cfstart = customFieldManager.getCustomFieldObjectByName("Start Date")
def cfdays = customFieldManager.getCustomFieldObjectByName("Used vacation days")
def reporter = issue.reporter.name
def worklogManager = ComponentAccessor.getWorklogManager();


//Take customfield date object and change it to days
int days = (issue.getCustomFieldValue(cfdays) as int)//return the number of days


ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
def UsersRole = projectRoleManager.getProjectRole("Users")
long timespent = 27000
int counter = 0;
int check = 0;
	for(int i=0; check == 0 ;i++){
//Checks if it is sunday
	 if(((issue.getCustomFieldValue(cfstart) as Date) + i).getDay() == 0){
		i++
       	 	def worklog = new WorklogImpl2(issue, null, issue.reporter.name, issue.summary, (issue.getCustomFieldValue(cfstart) as Date)+ i, null, null,timespent, UsersRole)
			 worklogManager.create(issue.reporter, worklog, 0L, true)  
	}
//Checks if it is Saturday
	else if(((issue.getCustomFieldValue(cfstart) as Date) + i).getDay() == 6){
		i = i + 2
		def worklog = new WorklogImpl2(issue, null, issue.reporter.name, issue.summary, (issue.getCustomFieldValue(cfstart) as Date) + i, null, null,timespent, UsersRole)
			 worklogManager.create(issue.reporter, worklog, 0L, true)
	}  
//Any other day in the week	 
	else{
		def worklog = new WorklogImpl2(issue, null, issue.reporter.name, issue.summary, (issue.getCustomFieldValue(cfstart) as Date) + i, null, null,timespent, UsersRole)
			 worklogManager.create(issue.reporter, worklog, 0L, true)
	}

	counter++
	if(days == counter){
		check =1;
	}
}

return 0;

I am not to sure what the URLflooting and URLfixed returns. I want it to return a string or an array so I can compare it to a date. I checked the http addresses for both the URL's and they both gave me a page that looked like a text file. I have been stuck for a while on this spot and I am not sure how to continue or to progress.

I have put asterisks where I am having trouble so it is easy to find. Please let me know if anybody finds a way to import that data. 

1 answer

Hi Andrew,

I know I'm a bit late to the party, but this could be carried out using HTTP requests, and only HTTP requests. If you are not sure how to do this, please check this link, in which I explain how to do a POST request. In your case, you need a GET, so that's even easier.

Do tell if you need more help.

Cheers

DYelamos

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

74 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you