comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 1771:c62ff9e72cea

Restore mapping of state id to facets (revert, rev 3083 and 3088). flys-artifacts/trunk@3092 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Oct 2011 09:32:05 +0000
parents 5d8b3880a553
children a8aa343799a2
comparison
equal deleted inserted replaced
1770:e8a98eee816d 1771:c62ff9e72cea
95 protected String name; 95 protected String name;
96 96
97 /** The data that have been inserted into this artifact. */ 97 /** The data that have been inserted into this artifact. */
98 protected Map<String, StateData> data; 98 protected Map<String, StateData> data;
99 99
100 /** The list of facets produced by this artifact. */ 100 /** Mapping of state names to created facets. */
101 protected List<Facet> facets; 101 protected Map<String, List<Facet>> facets;
102 102
103 /** 103 /**
104 * Used to generates "view" on the facets (hides facets not matching the 104 * Used to generates "view" on the facets (hides facets not matching the
105 * filter in output of collection); out -&gt; facets. 105 * filter in output of collection); out -&gt; facets.
106 */ 106 */
111 * The default constructor that creates an empty FLYSArtifact. 111 * The default constructor that creates an empty FLYSArtifact.
112 */ 112 */
113 public FLYSArtifact() { 113 public FLYSArtifact() {
114 data = new TreeMap<String, StateData>(); 114 data = new TreeMap<String, StateData>();
115 previousStateIds = new ArrayList<String>(); 115 previousStateIds = new ArrayList<String>();
116 facets = new ArrayList<Facet>(); 116 facets = new HashMap<String, List<Facet>>();
117 } 117 }
118 118
119 119
120 /** 120 /**
121 * Returns the name of the concrete artifact. 121 * Returns the name of the concrete artifact.
206 return copy; 206 return copy;
207 } 207 }
208 208
209 /** 209 /**
210 * Return a copy of the facet mapping. 210 * Return a copy of the facet mapping.
211 * @return Copy of facets list. 211 * @return Mapping of state-ids to facets.
212 */ 212 */
213 protected List<Facet> cloneFacets() { 213 protected Map<String, List<Facet>> cloneFacets() {
214 List copy = new ArrayList<Facet>(facets.size()); 214 Map copy = new HashMap<String, List<Facet>>();
215 215
216 for (Facet facet: facets) { 216 for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) {
217 copy.add(facet.deepCopy()); 217 List<Facet> facets = entry.getValue();
218 List<Facet> facetCopies = new ArrayList<Facet>(facets.size());
219 for (Facet facet: facets) {
220 facetCopies.add(facet.deepCopy());
221 }
222 copy.put(entry.getKey(), facetCopies);
218 } 223 }
219 224
220 return copy; 225 return copy;
221 } 226 }
222 227
223 228
224 /** 229 /**
225 * (called from setup). 230 * (called from setup).
231 * @param artifact master-artifact (if any, otherwise initialize is not called).
226 */ 232 */
227 protected void initialize( 233 protected void initialize(
228 Artifact artifact, 234 Artifact artifact,
229 Object context, 235 Object context,
230 CallMeta callMeta) 236 CallMeta callMeta)
538 public Collection<StateData> getAllData() { 544 public Collection<StateData> getAllData() {
539 return data.values(); 545 return data.values();
540 } 546 }
541 547
542 548
549 /**
550 * Get facet as stored internally, with equalling name and index than given
551 * facet.
552 * @param facet that defines index and name of facet searched.
553 * @return facet instance or null if not found.
554 */
543 public Facet getNativeFacet(Facet facet) { 555 public Facet getNativeFacet(Facet facet) {
544 String name = facet.getName(); 556 String name = facet.getName();
545 int index = facet.getIndex(); 557 int index = facet.getIndex();
546 558
547 for (Facet f: facets) { 559 for (Map.Entry<String, List<Facet>> facetList: facets.entrySet()) {
548 if (f.getIndex() == index && f.getName().equals(name)) { 560 for (Facet f: facetList.getValue()) {
549 return f; 561 if (f.getIndex() == index && f.getName().equals(name)) {
562 return f;
563 }
550 } 564 }
551 } 565 }
552 566
553 logger.warn("Could not find facet: " + name + " at " + index); 567 logger.warn("Could not find facet: " + name + " at " + index);
554 return null; 568 return null;
773 if (list == null || list.size() == 0) { 787 if (list == null || list.size() == 0) {
774 logger.debug("-> No output modes for this state."); 788 logger.debug("-> No output modes for this state.");
775 return new ArrayList<Output>(); 789 return new ArrayList<Output>();
776 } 790 }
777 791
778 if (facets == null || facets.size() == 0) { 792 List<Facet> fs = facets.get(state.getID());
793
794 if (fs == null || fs.size() == 0) {
779 logger.debug("No facets found."); 795 logger.debug("No facets found.");
780 return new ArrayList<Output>(); 796 return new ArrayList<Output>();
781 } 797 }
782 798
783 return generateOutputs(list, facets); 799 return generateOutputs(list, fs);
784 } 800 }
785 801
786 802
787 /** 803 /**
788 * Generate a list of outputs with facets from fs if type is found in list 804 * Generate a list of outputs with facets from fs if type is found in list
949 return res; 965 return res;
950 } 966 }
951 finally { 967 finally {
952 if (generateFacets) { 968 if (generateFacets) {
953 if (fs.isEmpty()) { 969 if (fs.isEmpty()) {
954 facets.removeAll(fs); 970 facets.remove(stateID);
955 } 971 }
956 else { 972 else {
957 facets.addAll(fs); 973 facets.put(stateID, fs);
958 } 974 }
959 } 975 }
960 } 976 }
961 } 977 }
962 978

http://dive4elements.wald.intevation.org