Need help with get due date field in java

Everly mc May 29, 2014

Hi there !

I need to know how can I extract due date value of a jira ticket in my java code ?

which classes and packages do I need to include and use? I feel it is so simple, but I'm really confused how to do it .

the steps would be :

1- give the ticket number

2- extract the due date

I saw getDueDate() method in Issue interface, is that the right method to use ?

Thanks in advance for your help !

12 answers

0 votes
Everly mc August 11, 2014

I'm trying to build a rest project following this link : https://ecosystem.atlassian.net/wiki/display/JRJC/Download

but after checking out the source -> run mvn package -> I'm getting error

[WARNING] The POM for com.atlassian.maven.plugins:maven-amps-plugin:jar:4.1.1 is missing, no dependency information available
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.atlassian.jira:jira-rest-java-client-plugin:2.0.0-m31-SNAPSHOT (C:\Users\501648\atlastutorial\jira-rest-java-client\plugin\pom.xml) has 1 error
[ERROR]     Unresolveable build extension: Plugin com.atlassian.maven.plugins:maven-amps-plugin:4.1.1 or one of its dependencies could not be resolved: Failure to find com.atlassian.maven.plugins:maven-amps-plugin:jar:4.1.1 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

I'm using sdk and also after trying to import my project to eclipse I'm getting

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.871 s
[INFO] Finished at: 2014-08-11T12:31:40-07:00
[INFO] Final Memory: 19M/148M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project jira-rest-java-client-plugin: Could not resolve dependencies for project com.atlassian.jira:jira-rest-java-client-plugin:atlassian-plugin:2.0.0-m31-SNAPSHOT: Failure to find com.atlassian.jira:jira-rest-java-client-core:jar:2.0.0-m31-SNAPSHOT in https://maven.atlassian.com/repository/public was cached in the local repository, resolution will not be reattempted until the update interval of atlassian-public has elapsed or updates are forced -> [Help 1]

can someone please help me out with these errors ? I googled my errors and there are discussion of adding jrjc dependencies to pom file (api-core-plugin), I did that too but still having problem !

-Thanks a lot for your helps !

0 votes
Everly mc June 22, 2014

Well, I think I need to explain the project that I'm trying to write. I have an excel file that includes platforms of our company and the related jira issue numbers, I want to look for a specific platform and retrieve the related issue number then connect to jira and extract due date for that issue and determine if the due date is past.

here is my java code :

public static List<Object> readData(String file, String platform)
	{
		List<Object>  platforms= new ArrayList<Object>();
		try
		{
			FileInputStream fis = new FileInputStream(file);
			Workbook wb = null;
			if(file.toLowerCase().endsWith(".xlsx"))
				wb = new XSSFWorkbook(fis);
			else if (file.toLowerCase().endsWith(".xls"))
				wb = new HSSFWorkbook(fis);
			int numberOfSheets = wb.getNumberOfSheets();
			{
				Sheet sheet = wb.getSheet("Allocation and Assignments");
				CellReference platformRef = new CellReference("E23");
				CellReference specialRef = new CellReference("H23");
				Iterator<Row> rowIterator = sheet.iterator();
				Iterator<Row> row2Iterator = sheet.iterator();
				Row platformRow = sheet.getRow(platformRef.getRow());
				Row specialRow = sheet.getRow(specialRef.getRow());
				
				while(rowIterator.hasNext() && row2Iterator.hasNext())
				{
					platformRow = rowIterator.next();
            		specialRow = row2Iterator.next();

					
					if(platformRow != null )
					{
						
						Cell c = platformRow.getCell(platformRef.getCol());
						
						if (c != null )
					     	{
							switch (c.getCellType()) {
							
			                case Cell.CELL_TYPE_STRING:
			                
			                	if (c.getStringCellValue().toLowerCase().contains(platform))
			                	  System.out.println("platform found . . .");
	                			    Cell c1 = specialRow.getCell(specialRef.getCol());

			                		
			                			     if (c1 != null)
			                			     
			                			      {
			                			         switch( c1.getCellType())

			                			             {
			                			                 case Cell.CELL_TYPE_STRING:
			                			                 {
			                			                     if (c1.getStringCellValue().contains("SS") && c.getStringCellValue().toLowerCase().contains(platform))
		                			                              platforms.add(c.getStringCellValue());
			                			                         break;
			                			                  }
			                			 
			                			                  case Cell.CELL_TYPE_NUMERIC:
			                			                    if (c1.getStringCellValue().contains("SS") && c.getStringCellValue().toLowerCase().contains(platform))
			                			                         {
			                			                           platforms.add(c.getNumericCellValue());
			                			                           break;
			                			                         }
			                			                  case Cell.CELL_TYPE_BOOLEAN:

			                			                    platforms.add(c.getBooleanCellValue());
			                			                    break;
			                			                  case Cell.CELL_TYPE_FORMULA:
			                			                      platforms.add(c.getCellFormula());
			                			                      break;
			                			                   default:
			                			                       System.out.println();
			                				                	break;

			                			                 }
			                			               } 
			                			             }
	                                               }
					                            }
		                                      }
				}
		}catch(IOException e)
		{
			e.printStackTrace();
		}			

	
		return platforms;
		}
