Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 638:9c565eb46f06
Fixed the process of creating and storing the attribute of a collection.
flys-artifacts/trunk@2015 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 27 May 2011 08:46:26 +0000 |
parents | 046bd86ae41d |
children | deb5e9840813 |
comparison
equal
deleted
inserted
replaced
637:f0c1250d1e7b | 638:9c565eb46f06 |
---|---|
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.io.OutputStream; | 4 import java.io.OutputStream; |
5 import java.util.ArrayList; | 5 import java.util.ArrayList; |
6 import java.util.Date; | 6 import java.util.Date; |
7 import java.util.HashMap; | |
7 import java.util.List; | 8 import java.util.List; |
8 import java.util.Map; | 9 import java.util.Map; |
9 import java.util.Vector; | 10 import java.util.Vector; |
10 | 11 |
11 import javax.xml.xpath.XPathConstants; | 12 import javax.xml.xpath.XPathConstants; |
76 ? Long.toString(creationTime.getTime()) | 77 ? Long.toString(creationTime.getTime()) |
77 : ""; | 78 : ""; |
78 | 79 |
79 Element collection = ec.create("artifact-collection"); | 80 Element collection = ec.create("artifact-collection"); |
80 Element artifacts = ec.create("artifacts"); | 81 Element artifacts = ec.create("artifacts"); |
81 Element attributes = ec.create("attribute"); | |
82 | 82 |
83 ec.addAttr(collection, "name", getName(), true); | 83 ec.addAttr(collection, "name", getName(), true); |
84 ec.addAttr(collection, "uuid", identifier(), true); | 84 ec.addAttr(collection, "uuid", identifier(), true); |
85 ec.addAttr(collection, "creation", creation, true); | 85 ec.addAttr(collection, "creation", creation, true); |
86 | 86 |
87 collection.appendChild(artifacts); | 87 collection.appendChild(artifacts); |
88 collection.appendChild(attributes); | |
89 doc.appendChild(collection); | 88 doc.appendChild(collection); |
90 | 89 |
91 ArtifactDatabase db = context.getDatabase(); | 90 ArtifactDatabase db = context.getDatabase(); |
92 | 91 |
93 try { | 92 try { |
94 String[] artifactUUIDs = getArtifactUUIDs(context); | 93 String[] artifactUUIDs = getArtifactUUIDs(context); |
95 | 94 |
96 Document oldAttrs = getAttribute(); | 95 Document oldAttrs = getAttribute(); |
97 Document attrs = buildAttributes( | 96 |
97 Document attrs = buildAttributes( | |
98 db, context, | 98 db, context, |
99 oldAttrs, | 99 oldAttrs, |
100 artifactUUIDs); | 100 artifactUUIDs); |
101 | 101 |
102 log.debug("============== FINAL ATTRIBUTES AFTER MERGE ======="); | |
103 de.intevation.flys.artifacts.XMLDebug.out(attrs); | |
104 log.debug("============== THIS WAS THE FINAL ATTRIBUTE ======="); | |
105 | |
106 collection.appendChild(doc.importNode(attrs.getFirstChild(), true)); | |
107 | |
108 // save the merged document into database | |
102 db.setCollectionAttribute(identifier(), context.getMeta(), attrs); | 109 db.setCollectionAttribute(identifier(), context.getMeta(), attrs); |
103 | |
104 Node child = attrs.getFirstChild(); | |
105 attributes.appendChild(doc.importNode(child, true)); | |
106 | 110 |
107 for (String uuid: artifactUUIDs) { | 111 for (String uuid: artifactUUIDs) { |
108 try { | 112 try { |
109 artifacts.appendChild( | 113 artifacts.appendChild( |
110 buildArtifactNode(db, uuid, context, ec)); | 114 buildArtifactNode(db, uuid, context, ec)); |
276 getAttribute(), | 280 getAttribute(), |
277 getArtifactUUIDs(context)); | 281 getArtifactUUIDs(context)); |
278 | 282 |
279 Node out = (Node) XMLUtils.xpath( | 283 Node out = (Node) XMLUtils.xpath( |
280 attr, | 284 attr, |
281 "art:outputs/art:output[@name='" + output + "']", | 285 "art:attribute/art:outputs/art:output[@name='" + output + "']", |
282 XPathConstants.NODE, | 286 XPathConstants.NODE, |
283 ArtifactNamespaceContext.INSTANCE); | 287 ArtifactNamespaceContext.INSTANCE); |
284 | 288 |
285 | 289 |
286 if (out != null) { | 290 if (out != null) { |
674 /** | 678 /** |
675 * Inner class to structure/order the themes of a chart. | 679 * Inner class to structure/order the themes of a chart. |
676 */ | 680 */ |
677 private class ThemeList { | 681 private class ThemeList { |
678 private Logger logger = Logger.getLogger(ThemeList.class); | 682 private Logger logger = Logger.getLogger(ThemeList.class); |
679 protected Vector<ManagedFacet> themes; | 683 protected Map<Integer, ManagedFacet> themes; |
680 | 684 |
681 public ThemeList(Document output) { | 685 public ThemeList(Document output) { |
682 themes = new Vector<ManagedFacet>(); | 686 themes = new HashMap<Integer, ManagedFacet>(); |
683 parse(output); | 687 parse(output); |
684 } | 688 } |
685 | 689 |
686 protected void parse(Document output) { | 690 protected void parse(Document output) { |
687 NodeList themes = (NodeList) XMLUtils.xpath( | 691 NodeList themes = (NodeList) XMLUtils.xpath( |
733 | 737 |
734 try { | 738 try { |
735 int pos = Integer.parseInt(position); | 739 int pos = Integer.parseInt(position); |
736 int act = Integer.parseInt(active); | 740 int act = Integer.parseInt(active); |
737 | 741 |
738 themes.add(pos-1, new ManagedFacet(name, null, uuid, pos, act)); | 742 themes.put( |
743 new Integer(pos-1), | |
744 new ManagedFacet(name, null, uuid, pos, act)); | |
739 } | 745 } |
740 catch (NumberFormatException nfe) { | 746 catch (NumberFormatException nfe) { |
741 logger.warn(nfe, nfe); | 747 logger.warn(nfe, nfe); |
742 } | 748 } |
743 } | 749 } |
744 | 750 |
745 public ManagedFacet get(int idx) { | 751 public ManagedFacet get(int idx) { |
746 return themes.get(idx); | 752 return themes.get(new Integer(idx)); |
747 } | 753 } |
748 | 754 |
749 public int size() { | 755 public int size() { |
750 return themes.size(); | 756 return themes.size(); |
751 } | 757 } |