From 616cdc52fd0e998a95ceb3f7a56a2d4eee20e68f Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 19 Oct 2007 13:05:10 +0000 Subject: [PATCH] made SimpleClientConfig externally configurable and added mechanism to prevent invalid documents being written to session. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@484 be28352e-c001-0410-b1a7-c7978e42abec --- .../vamsas/client/simpleclient/ClientDocument.java | 31 ++++++++++++++++++-- .../vamsas/client/simpleclient/SimpleClient.java | 27 +++++++++++++---- .../client/simpleclient/SimpleClientConfig.java | 13 ++++---- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java index 0a8dc41..b9e918e 100644 --- a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java +++ b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java @@ -103,6 +103,11 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement * internal reference to single copy of Document Roots array */ private VAMSAS[] _VamsasRoots=null; + /** + * set if the client has corrupted the Vamsas Document structure somehow. + * if this is set the document will never be written back to the session unless the corruption is fixed. + */ + private boolean invalidModification=false; protected void updateDocumentRoots() { if (doc==null) { @@ -189,13 +194,16 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement } // just do internal validation for moment. try { - if (SimpleClientConfig.validateUpdatedRoots()) + if (getSimpleClientConfig().validateUpdatedRoots()) + { newVersion.validate(); + } return true; } catch (Exception e) { log.error("Validation Exception for new vamsas root :"+newVersion.getVorbaId(),e); + modflag.invalidModification=true; } return false; } else { @@ -206,7 +214,7 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement modflag.isModified=true; } try { - if (SimpleClientConfig.validateMergedRoots()) + if (getSimpleClientConfig().validateMergedRoots()) { newVersion.validate(); } @@ -268,6 +276,9 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement } }*/ } + private SimpleClientConfig getSimpleClientConfig() { + return sclient.getSimpleClientConfig(); +} /** * merge old and new root vectors * @param newr This array may be written to @@ -277,7 +288,6 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement */ private VAMSAS[] _combineRoots(VAMSAS[] newr, final VAMSAS[] original, ClientDocument modflag) { Vector rts = new Vector(); - boolean modified=false; for (int i=0,j=original.length; i-1) { @@ -581,4 +591,19 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement // TODO: WALK through the document objects calling the update mechanism for each one, or just pass this vector back to client ?return updatedObjects; return null; } + /** + * if this is set the document will never be written back to the session unless the corruption is fixed. + * @return the invalidModification + */ + public boolean isInvalidModification() { + return invalidModification; + } + /** + * set if the client has corrupted the Vamsas Document structure somehow. + * if this is set the document will never be written back to the session unless the corruption is fixed. + * @param invalidModification the invalidModification to set + */ + public void setInvalidModification(boolean invalidModification) { + this.invalidModification = invalidModification; + } } diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java index 43ec15d..d13fe24 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java @@ -308,14 +308,21 @@ public class SimpleClient implements IClient { if (evgen.isDocumentWatchEnabled()) throw new Error("Probable Client Error (did you remember to call SimpleClient.updateDocument(clientdoc) at the end of the document update handler?) - or Library Bug : Document watcher still enabled whilst ClientDocument instance exists."); - - if (!cdocument.isModified()) { - // client document is silently got rid of, with no session update events. - if (log.isDebugEnabled()) - log.debug("updateDocument for "+session.getSessionUrn()+" with unmodified IClientDocument (skipping the write)"); + if (cdocument.isInvalidModification()) + { + log.info("Client has corrupted the vamsas document. It will not be written back to the session - sorry."); + // TODO: modify updateDocument signature: We should really raise an exception here to tell the client that it broke the datamodel. } else { - writeSessionDocument(); + // actually try to write - if necessary. + if (!cdocument.isModified()) { + // client document is silently got rid of, with no session update events. + if (log.isDebugEnabled()) + log.debug("updateDocument for "+session.getSessionUrn()+" with unmodified IClientDocument (skipping the write)"); + } else { + writeSessionDocument(); + } } + // release locks, reset and start to receive events again tidyAwaySessionDocumentState(); } /** @@ -581,5 +588,13 @@ public class SimpleClient implements IClient { protected Lock getClientLock() { return activeClientFilelock; } + SimpleClientConfig _config = null; + public SimpleClientConfig getSimpleClientConfig() { + if (_config==null) + { + _config = new SimpleClientConfig(); + } + return _config; + } } diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClientConfig.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClientConfig.java index 671740c..379d3a0 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClientConfig.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClientConfig.java @@ -5,14 +5,15 @@ package uk.ac.vamsas.client.simpleclient; * */ public class SimpleClientConfig { - + public boolean _validatemergedroots=false; + public boolean _validateupdatedroots=false; /** * New VAMSAS roots added (merged) into the document * will be validated before actually being added. * @return */ - public static boolean validateMergedRoots() { - return false; + public boolean validateMergedRoots() { + return _validatemergedroots; } /** @@ -21,8 +22,8 @@ public class SimpleClientConfig { * be written. * @return */ - public static boolean validateUpdatedRoots() { - return false; + public boolean validateUpdatedRoots() { + return _validateupdatedroots; } - + } -- 1.7.10.2