diff --git a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java index c2adc682ff9e0707875fcae7672d0c150a9ec91b..b143db3e7ea20cf37d0663a983fac426dbf41801 100644 --- a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java +++ b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java @@ -432,12 +432,12 @@ public class AServProtocolManager { *********************************************************************/ // Implementation specific - public Message store( Message mess ){ + public Message store( Message mess ) { String id = mess.getContent(); Alignment al=null; try { - try{ + try { al = alignmentCache.getAlignment( id ); } catch(Exception ex) { //System.err.println("Unknown Id in Store :=" + id ); @@ -454,7 +454,7 @@ public class AServProtocolManager { for ( Directory d : directories.values() ){ // Declare the alignment in the directory try { d.register( al ); } - catch (AServException e) { e.printStackTrace(); }// ignore + catch ( AServException e ) { e.printStackTrace(); }// ignore } } // register by them @@ -466,6 +466,29 @@ public class AServProtocolManager { } } + // Implementation specific + public Message erase( Message mess ) { + String id = mess.getContent(); + Alignment al = null; + try { + al = alignmentCache.getAlignment( id ); + // Erase it from directories + for ( Directory d : directories.values() ){ + try { d.register( al ); } + catch ( AServException e ) { e.printStackTrace(); }// ignore + } + // Erase it from storage + try { + alignmentCache.eraseAlignment( id ); + } catch ( Exception ex ) { ex.printStackTrace(); }// ignore + // Should be a SuppressedAlignment + return new AlignmentId(newId(),mess,myId,mess.getSender(),id,(Properties)null, + al.getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY )); + } catch ( Exception ex ) { + return new UnknownAlignment(newId(),mess,myId,mess.getSender(),id,(Properties)null); + } + } + /* * Returns only the metadata of an alignment and returns it in * parameters @@ -682,11 +705,7 @@ public class AServProtocolManager { } catch (Exception e) { return false; } - if ( al.getExtension(CacheImpl.SVCNS, CacheImpl.STORED) != null && al.getExtension(CacheImpl.SVCNS, CacheImpl.STORED) != "" ) { - return true; - } else { - return false; - } + return alignmentCache.isAlignmentStored( al ); } /********************************************************************* diff --git a/src/fr/inrialpes/exmo/align/service/CacheImpl.java b/src/fr/inrialpes/exmo/align/service/CacheImpl.java index d8c3a277b1facc972c613758f3e7468c13a7ff68..08dbd66762f4666a844e7cb5bb95dd5384177075 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-2010 + * Copyright (C) INRIA, 2006-2011 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -90,11 +90,11 @@ public class CacheImpl { final int INIT_ERROR = 3; //static public final String SVCNS = "http://exmo.inrialpes.fr/align/service#"; - static public final String SVCNS = Namespace.ALIGNSVC.getUriPrefix(); - static public final String CACHED = "cached"; - static public final String STORED = "stored"; - static public final String OURI1 = "ouri1"; - static public final String OURI2 = "ouri2"; + static private final String SVCNS = Namespace.ALIGNSVC.getUriPrefix(); + static private final String CACHED = "cached"; + static private final String STORED = "stored"; + static private final String OURI1 = "ouri1"; + static private final String OURI2 = "ouri2"; //********************************************************************** @@ -458,7 +458,7 @@ public class CacheImpl { /** * records alignment identified by id */ - public String recordAlignment( String id, Alignment alignment, boolean force ){ + public String recordAlignment( String id, Alignment alignment, boolean force ) { // record the Id! //CLD put in comment this line for allowing to create a new ID for any alignment //if ( alignment.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ) == null ) @@ -490,7 +490,23 @@ public class CacheImpl { return null; } } - + + /** + * suppresses the record for an alignment + */ + public void unRecordAlignment( Alignment alignment ) { + String id = alignment.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); + try { + Set<Alignment> s1 = ontologyTable.get( new URI( alignment.getExtension( SVCNS, OURI1) ) ); + if ( s1 != null ) s1.remove( alignment ); + Set<Alignment> s2 = ontologyTable.get( new URI( alignment.getExtension( SVCNS, OURI2) ) ); + if ( s2 != null ) s2.remove( alignment ); + } catch ( URISyntaxException uriex ) { + uriex.printStackTrace(); // should never happen + } + alignmentTable.remove( id ); + } + //********************************************************************** // STORING IN DATABASE /** @@ -529,24 +545,41 @@ public class CacheImpl { else return false; } + + /** + * Non publicised class + */ + public void eraseAlignment( String id ) throws SQLException, AlignmentException { + Alignment alignment = getAlignment( id ); + if ( alignment != null ) { + unstoreAlignment( id, alignment ); + // Suppress it from the cache... + unRecordAlignment( alignment ); + } + } + /** * Non publicised class */ public void unstoreAlignment( String id ) throws SQLException, AlignmentException { Alignment alignment = getAlignment( id ); if ( alignment != null ) { - Statement st = createStatement(); - String query = "DELETE FROM extension WHERE id='"+id+"'"; - st.executeUpdate(query); - query = "DELETE FROM alignment WHERE id='"+id+"'"; - st.executeUpdate(query); - query = "DELETE FROM cell WHERE id='"+id+"'"; - st.executeUpdate(query); - alignment.setExtension( SVCNS, STORED, (String)null); - st.close(); + unstoreAlignment( id, alignment ); } } + public void unstoreAlignment( String id, Alignment alignment ) throws SQLException, AlignmentException { + Statement st = createStatement(); + String query = "DELETE FROM extension WHERE id='"+id+"'"; + st.executeUpdate(query); + query = "DELETE FROM alignment WHERE id='"+id+"'"; + st.executeUpdate(query); + query = "DELETE FROM cell WHERE id='"+id+"'"; + st.executeUpdate(query); + alignment.setExtension( SVCNS, STORED, (String)null); + st.close(); + } + public void storeAlignment( String id ) throws AlignmentException, SQLException { String query = null; Alignment alignment = getAlignment( id ); diff --git a/src/fr/inrialpes/exmo/align/service/Directory.java b/src/fr/inrialpes/exmo/align/service/Directory.java index 9f71ccbf49b454250d78b863d8fb746ef2a56750..f5cc91e3c118d85f474dfa33519f0988fcf1186a 100644 --- a/src/fr/inrialpes/exmo/align/service/Directory.java +++ b/src/fr/inrialpes/exmo/align/service/Directory.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2007, 2009 + * Copyright (C) INRIA, 2007, 2009, 2011 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -39,6 +39,11 @@ public interface Directory { */ public void register( Alignment al ) throws AServException; + /** + * Unregister an alignment to the directory (if necessary) + */ + public void unregister( Alignment al ) throws AServException; + /** * Shutdown the connection and/or registration to the directory */ diff --git a/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java b/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java index fa14b4953d7512f78ff08c1d8f5a364bab7845fb..1ce3bf8049f50fa3f558d397ac95f380aae85ebd 100644 --- a/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java +++ b/src/fr/inrialpes/exmo/align/service/HTMLAServProfile.java @@ -501,6 +501,26 @@ public class HTMLAServProfile implements AlignmentServiceProfile { msg += "<li><a href=\"../html/retrieve?method=fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor&id="+id+"\">"+pid+"</a></li>"; } msg += "</ul>"; + } if ( perf.equals("manalignments") ){ // Manage ailignments + msg = "<h1>Available alignments</h1><ul compact=\"1\">"; + for ( Alignment al : manager.alignments() ) { + String id = al.getExtension( Namespace.ALIGNMENT.uri, Annotations.ID ); + String pid = al.getExtension( Namespace.ALIGNMENT.uri, Annotations.PRETTY ); + if ( pid == null ) pid = id; else pid = id+" ("+pid+")"; + msg += "<li><a href=\"../html/retrieve?method=fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor&id="+id+"\">"+pid+"</a> "+al.nbCells()+" <a href=\"../html/errrazze?id="+id+"\">DEL</a></li>"; + } + msg += "</ul>"; + } if ( perf.equals("errrazze") ){ // Suppress an alignment + String id = params.getProperty("id"); + if ( id != null && !id.equals("") ) { // Erase it + Message answer = manager.erase( new Message(newId(),(Message)null,myId,serverId,id, params) ); + if ( answer instanceof ErrorMsg ) { + msg = testErrorMessages( answer, params ); + } else { + msg = "<h1>Alignment deleted</h1>"; + msg += displayAnswer( answer, params ); + } + } } else if ( perf.equals("prmstore") ) { msg = "<h1>Store an alignment</h1><form action=\"store\">"; msg += "Alignment id: <select name=\"id\">"; diff --git a/src/fr/inrialpes/exmo/align/service/OysterDirectory.java b/src/fr/inrialpes/exmo/align/service/OysterDirectory.java index b6ea6a7b1257210725288c103a67bb4d79e631e9..2029b696e91affec7e70a725465e52037cd77b19 100644 --- a/src/fr/inrialpes/exmo/align/service/OysterDirectory.java +++ b/src/fr/inrialpes/exmo/align/service/OysterDirectory.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2007-2010 + * Copyright (C) INRIA, 2007-2011 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -91,6 +91,13 @@ public class OysterDirectory implements Directory { public void getAlignmentReferences( Ontology o1, Ontology o2 ){ } + /** + * unregister an alignment from the directory (if necessary) + * This is not implemented + */ + public void unregister( Alignment al ) { + } + /** * Shutdown the connection and/or registration to the directory */