public static void main(String[] args) {

		List<Object>  platforms = readData("C://platforms.xlsx"," platform1");
		System.out.println(platforms);
		}

0 votes
Everly mc June 11, 2014

I have Jira eclipse connector on my eclipse and it is connected to the server , how can I write code that connect to the Jira eclipse connector and retrieve data ?

As a whole I want to have an app that user can use and enter the issue number then my app searches the issue and get the due date and returns it.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 4, 2014

The correct method really is basically

issue.getDueDate()

That assumes that you've got an issue object (called "issue") in wherever you're running this code, but I don't know where you are trying to do this? You've said you've created a form of some sort, but is it in a Jira plugin? Your own application? Something in the IDE?

Everly mc June 7, 2014

So far I've developed my java codes and couldn't connect to jira. this is my question: how can I connect to jira ?

I stuck at this point for weeks

really appreciate your helps

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2014
You stroll haven't said where your code is running. Plugin, separate application, something else?
Everly mc June 7, 2014

I'm using eclipse, but don't know where to start to connect to jira. on atlassian website I'm seeing a lot of different info that just confuing me. somewhere I see that I need to have eclipse connector, some where else is saying to use SOAP or REST . . . some where else I found I need to have jql connection to retrieve due date, so I need help to clarify my way to start .

Thanks a lot

Everly mc June 7, 2014

I'dsay a seperate application, not a plugin.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2014
OK, it really does matter whether it is inside jira or external, bit the exact details over that, less so. Of you are writing a plugin, you have direct access to the internals of jira. If you are working externally, it's simple, use REST. Soap is deprecated, so forget that.
Everly mc June 11, 2014

I have Jira eclipse connector on my eclipse and it is connected to the server , how can I write code that connect to the Jira eclipse connector and retrieve data ?

As a whole I want to have an app that user can use and enter the issue number then my app searches the issue and get the due date and returns it.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 11, 2014

I think you're still confused about what you want to do.

  • I think you've ruled out writing an addon for Jira
  • The Eclipse connector is for connecting Eclipse to Jira
  • Eclipse is a tool for writing code for programs that will (mostly) not run in Eclipse.

So, you'd use Eclipse to write, but not run, a program that you can "enter an issue number and get the due date for it" - in fact, that program is only a few lines of code. Your code logs into Jira over REST, and extracts the due date from the response to "show me issue ID x".

Everly mc June 19, 2014

I tried this but keep getting error, would you please help me out . I also added all required .jar files based on https://ecosystem.atlassian.net/wiki/display/JRJC/Project+Dependencies

here is my code :

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.Issue;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;

public class Jrjc {

	public static void main(String[] args) throws URISyntaxException {
		final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
		final URI jiraServerUri = new URI("http://hostName:port/jira");
		final JiraRestClient restClient = 
				factory.createWithBasicHttpAuthentication(jiraServerUri, "username","password");
        final NullProgressMonitor pm = new NullProgressMonitor();

        final Issue issue = restClient.getIssueClient().getIssue("issueName",pm);

        System.out.println(issue);
        
        
	}

}

Everly mc June 19, 2014

and here is the error I got:

Jun 20, 2014 10:13:08 AM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: A message body reader for Java class org.codehaus.jettison.json.JSONObject, and Java type class org.codehaus.jettison.json.JSONObject, and MIME media type application/json;charset=UTF-8 was not found
Jun 20, 2014 10:13:08 AM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: The registered message body readers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
  com.sun.jersey.core.impl.provider.entity.EntityHolderReader

