Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 346:16161de47662
The Attributes of a collection are written into its DESCRIBE now.
flys-artifacts/trunk@1748 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 26 Apr 2011 13:29:18 +0000 |
parents | 9a0e1289bab6 |
children | a63d8bdb2d79 |
comparison
equal
deleted
inserted
replaced
345:88a669785863 | 346:16161de47662 |
---|---|
71 ? Long.toString(creationTime.getTime()) | 71 ? Long.toString(creationTime.getTime()) |
72 : ""; | 72 : ""; |
73 | 73 |
74 Element collection = ec.create("artifact-collection"); | 74 Element collection = ec.create("artifact-collection"); |
75 Element artifacts = ec.create("artifacts"); | 75 Element artifacts = ec.create("artifacts"); |
76 Element attributes = ec.create("attribute"); | |
76 | 77 |
77 ec.addAttr(collection, "name", getName(), true); | 78 ec.addAttr(collection, "name", getName(), true); |
78 ec.addAttr(collection, "uuid", identifier(), true); | 79 ec.addAttr(collection, "uuid", identifier(), true); |
79 ec.addAttr(collection, "creation", creation, true); | 80 ec.addAttr(collection, "creation", creation, true); |
80 | 81 |
81 collection.appendChild(artifacts); | 82 collection.appendChild(artifacts); |
83 collection.appendChild(attributes); | |
82 doc.appendChild(collection); | 84 doc.appendChild(collection); |
83 | 85 |
84 Document attribute = getAttribute(); | 86 ArtifactDatabase db = context.getDatabase(); |
85 if (attribute != null) { | |
86 Node child = attribute.getFirstChild(); | |
87 collection.appendChild(doc.importNode(child, true)); | |
88 } | |
89 | |
90 ArtifactDatabase db = context.getDatabase(); | |
91 | 87 |
92 try { | 88 try { |
93 String[] artifactUUIDs = getArtifactUUIDs(context); | 89 String[] artifactUUIDs = getArtifactUUIDs(context); |
90 | |
91 Document oldAttrs = getAttribute(); | |
92 Document attrs = buildAttributes( | |
93 db, context, | |
94 oldAttrs, | |
95 artifactUUIDs); | |
96 | |
97 db.setCollectionAttribute(identifier(), context.getMeta(), attrs); | |
98 | |
99 Node child = attrs.getFirstChild(); | |
100 attributes.appendChild(doc.importNode(child, true)); | |
94 | 101 |
95 for (String uuid: artifactUUIDs) { | 102 for (String uuid: artifactUUIDs) { |
96 try { | 103 try { |
97 artifacts.appendChild( | 104 artifacts.appendChild( |
98 buildArtifactNode(db, uuid, context, ec)); | 105 buildArtifactNode(db, uuid, context, ec)); |
145 | 152 |
146 generator.generate(); | 153 generator.generate(); |
147 } | 154 } |
148 | 155 |
149 | 156 |
157 protected Document buildAttributes( | |
158 ArtifactDatabase db, | |
159 CallContext context, | |
160 Document oldAttr, | |
161 String[] items) | |
162 { | |
163 Document doc = XMLUtils.newDocument(); | |
164 | |
165 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
166 doc, | |
167 ArtifactNamespaceContext.NAMESPACE_URI, | |
168 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
169 | |
170 AttributeParser aParser = new AttributeParser(); | |
171 OutputParser oParser = new OutputParser(db, context.getMeta()); | |
172 | |
173 for (String uuid: items) { | |
174 try { | |
175 oParser.parse(uuid); | |
176 } | |
177 catch (ArtifactDatabaseException ade) { | |
178 log.warn(ade, ade); | |
179 } | |
180 } | |
181 | |
182 aParser.parse(oldAttr); | |
183 | |
184 return new AttributeWriter(aParser.getOuts(), oParser.getOuts()).write(); | |
185 } | |
186 | |
187 | |
150 /** | 188 /** |
151 * This method returns the list of artifact UUIDs that this collections | 189 * This method returns the list of artifact UUIDs that this collections |
152 * contains. | 190 * contains. |
153 * | 191 * |
154 * @param context The CallContext that is necessary to get information about | 192 * @param context The CallContext that is necessary to get information about |
322 XMLUtils.ElementCreator ec) | 360 XMLUtils.ElementCreator ec) |
323 throws ArtifactDatabaseException | 361 throws ArtifactDatabaseException |
324 { | 362 { |
325 log.debug("Append artifact '" + uuid + "' to collection description"); | 363 log.debug("Append artifact '" + uuid + "' to collection description"); |
326 | 364 |
365 // TODO | |
366 String hash = "MYHASH"; | |
367 | |
368 Element ci = ec.create("artifact"); | |
369 ec.addAttr(ci, "uuid", uuid, true); | |
370 ec.addAttr(ci, "hash", hash, true); | |
371 | |
327 // XXX I am not sure if it works well every time with an empty document | 372 // XXX I am not sure if it works well every time with an empty document |
328 // in the describe operation of an artifact. | 373 // in the describe operation of an artifact. |
329 Document description = database.describe(uuid, null, context.getMeta()); | 374 Document description = database.describe(uuid, null, context.getMeta()); |
330 | |
331 String hash = "MYHASH"; | |
332 // TODO | |
333 | |
334 Element ci = ec.create("artifact"); | |
335 ec.addAttr(ci, "uuid", uuid, true); | |
336 ec.addAttr(ci, "hash", hash, true); | |
337 | 375 |
338 Node outputModes = (Node) XMLUtils.xpath( | 376 Node outputModes = (Node) XMLUtils.xpath( |
339 description, | 377 description, |
340 XPATH_ARTIFACT_OUTPUTMODES, | 378 XPATH_ARTIFACT_OUTPUTMODES, |
341 XPathConstants.NODE, | 379 XPathConstants.NODE, |