[MOBY-guts] biomoby commit
Eddie Kawas
kawas at dev.open-bio.org
Thu Feb 14 02:59:41 UTC 2008
kawas
Wed Feb 13 21:59:32 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder
In directory dev.open-bio.org:/tmp/cvs-serv19311/Java/src/main/org/biomoby/client/rdf/builder
Modified Files:
ServiceInstanceRDF.java
Log Message:
code cleanup to do a few things ...
- break code for those that use this class ...
- clean up the code
- move to object, rather than function calls
- remove dependencies on internal registry
moby-live/Java/src/main/org/biomoby/client/rdf/builder ServiceInstanceRDF.java,1.34,1.35
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java 2007/01/27 00:14:55 1.34
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java 2008/02/14 02:59:32 1.35
@@ -1,26 +1,22 @@
package org.biomoby.client.rdf.builder;
-import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.discovery.tools.DiscoverSingleton;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.biomoby.client.CentralImpl;
import org.biomoby.client.rdf.vocabulary.DC_PROTEGE;
import org.biomoby.client.rdf.vocabulary.FetaVocabulary;
-import org.biomoby.client.ui.graphical.servlet.utilities.ContextLoader;
-import org.biomoby.registry.properties.RegistryOS;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.Central;
import org.biomoby.shared.MobyData;
import org.biomoby.shared.MobyException;
import org.biomoby.shared.MobyNamespace;
import org.biomoby.shared.MobyPrimaryDataSet;
import org.biomoby.shared.MobyPrimaryDataSimple;
+import org.biomoby.shared.MobyResourceRef;
import org.biomoby.shared.MobySecondaryData;
import org.biomoby.shared.MobyService;
import org.biomoby.shared.data.MobyDataSecondaryInstance;
@@ -51,1041 +47,1008 @@
@SuppressWarnings("unchecked")
public class ServiceInstanceRDF {
- // some URIs
- private static final String empty = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
- + System.getProperty("line.separator")
- + " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
- + System.getProperty("line.separator")
- + " <rdf:Description rdf:about=\"http://www.w3.org/\">"
- + System.getProperty("line.separator")
- + " <dc:title>Service Instance Not Found</dc:title>"
- + System.getProperty("line.separator")
- + " </rdf:Description>"
- + System.getProperty("line.separator") + "</rdf:RDF>";
-
- private static Map URI_MAP = new HashMap();
-
- private static Log log = LogFactory.getLog(ServiceInstanceRDF.class);
-
- private static final String DCP = DC_PROTEGE.getURI();
-
- private static final String OBJ;
- private static final String SRV;
- private static final String NS;
- private static final String MP;
- private static final String SI;
-
- private static final String SERVER;
-
- static {
- ContextLoader cLoader = null;
- try {
- cLoader = (ContextLoader) DiscoverSingleton.find(Class
- .forName((String) ContextLoader.class.getCanonicalName()), Class.forName(
- (String) ContextLoader.class.getCanonicalName()).getName());
- log
- .info((cLoader == null ? "ContextLoader is null and is therefore not loaded. This is BAD!"
- : "ContextLoader has loaded successfully."));
- } catch (Exception e) {
- log.warn("ContextLoader is null and is therefore not loaded. This is BAD!"
- + System.getProperty("line.separator") + e.getMessage());
- }
-
- log.info("Setting RDF ResourceLocations (RDFConfigure) for current registry...");
-
-
- OBJ = (String) cLoader.getURI_MAP().get("Object");
-
- SRV = (String) cLoader.getURI_MAP().get("Service");
-
- NS = (String) cLoader.getURI_MAP().get("Namespace");
-
- MP = "http://biomoby.org/RESOURCES/MOBY-S/Predicates#";
-
- SI = (String) cLoader.getURI_MAP().get("ServiceInstance");
-
- SERVER = cLoader.getFULL_SERVER_URL();
+ // some URIs
+ private static final String empty = "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
+ + System.getProperty("line.separator")
+ + " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">"
+ + System.getProperty("line.separator")
+ + " <rdf:Description rdf:about=\"http://www.w3.org/\">"
+ + System.getProperty("line.separator")
+ + " <dc:title>Service Instance Not Found</dc:title>"
+ + System.getProperty("line.separator")
+ + " </rdf:Description>"
+ + System.getProperty("line.separator") + "</rdf:RDF>";
+
+ private static Map URI_MAP = new HashMap();
+
+ private static Log log = LogFactory.getLog(ServiceInstanceRDF.class);
+
+ private static final String DCP = DC_PROTEGE.getURI();
+
+ private Registry registry = null;
+
+ private CentralImpl central = null;
+
+ // character is a has
+ private String trailing_character = "#";
+
+ private String OBJ;
+
+ private String SRV;
+
+ private String NS;
+
+ private String MP = "http://biomoby.org/RESOURCES/MOBY-S/Predicates"
+ + trailing_character;
+
+ private String SI;
+
+ public final String getLatestLSID(String uri, String name, String lsid) {
+ Central central = null;
+ MobyService service = null;
+ MobyService[] services = null;
+ // initialize central
+ central = getCentralImpl();
+ // set up the query service
+ service = new MobyService(name);
+ service.setCategory("");
+ service.setAuthority(uri);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ return "";
}
-
- /**
- *
- * <b>PRE: </b>name is either a valid name or null
- * <p>
- * <b>POST: </b>If authorURI is a valid authority, then a RDF containing all
- * of the service instances will be returned. If authorURI and name are
- * valid then a single RDF containing just the service instance identified
- * by name is returned. <b><i>This method tries to use the local registry.
- * It will fail if one doesnt exist. Please use the other
- * findService(String, String, String, String) method if you wish to specify
- * a non local registry.</i></b>
- * <p>
- *
- * @param authorURI -
- * the authority to query
- * @param name -
- * the name of the service instance if applicable or null.
- * @param useTestMachine -
- * if true then services are searched for on the test server,
- * otherwise the production server is used. <b>this param is no
- * longer supported. Please set to false.</B>
- * @return a string representing either all of services defined by
- * authorURI, (if name is null) or a single service instances' rdf
- * if name and authorURI are valid. If name and/or authorURI are
- * invalid an empty rdf document is returned.
- */
- public final static String findService(String authorURI, String name, boolean useTestMachine) {
- if (name == null || name.equals("")) {
- return getAllServices(authorURI, useTestMachine);
- } else {
- return getService(authorURI, name, useTestMachine);
- }
- }
-
- /**
- *
- * <b>PRE: </b>name is either a valid name or null
- * <p>
- * <b>POST: </b>If authorURI is a valid authority, then a RDF containing all
- * of the service instances will be returned. If authorURI and name are
- * valid then a single RDF containing just the service instance identified
- * by name is returned. <b><i>This method tries to use the local registry.
- * It will fail if one doesnt exist. Please use the other
- * findService(String, String, String, String) method if you wish to specify
- * a non local registry.</i></b>
- * <p>
- *
- * @param authorURI -
- * the authority to query
- * @param name -
- * the name of the service instance if applicable or null.
- * @param useTestMachine -
- * if true then services are searched for on the test server,
- * otherwise the production server is used. <b>this param is no
- * longer supported. Please set to false.</B>
- * @param useLSIDs whether or not we should include lsids
- * @return a string representing either all of services defined by
- * authorURI, (if name is null) or a single service instances' rdf
- * if name and authorURI are valid. If name and/or authorURI are
- * invalid an empty rdf document is returned.
- */
- public final static String findService(String authorURI, String name, boolean useTestMachine, boolean useLSIDs) {
- if (name == null || name.equals("")) {
- return (useLSIDs ? getAllServices(authorURI, useTestMachine) : getAllServices(authorURI, useTestMachine, false));
- } else {
- return (useLSIDs ? getService(authorURI, name, useTestMachine) : getService(authorURI, name, useTestMachine, false));
- }
+ if (services.length == 1) {
+ service = services[0];
+ return (service.getLSID());
}
+ return "";
+ }
- /**
- *
- * method that retrieves the RDF describing a specific service instance
- * based on the parameters domain, serviceName, url and uri.
- * <p>
- * <b>PRE: </b>None.
- * <p>
- * <b>POST: </b>The RDF describing the service with parameters domain,
- * serviceName, url and uri is created.
- *
- * @param domain -
- * the authoring domain of the service instance in question.
- * @param serviceName -
- * the name of the service instance in question.
- * @param url -
- * the URL of the endpoint of the BioMoby registry that you would
- * like to query. If null, the mobycentral registry is queried.
- * @param uri -
- * the URI of the BioMoby registry that you would like to query.
- * If null, the mobycentral registry is queried.
- * @param useLSIDs -
- * whether or not the returned RDF document should contain an
- * LSID. Set this to false to retrieve RDF that service providers
- * should have.
- * @return - the string representation of the RDF describing the service
- * instance based on the parameters given.
- */
- public final static String findService(String domain, String serviceName, String url,
- String uri, boolean useLSIDs) {
- if (serviceName != null) {
- // variables needed
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- central = new CentralImpl(url, uri);
- } catch (MobyException e) {
- log.error("Could not connect to " + url + " in findService.");
- return empty;
- }
- // set up the query service
- service = new MobyService(serviceName);
- service.setCategory("");
- service.setAuthority(domain);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("Could not find service:\n" + e1.getMessage());
- return empty;
- }
- // only one service should be returned!
- if (services.length != 1)
- return empty;
- // get the rdf
- String str = createRDF(services,useLSIDs);
- if (str == null)
- return empty;
- return str;
- } else {
- // servicename is null
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- central = new CentralImpl(url, uri);
- } catch (MobyException e) {
- log.error("Could not connect to " + url + " in findService.");
- return empty;
- }
- // set up the query service
- service = new MobyService();
- service.setAuthority(domain);
- service.setCategory("");
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("Could not find service:\n" + e1.getMessage());
- return empty;
- }
- // get the rdf
- String str = createRDF(services, useLSIDs);
- if (str == null)
- return empty;
- return str;
- }
+ public static void main(String[] args) throws Exception {
+ System.out.println(new ServiceInstanceRDF().findService("bioinfo.icapture.ubc.ca", "", false));
+ }
+
+ /**
+ *
+ * <b>PRE: </b>None
+ * <p>
+ * <b>POST: </b>If a service instance exists such that it has a name of name
+ * and an authoring URI of uri true is returned, otherwise false is
+ * returned.
+ * <p>
+ *
+ * @param uri -
+ * the authors uri
+ * @param name -
+ * the name of the service instance
+ * @return true if a service instance exists with authority uri, and name
+ * name, otherwise false is returned.
+ */
+ public final boolean serviceInstanceExists(String uri, String name) {
+ Central central = null;
+ MobyService service = null;
+ MobyService[] services = null;
+ // initialize central
+ central = getCentralImpl();
+ // set up the query service
+ service = new MobyService(name);
+ service.setCategory("");
+ service.setAuthority(uri);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ return false;
}
+ return services.length == 1;
+ }
- /**
- *
- * method that retrieves the RDF describing a specific service instance
- * based on the parameters domain, serviceName, url and uri.
- * <p>
- * <b>PRE: </b>None.
- * <p>
- * <b>POST: </b>The RDF describing the service with parameters domain,
- * serviceName, url and uri is created.
- *
- * @param domain -
- * the authoring domain of the service instance in question.
- * @param serviceName -
- * the name of the service instance in question.
- * @param url -
- * the URL of the endpoint of the BioMoby registry that you would
- * like to query. If null, the mobycentral registry is queried.
- * @param uri -
- * the URI of the BioMoby registry that you would like to query.
- * If null, the mobycentral registry is queried.
- * @return - the string representation of the RDF describing the service
- * instance based on the parameters given.
- */
- public final static String findService(String domain, String serviceName, String url, String uri) {
- if (serviceName != null) {
- // variables needed
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- central = new CentralImpl(url, uri);
- } catch (MobyException e) {
- log.error("Could not connect to " + url + " in findService.");
- return empty;
- }
- // set up the query service
- service = new MobyService(serviceName);
- service.setAuthority(domain);
- service.setCategory("");
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("Could not find service:\n" + e1.getMessage());
- return empty;
- }
- // only one service should be returned!
- if (services.length != 1)
- return empty;
- // get the rdf
- String str = createRDF(services, true);
- if (str == null)
- return empty;
- return str;
- } else {
- // servicename is null
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- central = new CentralImpl(url, uri);
- } catch (MobyException e) {
- log.error("Could not connect to " + url + " in findService.");
- return empty;
- }
- // set up the query service
- service = new MobyService();
- service.setAuthority(domain);
- service.setCategory("");
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("Could not find service:\n" + e1.getMessage());
- return empty;
- }
- // get the rdf
- String str = createRDF(services, true);
- if (str == null)
- return empty;
- return str;
- }
+ public final boolean serviceInstanceExists(String uri, String name,
+ String lsid) {
+ Central central = null;
+ MobyService service = null;
+ MobyService[] services = null;
+ // initialize central
+ central = getCentralImpl();
+ // set up the query service
+ service = new MobyService(name);
+ service.setCategory("");
+ service.setAuthority(uri);
+ // service.setLSID(lsid);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ return false;
}
- /*
- * a method that retrieves all of the service instances based on an
- * authoriy.
- */
- private final static String getAllServices(String URI, boolean useTestMachine) {
- // variables needed
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- if (!useTestMachine) {
- central = getCentralImpl();
- } else {
- // use test machine no longer supported
- return empty;
- }
- } catch (MobyException e) {
- log.error("error in getAllServices 1:\n" + e.getMessage());
- return empty;
- }
- // set up the query service
- service = new MobyService("");
- service.setCategory("");
- service.setAuthority(URI);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("error in getAllServices 2:\n" + e1.getMessage());
- return empty;
- }
- // should have >= 1 service returned
- if (services.length <= 0)
- return empty;
- // get the rdf
- String str = createRDF(services, true);
- if (str == null)
- return empty;
- return str;
+ if (services.length == 1) {
+ service = services[0];
+ return (service.getLSID().equals(lsid));
}
+ return false;
+ }
- /**
- * @return
- * @throws MobyException
- */
- private static Central getCentralImpl() throws MobyException {
- Central central;
- String registryURL = null;
- String registryNamespace = null;
-
- // are they set in the system?
- registryURL = System.getProperty("MOBY_SERVER");
- registryNamespace = System.getProperty("MOBY_URI");
-
- // if we didnt set them check the environment
- if (registryURL == null) {
- Map map = RegistryOS.getEnv();
- if (!map.isEmpty()) {
- registryURL = (String) map.get("MOBY_SERVER");
- registryNamespace = (String) map.get("MOBY_URI");
- }
- }
-
- log.info("Using URL: " + (registryURL == null ? CentralImpl.DEFAULT_ENDPOINT : registryURL) + " URI: " + (registryNamespace == null ? CentralImpl.DEFAULT_NAMESPACE: registryNamespace));
- if (registryURL == null) {
- // use default registry, since we dont have a local one
- central = new CentralImpl();
- } else if (registryNamespace == null) {
- // use default namespace since one isnt defined
- central = new CentralImpl(registryURL);
- } else {
- // use defined url and namespacce
- central = new CentralImpl(registryURL, registryNamespace);
- }
- return central;
+ /**
+ * Default Constructor: Uses the default mobycentral
+ *
+ * @throws MobyException
+ * if there is a problem communicating with the registry
+ */
+ public ServiceInstanceRDF() throws MobyException {
+ this(new Registry(CentralImpl.getDefaultURL(), CentralImpl
+ .getDefaultURL(), CentralImpl.getDefaultURI()));
+ }
+
+ /**
+ * Constructor:
+ *
+ * @param reg
+ * the registry to use
+ * @throws MobyException
+ * if there is a problem communicating with the registry
+ */
+ public ServiceInstanceRDF(Registry reg) throws MobyException {
+ registry = reg;
+ central = new CentralImpl(reg.getEndpoint(), reg.getNamespace());
+ MobyResourceRef[] refs = central.getResourceRefs();
+ for (MobyResourceRef ref : refs) {
+ if (ref.getResourceName().equals(
+ CentralImpl.DATA_TYPES_RESOURCE_NAME)) {
+ OBJ = ref.getResourceLocation().toString();
+ if (!OBJ.endsWith(trailing_character))
+ OBJ = OBJ + trailing_character;
+ } else if (ref.getResourceName().equals(
+ CentralImpl.SERVICE_INSTANCES_RESOURCE_NAME)) {
+ SI = ref.getResourceLocation().toString();
+ if (!SI.endsWith(trailing_character))
+ SI = SI + trailing_character;
+ } else if (ref.getResourceName().equals(
+ CentralImpl.NAMESPACES_RESOURCE_NAME)) {
+ NS = ref.getResourceLocation().toString();
+ if (!NS.endsWith(trailing_character))
+ NS = NS + trailing_character;
+ } else if (ref.getResourceName().equals(
+ CentralImpl.SERVICE_TYPES_RESOURCE_NAME)) {
+ SRV = ref.getResourceLocation().toString();
+ if (!SRV.endsWith(trailing_character))
+ SRV = SRV + trailing_character;
+ }
}
+ }
+
+ /*
+ * method that actually creates the rdf based on one or more services
+ * contained in the array services
+ */
+ private final String createRDF(MobyService[] services) {
+ Model model = createRDFModel(ModelFactory.createDefaultModel(),
+ services, true);
+ FilteredStream stream = new FilteredStream(new ByteArrayOutputStream());
+ RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
+ writer.setProperty("showXmlDeclaration", "false");
+ writer.setProperty("tab", "5");
+ writer.write(model, stream, null);
+
+ return stream.getOutput();
+ }
+
+ /*
+ * method that actually creates the rdf based on one or more services
+ * contained in the array services
+ */
+ private final String createRDF(MobyService[] services, boolean useLSIDs) {
+ Model model = createRDFModel(ModelFactory.createDefaultModel(),
+ services, useLSIDs);
+ FilteredStream stream = new FilteredStream(new ByteArrayOutputStream());
+ RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
+ writer.setProperty("showXmlDeclaration", "false");
+ writer.setProperty("tab", "5");
+ writer.write(model, stream, null);
+
+ return stream.getOutput();
+ }
+
+ /**
+ *
+ * @param model
+ * an RDF model to add the services.
+ * @param services
+ * an array of MobyService objects.
+ * @param useLSIDs
+ * if true then the LSID for the service is added to the RDF
+ * model otherwise it is not.
+ * @return the model with service signatures contained within.
+ */
+ public final Model createRDFModel(Model model, MobyService[] services,
+ boolean useLSIDs) {
+ // set up the prefixes/namespaces
+ Map map = model.getNsPrefixMap();
+ map.put("mobyService", SRV);
+ map.put("mobyNamespace", NS);
+ map.put("mobyObject", OBJ);
+ map.put("protege-dc", DC_PROTEGE.getURI());
+ map.put("mygrid", FetaVocabulary.getURI());
+ model.setNsPrefixes(map);
+
+ for (int i = 0; i < services.length; i++) {
+ MobyData[] primaryInputs = services[i].getPrimaryInputs(); // consumes
+ MobyData[] secondaryInputs = services[i].getSecondaryInputs(); // consumes
+ MobyData[] outputs = services[i].getPrimaryOutputs(); // produces
+
+ // start creating the rdf
+ Resource subject = model.createResource(SI
+ + services[i].getAuthority() + "," + services[i].getName(),
+ FetaVocabulary.serviceDescription);
+ subject.addProperty(FetaVocabulary.hasServiceDescriptionLocation,
+ services[i].getSignatureURL());
+ subject.addProperty(DC_PROTEGE.format, services[i].getCategory());
+ subject.addProperty(FetaVocabulary.locationURI, services[i]
+ .getURL());
+ subject.addProperty(FetaVocabulary.hasServiceDescriptionText,
+ services[i].getDescription());
+ subject.addProperty(FetaVocabulary.hasServiceNameText, services[i]
+ .getName());
+ if (useLSIDs)
+ subject.addProperty(DC_PROTEGE.identifier, services[i]
+ .getLSID());
+ /*
+ * subject.addProperty(ServiceDescriptionPredicates.hasServiceType,
+ * services[i] .getType());
+ */
+
+ // create the organization node
+ Resource publishedBy = model
+ .createResource(FetaVocabulary.organisation);
+ publishedBy.addProperty(DC_PROTEGE.creator, services[i]
+ .getEmailContact());
+ publishedBy.addProperty(DC_PROTEGE.publisher, services[i]
+ .getAuthority());
+ publishedBy.addProperty(FetaVocabulary.authoritative, ((services[i]
+ .isAuthoritative()) ? "true" : "false"));
+ subject.addProperty(FetaVocabulary.providedBy, publishedBy);
+
+ // add the inputs/outputs
+ Resource hasOperation = model
+ .createResource(FetaVocabulary.operation);
+ // add the hasOperation to the resource
+ subject.addProperty(FetaVocabulary.hasOperation, hasOperation);
+ hasOperation.addProperty(FetaVocabulary.hasOperationNameText,
+ services[i].getName());
+
+ // add the performsTask information
+ Resource performs = model
+ .createResource(FetaVocabulary.operationTask);
+ // if service type is lsid, dont append to URI
+ try {
+ new LSID(services[i].getServiceType().getName());
+ performs.addProperty(RDF.type, model.createResource(services[i]
+ .getServiceType().getName()));
+ } catch (MalformedLSIDException e) {
+ // not an lsid
+ performs.addProperty(RDF.type, model.createResource(SRV
+ + services[i].getServiceType().getName()));
+ }
+
+ hasOperation.addProperty(FetaVocabulary.performsTask, performs);
+
+ if (primaryInputs.length > 0) {
+ for (int j = 0; j < primaryInputs.length; j++) {
+ if (primaryInputs[j] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simpleData = (MobyPrimaryDataSimple) primaryInputs[j];
+ Resource parameter = model
+ .createResource(FetaVocabulary.parameter);
+ parameter.addProperty(
+ FetaVocabulary.hasParameterNameText, simpleData
+ .getName());
+ parameter
+ .addProperty(
+ FetaVocabulary.hasParameterType,
+ model
+ .createResource(FetaVocabulary.simpleParameter));
+ // if object is lsid, dont append to URI
+
+ try {
+ // an lsid
+ Resource bnode = model.createResource();
+ new LSID(simpleData.getDataType().getName());
+ bnode.addProperty(RDF.type, model
+ .createResource(simpleData.getDataType()
+ .getName()));
+ parameter.addProperty(FetaVocabulary.object_type,
+ bnode);
+ } catch (MalformedLSIDException e) {
+ // not an lsid
+ Resource bnode = model.createResource();
+ bnode.addProperty(RDF.type, model
+ .createResource(OBJ
+ + simpleData.getDataType()
+ .getName()));
+ parameter.addProperty(FetaVocabulary.object_type,
+ bnode);
-
- /*
- * a method that retrieves all of the service instances based on an
- * authoriy.
- */
- private final static String getAllServices(String URI, boolean useTestMachine, boolean useLSIDs) {
- // variables needed
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- if (!useTestMachine) {
- central = getCentralImpl();
- } else {
- // use test machine no longer supported
- return empty;
- }
- } catch (MobyException e) {
- log.error("error in getAllServices 1:\n" + e.getMessage());
- return empty;
- }
- // set up the query service
- service = new MobyService("");
- service.setCategory("");
- service.setAuthority(URI);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("error in getAllServices 2:\n" + e1.getMessage());
- return empty;
- }
- // should have >= 1 service returned
- if (services.length <= 0)
- return empty;
- // get the rdf
- String str = createRDF(services, useLSIDs);
- if (str == null)
- return empty;
- return str;
- }
-
- /*
- * a method that retrieves a single service instance rdf document based on
- * the URI and name of that service.
- */
- private final static String getService(String URI, String name, boolean useTestMachine) {
- // variables needed
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- if (!useTestMachine) {
- central = getCentralImpl();
- } else {
- // use test machine no longer supported
- return empty;
}
- } catch (MobyException e) {
- log.error("error in getService 1:\n" + e.getMessage());
- return empty;
- }
- // set up the query service
- service = new MobyService(name);
- service.setCategory("");
- service.setAuthority(URI);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("error in getService 2:\n" + e1.getMessage());
- return empty;
- }
- // only one service should be returned!
- if (services.length != 1)
- return empty;
- // get the rdf
- String str = createRDF(services, true);
- if (str == null)
- return empty;
- return str;
- }
-
- /*
- * a method that retrieves a single service instance rdf document based on
- * the URI and name of that service.
- */
- private final static String getService(String URI, String name, boolean useTestMachine, boolean useLSIDs) {
- // variables needed
- MobyService service = null;
- MobyService[] services = null;
- Central central = null;
- // initialize central
- try {
- if (!useTestMachine) {
- central = getCentralImpl();
- } else {
- // use test machine no longer supported
- return empty;
+ MobyNamespace[] namespaces = simpleData.getNamespaces();
+ if (namespaces.length > 0) {
+ // Resource parameterNamespace = model
+ // .createResource(FetaVocabulary.parameterNamespace);
+ // parameter.addProperty(FetaVocabulary.inNamespaces,
+ // parameterNamespace);
+ for (int k = 0; k < namespaces.length; k++) {
+ // if namespace is lsid, dont append to URI
+ Resource parameterNamespace = model
+ .createResource(FetaVocabulary.parameterNamespace);
+ parameter.addProperty(
+ FetaVocabulary.inNamespaces,
+ parameterNamespace);
+ try {
+ new LSID(namespaces[k].getName());
+ parameterNamespace.addProperty(RDF.type,
+ model.createResource(namespaces[k]
+ .getName()));
+ } catch (MalformedLSIDException e) {
+ parameterNamespace.addProperty(RDF.type,
+ model.createResource(NS
+ + namespaces[k].getName()));
+ }
+ }
}
- } catch (MobyException e) {
- log.error("error in getService 1:\n" + e.getMessage());
- return empty;
- }
- // set up the query service
- service = new MobyService(name);
- service.setCategory("");
- service.setAuthority(URI);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- log.error("error in getService 2:\n" + e1.getMessage());
- return empty;
- }
- // only one service should be returned!
- if (services.length != 1)
- return empty;
- // get the rdf
- String str = createRDF(services, useLSIDs);
- if (str == null)
- return empty;
- return str;
- }
+ hasOperation.addProperty(FetaVocabulary.inputParameter,
+ parameter);
+ } else if (primaryInputs[j] instanceof MobyPrimaryDataSet) {
+ MobyPrimaryDataSimple[] setOfSimpleData = ((MobyPrimaryDataSet) primaryInputs[j])
+ .getElements();
+ if (setOfSimpleData.length < 1) {
+ continue;
+ }
+ String collectionName = ((MobyPrimaryDataSet) primaryInputs[j])
+ .getName();
+ for (int k = 0; k < setOfSimpleData.length; k++) {
+ if (setOfSimpleData[k] instanceof MobyPrimaryDataSimple) {
+ Resource parameter = model
+ .createResource(FetaVocabulary.parameter);
+ parameter.addProperty(
+ FetaVocabulary.hasParameterNameText,
+ collectionName);
+ parameter
+ .addProperty(
+ FetaVocabulary.hasParameterType,
+ model
+ .createResource(FetaVocabulary.collectionParameter));
+ // if object is lsid, dont append to URI
+ try {
- /*
- * method that actually creates the rdf based on one or more services
- * contained in the array services
- */
- private final static String createRDF(MobyService[] services, boolean useLSIDs) {
- Model model = createRDFModel(ModelFactory.createDefaultModel(), services, useLSIDs);
- FilteredStream stream = new FilteredStream(new ByteArrayOutputStream());
- RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
- writer.setProperty("showXmlDeclaration", "false");
- writer.setProperty("tab", "5");
- writer.write(model, stream, null);
+ Resource bnode = model.createResource();
+ new LSID(setOfSimpleData[k].getDataType()
+ .getName());
+ bnode.addProperty(RDF.type, model
+ .createResource(setOfSimpleData[k]
+ .getDataType().getName()));
+ parameter.addProperty(
+ FetaVocabulary.object_type, bnode);
+
+ } catch (MalformedLSIDException e) {
+ Resource bnode = model.createResource();
+ bnode.addProperty(RDF.type, model
+ .createResource(OBJ
+ + setOfSimpleData[k]
+ .getDataType()
+ .getName()));
+ parameter.addProperty(
+ FetaVocabulary.object_type, bnode);
+ }
- return stream.getOutput();
- }
- /*
- * method that actually creates the rdf based on one or more services
- * contained in the array services
- */
- private final static String createRDF(MobyService[] services) {
- Model model = createRDFModel(ModelFactory.createDefaultModel(), services, true);
- FilteredStream stream = new FilteredStream(new ByteArrayOutputStream());
- RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
- writer.setProperty("showXmlDeclaration", "false");
- writer.setProperty("tab", "5");
- writer.write(model, stream, null);
+ MobyNamespace[] namespaces = setOfSimpleData[k]
+ .getNamespaces();
+ if (namespaces.length > 0) {
+ /*
+ * Resource parameterNamespace = model
+ * .createResource(FetaVocabulary.parameterNamespace);
+ */
+ for (int index = 0; index < namespaces.length; index++) {
+ // if namespace is lsid, dont
+ // append to URI
+ Resource parameterNamespace = model
+ .createResource(FetaVocabulary.parameterNamespace);
+ parameter.addProperty(
+ FetaVocabulary.inNamespaces,
+ parameterNamespace);
+ try {
+ LSID theLSID = new LSID(
+ namespaces[index].getName());
+ parameterNamespace
+ .addProperty(
+ RDF.type,
+ model
+ .createResource(namespaces[index]
+ .getName()));
+ } catch (MalformedLSIDException e) {
+ parameterNamespace
+ .addProperty(
+ RDF.type,
+ model
+ .createResource(NS
+ + namespaces[index]
+ .getName()));
+ }
- return stream.getOutput();
- }
+ }
+ /*
+ * parameter.addProperty(
+ * FetaVocabulary.inNamespaces,
+ * parameterNamespace);
+ */
+ }
+ hasOperation.addProperty(
+ FetaVocabulary.inputParameter,
+ parameter);
+ } else {
+ System.err
+ .print("A collection of a collection in getServiceInstances()!");
+ return null;
+ }
+ }
+ } else {
+ // ERROR
+ System.err
+ .println("Primary input was not of known subtype (simple or collection)");
+ return null;
+ }
+
+ }
+ }
+ if (secondaryInputs.length > 0) {
+ for (int j = 0; j < secondaryInputs.length; j++) {
+ if (secondaryInputs[j] instanceof MobySecondaryData) {
+ MobySecondaryData data = (MobySecondaryData) secondaryInputs[j];
+ Resource _li = model
+ .createResource(FetaVocabulary.parameter);
+ _li
+ .addProperty(
+ FetaVocabulary.hasParameterType,
+ model
+ .createResource(FetaVocabulary.secondaryParameter));
+
+ if (!data.getName().equals(""))
+ _li
+ .addProperty(
+ FetaVocabulary.hasParameterNameText,
+ model.createTypedLiteral(data
+ .getName()));
+ if (!data.getDefaultValue().equals(""))
+ _li.addProperty(FetaVocabulary.hasDefaultValue,
+ model.createTypedLiteral(data
+ .getDefaultValue()));
+ _li.addProperty(FetaVocabulary.datatype, model
+ .createTypedLiteral(data.getDataType()));
+
+ // add the secondary description if necessary
+ if (!data.getDescription().equals("")) // FIXME should
+ // be defined in
+ // FetaVocabulary
+ _li.addProperty(
+ FetaVocabulary.hasParameterDescriptionText,
+ model.createTypedLiteral(data
+ .getDescription()));
- /**
- *
- * @param model
- * an RDF model to add the services.
- * @param services
- * an array of MobyService objects.
- * @return the model with service signatures contained within.
- */
- public final static Model createRDFModel(Model model, MobyService[] services, boolean useLSIDs) {
- // set up the prefixes/namespaces
- Map map = model.getNsPrefixMap();
- map.put("mobyService", SRV);
- map.put("mobyNamespace", NS);
- map.put("mobyObject", OBJ);
- map.put("protege-dc", DC_PROTEGE.getURI());
- map.put("mygrid", FetaVocabulary.getURI());
- model.setNsPrefixes(map);
-
- for (int i = 0; i < services.length; i++) {
- MobyData[] primaryInputs = services[i].getPrimaryInputs(); // consumes
- MobyData[] secondaryInputs = services[i].getSecondaryInputs(); // consumes
- MobyData[] outputs = services[i].getPrimaryOutputs(); // produces
-
- // start creating the rdf
- Resource subject = model.createResource(SI + services[i].getAuthority() + ","
- + services[i].getName(), FetaVocabulary.serviceDescription);
- subject.addProperty(FetaVocabulary.hasServiceDescriptionLocation, services[i]
- .getSignatureURL());
- subject.addProperty(DC_PROTEGE.format, services[i].getCategory());
- subject.addProperty(FetaVocabulary.locationURI, services[i].getURL());
- subject.addProperty(FetaVocabulary.hasServiceDescriptionText, services[i]
- .getDescription());
- subject.addProperty(FetaVocabulary.hasServiceNameText, services[i].getName());
- if (useLSIDs)
- subject.addProperty(DC_PROTEGE.identifier, services[i].getLSID());
/*
- * subject.addProperty(ServiceDescriptionPredicates.hasServiceType,
- * services[i] .getType());
+ * _li.addProperty(RDF.type, model
+ * .getProperty(FetaModelRDF.getURI() +
+ * "secondaryParameter"));
*/
-
- { // add meta information on whether or not this service is
- // callable (i.e. times out or not)
- if (useLSIDs)
- try {
- URL _url_ = new URL(
- SERVER + "ValidateService?authority="
- + services[i].getAuthority() + "&service="
- + services[i].getName());
- BufferedReader in = new BufferedReader(
- new InputStreamReader(_url_.openStream()));
-
- String inputLine = in.readLine();
- in.close();
- if (inputLine != null) {
- inputLine = inputLine.trim();
- if (!inputLine.equals("") && (inputLine.equals("true") || inputLine.equals("false"))) {
- subject.addProperty(model.createProperty(FetaVocabulary.getURI()
- + "isAlive"), Boolean.valueOf(inputLine));
- } else {
- // defaults to true
- subject.addProperty(model.createProperty(FetaVocabulary.getURI()
- + "isAlive"), true);
- }
- } else {
- subject.addProperty(model.createProperty(FetaVocabulary.getURI()
- + "isAlive"), true);
- }
-
- } catch (Exception e) {
- subject.addProperty(model.createProperty(FetaVocabulary.getURI()
- + "isAlive"), true);
- }
+ if (data.getDataType().equals("Integer")) {
+ _li.addProperty(FetaVocabulary.min, model
+ .createTypedLiteral(data.getMinValue()));
+ _li.addProperty(FetaVocabulary.max, model
+ .createTypedLiteral(data.getMaxValue()));
}
- // create the organization node
- Resource publishedBy = model.createResource(FetaVocabulary.organisation);
- publishedBy.addProperty(DC_PROTEGE.creator, services[i].getEmailContact());
- publishedBy.addProperty(DC_PROTEGE.publisher, services[i].getAuthority());
- publishedBy.addProperty(FetaVocabulary.authoritative,
- ((services[i].isAuthoritative()) ? "true" : "false"));
- subject.addProperty(FetaVocabulary.providedBy, publishedBy);
-
- // add the inputs/outputs
- Resource hasOperation = model.createResource(FetaVocabulary.operation);
- // add the hasOperation to the resource
- subject.addProperty(FetaVocabulary.hasOperation, hasOperation);
- hasOperation.addProperty(FetaVocabulary.hasOperationNameText, services[i].getName());
-
- // add the performsTask information
- Resource performs = model.createResource(FetaVocabulary.operationTask);
- // if service type is lsid, dont append to URI
+ String[] vals = data.getAllowedValues();
+ for (int k = 0; k < vals.length; k++) {
+ _li.addProperty(FetaVocabulary.enumeration, model
+ .createTypedLiteral(vals[k]));
+ }
+ hasOperation.addProperty(FetaVocabulary.inputParameter,
+ _li);
+ } else if (secondaryInputs[j] instanceof MobyDataSecondaryInstance) {
+ // should not be here, but ...
+ } else {
+ // ERROR
+ log
+ .error("Secondary input was not of known subtype (Secondary)");
+ return null;
+ }
+ }
+ }
+ if (outputs.length > 0) {
+ for (int j = 0; j < outputs.length; j++) {
+ if (outputs[j] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simpleData = (MobyPrimaryDataSimple) outputs[j];
+ Resource parameter = model
+ .createResource(FetaVocabulary.parameter);
+ parameter.addProperty(
+ FetaVocabulary.hasParameterNameText, simpleData
+ .getName());
+ parameter
+ .addProperty(
+ FetaVocabulary.hasParameterType,
+ model
+ .createResource(FetaVocabulary.simpleParameter));
+ // if object is lsid, dont append to URI
try {
- new LSID(services[i].getServiceType().getName());
- performs.addProperty(RDF.type, model.createResource(services[i].getServiceType()
- .getName()));
+ Resource bnode = model.createResource();
+ new LSID(simpleData.getDataType().getName());
+ bnode.addProperty(RDF.type, model
+ .createResource(simpleData.getDataType()
+ .getName()));
+ parameter.addProperty(FetaVocabulary.object_type,
+ bnode);
} catch (MalformedLSIDException e) {
- // not an lsid
- performs.addProperty(RDF.type, model.createResource(SRV
- + services[i].getServiceType().getName()));
+ Resource bnode = model.createResource();
+ bnode.addProperty(RDF.type, model
+ .createResource(OBJ
+ + simpleData.getDataType()
+ .getName()));
+ parameter.addProperty(FetaVocabulary.object_type,
+ bnode);
}
- hasOperation.addProperty(FetaVocabulary.performsTask, performs);
-
- if (primaryInputs.length > 0) {
- for (int j = 0; j < primaryInputs.length; j++) {
- if (primaryInputs[j] instanceof MobyPrimaryDataSimple) {
- MobyPrimaryDataSimple simpleData = (MobyPrimaryDataSimple) primaryInputs[j];
- Resource parameter = model.createResource(FetaVocabulary.parameter);
- parameter.addProperty(FetaVocabulary.hasParameterNameText, simpleData
- .getName());
- parameter.addProperty(FetaVocabulary.hasParameterType, model
- .createResource(FetaVocabulary.simpleParameter));
- // if object is lsid, dont append to URI
-
- try {
- // an lsid
- Resource bnode = model.createResource();
- new LSID(simpleData.getDataType().getName());
- bnode.addProperty(RDF.type, model.createResource(simpleData
- .getDataType().getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
- } catch (MalformedLSIDException e) {
- // not an lsid
- Resource bnode = model.createResource();
- bnode.addProperty(RDF.type, model.createResource(OBJ
- + simpleData.getDataType().getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
-
- }
-
- MobyNamespace[] namespaces = simpleData.getNamespaces();
- if (namespaces.length > 0) {
- // Resource parameterNamespace = model
- // .createResource(FetaVocabulary.parameterNamespace);
- // parameter.addProperty(FetaVocabulary.inNamespaces,
- // parameterNamespace);
- for (int k = 0; k < namespaces.length; k++) {
- // if namespace is lsid, dont append to URI
- Resource parameterNamespace = model
- .createResource(FetaVocabulary.parameterNamespace);
- parameter.addProperty(FetaVocabulary.inNamespaces,
- parameterNamespace);
- try {
- new LSID(namespaces[k].getName());
- parameterNamespace.addProperty(RDF.type, model
- .createResource(namespaces[k].getName()));
- } catch (MalformedLSIDException e) {
- parameterNamespace.addProperty(RDF.type, model
- .createResource(NS + namespaces[k].getName()));
- }
- }
- }
- hasOperation.addProperty(FetaVocabulary.inputParameter, parameter);
- } else if (primaryInputs[j] instanceof MobyPrimaryDataSet) {
- MobyPrimaryDataSimple[] setOfSimpleData = ((MobyPrimaryDataSet) primaryInputs[j])
- .getElements();
- if (setOfSimpleData.length < 1) {
- continue;
- }
- String collectionName = ((MobyPrimaryDataSet) primaryInputs[j]).getName();
- for (int k = 0; k < setOfSimpleData.length; k++) {
- if (setOfSimpleData[k] instanceof MobyPrimaryDataSimple) {
- Resource parameter = model.createResource(FetaVocabulary.parameter);
- parameter.addProperty(FetaVocabulary.hasParameterNameText,
- collectionName);
- parameter.addProperty(FetaVocabulary.hasParameterType, model
- .createResource(FetaVocabulary.collectionParameter));
- // if object is lsid, dont append to URI
- try {
-
- Resource bnode = model.createResource();
- new LSID(setOfSimpleData[k].getDataType().getName());
- bnode.addProperty(RDF.type, model
- .createResource(setOfSimpleData[k].getDataType()
- .getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
-
- } catch (MalformedLSIDException e) {
- Resource bnode = model.createResource();
- bnode.addProperty(RDF.type, model.createResource(OBJ
- + setOfSimpleData[k].getDataType().getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
- }
-
- MobyNamespace[] namespaces = setOfSimpleData[k].getNamespaces();
- if (namespaces.length > 0) {
- /*
- * Resource parameterNamespace = model
- * .createResource(FetaVocabulary.parameterNamespace);
- */
- for (int index = 0; index < namespaces.length; index++) {
- // if namespace is lsid, dont
- // append to URI
- Resource parameterNamespace = model
- .createResource(FetaVocabulary.parameterNamespace);
- parameter.addProperty(FetaVocabulary.inNamespaces,
- parameterNamespace);
- try {
- LSID theLSID = new LSID(namespaces[index].getName());
- parameterNamespace.addProperty(RDF.type, model
- .createResource(namespaces[index].getName()));
- } catch (MalformedLSIDException e) {
- parameterNamespace.addProperty(RDF.type, model
- .createResource(NS
- + namespaces[index].getName()));
- }
-
- }
- /*
- * parameter.addProperty(
- * FetaVocabulary.inNamespaces,
- * parameterNamespace);
- */
- }
- hasOperation.addProperty(FetaVocabulary.inputParameter, parameter);
- } else {
- System.err
- .print("A collection of a collection in getServiceInstances()!");
- return null;
- }
- }
- } else {
- // ERROR
- System.err
- .println("Primary input was not of known subtype (simple or collection)");
- return null;
- }
-
+ MobyNamespace[] namespaces = simpleData.getNamespaces();
+ if (namespaces.length > 0) {
+ /*
+ * Resource parameterNamespace =
+ * model.createResource(ModelFactory
+ * .createDefaultModel().createProperty(
+ * FetaVocabulary.getURI() + "parameterNamespace"));
+ * parameter.addProperty(FetaVocabulary.inNamespaces,
+ * parameterNamespace);
+ */
+ for (int k = 0; k < namespaces.length; k++) {
+ // if namespace is lsid, dont append to URI
+ Resource parameterNamespace = model
+ .createResource(ModelFactory
+ .createDefaultModel()
+ .createProperty(
+ FetaVocabulary.getURI()
+ + "parameterNamespace"));
+ parameter.addProperty(
+ FetaVocabulary.inNamespaces,
+ parameterNamespace);
+ try {
+ new LSID(namespaces[k].getName());
+ parameterNamespace.addProperty(RDF.type,
+ model.createResource(namespaces[k]
+ .getName()));
+ } catch (MalformedLSIDException e) {
+ parameterNamespace.addProperty(RDF.type,
+ model.createResource(NS
+ + namespaces[k].getName()));
}
+ }
}
- if (secondaryInputs.length > 0) {
- for (int j = 0; j < secondaryInputs.length; j++) {
- if (secondaryInputs[j] instanceof MobySecondaryData) {
- MobySecondaryData data = (MobySecondaryData) secondaryInputs[j];
- Resource _li = model.createResource(FetaVocabulary.parameter);
- _li.addProperty(FetaVocabulary.hasParameterType, model
- .createResource(FetaVocabulary.secondaryParameter));
-
- if (!data.getName().equals(""))
- _li.addProperty(FetaVocabulary.hasParameterNameText, model
- .createTypedLiteral(data.getName()));
- if (!data.getDefaultValue().equals(""))
- _li.addProperty(FetaVocabulary.hasDefaultValue, model
- .createTypedLiteral(data.getDefaultValue()));
- _li.addProperty(FetaVocabulary.datatype, model.createTypedLiteral(data
- .getDataType()));
-
- // add the secondary description if necessary
- if (!data.getDescription().equals("")) // FIXME should
- // be defined in
- // FetaVocabulary
- _li.addProperty(FetaVocabulary.hasParameterDescriptionText, model
- .createTypedLiteral(data.getDescription()));
-
- /*
- * _li.addProperty(RDF.type, model
- * .getProperty(FetaModelRDF.getURI() +
- * "secondaryParameter"));
- */
- if (data.getDataType().equals("Integer")) {
- _li.addProperty(FetaVocabulary.min, model.createTypedLiteral(data
- .getMinValue()));
- _li.addProperty(FetaVocabulary.max, model.createTypedLiteral(data
- .getMaxValue()));
- }
- String[] vals = data.getAllowedValues();
- for (int k = 0; k < vals.length; k++) {
- _li.addProperty(FetaVocabulary.enumeration, model
- .createTypedLiteral(vals[k]));
- }
- hasOperation.addProperty(FetaVocabulary.inputParameter, _li);
- } else if (secondaryInputs[j] instanceof MobyDataSecondaryInstance) {
- // should not be here, but ...
- } else {
- // ERROR
- log.error("Secondary input was not of known subtype (Secondary)");
- return null;
- }
- }
+ hasOperation.addProperty(
+ FetaVocabulary.outputParameter, parameter);
+ } else if (outputs[j] instanceof MobyPrimaryDataSet) {
+ MobyPrimaryDataSimple[] setOfSimpleData = ((MobyPrimaryDataSet) outputs[j])
+ .getElements();
+ if (setOfSimpleData.length < 1) {
+ continue;
}
- if (outputs.length > 0) {
- for (int j = 0; j < outputs.length; j++) {
- if (outputs[j] instanceof MobyPrimaryDataSimple) {
- MobyPrimaryDataSimple simpleData = (MobyPrimaryDataSimple) outputs[j];
- Resource parameter = model.createResource(FetaVocabulary.parameter);
- parameter.addProperty(FetaVocabulary.hasParameterNameText, simpleData
- .getName());
- parameter.addProperty(FetaVocabulary.hasParameterType, model
- .createResource(FetaVocabulary.simpleParameter));
- // if object is lsid, dont append to URI
- try {
- Resource bnode = model.createResource();
- new LSID(simpleData.getDataType().getName());
- bnode.addProperty(RDF.type, model.createResource(simpleData
- .getDataType().getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
- } catch (MalformedLSIDException e) {
- Resource bnode = model.createResource();
- bnode.addProperty(RDF.type, model.createResource(OBJ
- + simpleData.getDataType().getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
- }
-
- MobyNamespace[] namespaces = simpleData.getNamespaces();
- if (namespaces.length > 0) {
- /*
- * Resource parameterNamespace =
- * model.createResource(ModelFactory
- * .createDefaultModel().createProperty(
- * FetaVocabulary.getURI() + "parameterNamespace"));
- * parameter.addProperty(FetaVocabulary.inNamespaces,
- * parameterNamespace);
- */
- for (int k = 0; k < namespaces.length; k++) {
- // if namespace is lsid, dont append to URI
- Resource parameterNamespace = model.createResource(ModelFactory
- .createDefaultModel().createProperty(
- FetaVocabulary.getURI() + "parameterNamespace"));
- parameter.addProperty(FetaVocabulary.inNamespaces,
- parameterNamespace);
- try {
- new LSID(namespaces[k].getName());
- parameterNamespace.addProperty(RDF.type, model
- .createResource(namespaces[k].getName()));
- } catch (MalformedLSIDException e) {
- parameterNamespace.addProperty(RDF.type, model
- .createResource(NS + namespaces[k].getName()));
- }
- }
- }
- hasOperation.addProperty(FetaVocabulary.outputParameter, parameter);
- } else if (outputs[j] instanceof MobyPrimaryDataSet) {
- MobyPrimaryDataSimple[] setOfSimpleData = ((MobyPrimaryDataSet) outputs[j])
- .getElements();
- if (setOfSimpleData.length < 1) {
- continue;
- }
- String collectionName = ((MobyPrimaryDataSet) outputs[j]).getName();
- for (int k = 0; k < setOfSimpleData.length; k++) {
- if (setOfSimpleData[k] instanceof MobyPrimaryDataSimple) {
- Resource parameter = model.createResource(FetaVocabulary.parameter);
- parameter.addProperty(FetaVocabulary.hasParameterNameText,
- collectionName);
- parameter.addProperty(FetaVocabulary.hasParameterType, model
- .createResource(FetaVocabulary.collectionParameter));
- // if object is lsid, dont append to URI
- try {
- Resource bnode = model.createResource();
- new LSID(setOfSimpleData[k].getDataType().getName());
- bnode.addProperty(RDF.type, model
- .createResource(setOfSimpleData[k].getDataType()
- .getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
- } catch (MalformedLSIDException e) {
- Resource bnode = model.createResource();
- bnode.addProperty(RDF.type, model.createResource(OBJ
- + setOfSimpleData[k].getDataType().getName()));
- parameter.addProperty(FetaVocabulary.object_type, bnode);
- }
-
- MobyNamespace[] namespaces = setOfSimpleData[k].getNamespaces();
- if (namespaces.length > 0) {
- /*
- * Resource parameterNamespace = model
- * .createResource(FetaVocabulary.parameterNamespace);
- */
- for (int index = 0; index < namespaces.length; index++) {
- Resource parameterNamespace = model
- .createResource(FetaVocabulary.parameterNamespace);
- try {
- LSID theLSID = new LSID(namespaces[index].getName());
- parameterNamespace.addProperty(RDF.type, model
- .createResource(namespaces[index].getName()));
- } catch (MalformedLSIDException e) {
- parameterNamespace.addProperty(RDF.type, model
- .createResource(NS
- + namespaces[index].getName()));
- }
- parameter.addProperty(FetaVocabulary.inNamespaces,
- parameterNamespace);
- }
- /*
- * parameter.addProperty(
- * FetaVocabulary.inNamespaces,
- * parameterNamespace);
- */
- }
- hasOperation.addProperty(FetaVocabulary.outputParameter, parameter);
- } else {
- System.err
- .print("A collection of a collection (output) in getServiceInstances()!");
- return null;
- }
- }
- } else {
- // ERROR
- System.err
- .println("Output was not of known subtype (simple or collection)");
- return null;
+ String collectionName = ((MobyPrimaryDataSet) outputs[j])
+ .getName();
+ for (int k = 0; k < setOfSimpleData.length; k++) {
+ if (setOfSimpleData[k] instanceof MobyPrimaryDataSimple) {
+ Resource parameter = model
+ .createResource(FetaVocabulary.parameter);
+ parameter.addProperty(
+ FetaVocabulary.hasParameterNameText,
+ collectionName);
+ parameter
+ .addProperty(
+ FetaVocabulary.hasParameterType,
+ model
+ .createResource(FetaVocabulary.collectionParameter));
+ // if object is lsid, dont append to URI
+ try {
+ Resource bnode = model.createResource();
+ new LSID(setOfSimpleData[k].getDataType()
+ .getName());
+ bnode.addProperty(RDF.type, model
+ .createResource(setOfSimpleData[k]
+ .getDataType().getName()));
+ parameter.addProperty(
+ FetaVocabulary.object_type, bnode);
+ } catch (MalformedLSIDException e) {
+ Resource bnode = model.createResource();
+ bnode.addProperty(RDF.type, model
+ .createResource(OBJ
+ + setOfSimpleData[k]
+ .getDataType()
+ .getName()));
+ parameter.addProperty(
+ FetaVocabulary.object_type, bnode);
+ }
+
+ MobyNamespace[] namespaces = setOfSimpleData[k]
+ .getNamespaces();
+ if (namespaces.length > 0) {
+ /*
+ * Resource parameterNamespace = model
+ * .createResource(FetaVocabulary.parameterNamespace);
+ */
+ for (int index = 0; index < namespaces.length; index++) {
+ Resource parameterNamespace = model
+ .createResource(FetaVocabulary.parameterNamespace);
+ try {
+ LSID theLSID = new LSID(
+ namespaces[index].getName());
+ parameterNamespace
+ .addProperty(
+ RDF.type,
+ model
+ .createResource(namespaces[index]
+ .getName()));
+ } catch (MalformedLSIDException e) {
+ parameterNamespace
+ .addProperty(
+ RDF.type,
+ model
+ .createResource(NS
+ + namespaces[index]
+ .getName()));
}
+ parameter.addProperty(
+ FetaVocabulary.inNamespaces,
+ parameterNamespace);
+ }
+ /*
+ * parameter.addProperty(
+ * FetaVocabulary.inNamespaces,
+ * parameterNamespace);
+ */
}
+ hasOperation.addProperty(
+ FetaVocabulary.outputParameter,
+ parameter);
+ } else {
+ System.err
+ .print("A collection of a collection (output) in getServiceInstances()!");
+ return null;
+ }
}
+ } else {
+ // ERROR
+ System.err
+ .println("Output was not of known subtype (simple or collection)");
+ return null;
+ }
}
-
- return model;
+ }
}
- /**
- *
- * <b>PRE: </b>None
- * <p>
- * <b>POST: </b>If a service instance exists such that it has a name of name
- * and an authoring URI of uri true is returned, otherwise false is
- * returned.
- * <p>
- *
- * @param uri -
- * the authors uri
- * @param name -
- * the name of the service instance
- * @return true if a service instance exists with authority uri, and name
- * name, otherwise false is returned.
- */
- public final static boolean serviceInstanceExists(String uri, String name) {
- Central central = null;
- MobyService service = null;
- MobyService[] services = null;
- // initialize central
- try {
- central = getCentralImpl();
- } catch (MobyException e) {
- return false;
- }
- // set up the query service
- service = new MobyService(name);
- service.setCategory("");
- service.setAuthority(uri);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- return false;
- }
- return services.length == 1;
+ return model;
+ }
+
+ /**
+ *
+ * <b>PRE: </b>name is either a valid name or null
+ * <p>
+ * <b>POST: </b>If authorURI is a valid authority, then a RDF containing all
+ * of the service instances will be returned. If authorURI and name are
+ * valid then a single RDF containing just the service instance identified
+ * by name is returned.
+ * <p>
+ *
+ * @param authorURI -
+ * the authority to query
+ * @param name -
+ * the name of the service instance if applicable or null.
+ * @param useLSIDs
+ * whether or not we should include lsids
+ * @return a string representing either all of services defined by
+ * authorURI, (if name is null) or a single service instances' rdf
+ * if name and authorURI are valid. If name and/or authorURI are
+ * invalid an empty rdf document is returned.
+ */
+ public final String findService(String authorURI, String name, boolean useLSIDs) {
+ if (name == null || name.trim().equals("")) {
+ return (useLSIDs ? getAllServices(authorURI)
+ : getAllServices(authorURI, false));
+ } else {
+ return (useLSIDs ? getService(authorURI, name)
+ : getService(authorURI, name, false));
}
+ }
- public final static boolean serviceInstanceExists(String uri, String name, String lsid) {
- Central central = null;
- MobyService service = null;
- MobyService[] services = null;
- // initialize central
- try {
- central = getCentralImpl();
- } catch (MobyException e) {
- return false;
- }
- // set up the query service
- service = new MobyService(name);
- service.setCategory("");
- service.setAuthority(uri);
- // service.setLSID(lsid);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- return false;
- }
+ /**
+ *
+ * method that retrieves the RDF describing a specific service instance
+ * based on the parameters domain, serviceName.
+ * <p>
+ * <b>PRE: </b>None.
+ * <p>
+ * <b>POST: </b>The RDF describing the service with parameters domain,
+ * serviceName is created.
+ *
+ * @param domain -
+ * the authoring domain of the service instance in question.
+ * @param serviceName -
+ * the name of the service instance in question.
+ * @return - the string representation of the RDF describing the service
+ * instance based on the parameters given.
+ */
+ public final String findService(String domain, String serviceName) {
+ if (serviceName != null && !serviceName.trim().equals("")) {
+ // variables needed
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = null;
+ // initialize central
+ central = getCentralImpl();
+ // set up the query service
+ service = new MobyService(serviceName);
+ service.setAuthority(domain);
+ service.setCategory("");
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("Could not find service:\n" + e1.getMessage());
+ return empty;
+ }
+ // only one service should be returned!
+ if (services.length != 1)
+ return empty;
+ // get the rdf
+ String str = createRDF(services, true);
+ if (str == null)
+ return empty;
+ return str;
+ } else {
+ // servicename is null
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = getCentralImpl();
+ // set up the query service
+ service = new MobyService();
+ service.setAuthority(domain);
+ service.setCategory("");
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("Could not find service:\n" + e1.getMessage());
+ return empty;
+ }
+ // get the rdf
+ String str = createRDF(services, true);
+ if (str == null)
+ return empty;
+ return str;
+ }
+ }
- if (services.length == 1) {
- service = services[0];
- return (service.getLSID().equals(lsid));
- }
- return false;
+ /**
+ *
+ * method that retrieves the RDF describing a specific service instance
+ * based on the parameters domain, serviceName, url and uri.
+ * <p>
+ * <b>PRE: </b>None.
+ * <p>
+ * <b>POST: </b>The RDF describing the service with parameters domain,
+ * serviceName, url and uri is created.
+ *
+ * @param domain -
+ * the authoring domain of the service instance in question.
+ * @param serviceName -
+ * the name of the service instance in question.
+ * @param url -
+ * the URL of the endpoint of the BioMoby registry that you
+ * would like to query. If null, the mobycentral registry is
+ * queried.
+ * @param uri -
+ * the URI of the BioMoby registry that you would like to
+ * query. If null, the mobycentral registry is queried.
+ * @param useLSIDs -
+ * whether or not the returned RDF document should contain an
+ * LSID. Set this to false to retrieve RDF that service
+ * providers should have.
+ * @return - the string representation of the RDF describing the service
+ * instance based on the parameters given.
+ */
+ public final String findService(String domain, String serviceName,
+ String url, String uri, boolean useLSIDs) {
+ if (serviceName != null) {
+ // variables needed
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = null;
+ // initialize central
+ try {
+ central = new CentralImpl(url, uri);
+ } catch (MobyException e) {
+ log.error("Could not connect to " + url + " in findService.");
+ return empty;
+ }
+ // set up the query service
+ service = new MobyService(serviceName);
+ service.setCategory("");
+ service.setAuthority(domain);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("Could not find service:\n" + e1.getMessage());
+ return empty;
+ }
+ // only one service should be returned!
+ if (services.length != 1)
+ return empty;
+ // get the rdf
+ String str = createRDF(services, useLSIDs);
+ if (str == null)
+ return empty;
+ return str;
+ } else {
+ // servicename is null
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = null;
+ // initialize central
+ try {
+ central = new CentralImpl(url, uri);
+ } catch (MobyException e) {
+ log.error("Could not connect to " + url + " in findService.");
+ return empty;
+ }
+ // set up the query service
+ service = new MobyService();
+ service.setAuthority(domain);
+ service.setCategory("");
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("Could not find service:\n" + e1.getMessage());
+ return empty;
+ }
+ // get the rdf
+ String str = createRDF(services, useLSIDs);
+ if (str == null)
+ return empty;
+ return str;
}
+ }
- public final static String getLatestLSID(String uri, String name, String lsid) {
- Central central = null;
- MobyService service = null;
- MobyService[] services = null;
- // initialize central
- try {
- central = getCentralImpl();
- } catch (MobyException e) {
- return "";
- }
- // set up the query service
- service = new MobyService(name);
- service.setCategory("");
- service.setAuthority(uri);
- // query for the service
- try {
- services = central.findService(service);
- } catch (MobyException e1) {
- return "";
- }
- if (services.length == 1) {
- service = services[0];
- return (service.getLSID());
- }
- return "";
+ /*
+ * a method that retrieves all of the service instances based on an
+ * authoriy.
+ */
+ private final String getAllServices(String URI) {
+ // variables needed
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = getCentralImpl();
+ // set up the query service
+ service = new MobyService("");
+ service.setCategory("");
+ service.setAuthority(URI);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("error in getAllServices 2:\n" + e1.getMessage());
+ return empty;
+ }
+ // should have >= 1 service returned
+ if (services.length <= 0)
+ return empty;
+ // get the rdf
+ String str = createRDF(services, true);
+ if (str == null)
+ return empty;
+ return str;
+ }
+
+ /*
+ * a method that retrieves all of the service instances based on an
+ * authoriy.
+ */
+ private final String getAllServices(String URI,boolean useLSIDs) {
+ // variables needed
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = getCentralImpl();
+ // set up the query service
+ service = new MobyService("");
+ service.setCategory("");
+ service.setAuthority(URI);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("error in getAllServices 2:\n" + e1.getMessage());
+ return empty;
+ }
+ // should have >= 1 service returned
+ if (services.length <= 0)
+ return empty;
+ // get the rdf
+ String str = createRDF(services, useLSIDs);
+ if (str == null)
+ return empty;
+ return str;
+ }
+
+ /**
+ * @return
+ * @throws MobyException
+ */
+ private Central getCentralImpl() {
+ return this.central;
+ }
+
+ /*
+ * a method that retrieves a single service instance rdf document based on
+ * the URI and name of that service.
+ */
+ private final String getService(String URI, String name) {
+ // variables needed
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = getCentralImpl();
+
+ // set up the query service
+ service = new MobyService(name);
+ service.setCategory("");
+ service.setAuthority(URI);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("error in getService 2:\n" + e1.getMessage());
+ return empty;
+ }
+ // only one service should be returned!
+ if (services.length != 1)
+ return empty;
+ // get the rdf
+ String str = createRDF(services, true);
+ if (str == null)
+ return empty;
+ return str;
+ }
+
+ /*
+ * a method that retrieves a single service instance rdf document based on
+ * the URI and name of that service.
+ */
+ private final String getService(String URI, String name, boolean useLSIDs) {
+ // variables needed
+ MobyService service = null;
+ MobyService[] services = null;
+ Central central = getCentralImpl();
+
+ // set up the query service
+ service = new MobyService(name);
+ service.setCategory("");
+ service.setAuthority(URI);
+ // query for the service
+ try {
+ services = central.findService(service);
+ } catch (MobyException e1) {
+ log.error("error in getService 2:\n" + e1.getMessage());
+ return empty;
}
+ // only one service should be returned!
+ if (services.length != 1)
+ return empty;
+ // get the rdf
+ String str = createRDF(services, useLSIDs);
+ if (str == null)
+ return empty;
+ return str;
+ }
}
More information about the MOBY-guts
mailing list