Skip to content

Commit

Permalink
Fixed #5. Finished datastore service.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmikecreations committed Dec 15, 2022
1 parent ccc5ebc commit 601f56b
Show file tree
Hide file tree
Showing 27 changed files with 911 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models.Catalog
{
public class ConnectionParameter
{
[JsonPropertyName("@key")]
public string Key { get; }

[JsonPropertyName("$")]
public string Value { get; }

[JsonConstructor]
public ConnectionParameter(string key, string value)
{
Key = key;
Value = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models.Catalog
{
public class ConnectionParameters
{
[JsonPropertyName("entry")]
public IList<ConnectionParameter> ConnectionParameterList { get; }

[JsonConstructor]
public ConnectionParameters(IList<ConnectionParameter> connectionParameters)
{
ConnectionParameterList = connectionParameters;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models
namespace GeoTools.GeoServer.Models.CatalogResponses
{
public class NamedLink
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using GeoTools.GeoServer.Models.Catalog;
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models.Datastore
{
/// <summary>
/// Datastore.
/// </summary>
public class DataStoreInfo
{
/// <summary>
/// Name of data store.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; }

/// <summary>
/// Description of data store.
/// </summary>
[JsonPropertyName("description")]
public string Description { get; }

/// <summary>
/// Whether or not the data store is enabled.
/// </summary>
[JsonPropertyName("enabled")]
public bool Enabled { get; } = true;

[JsonPropertyName("connectionParameters")]
public ConnectionParameters ConnectionParameters { get; }

[JsonPropertyName("disableOnConnFailure")]
public bool DisableOnConnFailure { get; }

[JsonConstructor]
public DataStoreInfo(string name, string description, bool enabled, ConnectionParameters connectionParameters, bool disableOnConnFailure)
{
Name = name;
Description = description;
Enabled = enabled;
ConnectionParameters = connectionParameters;
DisableOnConnFailure = disableOnConnFailure;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using GeoTools.GeoServer.Models.Catalog;
using GeoTools.GeoServer.Models.CatalogResponses;
using System;
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models.Datastore
{
/// <summary>
/// Datastore.
/// </summary>
public class DataStoreSummary
{
/// <summary>
/// Name of data store.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; }

/// <summary>
/// Description of data store.
/// </summary>
[JsonPropertyName("description")]
public string Description { get; }

/// <summary>
/// Whether or not the data store is enabled.
/// </summary>
[JsonPropertyName("enabled")]
public bool Enabled { get; } = true;

[JsonPropertyName("connectionParameters")]
public ConnectionParameters ConnectionParameters { get; }

[JsonPropertyName("workspace")]
public NamedLink Workspace { get; }

[JsonPropertyName("_default")]
public bool Default { get; }

[JsonPropertyName("disableOnConnFailure")]
public bool DisableOnConnFailure { get; }

[JsonPropertyName("featureTypes")]
public Uri FeatureTypes { get; }

[JsonConstructor]
public DataStoreSummary(string name, string description, bool enabled, ConnectionParameters connectionParameters, NamedLink workspace, bool @default, bool disableOnConnFailure, Uri featureTypes)
{
Name = name;
Description = description;
Enabled = enabled;
ConnectionParameters = connectionParameters;
Workspace = workspace;
Default = @default;
DisableOnConnFailure = disableOnConnFailure;
FeatureTypes = featureTypes;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using GeoTools.GeoServer.Models.Catalog;
using System;
using System.Collections.Generic;

namespace GeoTools.GeoServer.Models.Datastore.Sources
{
public class ShapefileConnectionParameters : ConnectionParameters
{
public ShapefileConnectionParameters(Uri shapefilePath, Uri @namespace) : base(CreateConnectionParameters(shapefilePath, @namespace))
{

}

private static IList<ConnectionParameter> CreateConnectionParameters(Uri shapefilePath, Uri @namespace)
{
return new List<ConnectionParameter>
{
new ConnectionParameter("namespace", @namespace.ToString()),
new ConnectionParameter("url", shapefilePath.ToString()),
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models
namespace GeoTools.GeoServer.Models.Workspace
{
/// <summary>
/// Workspace.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using GeoTools.GeoServer.Models.CatalogResponses;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models
namespace GeoTools.GeoServer.Models.Workspace
{
public class WorkspaceResponseWrapper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;

namespace GeoTools.GeoServer.Models
namespace GeoTools.GeoServer.Models.Workspace
{
/// <summary>
/// Workspace Response.
Expand Down Expand Up @@ -29,28 +30,35 @@ public class WorkspaceSummary
/// URL to Datas tores in this workspace.
/// </summary>
[JsonPropertyName("dataStores")]
public string DataStores { get; }
public Uri DataStores { get; }

/// <summary>
/// URL to Coverage stores in this workspace.
/// </summary>
[JsonPropertyName("coverageStores")]
public string CoverageStores { get; }
public Uri CoverageStores { get; }

/// <summary>
/// URL to WMS stores in this workspace.
/// </summary>
[JsonPropertyName("wmsStores")]
public string WmsStores { get; }
public Uri WmsStores { get; }

/// <summary>
/// URL to WMTS stores in this workspace.
/// </summary>
[JsonPropertyName("wmtsStores")]
public Uri WmtsStores { get; }

[JsonConstructor]
public WorkspaceSummary(string name, string dataStores, string coverageStores, string wmsStores, bool isolated = false)
public WorkspaceSummary(string name, Uri dataStores, Uri coverageStores, Uri wmsStores, Uri wmtsStores, bool isolated = false)
{
Name = name;
Isolated = isolated;
DataStores = dataStores;
CoverageStores = coverageStores;
WmsStores = wmsStores;
WmtsStores = wmtsStores;
}
}
}
84 changes: 82 additions & 2 deletions src/GeoTools.GeoServer.Abstractions/Services/IDatastoreService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using GeoTools.GeoServer.Models;
using GeoTools.GeoServer.Models.CatalogResponses;
using GeoTools.GeoServer.Models.Datastore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;

namespace GeoTools.GeoServer.Services
{
public interface IDatastoreService
{

/// <summary>
/// Get a list of data stores.
/// </summary>
Expand All @@ -22,5 +23,84 @@ public interface IDatastoreService
/// <para>Def: Returns null / <seealso cref="ArgumentOutOfRangeException"/>.</para>
/// </remarks>
Task<GeoServerResponse<IList<NamedLink>>> GetDatastoresAsync(string workspaceName, CancellationToken token);

/// <summary>
/// Retrieve a particular data store from a workspace.
/// </summary>
/// <param name="workspaceName">The name of the worskpace containing the data store.</param>
/// <param name="datastoreName">The name of the data store to retrieve.</param>
/// <param name="token"></param>
/// <returns>Controls a particular data store in a given workspace.</returns>
/// <remarks>
/// <para>200: OK. Returns the model.</para>
/// <para>401: Missing auth configuration. Returns null / <seealso cref="UnauthorizedAccessException"/>.</para>
/// <para>404: Workspace or datastore does not exist. Returns null.</para>
/// <para>Def: Returns null / <seealso cref="ArgumentOutOfRangeException"/>.</para>
/// </remarks>
Task<GeoServerResponse<DataStoreSummary>> GetDatastoreAsync(string workspaceName, string datastoreName, CancellationToken token);

/// <summary>
/// Create a new data store.
/// </summary>
/// <param name="workspaceName">The name of the worskpace containing the data stores.</param>
/// <param name="datastoreInfo">
/// The data store body information to upload.
/// The contents of the connection parameters will differ depending on the type of data store being added.
/// </param>
/// <param name="token"></param>
/// <returns>Adds a new data store to the workspace.</returns>
/// <remarks>
/// <para>201: Created. Returns true if created successfully, false if already exists.</para>
/// <para>401: Missing auth configuration. Returns null / <seealso cref="UnauthorizedAccessException"/>.</para>
/// <para>500: Workspace not found. Returns null.</para>
/// <para>Def: Returns null / <seealso cref="ArgumentOutOfRangeException"/>.</para>
/// See examples at https://github.com/geoserver/geoserver/blob/main/src/community/rest-openapi/openapi/src/main/resources/org/geoserver/rest/openapi/1.0.0/datastores.yaml#L61.
/// </remarks>
Task<GeoServerResponse<Uri>> CreateDatastoreAsync(string workspaceName, DataStoreInfo datastoreInfo, CancellationToken token);

/// <summary>
/// Delete data store.
/// </summary>
/// <param name="workspaceName">The name of the worskpace containing the data store.</param>
/// <param name="datastoreName">The name of the data store to delete.</param>
/// <param name="recurse">
/// The recurse controls recursive deletion. When set to true all
/// resources contained in the store are also removed.The default value
/// is "false".
/// </param>
/// <param name="token"></param>
/// <returns>Deletes a data store from the server.</returns>
/// <remarks>
/// <para>200: Success datastore deleted. Returns true.</para>
/// <para>401: Missing auth configuration. Returns false / <seealso cref="UnauthorizedAccessException"/>.</para>
/// <para>403: Datastore is not empty (and recurse not true). Returns false.</para>
/// <para>404: Workspace or datastore doesn't exist. Returns false.</para>
/// <para>Def: Returns false / <seealso cref="ArgumentOutOfRangeException"/>.</para>
/// </remarks>
Task<GeoServerResponse<bool>> DeleteDatastoreAsync(string workspaceName, string datastoreName, bool? recurse, CancellationToken token);

/// <summary>
/// Modify a data store.
/// </summary>
/// <param name="workspaceName">The name of the worskpace containing the data store.</param>
/// <param name="datastore">
/// The updated data store definition.
/// For a PUT, only values which should be changed need to be included.
/// The connectionParameters map counts as a single value,
/// so if you change it all preexisting connection parameters will be
/// overwritten.
/// The contents of the connection parameters will differ depending on the
/// type of data store being added.
/// </param>
/// <param name="token"></param>
/// <returns>Modify data store ds.</returns>
/// <remarks>
/// <para>200: Modified. Returns true.</para>
/// <para>401: Missing auth configuration. Returns false / <seealso cref="UnauthorizedAccessException"/>.</para>
/// <para>404: Workspace not found. Returns false.</para>
/// <para>405: Forbidden to change the name of the datastore. Returns false.</para>
/// <para>Def: Returns false / <seealso cref="ArgumentOutOfRangeException"/>.</para>
/// </remarks>
Task<GeoServerResponse<bool>> UpdateDatastoreAsync(string workspaceName, DataStoreInfo datastore, CancellationToken token);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using GeoTools.GeoServer.Models;
using GeoTools.GeoServer.Models.CatalogResponses;
using GeoTools.GeoServer.Models.Workspace;
using System;
using System.Collections.Generic;
using System.Threading;
Expand Down Expand Up @@ -57,6 +59,7 @@ public interface IWorkspaceService
/// Delete a Workspace.
/// </summary>
/// <param name="name">The name of the workspace to delete.</param>
/// <param name="recurse">Delete workspace contents (default false).</param>
/// <param name="token"></param>
/// <returns>Deletes a single workspace definition.</returns>
/// <remarks>
Expand Down
3 changes: 2 additions & 1 deletion src/GeoTools.GeoServer/Extensions/GeoServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static IServiceCollection AddGeoServer(this IServiceCollection services,
.AddHttpClient(GeoServerOptions.HttpClientName, ConfigureHttpClient);

return services
.AddTransient<IWorkspaceService, WorkspaceService>();
.AddTransient<IWorkspaceService, WorkspaceService>()
.AddTransient<IDatastoreService, DatastoreService>();
}

private static void ConfigureHttpClient(IServiceProvider provider, HttpClient client)
Expand Down
Loading

0 comments on commit 601f56b

Please sign in to comment.