X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FClientDocument.java;h=b9e918e2475d02185fb24944cc492d351381ca9d;hb=1e940bf58bbd9f228ff991b5ee6e5b38c36a78fe;hp=ef0a7d50318965acceaaf52e2769c6a3b9c64b4f;hpb=61966e1add4b7705ff7b5f1e1239156c06f9abd7;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java index ef0a7d5..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) { @@ -164,33 +169,56 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement * verify that newr version is really an intact version of the * @param newVersion (may be modified) * @param oldVersion + * @param modflag * @return true if newVersion is a valid root that preserves original references */ - private boolean isValidUpdate(VAMSAS newVersion, final VAMSAS oldVersion) { + private boolean isValidUpdate(VAMSAS newVersion, final VAMSAS oldVersion, ClientDocument modflag) { // ideal - this cascades down the two structures, ensuring that all ID'd objects in one are present in the other. if (oldVersion==newVersion) { // may be a virgin root element. if (!newVersion.isRegistered()) - _registerObject(newVersion); // TODO: check - this call hasn't been tested. - // Should retrieve original version and compare - unless local hashes can be used to determine if resultSet has been truncated. + { + _registerObject(newVersion); // TODO: check - this call hasn't been tested. (seems to work now) + modflag.isModified=true; + } + // TODO: Should attempt to repair document if client app has deleted/broken bits of it + if (oldVersion.is__stored_in_document()) { + // retrieve compare hashCodes to detect update. + if (oldVersion.get__last_hash()!=oldVersion.hashCode()) + { + log.debug("Modified hashcode for vamsas root "+oldVersion.getVorbaId()); + modflag.isModified = true; + } else { + log.debug("Unmodified vamsas root "+oldVersion.getVorbaId()); + } + } // 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 { // redundant ? if (oldVersion.is__stored_in_document()) if (!newVersion.isRegistered()) + { _registerObject(newVersion); + modflag.isModified=true; + } try { - if (SimpleClientConfig.validateMergedRoots()) + if (getSimpleClientConfig().validateMergedRoots()) + { newVersion.validate(); + } + modflag.isModified=true; return true; } catch (Exception e) @@ -248,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 @@ -257,12 +288,11 @@ 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) { - if (isValidUpdate(newr[k], original[i])) { - modified=true; + if (isValidUpdate(newr[k], original[i], modflag)) { + // set by isValidUpdate if the hashcodes were really different from last store rts.add(newr[k]); newr[k]=null; } else { @@ -279,14 +309,12 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement for (int i=0,j=newr.length; i