Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java @ 8452:b9a8463ac636
(issue1732) When duplication wsplgen artificats fix shapefile layers
The shapefile layers are copied but still contained the old names
and paths and the wms layer refered to layers from the old
artifact. This was broken.
Now the old artificat id is replaced by the new artifact id in the
mapfiles.
Duplication most wsplgen artifacts
should now work.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 28 Oct 2014 18:52:35 +0100 |
parents | e4606eae8ea5 |
children | 572c102b1819 |
comparison
equal
deleted
inserted
replaced
8451:e3e5d6bb4902 | 8452:b9a8463ac636 |
---|---|
21 import java.util.Arrays; | 21 import java.util.Arrays; |
22 import java.util.List; | 22 import java.util.List; |
23 | 23 |
24 import org.apache.log4j.Logger; | 24 import org.apache.log4j.Logger; |
25 import org.apache.velocity.Template; | 25 import org.apache.velocity.Template; |
26 import org.apache.commons.io.FileUtils; | |
26 import org.dive4elements.artifactdatabase.state.Facet; | 27 import org.dive4elements.artifactdatabase.state.Facet; |
27 import org.dive4elements.artifacts.Artifact; | 28 import org.dive4elements.artifacts.Artifact; |
28 import org.dive4elements.artifacts.CallContext; | 29 import org.dive4elements.artifacts.CallContext; |
29 import org.dive4elements.artifacts.CallMeta; | 30 import org.dive4elements.artifacts.CallMeta; |
30 import org.dive4elements.artifacts.GlobalContext; | 31 import org.dive4elements.artifacts.GlobalContext; |
107 private static final String I18N_HWS_LINES_OFFICIAL = "floodmap.hws.lines.official"; | 108 private static final String I18N_HWS_LINES_OFFICIAL = "floodmap.hws.lines.official"; |
108 private static final String HWS_LINES = "hws-lines"; | 109 private static final String HWS_LINES = "hws-lines"; |
109 private static final String HWS_POINT_SHAPE = "hws-points.shp"; | 110 private static final String HWS_POINT_SHAPE = "hws-points.shp"; |
110 private static final String HWS_POINTS = "hws-points"; | 111 private static final String HWS_POINTS = "hws-points"; |
111 | 112 |
113 | |
114 /* List of possible map files this state handles . */ | |
115 private static final String[] POSSIBLE_ADDITIONAL_MAPFILES = {HWS_LINES, | |
116 HWS_POINTS, | |
117 WSPLGEN_USER_RGD, | |
118 "barriers-lines", | |
119 "barriers-poly"}; | |
120 | |
121 | |
122 | |
112 /** | 123 /** |
113 * @param orig | 124 * @param orig |
114 * @param owner | 125 * @param owner |
115 * @param context | 126 * @param context |
116 * @param callMeta | 127 * @param callMeta |
122 Object context, | 133 Object context, |
123 CallMeta callMeta | 134 CallMeta callMeta |
124 ) { | 135 ) { |
125 log.info("Initialize State with Artifact: " + orig.identifier()); | 136 log.info("Initialize State with Artifact: " + orig.identifier()); |
126 | 137 |
127 copyShapeDir(orig, owner); | 138 copyAndFixShapeDir(orig, owner); |
128 modifyFacets(orig, owner, context, callMeta); | 139 modifyFacets(orig, owner, context, callMeta); |
129 | 140 |
130 ArtifactMapfileGenerator amfg = new ArtifactMapfileGenerator(); | 141 ArtifactMapfileGenerator amfg = new ArtifactMapfileGenerator(); |
131 try { | 142 try { |
132 amfg.generate(); | 143 amfg.generate(); |
135 log.error(e.getMessage(), e); | 146 log.error(e.getMessage(), e); |
136 } | 147 } |
137 } | 148 } |
138 | 149 |
139 | 150 |
140 protected void copyShapeDir(Artifact orig, Artifact owner) { | 151 protected void copyAndFixShapeDir(Artifact orig, Artifact owner) { |
152 /* We have a lot of generated mapfiles in here possibly. | |
153 * They use the orig artificact identifier. That has to | |
154 * be fixed.*/ | |
141 File origDir = getDirectory((D4EArtifact) orig); | 155 File origDir = getDirectory((D4EArtifact) orig); |
142 File thisDir = getDirectory((D4EArtifact) owner); | 156 File thisDir = getDirectory((D4EArtifact) owner); |
143 | 157 |
144 FileTools.copyDirectory(origDir, thisDir); | 158 FileTools.copyDirectory(origDir, thisDir); |
159 | |
160 for (String candidate: POSSIBLE_ADDITIONAL_MAPFILES) { | |
161 File f = new File(thisDir, MapfileGenerator.MS_LAYER_PREFIX + candidate); | |
162 if (f.exists()) { | |
163 log.debug("Fixing artifiact id's in: " + f); | |
164 try { | |
165 String content = FileUtils.readFileToString(f); | |
166 FileUtils.writeStringToFile(f, | |
167 content.replaceAll(orig.identifier(), owner.identifier())); | |
168 } catch (IOException e) { | |
169 log.debug("failed."); | |
170 } | |
171 } | |
172 } | |
145 } | 173 } |
146 | 174 |
147 | 175 |
148 protected void modifyFacets( | 176 protected void modifyFacets( |
149 Artifact orig, | 177 Artifact orig, |
163 WMSLayerFacet wms = (WMSLayerFacet) facet; | 191 WMSLayerFacet wms = (WMSLayerFacet) facet; |
164 | 192 |
165 List<String> layers = wms.getLayers(); | 193 List<String> layers = wms.getLayers(); |
166 | 194 |
167 for (String layer: layers) { | 195 for (String layer: layers) { |
168 if (layer.startsWith(MapfileGenerator.MS_WSPLGEN_PREFIX)) { | 196 log.debug("Have layer: " + layer); |
197 if (layer.contains(orig.identifier())) { | |
169 wms.removeLayer(layer); | 198 wms.removeLayer(layer); |
170 | 199 |
171 String newLayer = MapfileGenerator.MS_WSPLGEN_PREFIX + | 200 String newLayer = layer.replace(orig.identifier(), owner.identifier()); |
172 owner.identifier(); | |
173 | 201 |
174 wms.addLayer(newLayer); | 202 wms.addLayer(newLayer); |
175 | 203 |
176 log.debug( | 204 log.debug( |
177 "Replaced layer: " + layer + " with " + newLayer); | 205 "Replaced layer: " + layer + " with " + newLayer); |