Skip to content

Commit

Permalink
change map abstract to description and modied list from map layers put
Browse files Browse the repository at this point in the history
  • Loading branch information
jodygarnett committed Oct 27, 2014
1 parent 30e0dc1 commit a39427c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
Expand Up @@ -523,6 +523,7 @@ static JSONObj date(JSONObj obj, Date date) {
return obj.put("timestamp", timestamp).put("pretty", PRETTY_TIME.format(date));
}

/** Metadata: created and modified */
static JSONObj metadata(JSONObj obj, Info i) {
Date created = Metadata.created(i);
if (created != null) {
Expand Down
Expand Up @@ -26,6 +26,10 @@
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.catalog.util.CloseableIterator;
import org.geoserver.config.GeoServer;
import org.geoserver.platform.GeoServerResourceLoader;
import org.geoserver.platform.resource.Paths;
import org.geoserver.platform.resource.Resource;
import org.geoserver.platform.resource.Resource.Type;
import org.geotools.feature.NameImpl;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
Expand Down Expand Up @@ -271,20 +275,21 @@ JSONArr delete(@PathVariable String wsName,

return arr;
}

@RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.GET)
public @ResponseBody JSONArr layers(@PathVariable String wsName, @PathVariable String name) {
LayerGroupInfo m = findMap(wsName, name);

private JSONArr mapLayers(LayerGroupInfo map){
JSONArr arr = new JSONArr();
for (LayerInfo l : m.layers()) {
for (LayerInfo l : map.layers()) {
IO.layer(arr.addObject(), l);
}
return arr;
}
@RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.GET)
public @ResponseBody JSONArr mapLayers(@PathVariable String wsName, @PathVariable String name) {
LayerGroupInfo m = findMap(wsName, name);
return mapLayers(m);
}

@RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.PUT)
public @ResponseBody void layers(@RequestBody JSONArr layers, @PathVariable String wsName, @PathVariable String name) {
public @ResponseBody JSONArr mapLayers(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONArr layers) {
LayerGroupInfo m = findMap(wsName, name);

List<MapLayer> mapLayers = new ArrayList<MapLayer>();
Expand Down Expand Up @@ -332,6 +337,7 @@ public String apply(@Nullable MapLayer input) {
m.getStyles().addAll(reStyles);

cat.save(m);
return mapLayers(m);
}

private boolean checkMap(LayerGroupInfo map) {
Expand Down Expand Up @@ -362,27 +368,29 @@ JSONObj map(JSONObj obj, LayerGroupInfo map, String wsName) {
obj.put("name", map.getName())
.put("workspace", wsName)
.put("title", map.getTitle())
.put("abstract", map.getAbstract());

.put("description", map.getAbstract());
ReferencedEnvelope bounds = map.getBounds();
IO.proj(obj.putObject("proj"), bounds.getCoordinateReferenceSystem(), null);
IO.bounds(obj.putObject("bbox"), bounds);

if(!obj.has("modified")){
//JD: we don't need this, the modified flag will get populated when the user actually edits the map
/*
String path = Paths.path( "workspaces", wsName, "layergroups", String.format("%s.xml", map.getName()));
Resource r = geoServer.getCatalog().getResourceLoader().get( path );
if( r.getType() == Type.RESOURCE ){
long modified = r.lastmodified();
String time = DateUtil.formatDate( new Date(modified));
obj.put("modified", time );
obj.put("layer_count", map.getLayers().size());

// List date map was last modified
if( obj.has("modified") ){
IO.metadata(obj, map);
}
else {
// Generate metadatabased on resource timestamp
String path = Paths.path("workspaces", wsName, "layergroups",
String.format("%s.xml", map.getName()));
GeoServerResourceLoader resourceLoader = geoServer.getCatalog().getResourceLoader();
if( resourceLoader != null ){
Resource r = resourceLoader.get(path);
if (r != null && r.getType() == Type.RESOURCE) {
long modified = r.lastmodified();
IO.date(obj.putObject("modified"), new Date(modified));
}
}
*/
}

obj.put("layer_count", map.getLayers().size() );

return obj;
}
JSONObj mapDetails(JSONObj obj, LayerGroupInfo map, String wsName) {
Expand Down Expand Up @@ -418,8 +426,7 @@ else if( l instanceof LayerGroupInfo){
}

}

return IO.metadata(obj, map);
return obj;
}

LayerGroupInfo findMap(String wsName, String name) {
Expand Down
Expand Up @@ -179,7 +179,7 @@ public void testGet() throws Exception {
assertEquals("map", obj.str("name"));
assertEquals("foo", obj.str("workspace"));
assertEquals("The map", obj.str("title"));
assertEquals("This map is cool!", obj.str("abstract"));
assertEquals("This map is cool!", obj.str("description"));

assertEquals(-180d, obj.object("bbox").doub("west"), 0.1);
assertEquals(-90d, obj.object("bbox").doub("south"), 0.1);
Expand All @@ -203,7 +203,6 @@ public boolean apply(@Nullable Object o) {
}
});

assertNotNull(obj.get("created"));
assertNotNull(obj.get("modified"));
}

Expand Down Expand Up @@ -243,9 +242,11 @@ public void testPutLayers() throws Exception {
.map("map")
.defaults()
.layer("one")
.style().ysld("one.ysld").layer().map()
.style().ysld("one.ysld").layer()
.featureType().defaults().map()
.layer("two")
.style().ysld("two.ysld").layer()
.featureType().defaults()
.geoServer().build(geoServer);

JSONArr arr = new JSONArr();
Expand Down
Expand Up @@ -19,6 +19,7 @@
import javax.annotation.Nullable;
import javax.xml.transform.TransformerException;


//import org.apache.wicket.util.file.Files;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.FeatureTypeInfo;
Expand Down Expand Up @@ -55,6 +56,7 @@
import org.mockito.stubbing.Answer;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

import com.boundlessgeo.geoserver.api.controllers.MockGeoServer.LayerBuilder;
import com.google.common.base.Function;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -541,7 +543,6 @@ protected ResourceBuilder(T resource, LayerBuilder layerBuilder) {
LayerInfo layer = layerBuilder.layer;
when(resource.getName()).thenReturn(layerBuilder.name);
when(resource.getNativeName()).thenReturn(layerBuilder.name);

when(resource.getNamespace()).thenAnswer(new Answer<NamespaceInfo>() {
@Override
public NamespaceInfo answer(InvocationOnMock invocation) throws Throwable {
Expand Down Expand Up @@ -604,6 +605,14 @@ public FeatureTypeBuilder defaults() {

return schema("geom:Point,name:String");
}

public LayerBuilder layer() {
return this.layerBuilder;
}

public MapBuilder map() {
return this.layerBuilder.mapBuilder;
}
}

public class StyleBuilder extends Builder {
Expand Down

0 comments on commit a39427c

Please sign in to comment.