From: jprocter Date: Tue, 11 Sep 2007 09:14:29 +0000 (+0000) Subject: ensure that document updates only occur if the vamsas objects have been changed or... X-Git-Tag: Release_0.2~64 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=42180adec33ae51f866af05379551be34bd98281;p=vamsas.git ensure that document updates only occur if the vamsas objects have been changed or an appdata has been written. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@456 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java index ef0a7d5..ee88640 100644 --- a/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java +++ b/src/uk/ac/vamsas/client/simpleclient/ClientDocument.java @@ -164,15 +164,29 @@ 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()) @@ -187,10 +201,16 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement } else { // redundant ? if (oldVersion.is__stored_in_document()) if (!newVersion.isRegistered()) + { _registerObject(newVersion); + modflag.isModified=true; + } try { if (SimpleClientConfig.validateMergedRoots()) + { newVersion.validate(); + } + modflag.isModified=true; return true; } catch (Exception e) @@ -261,8 +281,8 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement 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 +299,12 @@ public class ClientDocument extends uk.ac.vamsas.client.ClientDocument implement for (int i=0,j=newr.length; i