+package jalview.ws.intermine;
+
+import jalview.ws.HttpClientUtils;
+
+import java.io.IOException;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.apache.http.client.ClientProtocolException;
+
+import com.sun.jersey.api.client.Client;
+
+public class IntermineFetchClient
+{
+
+ private static final Client client = Client.create();
+
+ public static enum IntermineDB
+ {
+ YeastMine("Yeast Mine", "http://yeastmine.yeastgenome.org/yeastmine"), FlyMine(
+ "Fly Mine", "http://www.flymine.org/query"), FlyMine_Beta(
+ "Fly Mine Beta",
+ "http://beta.flymine.org/beta"), MouseMine("Mouse Mine",
+ "http://www.mousemine.org/mousemine"), modMine(
+ "Mod Mine",
+ "http://intermine.modencode.org/modminetest"), RatMine(
+ "Rat Mine", "http://ratmine.mcw.edu/ratmine");
+
+ private final String name;
+ private final String Url;
+
+ IntermineDB(String name, String Url)
+ {
+ this.Url = Url;
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public String getURL()
+ {
+ return this.Url;
+ }
+ }
+
+ public static enum IntermineMethod
+ {
+ GET_VERSION("/service/version"), GET_RELEASE("/service/version/release"), GET_FASTA_LIST(
+ "/service/list/results/fasta"), GET_FASTA_QUERY(
+ "/query/results/fasta");
+
+ private final String target;
+
+ IntermineMethod(String target)
+ {
+ this.target = target;
+ }
+
+ public String getTarget()
+ {
+ return target;
+ }
+
+ }
+
+ public static String[] getSupportedDBs()
+ {
+ String[] supportedDbs = new String[IntermineDB.values().length];
+ int count = 0;
+ for (IntermineDB db : IntermineDB.values())
+ {
+ supportedDbs[count++] = db.getName();
+ }
+ return supportedDbs;
+
+ }
+
+ public static String fetchData(IntermineDB Database,
+ IntermineMethod method, MultivaluedMap<String, String> params)
+ {
+ String response = "";
+ if (params.isEmpty())
+ {
+
+ response = client.resource(Database.getURL() + method.getTarget())
+ .accept("text/plain")
+ .get(String.class);
+
+ }
+ else
+ {
+ response = client.resource(Database.getURL() + method.getTarget())
+ .queryParams(params)
+ .get(String.class);
+ }
+ return response;
+ }
+
+ public static String fetchData(String url)
+ throws ClientProtocolException, IOException
+ {
+
+ return HttpClientUtils.doHttpUrlGet(url);// client.resource(url).get(String.class);
+ }
+
+
+}