Skip to content

Commit

Permalink
[GEOS-8764] Allow LayerGroups in default worksaces to be found when w…
Browse files Browse the repository at this point in the history
…orkspace isn't specified
  • Loading branch information
tbarsballe authored and jodygarnett committed Jun 22, 2018
1 parent 29a96ce commit dea9aaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1060,6 +1060,9 @@ public LayerGroupInfo getLayerGroupByName(String name) {


int colon = name.indexOf(':'); int colon = name.indexOf(':');
if (colon == -1) { if (colon == -1) {
// if there is no prefix, try the default workspace
WorkspaceInfo defaultWs = getDefaultWorkspace();
workspaceName = defaultWs == null ? null : defaultWs.getName();
layerGroupName = name; layerGroupName = name;
} }
if (colon != -1) { if (colon != -1) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2124,18 +2124,30 @@ public void testGetLayerGroupByName() {
assertNull(catalog.getLayerGroupByName(catalog.getDefaultWorkspace(), "layerGroup")); assertNull(catalog.getLayerGroupByName(catalog.getDefaultWorkspace(), "layerGroup"));


LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup(); LayerGroupInfo lg2 = catalog.getFactory().createLayerGroup();
WorkspaceInfo defaultWorkspace = catalog.getDefaultWorkspace(); lg2.setWorkspace(ws);
lg2.setWorkspace(defaultWorkspace); assertEquals(ws, catalog.getDefaultWorkspace());
lg2.setName("layerGroup2"); lg2.setName("layerGroup2");
lg2.getLayers().add(l); lg2.getLayers().add(l);
lg2.getStyles().add(s); lg2.getStyles().add(s);
catalog.add(lg2); catalog.add(lg2);


// When in the default workspace, we should be able to find it without the prefix
assertNotNull(catalog.getLayerGroupByName("layerGroup2"));
assertNotNull(catalog.getLayerGroupByName(ws.getName() + ":layerGroup2"));
assertNotNull(catalog.getLayerGroupByName(catalog.getDefaultWorkspace(), "layerGroup2"));
assertNull(catalog.getLayerGroupByName("cite", "layerGroup2"));

// Repeat in a non-default workspace
WorkspaceInfo ws2 = catalog.getFactory().createWorkspace();
ws2.setName("ws2");
catalog.add(ws2);
catalog.setDefaultWorkspace(ws2);

assertNull( assertNull(
"layerGropu2 is not global, should not be found", "layerGroup2 is not global, should not be found",
catalog.getLayerGroupByName("layerGroup2")); catalog.getLayerGroupByName("layerGroup2"));
assertNotNull(catalog.getLayerGroupByName(defaultWorkspace.getName() + ":layerGroup2")); assertNotNull(catalog.getLayerGroupByName(ws.getName() + ":layerGroup2"));
assertNotNull(catalog.getLayerGroupByName(catalog.getDefaultWorkspace(), "layerGroup2")); assertNotNull(catalog.getLayerGroupByName(ws, "layerGroup2"));
assertNull(catalog.getLayerGroupByName("cite", "layerGroup2")); assertNull(catalog.getLayerGroupByName("cite", "layerGroup2"));
} }


Expand Down Expand Up @@ -2165,6 +2177,7 @@ public void testGetLayerGroupByNameWithColon() {
@Test @Test
public void testGetLayerGroupByNameWithWorkspace() { public void testGetLayerGroupByNameWithWorkspace() {
addLayer(); addLayer();
assertEquals(ws, catalog.getDefaultWorkspace());


CatalogFactory factory = catalog.getFactory(); CatalogFactory factory = catalog.getFactory();
LayerGroupInfo lg1 = factory.createLayerGroup(); LayerGroupInfo lg1 = factory.createLayerGroup();
Expand Down Expand Up @@ -2220,8 +2233,9 @@ public void testGetLayerGroupByNameWithWorkspace() {
lg2.getStyles().add(s2); lg2.getStyles().add(s2);
catalog.add(lg2); catalog.add(lg2);


// lg is not global, should not be found at least we specify a prefixed name // lg is not global, but it is in the default workspace, so it should be found if we don't
assertNull(catalog.getLayerGroupByName("lg")); // specify the workspace
assertEquals(lg1, catalog.getLayerGroupByName("lg"));


assertEquals(lg1, catalog.getLayerGroupByName(ws.getName(), "lg")); assertEquals(lg1, catalog.getLayerGroupByName(ws.getName(), "lg"));
assertEquals(lg1, catalog.getLayerGroupByName(ws, "lg")); assertEquals(lg1, catalog.getLayerGroupByName(ws, "lg"));
Expand Down

0 comments on commit dea9aaf

Please sign in to comment.