annotate src/info/wilkinsonlab/sadi/galaxy/SADIGenericClient.java @ 2:977c838e3442 draft default tip

New dir structure, README improved, tests added and RDF merge tool created
author mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
date Fri, 25 Apr 2014 14:41:12 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
1 package info.wilkinsonlab.sadi.galaxy;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
2
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
3 import java.io.InputStream;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
4 import java.util.Collection;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
5
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
6 import org.apache.log4j.Logger;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
7
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
8 import org.sadiframework.SADIException;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
9 import org.sadiframework.client.Service;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
10 import org.sadiframework.client.ServiceFactory;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
11
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
12 import com.hp.hpl.jena.rdf.model.Model;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
13 import com.hp.hpl.jena.rdf.model.ModelFactory;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
14 import com.hp.hpl.jena.rdf.model.Resource;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
15 import com.hp.hpl.jena.util.FileManager;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
16
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
17 public class SADIGenericClient {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
18
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
19 /**
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
20 * @param service_URL
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
21 * @param input_RDF
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
22 *
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
23 * Given an RDF input and a service URL, infers whether the RDF
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
24 * complies with the service and if so executes it
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
25 *
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
26 */
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
27
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
28 // private static final Logger log = Logger.getLogger(SADIGenericClient.class);
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
29 public static void main(String[] args) {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
30 String service_URL = args[0];
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
31 String input_RDF = args[1];
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
32
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
33 Service service;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
34 try {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
35 service = ServiceFactory.createService(service_URL.trim());
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
36 }
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
37 catch (SADIException e) {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
38 System.out.println("[ERROR] Error creating service object: ");
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
39 System.out.println(e.getMessage());
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
40 e.printStackTrace();
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
41 service = null;
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
42 }
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
43
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
44 if (service != null) {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
45
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
46 Model model = ModelFactory.createOntologyModel();
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
47 InputStream in = FileManager.get().open(input_RDF);
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
48 model.read(in, null);
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
49
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
50 try {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
51 Collection<Resource> inputs = service.discoverInputInstances(model);
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
52 Model output = service.invokeService(inputs);
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
53 output.write(System.out, "RDF/XML");
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
54 output.close();
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
55 }
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
56 catch (SADIException e) {
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
57 System.out.println("[ERROR] Error invoking service: ");
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
58 System.out.println(e.getMessage());
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
59 e.printStackTrace();
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
60 }
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
61 }
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
62 }
977c838e3442 New dir structure, README improved, tests added and RDF merge tool created
mikel-egana-aranguren <mikel.egana.aranguren@gmail.com>
parents:
diff changeset
63 }