Skip to content

Commit

Permalink
[GEOS-7181] New layerGroup via REST ignores styles in a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
nmco authored and aaime committed Oct 10, 2015
1 parent f8c81a4 commit 1222946
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -93,7 +93,6 @@ protected void onSetUp(SystemTestData testData) throws Exception {
WorkspaceInfo wi = catalog.getWorkspaceByName(TEST_WORKSPACE_NAME);
testData.addStyle(wi, WORKSPACED_STYLE_NAME, WORKSPACED_STYLE_FILE, this.getClass(), catalog);

assertThat(catalog.getStyleByName(WORKSPACED_STYLE_NAME), Matchers.describedAs("Style %0 should not be in the global workspace.", (nullValue()), WORKSPACED_STYLE_NAME));
assertThat(catalog.getStyleByName(wi, WORKSPACED_STYLE_NAME), Matchers.describedAs("Style %0 should be in workspace %1.", (not(nullValue())), WORKSPACED_STYLE_NAME, TEST_WORKSPACE_NAME));

Map<LayerProperty, Object> props = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -1286,7 +1286,13 @@ public StyleInfo getStyleByName(String name) {
String resource = name.substring(colon + 1);

result = getStyleByName(prefix, resource);
}
} else {
// search in default workspace first
WorkspaceInfo ws = getDefaultWorkspace();
if ( ws != null ) {
result = getStyleByName(ws, name);
}
}
if (result == null) {
result = facade.getStyleByName(name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -826,11 +826,10 @@ public StyleInfo getStyle(String id) {
public StyleInfo getStyleByName(String name) {
for (Iterator s = styles.iterator(); s.hasNext();) {
StyleInfo style = (StyleInfo) s.next();
if (null == style.getWorkspace() && name.equals(style.getName())) {
if (name.equals(style.getName())) {
return ModificationProxy.create(style, StyleInfo.class);
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,11 @@ public void marshal(Object source, HierarchicalStreamWriter writer,

if ( name != null ) {
writer.startNode("name");
writer.setValue( name );
if(wsName == null) {
writer.setValue( name );
} else {
writer.setValue( wsName + ":" + name );
}
writer.endNode();

callback.postEncodeReference( source, name, wsName, writer, context );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -8,6 +8,7 @@
import static com.google.common.collect.Sets.newHashSet;
import static org.geoserver.catalog.Predicates.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.lang.reflect.Proxy;
import java.util.ArrayList;
Expand Down Expand Up @@ -1551,8 +1552,7 @@ public void testGetStyleByNameWithWorkspace() {
s2.setWorkspace(ws);
catalog.add(s2);

assertNull("style is not global, should't have been found",
catalog.getStyleByName("styleNameWithWorkspace"));
assertNotNull(catalog.getStyleByName("styleNameWithWorkspace"));
assertNotNull(catalog.getStyleByName(ws.getName(), "styleNameWithWorkspace"));
assertNotNull(catalog.getStyleByName(ws, "styleNameWithWorkspace"));
assertNull(catalog.getStyleByName((WorkspaceInfo)null, "styleNameWithWorkspace"));
Expand Down Expand Up @@ -1583,8 +1583,7 @@ public void testGetStyleByNameWithWorkspace2() throws Exception {
s2.setWorkspace(ws2);
catalog.add(s2);

//none is global, so none should be returned
assertNull(catalog.getStyleByName("foo"));
assertEquals(s1, catalog.getStyleByName("foo"));

assertEquals(s1, catalog.getStyleByName(ws.getName(), "foo"));
assertEquals(s1, catalog.getStyleByName(ws, "foo"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -814,7 +814,7 @@ public void testRemoveStyleWithWorkspace() throws Exception {
assertTrue( f.exists() );

s = catalog.getStyleByName("foostyle");
assertNull(s);
assertNotNull(s);
s = catalog.getStyleByName(catalog.getDefaultWorkspace(), "foostyle");
catalog.remove(s);
assertFalse( f.exists() );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testPutWorkspaceStyle() throws Exception {
assertNotNull(l.getDefaultStyle().getWorkspace());

Document dom = getAsDOM("/rest/layers/cite:Buildings.xml");
assertXpathExists("/layer/defaultStyle/name[text() = 'foo']", dom);
assertXpathExists("/layer/defaultStyle/name[text() = 'cite:foo']", dom);
assertXpathExists("/layer/defaultStyle/workspace[text() = 'cite']", dom);
assertXpathEvaluatesTo("http://localhost:8080/geoserver/rest/workspaces/cite/styles/foo.xml",
"//defaultStyle/atom:link/@href", dom );
Expand Down Expand Up @@ -238,7 +238,7 @@ public void testPutWorkspaceAlternateStyle() throws Exception {
assertNotNull(style.getWorkspace());

Document dom = getAsDOM("/rest/layers/cite:Buildings.xml");
assertXpathExists("/layer/styles/style/name[text() = 'foo']", dom);
assertXpathExists("/layer/styles/style/name[text() = 'cite:foo']", dom);
assertXpathExists("/layer/styles/style/workspace[text() = 'cite']", dom);
assertXpathEvaluatesTo("http://localhost:8080/geoserver/rest/workspaces/cite/styles/foo.xml",
"//styles/style/atom:link/@href", dom );
Expand Down

0 comments on commit 1222946

Please sign in to comment.