Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 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 | 59ae2a823e73 |
children | 73330e89b0af |
comparison
equal
deleted
inserted
replaced
970:e456aca4eb7b | 971:d0c9a5f32c30 |
---|---|
56 | 56 |
57 public static final String XPATH_OUT_NAME = "/art:action/@art:name"; | 57 public static final String XPATH_OUT_NAME = "/art:action/@art:name"; |
58 | 58 |
59 public static final String XPATH_OUT_TYPE = "/art:action/@art:type"; | 59 public static final String XPATH_OUT_TYPE = "/art:action/@art:type"; |
60 | 60 |
61 public static final String XPATH_LOADED_RECOMMENDATIONS = | |
62 "/art:attribute/art:loaded-recommendations"; | |
63 | |
61 | 64 |
62 | 65 |
63 @Override | 66 @Override |
64 public Document describe(CallContext context) { | 67 public Document describe(CallContext context) { |
65 log.debug("FLYSArtifactCollection.describe: " + identifier); | 68 log.debug("FLYSArtifactCollection.describe: " + identifier); |
86 | 89 |
87 collection.appendChild(artifacts); | 90 collection.appendChild(artifacts); |
88 doc.appendChild(collection); | 91 doc.appendChild(collection); |
89 | 92 |
90 ArtifactDatabase db = context.getDatabase(); | 93 ArtifactDatabase db = context.getDatabase(); |
94 Document oldAttrs = getAttribute(); | |
91 | 95 |
92 try { | 96 try { |
93 String[] artifactUUIDs = getArtifactUUIDs(context); | 97 String[] aUUIDs = getArtifactUUIDs(context); |
94 | 98 Node newAttr = mergeAttributes(db, context, oldAttrs, aUUIDs); |
95 Document oldAttrs = getAttribute(); | 99 |
96 | 100 collection.appendChild(doc.importNode(newAttr, true)); |
97 Document attrs = buildAttributes( | 101 |
98 db, context, | 102 for (String uuid: aUUIDs) { |
99 oldAttrs, | |
100 artifactUUIDs); | |
101 | |
102 collection.appendChild(doc.importNode(attrs.getFirstChild(), true)); | |
103 | |
104 // save the merged document into database | |
105 db.setCollectionAttribute(identifier(), context.getMeta(), attrs); | |
106 | |
107 for (String uuid: artifactUUIDs) { | |
108 try { | 103 try { |
109 artifacts.appendChild( | 104 artifacts.appendChild( |
110 buildArtifactNode(db, uuid, context, ec)); | 105 buildArtifactNode(db, uuid, context, ec)); |
111 } | 106 } |
112 catch (ArtifactDatabaseException dbe) { | 107 catch (ArtifactDatabaseException dbe) { |
114 } | 109 } |
115 } | 110 } |
116 } | 111 } |
117 catch (ArtifactDatabaseException ade) { | 112 catch (ArtifactDatabaseException ade) { |
118 log.error(ade, ade); | 113 log.error(ade, ade); |
114 | |
115 collection.appendChild( | |
116 doc.importNode(oldAttrs.getFirstChild(), true)); | |
119 } | 117 } |
120 | 118 |
121 return doc; | 119 return doc; |
120 } | |
121 | |
122 | |
123 /** | |
124 * Merge the current art:outputs nodes with the the outputs provided by the | |
125 * artifacts in the Collection. | |
126 */ | |
127 protected Node mergeAttributes( | |
128 ArtifactDatabase db, | |
129 CallContext context, | |
130 Document oldAttrs, | |
131 String[] uuids) | |
132 { | |
133 Document doc = buildOutAttributes(db, context, oldAttrs, uuids); | |
134 Node newAttr = doc.getFirstChild(); | |
135 | |
136 newAttr = mergeLoadedRecommendations(oldAttrs, newAttr); | |
137 | |
138 try { | |
139 // save the merged document into database | |
140 db.setCollectionAttribute(identifier(), context.getMeta(), doc); | |
141 } | |
142 catch (ArtifactDatabaseException adb) { | |
143 log.error(adb, adb); | |
144 } | |
145 | |
146 return newAttr; | |
147 } | |
148 | |
149 | |
150 /** | |
151 * Merge the recommendations which have already been loaded from the old | |
152 * attribute document into the new attribute document. This is necessary, | |
153 * because mergeAttributes() only merges the art:outputs nodes - all | |
154 * other nodes are skiped. | |
155 */ | |
156 protected Node mergeLoadedRecommendations(Document oldAttrs, Node newAttrs){ | |
157 Element loadedRecoms = (Element) XMLUtils.xpath( | |
158 oldAttrs, | |
159 XPATH_LOADED_RECOMMENDATIONS, | |
160 XPathConstants.NODE, | |
161 ArtifactNamespaceContext.INSTANCE); | |
162 | |
163 if (loadedRecoms != null) { | |
164 Document doc = newAttrs.getOwnerDocument(); | |
165 newAttrs.appendChild(doc.importNode(loadedRecoms, true)); | |
166 } | |
167 | |
168 return newAttrs; | |
122 } | 169 } |
123 | 170 |
124 | 171 |
125 @Override | 172 @Override |
126 public void out( | 173 public void out( |
249 | 296 |
250 generator.generate(); | 297 generator.generate(); |
251 } | 298 } |
252 | 299 |
253 | 300 |
254 protected Document buildAttributes( | 301 protected Document buildOutAttributes( |
255 ArtifactDatabase db, | 302 ArtifactDatabase db, |
256 CallContext context, | 303 CallContext context, |
257 Document oldAttr, | 304 Document oldAttr, |
258 String[] items) | 305 String[] items) |
259 { | 306 { |
290 * @return the attribute for the desired output type. | 337 * @return the attribute for the desired output type. |
291 */ | 338 */ |
292 protected Document getAttribute(CallContext context, String output) | 339 protected Document getAttribute(CallContext context, String output) |
293 throws ArtifactDatabaseException | 340 throws ArtifactDatabaseException |
294 { | 341 { |
295 Document attr = buildAttributes( | 342 Document attr = buildOutAttributes( |
296 context.getDatabase(), | 343 context.getDatabase(), |
297 context, | 344 context, |
298 getAttribute(), | 345 getAttribute(), |
299 getArtifactUUIDs(context)); | 346 getArtifactUUIDs(context)); |
300 | 347 |