summaryrefslogtreecommitdiffstats
path: root/sandbox/kgoodson/jagg/src/main/java/services/JiraQueryImpl.java
blob: 14931a1989a1dfe87dff3b988c685266f59414b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package services;
import java.io.IOException;
import java.lang.String;
import java.lang.reflect.Array;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;


public class JiraQueryImpl implements JiraQuery {

	private String rssfeed = null;
	private HashMap entries = null;
	
	public JiraQueryImpl() {
	
	}

	public JiraQueryImpl(String rssfeed) throws Exception {
		this.rssfeed = rssfeed;

	}
	public Collection<String> getJiraIDs() {
		try {
			refreshFeedData();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FeedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return entries.keySet();
	}
	public String getTitle(String ID) {
		return ((SyndEntry)entries.get(ID)).getTitle();
	}
	private void refreshFeedData() throws IllegalArgumentException, MalformedURLException, FeedException, IOException {

		
		SyndFeedInput input = new SyndFeedInput();
	    SyndFeed feed = input.build(new XmlReader(new URL(rssfeed)));

	    entries = new HashMap();
	    
	    for(Object entry: feed.getEntries()){
	        SyndEntry syndEntry = (SyndEntry)entry;
	        String id = jiraNumber(syndEntry.getTitle());
	        entries.put(id, syndEntry);
	    }

	}

	private String jiraNumber(String title) {
		String[] id = title.split("[\\[\\]]");
		return id[1];
	}
	
}