comparison flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java @ 2585:a71fc8f2030c

Issue 640. Remove all unnecessary output settings from attributes. flys-artifacts/trunk@4140 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 14 Mar 2012 15:00:30 +0000
parents 1fcaeced48f2
children 226c360febae 804088c2e23a
comparison
equal deleted inserted replaced
2584:5d5457a1bd5f 2585:a71fc8f2030c
90 Document oldAttrs = getAttribute(); 90 Document oldAttrs = getAttribute();
91 AttributeParser parser = new AttributeParser(oldAttrs); 91 AttributeParser parser = new AttributeParser(oldAttrs);
92 92
93 try { 93 try {
94 String[] aUUIDs = getArtifactUUIDs(context); 94 String[] aUUIDs = getArtifactUUIDs(context);
95
96 oldAttrs = removeAttributes(oldAttrs, context);
97 parser = new AttributeParser(oldAttrs);
98
95 CollectionAttribute newAttr = mergeAttributes( 99 CollectionAttribute newAttr = mergeAttributes(
96 db, context, parser, aUUIDs); 100 db, context, parser, aUUIDs);
97 101
98 if (checkOutputSettings(newAttr, context)) { 102 if (checkOutputSettings(newAttr, context)) {
99 saveCollectionAttribute(db, context, newAttr); 103 saveCollectionAttribute(db, context, newAttr);
141 saveCollectionAttribute(db, context, cAttribute); 145 saveCollectionAttribute(db, context, cAttribute);
142 146
143 return cAttribute; 147 return cAttribute;
144 } 148 }
145 149
150
151 protected Document removeAttributes(Document attrs, CallContext context) {
152 FLYSArtifact master = getMasterArtifact(context);
153 List<Output> outList = master.getOutputs(context);
154
155 Document doc = XMLUtils.newDocument();
156 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
157 doc,
158 ArtifactNamespaceContext.NAMESPACE_URI,
159 ArtifactNamespaceContext.NAMESPACE_PREFIX);
160
161 Element root = ec.create("attribute");
162 doc.appendChild(root);
163
164 if (outList.size() > 0) {
165 Element outs = ec.create("outputs");
166 root.appendChild(outs);
167
168 for (Output o : outList) {
169 Node n = (Node) XMLUtils.xpath(
170 attrs,
171 "/art:attribute/art:outputs/art:output[@name='" + o.getName() + "']",
172 XPathConstants.NODE,
173 ArtifactNamespaceContext.INSTANCE);
174 if (n != null) {
175 Node clone = doc.importNode(n, true);
176 outs.appendChild(clone);
177 }
178 }
179 }
180
181 return doc;
182 }
146 183
147 /** 184 /**
148 * @param db The ArtifactDatabase which is required to save the attribute 185 * @param db The ArtifactDatabase which is required to save the attribute
149 * into. 186 * into.
150 * @param attribute The CollectionAttribute that should be stored in the 187 * @param attribute The CollectionAttribute that should be stored in the

http://dive4elements.wald.intevation.org