Exception in thread "main" com.atlassian.jira.rest.client.RestClientException: com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class org.codehaus.jettison.json.JSONObject, and Java type class org.codehaus.jettison.json.JSONObject, and MIME media type application/json;charset=UTF-8 was not found
	at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:75)
	at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.getAndParse(AbstractJerseyRestClient.java:80)
	at com.atlassian.jira.rest.client.internal.jersey.JerseyIssueRestClient.getIssue(JerseyIssueRestClient.java:109)
	at jrjc.Jrjc.main(Jrjc.java:22)
Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class org.codehaus.jettison.json.JSONObject, and Java type class org.codehaus.jettison.json.JSONObject, and MIME media type application/json;charset=UTF-8 was not found
	at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:549)
	at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
	at com.sun.jersey.api.client.WebResource.handle(WebResource.java:674)
	at com.sun.jersey.api.client.WebResource.get(WebResource.java:191)
	at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient$1.call(AbstractJerseyRestClient.java:84)
	at com.atlassian.jira.rest.client.internal.jersey.AbstractJerseyRestClient.invoke(AbstractJerseyRestClient.java:54)
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 20, 2014

You still haven't said what you're trying to write and where the code is running. I know there can be issues trying to use REST inside plugins/jrjc code, but I'm not sure where you're running any of this.

Everly mc June 22, 2014

I'm using eclipse and want to connect to jira externally with rest to make a seperate app .

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2014

Ok, so Eclipse is not actually relevant - it's the tool you're your external system with, and it can talk to Jira for issue tracking, but the end product is a program that talks to Jira independently and has nothing to do with eclipse.

The problem you're having here appears to be to do with the program not being able to read/parse what is coming back from Jira. The only time I've seen that happen is when I'd messed up my imports and dependencies, so I'd say they need checking.

I'd also check the response from Jira - instead of trying to dive into all the code, what does a simple "curl" get back?

Everly mc July 6, 2014

Nic, I'm not sure what you exactly mean by "what you're trying to write and where the code is running." , can you please explain what do you mean by that?

I checked my jar files, the error I'm getting here defines the compatible reader types with MIME, which I have them all in jersey-core-1.17.jar that I added .

Also after running curl -u "url" .json I got the .json format of the jira in terminal.

-Thank you

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2014

Where is the code running? Part of an Eclipse function? In a Jira plugin? Inside Jira as a core code tweak? Another application? If it's another application then how is it talking to Jira?

Everly mc July 6, 2014

what is the difference between being part of an eclipse function or another application ? If I got your point, it is a seperate application and talks to jira through jrjc .

however I added my java codes below if that helps.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2014

Ok, so cut it right back to the basics. Remove the extra libraries, go back to something that simply tries to get an issue and look at the due date (literally just issue.getDueDate() and throw it out in the log)

What is going wrong, and where in your code?

Is it the fetch of the issue? Or just the due date line? Have you tried the really basic stuff at https://ecosystem.atlassian.net/wiki/display/JRJC/Tutorialand does that work ok?

Everly mc July 6, 2014

I followed the stuff at the link but instead of adding maven2 I added jar files. :

jira-rest-java-client-0.3.1.jar
org-apache-commons-codec.jar
jersey-apache-client-1.6.jar
com.sun.jersey.jersey-core-1.4.0.jar
org.apache.commons.httpclient.jar
org-apache-commons-logging.jar
jersey-client-1.9.jar
jettison-1.3.2.jar
jersey-json-1.8.jar
joda-time-2.0.jar
google-collections-1.0.jar
guava-r06.jar
jersey-core-1.17.jar
commons-logging-1.1.1.jar
google-api-client-1.18.0-rc.jar
google-api-client-android-1.18.0-rc.jar
google-api-client-appengine-1.18.0-rc.jar
google-api-client-gson-1.18.0-rc.jar
google-api-client-jackson2-1.18.0-rc.jar
google-api-client-java6-1.18.0-rc.jar
google-api-client-protobuf-1.18.0-rc.jar
google-api-client-servlet-1.18.0-rc.jar
google-api-client-xml-1.18.0-rc.jar
google-http-client-1.18.0-rc.jar
google-http-client-android-1.18.0-rc.jar
google-http-client-appengine-1.18.0-rc.jar
google-http-client-gson-1.18.0-rc.jar
google-http-client-jackson-1.18.0-rc.jar
google-http-client-jackson2-1.18.0-rc.jar
google-http-client-jdo-1.18.0-rc.jar
google-http-client-protobuf-1.18.0-rc.jar
google-http-client-xml-1.18.0-rc.jar
google-oauth-client-1.18.0-rc.jar
google-oauth-client-appengine-1.18.0-rc.jar
google-oauth-client-java6-1.18.0-rc.jar
google-oauth-client-jetty-1.18.0-rc.jar
google-oauth-client-servlet-1.18.0-rc.jar
gson-2.1.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
jackson-core-2.1.3.jar
jackson-core-asl-1.9.11.jar
jdo2-api-2.3-eb.jar
jetty-6.1.26.jar
jetty-util-6.1.26.jar
jsr305-1.3.9.jar
protobuf-java-2.4.1.jar
transaction-api-1.1.jar
xpp3-1.1.4c.jar
oauth-signature-1.6.jar
jaxb-impl-2.1.12.jar
activation-1.1.1.jar
jsr311-api-1.1.1.jar
jaxb-api-2.1.jar
stax-api-1.0-2.jar
jackson-core-asl-1.9.7.jar
json-simple-1.1.1 (1).jar

