Commit c9673bdd authored by Andrea Aime's avatar Andrea Aime
Browse files

[GEOS-7011] WPS Download fails if there is the same SLD as Default and Selected

parent 482155fc
......@@ -8,8 +8,8 @@ package org.geoserver.wps.gs.download;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -277,31 +277,26 @@ final class DownloadUtilities {
* @throws IOException
*/
static List<File> collectStyles(LayerInfo layerInfo) throws IOException {
final List<File> styles = new ArrayList<File>();
final List<File> styleFiles = new ArrayList<File>();
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Searching for default style");
}
// default style
final StyleInfo style = layerInfo.getDefaultStyle();
File styleFile = findStyle(style);
if (styleFile != null) {
styles.add(styleFile);
}
// other styles
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Searching for other styles");
// collect in a set to avoid duplicates (the styles can contain a copy of the
// default style)
LinkedHashSet<StyleInfo> styles = new LinkedHashSet<>();
styles.add(layerInfo.getDefaultStyle());
if (layerInfo.getStyles() != null) {
styles.addAll(layerInfo.getStyles());
}
final Set<StyleInfo> otherStyles = layerInfo.getStyles();
if (otherStyles != null && !otherStyles.isEmpty()) {
for (StyleInfo si : otherStyles) {
styleFile = findStyle(si);
if (styleFile != null) {
styles.add(styleFile);
}
for (StyleInfo si : styles) {
File styleFile = findStyle(si);
if (styleFile != null) {
styleFiles.add(styleFile);
}
}
return styles;
return styleFiles;
}
}
......@@ -19,6 +19,7 @@ import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.data.test.MockData;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.data.util.IOUtils;
......@@ -48,6 +49,7 @@ import org.geotools.util.DefaultProgressListener;
import org.geotools.util.NullProgressListener;
import org.geotools.util.logging.Logging;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.util.InternationalString;
......@@ -141,6 +143,11 @@ public class DownloadProcessTest extends WPSTestSupport {
"download-process/download.properties"), "download.properties");
}
@Before
public void clearPolygons() throws IOException {
revertLayer(MockData.POLYGONS);
}
/**
* Test get features as shapefile.
*
......@@ -181,6 +188,22 @@ public class DownloadProcessTest extends WPSTestSupport {
Assert.assertEquals(rawSource.size(), rawTarget.size());
}
/**
* Test downloading with a duplicate style
*
* @throws Exception the exception
*/
@Test
public void testDownloadWithDuplicateStyle() throws Exception {
String polygonsName = getLayerId(MockData.POLYGONS);
LayerInfo li = getCatalog().getLayerByName(polygonsName);
// setup an alternative equal to the main style
li.getStyles().add(li.getDefaultStyle());
getCatalog().save(li);
testGetFeaturesAsShapefile();
}
/**
* Test filtered clipped features.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment