GeoserverConfig.LayerGroups (GeoserverConfig v0.4.1)

Copy Markdown View Source

Provides functionality to manage Layer Groups in GeoServer via the REST API.

All functions require a GeoserverConfig.Connection as their first argument.

Summary

Functions

Adds a layer with an optional style to a GeoServer layer group.

Creates a new layer group in GeoServer.

Deletes a layer group from GeoServer by name.

Fetches a single layer group by name from GeoServer.

Lists all layer groups in GeoServer.

Lists layer groups scoped to a specific workspace.

Removes a layer from a GeoServer layer group.

Updates an existing layer group.

Functions

add_layer_to_group(conn, group_name, layer_name, style_name \\ nil)

Adds a layer with an optional style to a GeoServer layer group.

Fetches the current group state and appends the new layer before updating. If a style name is provided, it is also appended to the group-level styles array to maintain the layer:style count parity required by GeoServer.

Returns

  • {:ok, body} on success
  • {:error, reason} on failure

create_layer_group(conn, body)

Creates a new layer group in GeoServer.

Accepts either an XML string or a JSON map as the body.

Returns

  • {:ok, body} on success (2xx)
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, reason}} on transport error

delete_layer_group(conn, name)

Deletes a layer group from GeoServer by name.

Returns

  • {:ok, name} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, reason}} on transport error

get_layer_group(conn, group_name)

Fetches a single layer group by name from GeoServer.

Returns

  • {:ok, group} on success (a map with the layer group details as JSON)
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, {:request_failed, reason}} on transport error

list_layer_groups(conn)

Lists all layer groups in GeoServer.

When workspace is provided, only layer groups in that workspace are returned (hitting /workspaces/:workspace/layergroups). Without a workspace argument, the global /layergroups endpoint is used.

GeoServer returns a map instead of a list when only one group exists, and returns the string "" instead of an empty map when no groups exist; both cases are normalised to a list.

Returns

  • {:ok, [group]} on success
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, {:request_failed, reason}} on transport error

list_layer_groups(conn, workspace)

Lists layer groups scoped to a specific workspace.

Returns

  • {:ok, [group]} on success
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, {:request_failed, reason}} on transport error

remove_layer_from_group(conn, group_name, layer_name)

Removes a layer from a GeoServer layer group.

Fetches the current group state and filters out the named layer before updating. If the group has a matching number of styles, the corresponding style at the same index is also removed to maintain layer:style parity.

Returns

  • {:ok, body} on success
  • {:error, :layer_not_found} if the layer is not in the group
  • {:error, reason} on other failure

update_layer_group(conn, name, body)

Updates an existing layer group.

Accepts either an XML string or a JSON map as the body.

Returns

  • {:ok, body} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, reason}} on transport error