I got error at this line : final Issue issue = restClient.getIssueClient().getIssue("issueName",pm);

Everly mc July 6, 2014

actually I ran the code and when I got java.lang.NoClassDefFoundError I googled that specific class then download and add the jar file.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2014

So, what happens if you build the project with maven, as per the documentation?

Everly mc July 25, 2014

Hi Nic -

I got a chance today to try building the project with maven, but ran in to other problems !

1st of all I isntalled m2 plugin but to add dependency for jrjc I see no pom.xml in my root project, here is the Q1: what kind of project I should make ? i'm making java project (which has no pom.xml file in root), but with building a plugin with atlas-create-jira-plugin I see .xml file in root directory of my project .

Q2:when I make a plugin do I need jira-rest-java-client-2.0.0-m2.jar ?

so far I had atlassian SDK and maven2 downloaded and installed on my computer, would you please give me a straight forward roadmap how to push it forward ?

unfortunately the intrusctions on atlassian website are more confusing than being helpfull .wish the guides and instrauctions were at least updated .

Thank you

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 25, 2014

I don't understand why you keep making things complicated.

If you use the SDK and follow the docs, you don't need maven, you don't need to add dependencies while getting started, you don't need the m2 plugin. Strip it back to the core that works - install the SDK and generate a skeleton project without trying anything different. Once that works, you can build on it.

Everly mc July 25, 2014

but I followed this link and it needs to have both sdk and maven ! https://developer.atlassian.com/display/DOCS/Set+Up+the+Eclipse+IDE+for+Windows?focusedCommentId=29463203#comment-29463203

If I want to use REST I need to have maven installed + jira-rest-java-client-2.0.0-m2.jar + add the dependency to pom ?

AND in case of developing a plugin I only need atlassian sdk to be installed and push it forward with cmd prompt and atlassian commands ?

so please send me the link that I need to follow using REST to generate the project. believe me or not crawling atlassian website just makes me more and more confused and lost my way !

Everly mc August 9, 2014

I downgraded my jdk from 1.8 to 1.6 and now sdk is working fine for me , in case it could help others.

but when I try to build a REST module in a refapp plugin I get error , could you tell me why ?

-Thanks

0 votes
Everly mc June 3, 2014

It is really frustrating ! I'm working on this problem for a whole week crawling your web site , asking questins but no luck. There are lots of unresolved issues with configuration of rest api and other things for many years ago !! please either have a straight forward and helpful website or answer the questions !

0 votes
Everly mc June 3, 2014

It is really frustrating ! I'm working on this problem for a whole week crawling your web site , asking questins but no luck. There are lots of unresolved issues with configuration of rest api and other things for many years ago !! please either have a straight forward and helpful website or answer the questions !

0 votes
Everly mc June 3, 2014

It is really frustrating ! I'm working on this problem for a whole week crawling your web site , asking questins but no luck. There are lots of unresolved issues with configuration of rest api and other things for many years ago !! please either have a straight forward and helpful website or answer the questions !

0 votes
Everly mc June 1, 2014

I was able to connect to jira server and create repository through eclipse and search/ create and query new issues. now the only thing I need to do is to get due date for specified issues. I create a UI that asks user to enter issue number ,it looks for issue number and extract due date and returns it to the user. Is ther any code practices and examples on atlassian web site I can use to get an idea of which classes and methods I need to use ?

Thanks a lot for your help

-Everly

0 votes
Everly mc May 31, 2014

My understanding is that I need to have Atlassian Connector for Eclipse for the very first step , then have either SOAP or REST API , am I right ?

Thanks -

0 votes
Timothy
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.
May 30, 2014

Better start putting on your Google cap on..

0 votes
Everly mc May 29, 2014

I'm new to jira and have lots of Qs. Do I need to have a specific setting in order to have connection from my java code to jira ?

Thanks a lot for your help !

0 votes
Timothy
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.
May 29, 2014

I saw getDueDate() method in Issue interface, is that the right method to use ?

Have you tried? What is the result?

Everly mc May 29, 2014

I tried but no luck. I just don't know how to implement this method to return the right timeStamp.

Raju Adluru
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.
June 5, 2014

try this

issue.getDueDate().getTime()

Suggest an answer

Log in or Sign up to answer