Implementation of support for Intermine webservice as a source of sequence data
[jalview.git] / src / jalview / ws / intermine / IntermineFetchClient.java
1 package jalview.ws.intermine;
2
3 import jalview.ws.HttpClientUtils;
4
5 import java.io.IOException;
6
7 import javax.ws.rs.core.MultivaluedMap;
8
9 import org.apache.http.client.ClientProtocolException;
10
11 import com.sun.jersey.api.client.Client;
12
13 public class IntermineFetchClient
14 {
15
16   private static final Client client = Client.create();
17
18   public static enum IntermineDB
19   {
20     YeastMine("Yeast Mine", "http://yeastmine.yeastgenome.org/yeastmine"), FlyMine(
21             "Fly Mine", "http://www.flymine.org/query"), FlyMine_Beta(
22                     "Fly Mine Beta",
23                     "http://beta.flymine.org/beta"), MouseMine("Mouse Mine",
24                             "http://www.mousemine.org/mousemine"), modMine(
25                                     "Mod Mine",
26                                     "http://intermine.modencode.org/modminetest"), RatMine(
27                                             "Rat Mine", "http://ratmine.mcw.edu/ratmine");
28
29     private final String name;
30     private final String Url;
31
32     IntermineDB(String name, String Url)
33     {
34       this.Url = Url;
35       this.name = name;
36     }
37
38     public String getName()
39     {
40       return this.name;
41     }
42
43     public String getURL()
44     {
45       return this.Url;
46     }
47   }
48
49   public static enum IntermineMethod
50   {
51     GET_VERSION("/service/version"), GET_RELEASE("/service/version/release"), GET_FASTA_LIST(
52             "/service/list/results/fasta"), GET_FASTA_QUERY(
53                     "/query/results/fasta");
54
55     private final String target;
56
57     IntermineMethod(String target)
58     {
59       this.target = target;
60     }
61
62     public String getTarget()
63     {
64       return target;
65     }
66
67   }
68
69   public static String[] getSupportedDBs()
70   {
71     String[] supportedDbs = new String[IntermineDB.values().length];
72     int count = 0;
73     for (IntermineDB db : IntermineDB.values())
74     {
75       supportedDbs[count++] = db.getName();
76     }
77     return supportedDbs;
78
79   }
80
81   public static String fetchData(IntermineDB Database,
82           IntermineMethod method, MultivaluedMap<String, String> params)
83   {
84     String response = "";
85     if (params.isEmpty())
86     {
87
88       response = client.resource(Database.getURL() + method.getTarget())
89               .accept("text/plain")
90               .get(String.class);
91
92     }
93     else
94     {
95       response = client.resource(Database.getURL() + method.getTarget())
96               .queryParams(params)
97               .get(String.class);
98     }
99     return response;
100   }
101
102   public static String fetchData(String url)
103           throws ClientProtocolException, IOException
104   {
105
106     return HttpClientUtils.doHttpUrlGet(url);// client.resource(url).get(String.class);
107   }
108
109
110 }