diff --git a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java index 303e040573b34ce1223316cce5ca83771c0a73ba..19956142f344bc052185291d2364ee791beaec8d 100644 --- a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java +++ b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java @@ -23,21 +23,21 @@ package fr.inrialpes.exmo.align.service; import fr.inrialpes.exmo.align.parser.AlignmentParser; import fr.inrialpes.exmo.align.impl.Annotations; +import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; import fr.inrialpes.exmo.align.impl.Namespace; import fr.inrialpes.exmo.align.impl.BasicAlignment; import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.eval.DiffEvaluator; import fr.inrialpes.exmo.align.impl.rel.EquivRelation; - import fr.inrialpes.exmo.align.service.osgi.Service; - import fr.inrialpes.exmo.align.service.msg.Message; import fr.inrialpes.exmo.align.service.msg.AlignmentId; import fr.inrialpes.exmo.align.service.msg.AlignmentIds; import fr.inrialpes.exmo.align.service.msg.AlignmentMetadata; import fr.inrialpes.exmo.align.service.msg.EntityList; import fr.inrialpes.exmo.align.service.msg.EvalResult; +import fr.inrialpes.exmo.align.service.msg.OntologyNetworkId; import fr.inrialpes.exmo.align.service.msg.OntologyURI; import fr.inrialpes.exmo.align.service.msg.RenderedAlignment; import fr.inrialpes.exmo.align.service.msg.TranslatedMessage; @@ -46,10 +46,11 @@ import fr.inrialpes.exmo.align.service.msg.NonConformParameters; import fr.inrialpes.exmo.align.service.msg.RunTimeError; import fr.inrialpes.exmo.align.service.msg.UnknownAlignment; import fr.inrialpes.exmo.align.service.msg.UnknownMethod; +import fr.inrialpes.exmo.align.service.msg.UnknownOntologyNetwork; import fr.inrialpes.exmo.align.service.msg.UnreachableAlignment; import fr.inrialpes.exmo.align.service.msg.UnreachableOntology; import fr.inrialpes.exmo.align.service.msg.CannotRenderAlignment; - +import fr.inrialpes.exmo.align.service.msg.UnreachableOntologyNetwork; import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; @@ -60,7 +61,7 @@ import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Evaluator; - +import org.semanticweb.owl.align.OntologyNetwork; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -73,7 +74,9 @@ import java.lang.UnsatisfiedLinkError; import java.lang.ExceptionInInitializerError; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.FileNotFoundException; import java.io.InputStream; import java.io.OutputStream; import java.io.FileOutputStream; @@ -83,6 +86,7 @@ import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.IOException; import java.io.File; +import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URL; import java.net.JarURLConnection; @@ -209,11 +213,39 @@ public class AServProtocolManager implements Service { public Collection<URI> ontologies() { return alignmentCache.ontologies(); } - + + public Collection<URI> networkOntologyUri(String uri) { + OntologyNetwork noo = null; + try { + noo = alignmentCache.getOntologyNetwork(uri); + } catch (AlignmentException e) { + e.printStackTrace(); + } + return ((BasicOntologyNetwork) noo).getOntologies(); + } + + public Set<Alignment> networkAlignmentUri(String uri) { + OntologyNetwork noo = null; + try { + noo = alignmentCache.getOntologyNetwork(uri); + } catch (AlignmentException e) { + e.printStackTrace(); + } + return ((BasicOntologyNetwork) noo).getAlignments(); + } + public Collection<Alignment> alignments( URI uri1, URI uri2 ) { return alignmentCache.alignments( uri1, uri2 ); } + + public Collection<URI> ontologyNetworkUris() { + return ((VolatilCache) alignmentCache).ontologyNetworkUris(); + } + public Collection<OntologyNetwork> ontologyNetworks() { + return alignmentCache.ontologyNetworks(); + } + public String query( String query ){ //return alignmentCache.query( query ); return "Not available yet"; @@ -1173,5 +1205,188 @@ public class AServProtocolManager implements Service { } } + //* Ontology Networks */ + public Message loadonet( Properties params ) { + + // load the ontology network + String name = params.getProperty("url"); + String file = null; + if ( name == null || name.equals("") ){ + file = params.getProperty("filename"); + if ( file != null && !file.equals("") ) name = "file://"+file; + } + logger.trace("Preparing for loading {}", name); + BasicOntologyNetwork noo = null; + try { + noo = (BasicOntologyNetwork) BasicOntologyNetwork.read( name ); + logger.trace(" Ontology network parsed"); + } catch (Exception e) { + return new UnreachableOntologyNetwork( params, newId(), serverId, name ); + } + // We preserve the pretty tag within the loaded ontology network + String pretty = noo.getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); + if ( pretty == null ) pretty = params.getProperty("pretty"); + if ( pretty != null && !pretty.equals("") ) { + noo.setExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY, pretty ); + } + // register it + String id = alignmentCache.recordNewNetwork( noo, true ); + logger.debug(" Ontology network loaded, id: {} total ontologies: {} total alignments: {}",id, noo.getOntologies().size(),noo.getAlignments().size()); + + //=== The alignment has the id of the source file (e.g. file:///path/FileName.rdf) + Set<Alignment> networkAlignments = networkAlignmentUri(id); + for (Alignment al : networkAlignments) { + String idAl = alignmentCache.recordNewAlignment( al, true ); + } + + return new OntologyNetworkId( params, newId(), serverId, id ,pretty ); + } + + + public Message renderonet(Properties params) { + + OntologyNetwork noo = null; + noo = new BasicOntologyNetwork(); + String id = params.getProperty( "id" ); + try { + noo = alignmentCache.getOntologyNetwork(id); + } catch (AlignmentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + BasicOntologyNetwork newnoo = (BasicOntologyNetwork)noo; + newnoo.setIndentString( "" ); + newnoo.setNewLineString( "" ); + // Print it in a string + ByteArrayOutputStream result = new ByteArrayOutputStream(); + PrintWriter writer = null; + try { + writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( result, "UTF-8" )), true); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + newnoo.write( writer ); + } catch (AlignmentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + writer.flush(); + writer.close(); + } + return new RenderedAlignment( params, newId(), serverId, result.toString() ); //or RenderedOntologyNetwork + + } + + + + public boolean storedOntologyNetwork( Properties params ) { + // Retrieve the ontology network + String id = params.getProperty("id"); + OntologyNetwork noo = null; + try { + noo = alignmentCache.getOntologyNetwork( id ); + } catch (Exception e) { + return false; + } + return alignmentCache.isNetworkStored( noo ); + } + + + public Message storeonet( Properties params ) { + String id = params.getProperty("id"); + OntologyNetwork noo = null; + try { + noo = alignmentCache.getOntologyNetwork( id ); + // Be sure it is not already stored + if ( !alignmentCache.isNetworkStored(noo) ) { + try { + alignmentCache.storeOntologyNetwork( id ); + } catch (AlignmentException e) { + return new UnknownOntologyNetwork( params, newId(), serverId,id ); + } + return new OntologyNetworkId( params, newId(), serverId, id, + ((BasicOntologyNetwork) noo).getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY )); + } else { + return new ErrorMsg( params, newId(), serverId,"Network already stored" ); + } + } catch (Exception e) { + return new UnknownOntologyNetwork( params, newId(), serverId,id ); + } + + } + + private Message retrieveAlignmentON( Properties params, URI uri1, URI uri2 ){ + String method = params.getProperty("method"); + + Set<Alignment> alignments = alignmentCache.getAlignments( uri1, uri2 ); + if ( alignments != null && params.getProperty("force") == null ) { + for ( Alignment al: alignments ){ + String meth2 = al.getExtension( Namespace.ALIGNMENT.uri, Annotations.METHOD ); + if ( meth2 != null && meth2.equals(method) ) { + return new AlignmentId( params, newId(), serverId, + al.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ) , + al.getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ) ); + } + } + } + return (Message)null; + } + + public Message alignonet( Properties params ) { + Message result = null; + //not finished + //parameters: onID, method, reflexive, symmetric + for ( Enumeration<String> e = (Enumeration<String>)commandLineParams.propertyNames(); e.hasMoreElements();) { + String key = e.nextElement(); + if ( params.getProperty( key ) == null ){ + params.setProperty( key , commandLineParams.getProperty( key ) ); + } + } + //prepare for + String id = params.getProperty("id"); + Boolean reflexive = false; + if (params.getProperty("reflexive") != null) reflexive = true; + Boolean symmetric = false; + if (params.getProperty("symmetric") != null) symmetric = true; + + Collection<URI> networkOntologyA = networkOntologyUri(id); + Collection<URI> networkOntologyB = networkOntologyUri(id); + for ( URI ontoA : networkOntologyA ) { + for ( URI ontoB : networkOntologyB ) { + result = retrieveAlignmentON( params ,ontoA, ontoB); + if ( result != null ) return result; + } + } + return (Message)null; + + } + + public Message listNetworkOntology( Properties params ) { //not UsED?? + String result = ""; + + OntologyNetwork noo = null; + noo = new BasicOntologyNetwork(); + String id = params.getProperty( "id" ); + //URI onto2 = null; + + try { + noo = alignmentCache.getOntologyNetwork(id); + noo.getOntologies().size(); + Iterator<URI> iterator2 = noo.getOntologies().iterator(); + while (iterator2.hasNext()){ + URI onto2 = (URI) iterator2.next(); + result += "<li><a href=\""+onto2+"\">"+onto2+"</a></li>"; + } + return new OntologyNetworkId( params, newId(), serverId, id ,result ); + } catch (AlignmentException e) { + return new UnknownOntologyNetwork( params, newId(), serverId, id ); + } + } + } diff --git a/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java b/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java index 2e6c2376fd963c0f37e324808d4628312bb8c9d0..8cf64653321dde5edf860faa04eb58496f496036 100644 --- a/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java +++ b/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java @@ -21,14 +21,18 @@ package fr.inrialpes.exmo.align.service; import fr.inrialpes.exmo.align.impl.Annotations; +import fr.inrialpes.exmo.align.impl.BasicOntologyNetwork; import fr.inrialpes.exmo.align.impl.Namespace; import fr.inrialpes.exmo.align.service.msg.Message; import fr.inrialpes.exmo.align.service.msg.ErrorMsg; import fr.inrialpes.exmo.align.service.msg.AlignmentId; import fr.inrialpes.exmo.align.service.msg.AlignmentIds; import fr.inrialpes.exmo.align.service.msg.EvaluationId; +import fr.inrialpes.exmo.align.service.msg.OntologyNetworkId; +import fr.inrialpes.exmo.align.service.msg.UnknownOntologyNetwork; import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.OntologyNetwork; import java.io.File; import java.io.FileReader; @@ -42,8 +46,8 @@ import java.io.ByteArrayInputStream; import java.io.OutputStream; import java.io.BufferedInputStream; import java.io.FileOutputStream; - import java.util.Locale; +import java.util.Set; import java.util.TimeZone; import java.util.Hashtable; import java.util.Properties; @@ -52,10 +56,8 @@ import java.util.Date; import java.util.Enumeration; import java.util.Iterator; import java.util.Map; - import java.net.URI; import java.net.URISyntaxException; - import java.lang.Integer; import org.slf4j.Logger; @@ -83,7 +85,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } public boolean accept( String prefix ) { - if ( prefix.equals("admin") || prefix.equals("html") ) return true; + if ( prefix.equals("admin") || prefix.equals("html") || prefix.equals("ontonet")) return true; else return false; } @@ -92,7 +94,9 @@ public class HTMLAServProfile implements AlignmentServiceProfile { return htmlAnswer( uri, perf, header, params ); } else if ( prefix.equals("admin") ) { return adminAnswer( uri, perf, header, params ); - } else return about(); + } else if ( prefix.equals("ontonet") ) { + return ontologyNetworkAnswer( uri, perf, header, params ); + }else return about(); } public void close(){ @@ -182,6 +186,270 @@ public class HTMLAServProfile implements AlignmentServiceProfile { return "<html><head>"+HEADER+"</head><body>"+msg+"<hr /><center><small><a href=\".\">Alignment server administration</a></small></center></body></html>"; } + + /** + * HTTP ontology networks interface + * Allows the ontology networks management through HTTP + */ + public String ontologyNetworkAnswer( String uri, String perf, Properties header, Properties params ) { + logger.trace( "ONTONET[{}]", perf); + String msg = ""; + String eSource = "on"; + if ( perf.equals("prmlistonet") ){ + URI uriON = null; + String uON = params.getProperty("uri"); + try { + if ( uON != null && !uON.equals("all") ) uriON = new URI( uON ); + } catch ( URISyntaxException usex ) { + logger.debug( "IGNORED Invalid URI parameter", usex ); + }; + + Collection<URI> ontologyNetworksURI = manager.ontologyNetworkUris(); + msg = "<h1>Available networks</h1>"; + msg += "<form action=\"listNetOnto\">"; + msg += "Network: <select name=\"uri\"><option value=\"all\">all</option>"; + if ( uriON == null ) msg += " selected=\"1\""; + for ( URI onet : ontologyNetworksURI ) { + msg += "<option"; + if ( onet.equals( uriON ) ) msg += " selected =\"1\""; + msg += " value=\""+onet+"\">"+onet+"</option>"; + } + msg += "</select>"; + msg += " <input type=\"submit\" value=\"List ontologies\"/></form><ul compact=\"1\">"; + //msg += "<table><tr><td><input type=\"submit\" value=\"List ontologies\"name=\"listNetOnto\"/></form>"; + //msg += "<input type=\"submit\" value=\"List alignments\"/ name=\"listNetAlig\"></form></td></tr></table/>"; + + } else if ( perf.equals("listNetOnto") ){ + + msg = "<h1>Ontologies of the Network</h1>"; + msg += "<form action=\"listNetAlig\">"; + String uriON = params.getProperty("uri"); //send as parameter uriON for listNetAlig + int numOnto = 0; + Collection<URI> networkOntology = manager.networkOntologyUri(uriON); + msg += "<p>" + uriON + " "; + msg += " <input type=\"submit\" value=\"List alignments\"/></form><ul compact=\"1\"></p>"; + msg += "<p><tr><th><b>Total ontologies: </b>" + networkOntology.size() + "</th></tr></p>"; + for ( URI onto : networkOntology ) { + numOnto ++; + msg += "<li><a href=\""+onto.toString()+"\"> ("+String.format("%05d", numOnto)+") "+onto.toString()+"</a></li>"; + } + //msg += " <input type=\"submit\" value=\"List alignments\"/></form><ul compact=\"1\">"; + + } else if ( perf.equals("listNetAlig") ){ + + msg = "<h1>Alignments of the Network</h1>"; + String uriON = params.getProperty("uri"); + Set<Alignment> networkAlignments = manager.networkAlignmentUri(uriON); + int numAlig = 0; + msg += "<p>" + uriON + "</p>"; + msg += "<p><tr><th><b>Total alignments: </b>" + networkAlignments.size() + "</th></tr></p>"; + for (Alignment al : networkAlignments) { + numAlig ++; + msg += " <li><a href=\""+"idAlign" + "\"> ("+String.format("%05d", numAlig)+") " +"idAlign:"+"</a> "+ al.getFile1() + " " + al.getFile2() + "</li>"; + } + + } else if ( perf.equals("prmloadonet") ){ + //TODO add two more parameters TYPE of file (json/html, etc) and STRUCTURE of the file + msg = "<h1>Load an ontology network</h1>"; + msg += "<form action=\"loadonet\">"; + msg += "Network URL: <input type=\"text\" name=\"url\" size=\"80\"/><br />"; + msg += "<small>This is the URL of ontology network. It must be reachable by the server (i.e., file://localhost/absolutePathTo/file or file:///absolutePathTo/file if localhost omitted)</small><br />"; + msg += "Pretty name: <input type=\"text\" name=\"pretty\" size=\"80\"/><br />"; + msg += "<input type=\"submit\" value=\"Load\"></form>"; + msg += "Ontology network file: <form enctype=\"multipart/form-data\" action=\"loadonet\" method=\"POST\">"; + msg += "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\""+MAX_FILE_SIZE+"\"/>"; + msg += "<input name=\"content\" type=\"file\" size=\"35\"><br />"; + msg += "Pretty name: <input type=\"text\" name=\"pretty\" size=\"80\"/><br />"; + msg += "<input type=\"submit\" Value=\"Upload\">"; + msg += " </form>"; + } else if ( perf.equals("loadonet") ) { + + Message answer = manager.loadonet( params ); + if ( answer instanceof ErrorMsg ) { + msg = testErrorMessages( answer, params, eSource ); + } else { + msg = "<h1>Ontology Network loaded</h1>"; + msg += displayAnswerON( answer, params ); + } + } else if ( perf.equals("storeonet") ){ + + // here should be done the switch between store and load/store + String id = params.getProperty("id"); + String url = params.getProperty("url"); + if ( url != null && !url.equals("") ) { + Message answer = manager.loadonet( params ); + if ( answer instanceof ErrorMsg ) { + msg = testErrorMessages( answer, params, eSource ); + } else { + id = answer.getContent(); + } + } + if ( id != null ){ // Store it + Message answer = manager.storeonet( params ); + if ( answer instanceof ErrorMsg ) { + msg = testErrorMessages( answer, params, eSource ); + } else { + msg = "<h1>Ontology Network stored</h1>"; + msg += displayAnswer( answer, params ); + } + } + + } else if ( perf.equals("listonet") ){ + /* to be done + + msg = "<h1>Ontology Network listed</h1>"; + //msg += manager.listONetwork(params); + msg += "onet"; + Collection<OntologyNetworkSet> onsV = manager.ontologyNetworkSetV(); + Object onetwork = manager.onetworksT(); //send parameter uri + + msg += "<p><b>URI :</b>"+ onsV.getValue() +"<br>"; + //msg += "<p><b>URI :</b>"+ onetwork.toString() +"<br>"; //falta un getName + //msg += "<b>Name :</b>"+ onetwork.toString()+"<br>"; + + Hashtable<URI,NetOntology<Object>> oonetworkTable = manager.oonetworksT(); + + msg += "<tr><th><b>Total ontologies :</b>"+ oonetworkTable.size()+"</th></tr></p>"; + msg += "<table><tr><th>URI(ID)</th><th>NAME</th><th>FILE</th></tr>"; + Set<Entry<URI, NetOntology<Object>>> set = oonetworkTable.entrySet(); + Iterator<Entry<URI, NetOntology<Object>>> it = set.iterator(); + + while (it.hasNext()) { + Map.Entry<URI, NetOntology<Object>> entry = (Map.Entry<URI, NetOntology<Object>>) it.next(); + NetOntology<Object> oonetwork = entry.getValue(); + oonetwork.getFile(); + msg += "<tr><td>" + entry.getKey() + "</td><td>" + oonetwork.getName() + "</td><td>" + oonetwork.getFile() + "</td></tr>"; + //msg += "<tr><td>" + entry.getKey() + "</td><td>" + oonetwork.oonName + "</td><td>" + oonetwork.oonFile + "</td></tr>"; + + } + + msg += "</table>"; + //msg += displayAnswerON( answer, params ); + //msg += displayAnswerON( (Message)null, params ); + //} + * + */ + } else if ( perf.equals("prmstoreonet") ){ + + String sel = params.getProperty("id"); + msg = "<h1>Store an ontology network</h1><form action=\"storeonet\">"; + msg += "Network: <select name=\"id\">"; + for ( OntologyNetwork on : manager.ontologyNetworks() ) { + String id = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); //TODO eliminate BasicOntologyNetwork + String pid = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); //TODO eliminate BasicOntologyNetwork + if ( pid == null ) pid = id; else pid = id+" ("+pid+")"; + if ( sel != null && sel.equals( id ) ){ + msg += "<option selected=\"1\" value=\""+id+"\">"+pid+"</option>"; + } else { msg += "<option value=\""+id+"\">"+pid+"</option>";} + } + msg += "</select><br />"; + msg += "<br /><input type=\"submit\" value=\"Store\"/></form>"; + + } else if ( perf.equals("prmmatchonet") ){ + + msg = "<h1>Match an ontology network</h1><form action=\"matchonet\">"; + msg += "Network: <select name=\"id\">"; + String sel = params.getProperty("id"); + for ( OntologyNetwork on : manager.ontologyNetworks() ) { + String id = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); //TODO eliminate BasicOntologyNetwork + String pid = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); //TODO eliminate BasicOntologyNetwork + if ( pid == null ) pid = id; else pid = id+" ("+pid+")"; + if ( sel != null && sel.equals( id ) ){ + msg += "<option selected=\"1\" value=\""+id+"\">"+pid+"</option>"; + } else { msg += "<option value=\""+id+"\">"+pid+"</option>";} + } + msg += "<!--input type=\"submit\" name=\"action\" value=\"Find\"/>"; + msg += "<br /-->Methods: <select name=\"method\">"; + + for( String idMethod : manager.listmethods() ) { + msg += "<option value=\""+idMethod+"\">"+idMethod+"</option>"; + } + + msg += "</select><br />"; + msg += "<input type=\"checkbox\" name=\"reflexive\" /> Reflexive "; + msg += "<input type=\"checkbox\" name=\"symmetric\" /> Symmetric "; + msg += "<input type=\"checkbox\" name=\"new\" /> New "; + msg += "<br /><input type=\"submit\" name=\"action\" value=\"Match\"/> "; + + } else if ( perf.equals("matchonet") ) { + // DO MATCHING + Message answer = manager.alignonet( params ); + if ( answer instanceof ErrorMsg ) { + msg = testErrorMessages( answer, params, eSource ); + } else { + msg = "<h1>Network Alignments results</h1>"; + msg += displayAnswer( answer, params ); + } + + } else if ( perf.equals("prmretreiveonet") ){ + + + String sel = params.getProperty("id"); + msg = "<h1>Retrieve ontology network</h1><form action=\"retrieveonet\">"; + msg += "Network: <select name=\"id\">"; + for ( OntologyNetwork on : manager.ontologyNetworks() ) { + String id = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); //TODO eliminate BasicOntologyNetwork + String pid = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); //TODO eliminate BasicOntologyNetwork + if ( pid == null ) pid = id; else pid = id+" ("+pid+")"; + if ( sel != null && sel.equals( id ) ){ + msg += "<option selected=\"1\" value=\""+id+"\">"+pid+"</option>"; + } else { msg += "<option value=\""+id+"\">"+pid+"</option>";} + } + msg += "</select><br />"; + msg += "<br /><input type=\"submit\" value=\"Retrieve\"/></form>"; + + } else if ( perf.equals("retrieveonet") ) { + + Message answer = manager.renderonet( params ); + if ( answer instanceof ErrorMsg ) { + msg = testErrorMessages( answer, params, eSource ); + } else { + // Depending on the type we should change the MIME type + //return answer.getContent().replaceAll("&", "&").replaceAll("<", "<"); + return answer.getContent(); + } + + + + + + } else if ( perf.equals("prmcloseonet") ){ + + msg = "<h1>Close an ontology network</h1><form action=\"matchonet\">"; + msg += "Network: <select name=\"id\">"; + String sel = params.getProperty("id"); + for ( OntologyNetwork on : manager.ontologyNetworks() ) { + String id = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); //TODO eliminate BasicOntologyNetwork + String pid = ((BasicOntologyNetwork)on).getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); //TODO eliminate BasicOntologyNetwork + if ( pid == null ) pid = id; else pid = id+" ("+pid+")"; + if ( sel != null && sel.equals( id ) ){ + msg += "<option selected=\"1\" value=\""+id+"\">"+pid+"</option>"; + } else { msg += "<option value=\""+id+"\">"+pid+"</option>";} + } + + msg += "</select><br />"; + msg += "<input type=\"submit\" name=\"action\" value=\"Invert\" /> "; + msg += "<input type=\"submit\" name=\"action\" value=\"Compose\"/> "; + msg += "<input type=\"checkbox\" name=\"new\" /> New "; + + } else if ( perf.equals("prmresetonet") ){ + + } else if ( perf.equals("") ) { + msg = "<h1>Ontology Network commands</h1>"; + msg += "<form action=\"prmlistonet\"><button title=\"List networks stored in the server\" type=\"submit\">Available networks</button></form>"; + msg += "<form action=\"prmloadonet\"><button title=\"Load a network from a valid source\" type=\"submit\">Load a network</button></form>"; + msg += "<form action=\"prmstoreonet\"><button title=\"Store a network in the server\" type=\"submit\">Store network</button></form>"; + msg += "<form action=\"prmmatchonet\"><button title=\"Match an ontology network\" type=\"submit\">Match network </button></form>"; + msg += "<form action=\"prmretreiveonet\"><button title=\"Render an ontology network in a particular format\" type=\"submit\">Render network</button></form>"; + msg += "<form action=\"prmcloseonet\"><button title=\"Close an ontology network\" type=\"submit\">Close network</button></form>"; + msg += "<form action=\"prmresetonet\"><button title=\"Reset an ontology network\" type=\"submit\">Reset network</button></form>"; + msg += "<form action=\"../html/\"><button style=\"background-color: lightpink;\" title=\"Back to user menu\" type=\"submit\">User interface</button></form>"; + } else { + msg = "Cannot understand: "+perf; + } + return "<html><head>"+HEADER+"</head><body>"+msg+"<hr /><center><small><a href=\".\">Ontology Networks Management</a></small></center></body></html>"; + } + /** * User friendly HTTP interface * uses the protocol but offers user-targeted interaction @@ -190,6 +458,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { //logger.trace("HTML[{}]", perf ); // REST get String msg = ""; + String eSource = "al"; if ( perf.equals("listalignments") ) { URI uri1 = null; String u1 = params.getProperty("uri1"); @@ -243,7 +512,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { msg += "<li><a href=\""+id+"\">"+pid+"</a></li>"; } msg += "</ul>"; - } else if ( perf.equals("manalignments") ){ // Manage ailignments + } else if ( perf.equals("manalignments") ){ // Manage alignments msg = "<h1>Available alignments</h1><ul compact=\"1\">"; for ( Alignment al : manager.alignments() ) { String id = al.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); @@ -258,7 +527,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { if ( id != null && !id.equals("") ) { // Erase it Message answer = manager.erase( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Alignment deleted</h1>"; msg += displayAnswer( answer, params ); @@ -286,7 +555,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { if ( url != null && !url.equals("") ) { // Load the URL Message answer = manager.load( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { id = answer.getContent(); } @@ -294,7 +563,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { if ( id != null ){ // Store it Message answer = manager.store( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Alignment stored</h1>"; msg += displayAnswer( answer, params ); @@ -322,7 +591,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { if ( id != null && !id.equals("") && threshold != null && !threshold.equals("") ){ // Trim it Message answer = manager.trim( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Alignment trimed</h1>"; msg += displayAnswer( answer, params ); @@ -344,7 +613,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { if ( id != null && !id.equals("") ){ // Invert it Message answer = manager.inverse( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Alignment inverted</h1>"; msg += displayAnswer( answer, params ); @@ -381,7 +650,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } else if ( perf.equals("match") ) { Message answer = manager.align( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Alignment results</h1>"; msg += displayAnswer( answer, params ); @@ -391,7 +660,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } else if ( perf.equals("find") ) { Message answer = manager.existingAlignments( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Found alignments</h1>"; msg += displayAnswer( answer, params ); @@ -399,7 +668,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } else if ( perf.equals("corresp") ) { Message answer = manager.findCorrespondences( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Found correspondences</h1>"; msg += displayAnswer( answer, params ); @@ -425,13 +694,15 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } msg += "</select><br /><input type=\"submit\" value=\"Retrieve\"/></form>"; } else if ( perf.equals("retrieve") ) { + Message answer = manager.render( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { // Depending on the type we should change the MIME type // This should be returned in answer.getParameters() return answer.getContent(); + } // Metadata not done yet } else if ( perf.equals("prmmetadata") ) { @@ -452,7 +723,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { Message answer = manager.render( params ); //logger.trace( "Content: {}", answer.getContent() ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { // Depending on the type we should change the MIME type return answer.getContent(); @@ -474,7 +745,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { // load Message answer = manager.load( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Alignment loaded</h1>"; msg += displayAnswer( answer, params ); @@ -493,7 +764,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } else if ( perf.equals("translate") ) { Message answer = manager.translate( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Message translation</h1>"; msg += "<h2>Initial message</h2><pre>"+(params.getProperty("query")).replaceAll("&", "&").replaceAll("<", "<")+"</pre>"; @@ -531,7 +802,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } else if ( perf.equals("eval") ) { Message answer = manager.eval( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Evaluation results</h1>"; msg += displayAnswer( answer, params ); @@ -567,7 +838,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } else if ( perf.equals("diff") ) { Message answer = manager.diff( params ); if ( answer instanceof ErrorMsg ) { - msg = testErrorMessages( answer, params ); + msg = testErrorMessages( answer, params, eSource ); } else { msg = "<h1>Comparison results</h1>"; msg += displayAnswer( answer, params ); @@ -586,6 +857,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { msg += "<form action=\"prmeval\"><button title=\"Evaluation of an alignment\" type=\"submit\">Evaluate alignment</button></form>"; msg += "<form action=\"prmdiff\"><button title=\"Compare two alignments\" type=\"submit\">Compare alignment</button></form>"; msg += "<form action=\"../admin/\"><button style=\"background-color: lightpink;\" title=\"Server management functions\" type=\"submit\">Server management</button></form>"; + msg += "<form action=\"../ontonet/\"><button style=\"background-color: lightgreen;\" title=\"Ontology Networks commands\" type=\"submit\">Ontology Networks</button></form>"; } else { msg = "Cannot understand command "+perf; } @@ -595,15 +867,22 @@ public class HTMLAServProfile implements AlignmentServiceProfile { // =============================================== // Util - private String testErrorMessages( Message answer, Properties param ) { + private String testErrorMessages( Message answer, Properties param, String errorSource ) { /* if ( returnType == HTTPResponse.MIME_RDFXML ) { return answer.RESTString(); } else if ( returnType == HTTPResponse.MIME_JSON ) { - return answer.JSONString(); + return answer.JSONString();render + } else {*/ - return "<h1>Alignment error</h1>"+answer.HTMLString(); +// return "<h1>Alignment error</h1>"+answer.HTMLString(); /*}*/ + + switch (errorSource) { + case "al": return "<h1>Alignment error</h1>"+answer.HTMLString(); + case "on": return "<h1>Ontology Network error</h1>"+answer.HTMLString(); + default: return "<h1>Not know error source</h1>"+answer.HTMLString(); + } } private String displayAnswer( Message answer, Properties param ) { @@ -621,7 +900,7 @@ public class HTMLAServProfile implements AlignmentServiceProfile { result += "<td><form action=\"metadata\"><input type=\"hidden\" name=\"id\" value=\""+answer.getContent()+"\"/><input type=\"submit\" name=\"action\" value=\"Metadata\"/></form></td>"; result += "</tr></table>"; } else if( answer instanceof AlignmentIds && ( answer.getParameters() == null || answer.getParameters().getProperty("async") == null )) { - result = answer.HTMLRESTString(); + result = answer.HTMLRESTString(); } } else { result = answer.RESTString(); @@ -653,6 +932,43 @@ public class HTMLAServProfile implements AlignmentServiceProfile { } return result; } + + private String displayAnswerON( Message answer, Properties param ) { + return displayAnswerON( answer, param, null ); + } + + private String displayAnswerON( Message answer, Properties param, String returnType ) { + String result = null; + if ( returnType == HTTPResponse.MIME_RDFXML ) { + if( param.getProperty("return").equals("HTML") ) { // RESTFUL but in HTML ?? + result = answer.HTMLRESTString(); + if ( answer instanceof OntologyNetworkId && ( answer.getParameters() == null || answer.getParameters().getProperty("async") == null ) ) { + result += "<table><tr>"; + result += "<td><form action=\"getID\"><input type=\"hidden\" name=\"id\" value=\""+answer.getContent()+"\"/><input type=\"submit\" name=\"action\" value=\"GetID\" disabled=\"disabled\"/></form></td>"; + result += "<td><form action=\"metadata\"><input type=\"hidden\" name=\"id\" value=\""+answer.getContent()+"\"/><input type=\"submit\" name=\"action\" value=\"Metadata\"/></form></td>"; + result += "</tr></table>"; + //} else if( answer instanceof OntologyNetworkIds && ( answer.getParameters() == null || answer.getParameters().getProperty("async") == null )) { //TODO is it needed??create public class OntologyNetworkIds extends Success { + result = answer.HTMLRESTString(); + } + } else { + result = answer.RESTString(); + } + } else if ( returnType == HTTPResponse.MIME_JSON ) { + result = answer.JSONString(); + } else { + result = answer.HTMLString(); + // Improved return + if ( answer instanceof OntologyNetworkId && ( answer.getParameters() == null || answer.getParameters().getProperty("async") == null ) ){ + result += "<table><tr>"; + // STORE ONTOLOGY NETWORK + result += "<td><form action=\"storeonet\"><input type=\"hidden\" name=\"id\" value=\""+answer.getContent()+"\"/><input type=\"submit\" name=\"action\" value=\"Store\"/></form></td>"; + // RETREIVE ONTOLOGY NETWORK + result += "<td><form action=\"prmretreiveonet\"><input type=\"hidden\" name=\"id\" value=\""+answer.getContent()+"\"/><input type=\"submit\" name=\"action\" value=\"Show\"/></form></td>"; + result += "</tr></table>"; + } + } + return result; + } } diff --git a/src/fr/inrialpes/exmo/align/service/msg/OntologyNetworkId.java b/src/fr/inrialpes/exmo/align/service/msg/OntologyNetworkId.java new file mode 100644 index 0000000000000000000000000000000000000000..d4c80c16b36d7e1544086e460399442ac78afbc5 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/service/msg/OntologyNetworkId.java @@ -0,0 +1,72 @@ +/* + * $Id: OntologyNetworkId.java 1905 2014-03-21 09:12:16Z euzenat $ + * + * Copyright (C) INRIA, 2006-2009, 2011, 2013-2014 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package fr.inrialpes.exmo.align.service.msg; + +import java.util.Properties; + +/** + * Contains the messages that should be sent according to the protocol + */ + +public class OntologyNetworkId extends Success { + + String pretty = null; + + public OntologyNetworkId ( int surr, Message rep, String from, String to, String cont, Properties param ) { + super( surr, rep, from, to, cont, param ); + } + + public OntologyNetworkId ( int surr, Message rep, String from, String to, String cont, Properties param, String pretty ) { + super( surr, rep, from, to, cont, param ); + this.pretty = pretty; + } + + public OntologyNetworkId ( Properties mess, int surr, String from, String cont, String pretty) { + super( mess, surr, from, cont ); + this.pretty = pretty; + } + + public OntologyNetworkId ( Properties mess, int surr, String from, String cont ) { + super( mess, surr, from, cont ); + } + + public String getPretty( String ontonet ) { + if ( pretty == null ) { + return ontonet; + } else { + return ontonet+" ("+pretty+")"; + } + }; + public String HTMLString(){ + //return "Alignment ID: <a href=\"../html/retrieve?method=fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor&id="+getContent()+"\">"+getPretty(getContent())+"</a> "; + return "Ontology Network ID: <a href=\""+getContent()+"\">"+getPretty(getContent())+"</a> "; + } + public String HTMLRESTString(){ + return "Ontology Network ID: <a href=\"../rest/retrieve?method=fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor&id="+getContent()+"\">"+getPretty(getContent())+"</a> "; + } + public String RESTString(){ + return "<alid>"+content+"</alid>"; + } + public String JSONString(){ + return "\""+content+"\""; + } + +} \ No newline at end of file diff --git a/src/fr/inrialpes/exmo/align/service/msg/UnknownOntologyNetwork.java b/src/fr/inrialpes/exmo/align/service/msg/UnknownOntologyNetwork.java new file mode 100644 index 0000000000000000000000000000000000000000..d9ae0ec49eb8de55c885ae993cc4b8e5f585cee6 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/service/msg/UnknownOntologyNetwork.java @@ -0,0 +1,47 @@ +/* + * $Id: UnknownAlignment.java 1905 2014-03-21 09:12:16Z euzenat $ + * + * Copyright (C) INRIA, 2006-2009, 2011, 2014 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package fr.inrialpes.exmo.align.service.msg; + +import java.util.Properties; + +/** + * Contains the messages that should be sent according to the protocol + */ + +public class UnknownOntologyNetwork extends ErrorMsg { + public UnknownOntologyNetwork ( int surr, Message rep, String from, String to, String cont, Properties param ) { + super( surr, rep, from, to, cont, param ); + } + + public UnknownOntologyNetwork ( Properties mess, int surr, String from, String cont ) { + super( mess, surr, from, cont ); + } + + public String RESTString(){ + return "<UnknownOntologyNetwork>"+getXMLContent()+"</UnknownAlignment>"; + } + public String HTMLString(){ + return "Unknown ontology network: "+content; + } + public String JSONString(){ + return "{ \"type\" : \"UnknownOntologyNetwork\",\n \"content\" : \""+getJSONContent()+"\"\n}"; + } +} diff --git a/src/fr/inrialpes/exmo/align/service/msg/UnreachableOntologyNetwork.java b/src/fr/inrialpes/exmo/align/service/msg/UnreachableOntologyNetwork.java new file mode 100644 index 0000000000000000000000000000000000000000..0e416c625d717ac2b81a9c8474c414aaacde48e9 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/service/msg/UnreachableOntologyNetwork.java @@ -0,0 +1,47 @@ +/* + * $Id: UnreachableAlignment.java 1905 2014-03-21 09:12:16Z euzenat $ + * + * Copyright (C) INRIA, 2006-2009, 2011, 2014 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package fr.inrialpes.exmo.align.service.msg; + +import java.util.Properties; + +/** + * Contains the messages that should be sent according to the protocol + */ + +public class UnreachableOntologyNetwork extends ErrorMsg { + public UnreachableOntologyNetwork ( int surr, Message rep, String from, String to, String cont, Properties param ) { + super( surr, rep, from, to, cont, param ); + } + + public UnreachableOntologyNetwork ( Properties mess, int surr, String from, String cont ) { + super( mess, surr, from, cont ); + } + + public String RESTString() { + return "<UnreachableOntologyNetwork>"+getXMLContent()+"</UnreachableOntologyNetwork>"; + } + public String HTMLString() { + return "Unreachable ontology network: "+content; + } + public String JSONString(){ + return "{ \"type\" : \"UnreachableOntologyNetwork\",\n \"content\" : \""+getJSONContent()+"\"\n}"; + } +}