Mercurial > dive4elements > river
changeset 293:3419b1c8ca28
Removed the Backend reference from FLYSArtifactCollection.
flys-artifacts/trunk@1629 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 30 Mar 2011 16:00:51 +0000 (2011-03-30) |
parents | f44b11cc23b6 |
children | e5e7af208857 |
files | flys-artifacts/ChangeLog flys-artifacts/TODO flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java |
diffstat | 3 files changed, 62 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Mar 30 15:21:12 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Mar 30 16:00:51 2011 +0000 @@ -1,3 +1,11 @@ +2011-03-30 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Removed the Backend from FLYSArtifactCollection - used ArtifactDatabase + operations instead. + + * TODO: Removed 'remove Backend reference' TODO. + 2011-03-30 Ingo Weinzierl <ingo@intevation.de> * doc/conf/artifacts/winfo.xml: Enhanced the configuration of the
--- a/flys-artifacts/TODO Wed Mar 30 15:21:12 2011 +0000 +++ b/flys-artifacts/TODO Wed Mar 30 16:00:51 2011 +0000 @@ -1,4 +1,1 @@ - Validation of the input values of an incoming feed() call -- Remove the reference to Backend from FLYSArtifactCollection. Use the - methods of ArtifactDatabase (context.getDatabase()) to do the - necessary work.
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Wed Mar 30 15:21:12 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Wed Mar 30 16:00:51 2011 +0000 @@ -9,17 +9,17 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; -import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactDatabase; +import de.intevation.artifacts.ArtifactDatabaseException; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; -import de.intevation.artifacts.CollectionItem; +import de.intevation.artifacts.CallMeta; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifactdatabase.DefaultArtifactCollection; -import de.intevation.artifactdatabase.Backend; -import de.intevation.artifactdatabase.Backend.PersistentArtifact; /** @@ -35,6 +35,9 @@ public static final String XPATH_ARTIFACT_OUTPUTMODES = "/art:result/art:outputmodes"; + public static final String XPATH_COLLECTION_ITEMS = + "/art:result/art:artifact-collection/art:collection-item"; + @Override public Document describe(CallContext context) { @@ -68,12 +71,41 @@ collection.appendChild(doc.importNode(child, true)); } - Backend backend = Backend.getInstance(); - CollectionItem[] items = backend.listCollectionArtifacts(identifier()); + try { + ArtifactDatabase db = context.getDatabase(); + CallMeta meta = context.getMeta(); - for (CollectionItem item: items) { - artifacts.appendChild( - buildArtifactNode(item, backend, context, ec)); + Document itemList = db.listCollectionArtifacts(identifier(), meta); + NodeList items = (NodeList) XMLUtils.xpath( + itemList, + XPATH_COLLECTION_ITEMS, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (items == null || items.getLength() == 0) { + log.debug("No collection items found."); + return doc; + } + + int num = items.getLength(); + + for (int i = 0; i < num; i++) { + String uuid = XMLUtils.xpathString( + items.item(i), + "@art:uuid", + ArtifactNamespaceContext.INSTANCE); + + try { + artifacts.appendChild( + buildArtifactNode(db, uuid, context, ec)); + } + catch (ArtifactDatabaseException dbe) { + log.warn(dbe, dbe); + } + } + } + catch (ArtifactDatabaseException ade) { + log.error(ade, ade); } return doc; @@ -81,26 +113,28 @@ protected Element buildArtifactNode( - CollectionItem item, - Backend backend, + ArtifactDatabase database, + String uuid, CallContext context, XMLUtils.ElementCreator ec) + throws ArtifactDatabaseException { - String uuid = item.getArtifactIdentifier(); + log.debug("Append artifact '" + uuid + "' to collection description"); - log.debug("Append artifact '"+ uuid +"' to collection description"); + // XXX I am not sure if it works well every time with an empty document + // in the describe operation of an artifact. + Document description = database.describe(uuid, null, context.getMeta()); - PersistentArtifact pArtifact = backend.getArtifact(uuid); - Artifact artifact = pArtifact.getArtifact(); + de.intevation.flys.artifacts.XMLDebug.out(description); + + String hash = "MYHASH"; + // TODO Element ci = ec.create("artifact"); ec.addAttr(ci, "uuid", uuid, true); - ec.addAttr(ci, "hash", artifact.hash(), true); + ec.addAttr(ci, "hash", hash, true); - // XXX I am not sure if it works well every time with an empty document - // in the describe operation of an artifact. - Document description = artifact.describe(null, context); - Node outputModes = (Node) XMLUtils.xpath( + Node outputModes = (Node) XMLUtils.xpath( description, XPATH_ARTIFACT_OUTPUTMODES, XPathConstants.NODE,