Skip to content

Commit

Permalink
Sort styles for prettiness and easier testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ttislerdg committed Feb 16, 2017
1 parent dbb9b2a commit 6a0a9b0
Show file tree
Hide file tree
Showing 13 changed files with 634 additions and 231 deletions.
Expand Up @@ -22,15 +22,19 @@
import org.mrgeo.data.DataProviderFactory.AccessMode;
import org.mrgeo.data.adhoc.AdHocDataProvider;
import org.mrgeo.utils.HadoopUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;

public class ColorScaleManager
{
private static final Logger log = LoggerFactory.getLogger(ColorScale.class);

private static Map<String, ColorScale> colorscales;

Expand Down Expand Up @@ -67,15 +71,24 @@ public static ColorScale fromName(final String colorScaleName) throws ColorScale

public static ColorScale[] getColorScaleList() throws IOException
{
return colorscales.values().toArray(new ColorScale[0]);
// for convenience and testing, we'll sort the list...
ColorScale[] list = new ColorScale[colorscales.size()];
int cnt = 0;
for (Map.Entry<String, ColorScale> entry: colorscales.entrySet())
{
list[cnt++] = entry.getValue();
}

return list;
//return colorscales.values().toArray(new ColorScale[0]);
}

@SuppressFBWarnings(value = "WEAK_FILENAMEUTILS", justification = "Using Java 1.7+, weak filenames are fixed")
private static synchronized void initializeColorscales() throws ColorScale.ColorScaleException
{
if (colorscales == null)
{
colorscales = new HashMap<>();
colorscales = new TreeMap<>();

Properties props = MrGeoProperties.getInstance();

Expand All @@ -98,7 +111,7 @@ private static synchronized void initializeColorscales() throws ColorScale.Color
{
ColorScale cs = ColorScale.loadFromXML(fdis);

colorscales.put(FilenameUtils.getBaseName(name), cs);
colorscales.put(cs.getName(), cs);
}
}
}
Expand All @@ -113,6 +126,15 @@ private static synchronized void initializeColorscales() throws ColorScale.Color
{
throw new ColorScale.ColorScaleException("No color scale base directory configured");
}

if (log.isInfoEnabled())
{
log.info("ColorScales:");
for (String name : colorscales.keySet())
{
log.info(" - " + FilenameUtils.getBaseName(name));
}
}
}
}

Expand Down
Expand Up @@ -214,6 +214,10 @@ public Response getTile(@PathParam("version") final String version,
if (colorScaleName != null)
{
cs = ColorScaleManager.fromName(colorScaleName);
if (cs == null)
{
throw new ColorScale.ColorScaleException("Cannot open colorscale: " + colorScaleName);
}
}
else if (colorScale != null)
{
Expand Down
Expand Up @@ -569,7 +569,7 @@ public void testGetTileColorScaleNameNonExistent() throws Exception
.request().get();

Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
Assert.assertEquals("Unable to open color scale file", response.readEntity(String.class));
Assert.assertEquals("Unable to open color scale", response.readEntity(String.class));
}

@Override
Expand Down
Expand Up @@ -164,6 +164,7 @@ private void addLayersToDescribeTiles(Element dt, Version version,
ColorScale[] scales = ColorScaleManager.getColorScaleList();
for (ColorScale scale : scales)
{
System.out.println(scale.getName());
XmlUtils.createTextElement2(styles, "Value", scale.getName());
}
}
Expand Down
Expand Up @@ -96,6 +96,6 @@ public void testDescribeTiles140() throws Exception
.queryParam("VERSION", "1.4.0")
.request().get();

processXMLResponse(response, "DescribeTiles.xml");
processXMLResponse(response, "DescribeTiles140.xml");
}
}
Expand Up @@ -295,7 +295,8 @@ protected static void processXMLResponse(final Response response,
log.info("Comparing result to baseline text in " + baselineFile + " ...");
//Assert.assertEquals(IOUtils.toString(inputStream), content);

XMLAssert.assertXMLEqual(IOUtils.toString(inputStream), content);
String xml = IOUtils.toString(inputStream);
XMLAssert.assertXMLEqual(xml, content);
}
finally
{
Expand Down
Expand Up @@ -65,9 +65,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="IslandsElevation-v2-color-scale">
Expand Down Expand Up @@ -134,9 +133,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="IslandsElevation-v2-no-pyramid">
Expand All @@ -158,9 +156,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="IslandsElevation-v2-no-pyramid-extra-metadata">
Expand Down Expand Up @@ -227,9 +224,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="IslandsElevation-v2-no-stats">
Expand Down Expand Up @@ -296,9 +292,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="cost-distance">
Expand Down Expand Up @@ -375,9 +370,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="cost-distance-shift-2">
Expand Down Expand Up @@ -444,9 +438,8 @@
</TiledCrs>
<TiledStyles>
<Value>default</Value>
<Value>Default</Value>
<Value>Rainbow</Value>
<Value>elevation</Value>
<Value>rainbow</Value>
</TiledStyles>
</Layer>
<Layer name="small-3band">
Expand Down

0 comments on commit 6a0a9b0

Please sign in to comment.