From 060d098c770c48cc6b646749ab24970c2b8e6655 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Tue, 2 Feb 2010 14:24:17 +0000
Subject: [PATCH] - corrected a bug in the "find" REST primitive that required
 two ontologies and with one which only returned the result independently of
 onto1/onto2

---
 html/relnotes.html                            |  1 +
 .../align/service/AServProtocolManager.java   | 17 ++++-----
 .../exmo/align/service/CacheImpl.java         | 35 +++++++++++++------
 .../exmo/align/service/WSAServProfile.java    |  6 ++--
 4 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/html/relnotes.html b/html/relnotes.html
index 6a567aef..a79c32ce 100644
--- a/html/relnotes.html
+++ b/html/relnotes.html
@@ -133,6 +133,7 @@ UPGRADE ALL LIBRARIES
   alignment parsed by the same parser to go into the same alignment (parser)</li>
 <li>Corrected a bug introduced in 3.6 which prevented from storing the
   "stored" date of alignments (server)</li>
+<li>Corrected a bug in the "find" primitive of service (server)</li>
 <li>Corrected a bug in tests that did not forced to clean-up the state
   after <tt>OntoTest</tt> (test)</li>
 <li>Corrected a (commented) error in the <tt>wine.xml</tt> OMWG
diff --git a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java
index 8d778e1c..477d34f2 100644
--- a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java
+++ b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java
@@ -299,23 +299,18 @@ public class AServProtocolManager {
     public Message existingAlignments( Message mess ){
 	Properties params = mess.getParameters();
 	// find and access o, o'
+	String onto1 = params.getProperty("onto1");
+	String onto2 = params.getProperty("onto2");
 	URI uri1 = null;
 	URI uri2 = null;
 	Set<Alignment> alignments = new HashSet<Alignment>();
 	try {
-	    if( params.getProperty("onto1") == null || ((String)params.getProperty("onto1")).equals("") ) {
-		uri2 = new URI((String)params.getProperty("onto2"));
-		alignments = alignmentCache.getAlignments( uri2 );
-	    }
-	    else if( params.getProperty("onto2") == null || ((String)params.getProperty("onto2")).equals("") ) {
+	    if( onto1 != null || !onto1.equals("") ) {
 		uri1 = new URI((String)params.getProperty("onto1"));
-		alignments = alignmentCache.getAlignments( uri1 );
-	    }
-	    else {
-		uri1 = new URI((String)params.getProperty("onto1"));
-	    	uri2 = new URI((String)params.getProperty("onto2"));
-		alignments = alignmentCache.getAlignments( uri1, uri2 );
+	    } else if ( onto2 != null || !onto2.equals("") ) {
+		uri2 = new URI((String)params.getProperty("onto2"));
 	    }
+	    alignmentCache.getAlignments( uri1, uri2 );
 	} catch (Exception e) {
 	    return new ErrorMsg(newId(),mess,myId,mess.getSender(),"MalformedURI problem",(Properties)null);
 	}; //done below
diff --git a/src/fr/inrialpes/exmo/align/service/CacheImpl.java b/src/fr/inrialpes/exmo/align/service/CacheImpl.java
index 6052329d..73a80269 100644
--- a/src/fr/inrialpes/exmo/align/service/CacheImpl.java
+++ b/src/fr/inrialpes/exmo/align/service/CacheImpl.java
@@ -2,7 +2,7 @@
  * $Id$
  *
  * Copyright (C) Seungkeun Lee, 2006
- * Copyright (C) INRIA, 2006-2009
+ * Copyright (C) INRIA, 2006-2010
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -387,21 +387,34 @@ public class CacheImpl {
 	return ontologyTable.get( uri );
     }
 
+    /**
+     * returns the alignmants between two ontologies
+     * if one of the ontologies is null, then return them all
+     */
     public Set<Alignment> getAlignments( URI uri1, URI uri2 ) {
-	// Create the set and compare
-	Set<Alignment> result = new HashSet<Alignment>();
-	Set<Alignment> potentials = ontologyTable.get( uri1 );
-	if ( potentials != null ) {
+	Set<Alignment> result;
+	Set<Alignment> potential = new HashSet<Alignment>();
+
+	// Just does not work properly if there is a uri2 but no result
+	if ( uri2 != null ){
 	    String uri2String = uri2.toString();
-	    String uri1String = uri1.toString();
-	    for(  Alignment al : potentials ) {
+	    for(  Alignment al : ontologyTable.get( uri2 ) ) {
+		if ( al.getExtension(SVCNS, OURI2).equals( uri2String ) ) {
+		    potential.add( al );
+		}
+	    }
+	} 
+	if ( uri1 != null ) {
+	    if ( potential.isEmpty() ) potential = ontologyTable.get( uri1 );
+	    result = new HashSet<Alignment>();
+	    for(  Alignment al : potential ) {
+		String uri1String = uri1.toString();
 		// This is not the best because URI are not resolved here...
-		if ( al.getExtension(SVCNS, OURI2).equals( uri2String ) 
-		     && al.getExtension(SVCNS, OURI1).equals( uri1String ) ) {
+		if ( al.getExtension(SVCNS, OURI1).equals( uri1String ) ) {
 		    result.add( al );
- 		}
+		}
 	    }
-	}
+	} else { result = potential; }
 	return result;
     }
 
diff --git a/src/fr/inrialpes/exmo/align/service/WSAServProfile.java b/src/fr/inrialpes/exmo/align/service/WSAServProfile.java
index 7ae54bcd..500303f8 100644
--- a/src/fr/inrialpes/exmo/align/service/WSAServProfile.java
+++ b/src/fr/inrialpes/exmo/align/service/WSAServProfile.java
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) INRIA, 2007-2009
+ * Copyright (C) INRIA, 2007-2010
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -327,9 +327,7 @@ public class WSAServProfile implements AlignmentServiceProfile {
 	    }
 	    msg += "    </alignResponse>\n";
 	} else if ( method.equals("findRequest") || method.equals("find") ) { // URI * URI -> List of URI
-	    if ( newparameters.getProperty( "onto1" ) == null ) {
-		answer = new NonConformParameters(0,(Message)null,myId,"",message,(Properties)null);
-	    } else if ( newparameters.getProperty( "onto2" ) == null ) {
+	    if ( newparameters.getProperty( "onto1" ) == null && newparameters.getProperty( "onto2" ) == null ) {
 		answer = new NonConformParameters(0,(Message)null,myId,"",message,(Properties)null);
 	    } else {
 		answer = manager.existingAlignments( new Message(newId(),(Message)null,myId,serverURL,"", newparameters) );
-- 
GitLab