Mercurial > dive4elements > river
changeset 971:d0c9a5f32c30
Prepared the FLYSArtifactCollection to support the storage of already loaded recommendations.
flys-artifacts/trunk@2396 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 22 Jul 2011 11:18:00 +0000 |
parents | e456aca4eb7b |
children | 0c8aca463bd4 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java |
diffstat | 2 files changed, 68 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Jul 22 10:41:30 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Jul 22 11:18:00 2011 +0000 @@ -1,3 +1,9 @@ +2011-07-22 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Prepared the FLYSArtifactCollection to support the storage of already + loaded recommendations in its attribute document. + 2011-07-21 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/services/MetaDataService.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Fri Jul 22 10:41:30 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Fri Jul 22 11:18:00 2011 +0000 @@ -58,6 +58,9 @@ public static final String XPATH_OUT_TYPE = "/art:action/@art:type"; + public static final String XPATH_LOADED_RECOMMENDATIONS = + "/art:attribute/art:loaded-recommendations"; + @Override @@ -88,23 +91,15 @@ doc.appendChild(collection); ArtifactDatabase db = context.getDatabase(); + Document oldAttrs = getAttribute(); try { - String[] artifactUUIDs = getArtifactUUIDs(context); - - Document oldAttrs = getAttribute(); + String[] aUUIDs = getArtifactUUIDs(context); + Node newAttr = mergeAttributes(db, context, oldAttrs, aUUIDs); - Document attrs = buildAttributes( - db, context, - oldAttrs, - artifactUUIDs); + collection.appendChild(doc.importNode(newAttr, true)); - collection.appendChild(doc.importNode(attrs.getFirstChild(), true)); - - // save the merged document into database - db.setCollectionAttribute(identifier(), context.getMeta(), attrs); - - for (String uuid: artifactUUIDs) { + for (String uuid: aUUIDs) { try { artifacts.appendChild( buildArtifactNode(db, uuid, context, ec)); @@ -116,12 +111,64 @@ } catch (ArtifactDatabaseException ade) { log.error(ade, ade); + + collection.appendChild( + doc.importNode(oldAttrs.getFirstChild(), true)); } return doc; } + /** + * Merge the current art:outputs nodes with the the outputs provided by the + * artifacts in the Collection. + */ + protected Node mergeAttributes( + ArtifactDatabase db, + CallContext context, + Document oldAttrs, + String[] uuids) + { + Document doc = buildOutAttributes(db, context, oldAttrs, uuids); + Node newAttr = doc.getFirstChild(); + + newAttr = mergeLoadedRecommendations(oldAttrs, newAttr); + + try { + // save the merged document into database + db.setCollectionAttribute(identifier(), context.getMeta(), doc); + } + catch (ArtifactDatabaseException adb) { + log.error(adb, adb); + } + + return newAttr; + } + + + /** + * Merge the recommendations which have already been loaded from the old + * attribute document into the new attribute document. This is necessary, + * because mergeAttributes() only merges the art:outputs nodes - all + * other nodes are skiped. + */ + protected Node mergeLoadedRecommendations(Document oldAttrs, Node newAttrs){ + Element loadedRecoms = (Element) XMLUtils.xpath( + oldAttrs, + XPATH_LOADED_RECOMMENDATIONS, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + if (loadedRecoms != null) { + Document doc = newAttrs.getOwnerDocument(); + newAttrs.appendChild(doc.importNode(loadedRecoms, true)); + } + + return newAttrs; + } + + @Override public void out( String type, @@ -251,7 +298,7 @@ } - protected Document buildAttributes( + protected Document buildOutAttributes( ArtifactDatabase db, CallContext context, Document oldAttr, @@ -292,7 +339,7 @@ protected Document getAttribute(CallContext context, String output) throws ArtifactDatabaseException { - Document attr = buildAttributes( + Document attr = buildOutAttributes( context.getDatabase(), context, getAttribute(),