geoserver-node-client 0.0.3 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ jobs:
10
10
  run-tests-maintenance:
11
11
  runs-on: ubuntu-latest
12
12
  env:
13
- GEOSERVER_VERSION: 2.18.2
13
+ GEOSERVER_VERSION: 2.19.3
14
14
  steps:
15
15
  - uses: actions/checkout@v2
16
16
 
@@ -33,7 +33,7 @@ jobs:
33
33
  run-tests-stable:
34
34
  runs-on: ubuntu-latest
35
35
  env:
36
- GEOSERVER_VERSION: 2.19.0
36
+ GEOSERVER_VERSION: 2.20.1
37
37
  steps:
38
38
  - uses: actions/checkout@v2
39
39
 
package/DOCS_HOME.md CHANGED
@@ -8,8 +8,10 @@ Node.js / JavaScript Client for the [GeoServer REST API](https://docs.geoserver.
8
8
 
9
9
  Compatible with [GeoServer](https://geoserver.org)
10
10
 
11
- - v2.17.x
12
- - v2.18.x
11
+ - v2.20.x
12
+ - v2.19.x
13
+ - v2.18.x (no more maintained and officially deprecated)
14
+ - v2.17.x (no more maintained and officially deprecated)
13
15
 
14
16
  ### Who do I talk to? ###
15
17
 
package/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2021, meggsimum (Dipl.-Ing. (FH) Christian Mayer)
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # GeoServer Node Client
2
2
 
3
+ [![npm version](https://badge.fury.io/js/geoserver-node-client.svg)](https://www.npmjs.com/package/geoserver-node-client)
4
+ ![](https://github.com/meggsimum/geoserver-node-client/actions/workflows/ci-geoserver-node-client.yml/badge.svg)
5
+
3
6
  Node.js / JavaScript Client for the [GeoServer REST API](https://docs.geoserver.org/stable/en/user/rest/).
4
7
 
5
8
  **CAUTION: This is highly bleeding edge, heavily under development and therefore breaking changes can be made at every time!**
@@ -12,8 +15,9 @@ Detailed API-Docs can be found [here](https://meggsimum.github.io/geoserver-node
12
15
 
13
16
  Compatible with [GeoServer](https://geoserver.org)
14
17
 
18
+ - v2.20.x
15
19
  - v2.19.x
16
- - v2.18.x
20
+ - v2.18.x (no more maintained and officially deprecated)
17
21
  - v2.17.x (no more maintained and officially deprecated)
18
22
 
19
23
  ### Setup
@@ -39,20 +43,21 @@ First start a GeoServer, e.g. by using this Docker container:
39
43
  docker run \
40
44
  -p 8080:8080 \
41
45
  -v /path/to/geoserver_mnt:/opt/geoserver_data \
42
- meggsimum/geoserver:2.18.2
46
+ meggsimum/geoserver:2.20.1
43
47
  ```
44
48
 
45
49
  Then, in an other terminal, run:
46
50
 
47
51
  ```shell
48
- npm run test
52
+ # specify the GeoServer version and run the test suite
53
+ GEOSERVER_VERSION=2.20.1 npm run test
49
54
  ```
50
55
 
51
56
  ### Release
52
57
 
53
58
  The release to GitHub and npm is done via [release-it](https://github.com/release-it/release-it). This is the workflow for releasing:
54
59
 
55
- 1. Make sure a `GITHUB_TOKEN` is available as environment varible. See [here](https://github.com/release-it/release-it/blob/master/docs/github-releases.md) for more information.
60
+ 1. Make sure a `GITHUB_TOKEN` is available as environment variable. See [here](https://github.com/release-it/release-it/blob/master/docs/github-releases.md) for more information.
56
61
 
57
62
  ```shell
58
63
  export GITHUB_TOKEN=ADD-YOUR-TOKEN-HERE
@@ -72,6 +77,9 @@ npm run release
72
77
  ```
73
78
 
74
79
  4. Follow the questions in the commandline.
80
+ - automatically upgrades the version in `package.json`
81
+ - makes a release commit and pushes it to GitHub
82
+ - publishes the new version to npm
75
83
 
76
84
  ### Who do I talk to? ###
77
85
 
package/demo/index.js CHANGED
@@ -87,9 +87,9 @@ grc.getVersion().then(versionInfo => {
87
87
  // grc.datastores.createWmsStore(ws, 'testWmsDs', wmsUrl).then(retVal => {
88
88
  // console.log('Created WMS data store', prettyJson(retVal));
89
89
  // });
90
- // const wfsCapsUrl = 'https://ows.terrestris.de/geoserver/osm/wfs?service=wfs&version=1.1.0&request=GetCapabilities';
90
+ // const wfsCapsUrl = 'https://services.meggsimum.de/geoserver/ows?service=wfs&version=1.1.0&request=GetCapabilities';
91
91
  // const namespaceUrl = 'http://test';
92
- // grc.datastores.createWfsStore(ws, 'testWfsDs', wfsCapsUrl, namespaceUrl).then(retVal => {
92
+ // grc.datastores.createWfsStore(ws, 'testWfsDs', wfsCapsUrl, namespaceUrl, false).then(retVal => {
93
93
  // console.log('Created WFS data store', prettyJson(retVal));
94
94
  // });
95
95
  // grc.datastores.deleteDataStore(ws, 'testWfsDs', false).then(gsWmsStores => {
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "geoserver-node-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.7",
4
4
  "description": "Node.js client for GeoServer REST API",
5
5
  "type": "module",
6
6
  "main": "geoserver-rest-client.js",
7
7
  "scripts": {
8
8
  "demo": "node demo/index.js",
9
9
  "docs": "./node_modules/.bin/jsdoc geoserver-rest-client.js src/*.js DOCS_HOME.md",
10
- "lint": "eslint src/*.js demo/index.js test/test.js",
10
+ "lint": "eslint '**/*.js' --ignore-pattern node_modules/ --ignore-pattern out/",
11
+ "lint-fix": "eslint --fix '**/*.js' --ignore-pattern node_modules/ --ignore-pattern out/",
11
12
  "pretest": "npm run lint",
12
13
  "test": "mocha --timeout 10000",
13
14
  "release": "release-it"
@@ -20,18 +21,18 @@
20
21
  "author": "C. Mayer, meggsimum (info_at*meggsimum?dot?de)",
21
22
  "license": "BSD-2-Clause",
22
23
  "dependencies": {
23
- "node-fetch": "^2.6.1"
24
+ "node-fetch": "^2.6.5"
24
25
  },
25
26
  "devDependencies": {
26
- "chai": "^4.3.0",
27
- "eslint": "^7.21.0",
27
+ "chai": "^4.3.4",
28
+ "eslint": "^7.32.0",
28
29
  "eslint-config-standard": "^14.1.1",
29
- "eslint-plugin-import": "^2.22.1",
30
+ "eslint-plugin-import": "^2.25.2",
30
31
  "eslint-plugin-node": "^11.1.0",
31
32
  "eslint-plugin-promise": "^4.3.1",
32
33
  "eslint-plugin-standard": "^4.1.0",
33
- "jsdoc": "^3.6.6",
34
- "mocha": "^8.3.0",
35
- "release-it": "^14.10.0"
34
+ "jsdoc": "^3.6.7",
35
+ "mocha": "^9.1.3",
36
+ "release-it": "^14.11.6"
36
37
  }
37
38
  }
package/src/datastore.js CHANGED
@@ -401,10 +401,11 @@ s */
401
401
  * @param {String} dataStore The data store name
402
402
  * @param {String} wfsCapabilitiesUrl WFS capabilities URL
403
403
  * @param {String} namespaceUrl URL of the GeoServer namespace
404
+ * @param {Boolean} [useHttpConnectionPooling=true] use HTTP connection pooling for WFS connection
404
405
  *
405
406
  * @returns {Boolean} If store could be created
406
407
  */
407
- async createWfsStore (workspace, dataStore, wfsCapabilitiesUrl, namespaceUrl) {
408
+ async createWfsStore (workspace, dataStore, wfsCapabilitiesUrl, namespaceUrl, useHttpConnectionPooling) {
408
409
  const body = {
409
410
  dataStore: {
410
411
  name: dataStore,
@@ -418,6 +419,10 @@ s */
418
419
  {
419
420
  '@key': 'namespace',
420
421
  $: namespaceUrl
422
+ },
423
+ {
424
+ '@key': 'WFSDataStoreFactory:USE_HTTP_CONNECTION_POOLING',
425
+ $: useHttpConnectionPooling !== false ? 'true' : 'false'
421
426
  }
422
427
  ]
423
428
  }
package/src/layer.js CHANGED
@@ -369,10 +369,11 @@ export default class LayerClient {
369
369
  * @param {String} defaultValue The default time value, e.g. 'MINIMUM' or 'MAXIMUM' or 'NEAREST' or 'FIXED'
370
370
  * @param {Boolean} [nearestMatchEnabled] Enable nearest match
371
371
  * @param {Boolean} [rawNearestMatchEnabled] Enable raw nearest match
372
+ * @param {String} [acceptableInterval] Acceptable interval for nearest match, e.g.'PT30M'
372
373
  *
373
374
  * @returns If time dimension could be enabled
374
375
  */
375
- async enableTimeCoverage (workspace, dataStore, name, presentation, resolution, defaultValue, nearestMatchEnabled, rawNearestMatchEnabled) {
376
+ async enableTimeCoverage (workspace, dataStore, name, presentation, resolution, defaultValue, nearestMatchEnabled, rawNearestMatchEnabled, acceptableInterval) {
376
377
  try {
377
378
  const body = {
378
379
  coverage: {
@@ -389,7 +390,8 @@ export default class LayerClient {
389
390
  strategy: defaultValue
390
391
  },
391
392
  nearestMatchEnabled: nearestMatchEnabled,
392
- rawNearestMatchEnabled: rawNearestMatchEnabled
393
+ rawNearestMatchEnabled: rawNearestMatchEnabled,
394
+ acceptableInterval: acceptableInterval
393
395
  }
394
396
  }
395
397
  ]
package/src/style.js CHANGED
@@ -128,7 +128,7 @@ export default class StyleClient {
128
128
  /**
129
129
  * Publishes a new SLD style.
130
130
  *
131
- * @param {String} workspace The workspace to publish style in
131
+ * @param {String} workspace The workspace to publish the style in
132
132
  * @param {String} name Name of the style
133
133
  * @param {String} sldBody SLD style (as XML text)
134
134
  *
@@ -158,6 +158,65 @@ export default class StyleClient {
158
158
  }
159
159
  }
160
160
 
161
+ /**
162
+ * Deletes a style.
163
+ *
164
+ * @param {String} workspace The name of the workspace, can be undefined if style is not assigned to a workspace
165
+ * @param {String} name The name of the style to delete
166
+ * @param {Boolean} [recurse=false] If references to the specified style in existing layers should be deleted
167
+ * @param {Boolean} [purge=false] Whether the underlying file containing the style should be deleted on disk
168
+ *
169
+ * @returns {Boolean} If the style could be deleted
170
+ */
171
+ async delete (workspace, name, recurse, purge) {
172
+ let paramPurge = false;
173
+ let paramRecurse = false;
174
+
175
+ if (purge === true) {
176
+ paramPurge = true;
177
+ }
178
+ if (recurse === true) {
179
+ paramRecurse = true;
180
+ }
181
+
182
+ try {
183
+ const auth = Buffer.from(this.user + ':' + this.password).toString('base64');
184
+ let endpoint;
185
+
186
+ if (workspace) {
187
+ // delete style inside workspace
188
+ endpoint = this.url + 'workspaces/' + workspace + '/styles/' + name +
189
+ '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
190
+ } else {
191
+ // delete style without workspace
192
+ endpoint = this.url + 'styles/' + name +
193
+ '?' + 'purge=' + paramPurge + '&' + 'recurse=' + paramRecurse;
194
+ }
195
+
196
+ const response = await fetch(endpoint, {
197
+ credentials: 'include',
198
+ method: 'DELETE',
199
+ headers: {
200
+ Authorization: 'Basic ' + auth
201
+ }
202
+ });
203
+
204
+ if (response.ok) {
205
+ return true;
206
+ } else if (response.status === 403) {
207
+ console.warn('Deletion failed. There might be dependant objects to ' +
208
+ 'this style. Delete them first or call this with "recurse=false"');
209
+ console.warn(await response.text());
210
+ return false;
211
+ } else {
212
+ console.warn(await response.text());
213
+ return false;
214
+ }
215
+ } catch (error) {
216
+ return false;
217
+ }
218
+ }
219
+
161
220
  /**
162
221
  * Assigns a style to a layer.
163
222
  *
package/test/test.js CHANGED
@@ -452,6 +452,17 @@ describe('style', () => {
452
452
  expect(result.length).to.equal(1);
453
453
  })
454
454
 
455
+ it('can delete a style', async () => {
456
+ let recurse = false;
457
+ const purge = false;
458
+ const withOutRecurse = await grc.styles.delete(workSpace, styleName, recurse, purge)
459
+ expect(withOutRecurse).to.be.false;
460
+
461
+ recurse = true;
462
+ const withRecurse = await grc.styles.delete(workSpace, styleName, recurse, purge)
463
+ expect(withRecurse).to.be.true;
464
+ });
465
+
455
466
  after('delete Workspace', async () => {
456
467
  const recursive = true;
457
468
  await grc.workspaces.delete(createdWorkSpace, recursive);
package/demo/dev.js DELETED
@@ -1,275 +0,0 @@
1
- import GeoServerRestClient from '../geoserver-rest-client.js';
2
- import fs from 'fs';
3
- import { execSync } from 'child_process'
4
-
5
- const geoserverUrl = 'http://localhost:8080/geoserver/rest/';
6
- const geoserverDefaultUser = 'mgsm-admin';
7
- const geoserverDefaultPw = 'VB?w10&0A2s8PU?BPM&Nn!8kl';
8
- const role = 'ADMIN';
9
-
10
- // TODO: read from secrets
11
- const newGeoserverUser = 'mgsm-admin';
12
- const newGeoserverPw = 'VB?w10&0A2s8PU?BPM&Nn!8kl';
13
-
14
- const workspaceWorld = 'mgsm-world';
15
- const workspaceGermany = 'mgsm-ger';
16
-
17
- const gsDataDir = '/opt/geoserver_data/';
18
- const countriesGpkgUrl = 'https://github.com/JakobMiksch/geodata/raw/main/vector-data.gpkg?raw=true';
19
- const worldRasterUrl = 'https://github.com/JakobMiksch/geodata/raw/main/world.tiff';
20
- const neGpkgPath = gsDataDir + 'natural_earth_vector.gpkg';
21
- const neWorldRasterPath = gsDataDir + 'world.tif';
22
- const worldRasterDs = 'world-raster';
23
- const worldRasterLayer = 'ne_world';
24
- const worldRasterTitle = 'World Image';
25
-
26
- const postalCodesUrl = 'https://github.com/JakobMiksch/geodata/raw/main/postal_codes_germany.gpkg';
27
- const postalCodesPath = gsDataDir + 'postal_codes.gpkg';
28
-
29
- /**
30
- * Main function
31
- */
32
- async function initGeoserver () {
33
- console.log('accessing geoserver');
34
- const workspaceGermany = 'mgsm-ger';
35
- const gpkgStore = 'postal-code-store';
36
- const nativeLayerName = undefined;
37
- const layerName = 'postal_codes_germany';
38
- const layerTitle = 'Postal Codes Germany';
39
-
40
- const layerCreated = await grc.layers.publishFeatureType(
41
- workspaceGermany, gpkgStore, nativeLayerName, layerName, layerTitle,
42
- 'EPSG:4326', true, 'asdfasdfasdfasdf asdfasdfsadf asdfasdf afas asdf asdfas asdf asdfas asdf asdfas asfd asdfas as dfas dfasdf asdf asdfas asdfa sdfawesdf'
43
- );
44
-
45
- console.log(layerCreated);
46
-
47
- // let result;
48
- // result = await grc.layers.get('mgsm-ger:postal_codes_germany');
49
- // console.log(result);
50
-
51
- // result = await grc.layers.modifyAttribution('mgsm-ger:postal_codes_germany', 'Apfelbaum', 'www.zeit.de');
52
- // console.log(result);
53
-
54
- // result = await grc.layers.get('mgsm-ger:postal_codes_germany');
55
- // console.log(result);
56
-
57
- // await addContactInformation();
58
-
59
- // await adaptSecurity();
60
-
61
- // await createWorkspaces();
62
-
63
- // await publishGlobalVectorData();
64
-
65
- // await publishWorldRaster();
66
-
67
- // await publishPostalCodes();
68
- }
69
-
70
- /**
71
- * Adapts security settings for GeoServer
72
- */
73
- async function adaptSecurity () {
74
- const user = newGeoserverUser;
75
- const userPw = newGeoserverPw;
76
-
77
- if (!user || !userPw || user === '' || userPw === '') {
78
- console.error('No valid user or user password given - EXIT.');
79
- }
80
-
81
- const userCreated = await grc.security.createUser(user, userPw);
82
- if (userCreated) {
83
- console.info('Successfully created user', user);
84
- }
85
-
86
- const roleAssigend = await grc.security.associateUserRole(user, role);
87
- if (roleAssigend) {
88
- console.info(`Successfully added role ${role} to user ${user}`);
89
- }
90
-
91
- // disable user
92
- const adminDisabled = await grc.security.updateUser(geoserverDefaultUser, geoserverDefaultPw, false);
93
- if (adminDisabled) {
94
- console.info('Successfully disabled default "admin" user');
95
- }
96
- }
97
-
98
- /**
99
- * Adds basic contact information
100
- */
101
- async function addContactInformation () {
102
- const address = 'Schillerstraße 2a';
103
- const city = 'Mutterstadt';
104
- const country = 'Deutschland';
105
- const state = undefined;
106
- const postalCode = '67112';
107
- const email = 'info@meggsimum.de';
108
- const organization = 'meggsimum – Büro für Geoinformatik';
109
- const contactPerson = 'Christian Mayer';
110
- const phoneNumber = undefined;
111
-
112
- const result = await grc.settings.updateContactInformation(address, city, country, postalCode, state, email, organization, contactPerson, phoneNumber);
113
- if (result) {
114
- console.log('Changed contact information.');
115
- }
116
- }
117
-
118
- /**
119
- * Creates the basic workspaces
120
- */
121
- async function createWorkspaces () {
122
- const wsWorldCreated = await grc.workspaces.create(workspaceWorld);
123
- console.log('Created Workspace World', wsWorldCreated);
124
-
125
- const wsGermanyCreated = await grc.workspaces.create(workspaceGermany);
126
- console.log('Created Workspace Germany', wsGermanyCreated);
127
- }
128
-
129
- /**
130
- * Publish postal codes from Germany
131
- */
132
- async function publishPostalCodes () {
133
- const gpkgStore = 'postal-code-store';
134
- const nativeLayerName = undefined;
135
- const layerName = 'postal_codes_germany';
136
- const layerTitle = 'Postal Codes Germany';
137
-
138
- const wsExists =
139
- await grc.datastores.getDataStore(workspaceGermany, gpkgStore);
140
- const lyrExists =
141
- await grc.layers.get(`${workspaceGermany}:${layerName}`);
142
-
143
- if (wsExists && lyrExists) {
144
- console.info('Datastore and layer for postal codes already exist - SKIP!');
145
- return;
146
- }
147
-
148
- // TODO replace by native node call
149
- execSync(`wget -N -O ${postalCodesPath} ${postalCodesUrl}`);
150
-
151
- const postalStoreCreated = await grc.datastores.createGpkgStore(
152
- workspaceGermany, gpkgStore, postalCodesPath
153
- );
154
-
155
- console.log('Successfully created postal code GPKG store', postalStoreCreated);
156
-
157
- const layerCreated = await grc.layers.publishFeatureType(
158
- workspaceGermany, gpkgStore, nativeLayerName, layerName, layerTitle,
159
- 'EPSG:4326', true
160
- );
161
-
162
- if (layerCreated) {
163
- console.log(`Created vector layer for postal codes "${layerName}"`);
164
- }
165
- }
166
-
167
- /**
168
- * Publishes the world vector data (currently countries, rivers, places)
169
- */
170
- async function publishGlobalVectorData () {
171
- const gpkgStore = 'natural-earth-gpkg-store';
172
- const countriesLyr = 'ne_10m_admin_0_countries';
173
- const riversLyr = 'ne_10m_rivers_lake_centerlines';
174
- const placesLyr = 'ne_10m_populated_places';
175
-
176
- const wsExists =
177
- await grc.datastores.getDataStore(workspaceWorld, gpkgStore);
178
- const lyr1Exists =
179
- await grc.layers.get(`${workspaceWorld}:${countriesLyr}`);
180
- const lyr2Exists =
181
- await grc.layers.get(`${workspaceWorld}:${riversLyr}`);
182
- const lyr3Exists =
183
- await grc.layers.get(`${workspaceWorld}:${placesLyr}`);
184
-
185
- if (wsExists && lyr1Exists && lyr2Exists && lyr3Exists) {
186
- console.info('Datastore and layers for global vector data already exist - SKIP!');
187
- return;
188
- }
189
-
190
- // TODO replace by native node call
191
- execSync(`wget -N -O ${neGpkgPath} ${countriesGpkgUrl}`);
192
-
193
- // NOTE: here the relative path within the GeoServer is required
194
- const neStoreCreated = await grc.datastores.createGpkgStore(
195
- workspaceWorld, gpkgStore, neGpkgPath
196
- );
197
-
198
- console.log('Successfully created NE GPKG store', neStoreCreated);
199
-
200
- // publish vector layers
201
- publishVectorLayerWithStyle(gpkgStore, countriesLyr, 'World Countries', 'countries');
202
- publishVectorLayerWithStyle(gpkgStore, riversLyr, 'World Rivers', 'rivers');
203
- publishVectorLayerWithStyle(gpkgStore, placesLyr, 'World Places', 'places');
204
- }
205
-
206
- /**
207
- * Util for publishing a layer with a style
208
- */
209
- async function publishVectorLayerWithStyle (store, layerName, layerTitle, styleName) {
210
- const nativeLayerName = undefined;
211
-
212
- const layerCreated = await grc.layers.publishFeatureType(
213
- workspaceWorld, store, nativeLayerName, layerName, layerTitle,
214
- 'EPSG:4326', true
215
- );
216
-
217
- if (layerCreated) {
218
- console.log(`Created vector layer "${layerName}"`);
219
- }
220
-
221
- try {
222
- const sldFilePath = styleName + '.sld';
223
- const sldBody = fs.readFileSync(sldFilePath, 'utf8');
224
-
225
- // publish style
226
- const stylePublished = await grc.styles.publish(workspaceWorld, styleName, sldBody);
227
-
228
- console.log('Published style: ', stylePublished);
229
-
230
- const qualifiedName = `${workspaceWorld}:${layerName}`;
231
- const styleAssigend = await grc.styles.assignStyleToLayer(qualifiedName, styleName,
232
- workspaceWorld, true
233
- );
234
-
235
- console.log(`Style "${styleName}" assigned to layer "${qualifiedName}"`, styleAssigend);
236
- } catch (e) {
237
- console.error('Error:', e.stack);
238
- }
239
- }
240
-
241
- /**
242
- * Publishes the NE GeoTiff based World Raster
243
- */
244
- async function publishWorldRaster () {
245
- const wsExists =
246
- await grc.datastores.getCoverageStore(workspaceWorld, worldRasterDs);
247
- const lyrExists = await grc.layers.get(`${workspaceWorld}:${worldRasterLayer}`);
248
-
249
- if (wsExists && lyrExists) {
250
- console.info('Datastore and layer for world raster data already exist - SKIP!');
251
- return;
252
- }
253
-
254
- // TODO replace by native node call
255
- execSync(`wget -N -O ${neWorldRasterPath} ${worldRasterUrl}`);
256
-
257
- console.log('Downloaded GeoTIFF file');
258
-
259
- const geotiffCreated = await grc.datastores.createGeotiffFromFile(
260
- workspaceWorld, worldRasterDs, worldRasterLayer,
261
- worldRasterTitle, neWorldRasterPath
262
- );
263
-
264
- console.log('Created GeoTIFF world raster layer', geotiffCreated);
265
- }
266
-
267
- // check if we can connect to GeoServer REST API
268
- const grc = new GeoServerRestClient(geoserverUrl, geoserverDefaultUser, geoserverDefaultPw);
269
- grc.exists().then(gsExists => {
270
- if (gsExists === true) {
271
- initGeoserver();
272
- } else {
273
- console.error('Could not connect to GeoServer REST API - ABORT!');
274
- }
275
- });