Skip to content

Commit d6704ff

Browse files
kappu72offtherailz
authored andcommitted
Fix #3177 Moved geostrore api in persistence api (#3124)
1 parent 2f959b7 commit d6704ff

6 files changed

Lines changed: 106 additions & 7 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Copyright 2018, GeoSolutions Sas.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
const ConfigUtils = require("../../utils/ConfigUtils");
9+
const ApiProviders = {
10+
geostore: require("../../observables/geostore")
11+
};
12+
/**
13+
* MapStore Persistence layer.
14+
* By default MapStore persists resources on geostrore. You can add a persistence provider creating an object that
15+
* implements the CRUD interface (createResource, getResource, updateResource and deleteResource)
16+
* and adding it to the API providers calling `addApi`.
17+
* Then you can select your provider by settings the `persistenceApi` property in `localConfig.json`
18+
* or by programmatically calling `setApi` method. LocalConfig takes precedence.
19+
*/
20+
const Persistence = {
21+
api: "geostore",
22+
/**
23+
* Add a new API implementation
24+
* @param {string} name the key of the added api implementation
25+
* @param {object} api the api implementation
26+
*/
27+
addApi: (name, api) => {
28+
ApiProviders[name] = api;
29+
},
30+
/**
31+
* Set the current API
32+
* @param {string} name the key of the api implementation to be used
33+
*/
34+
setApi: (name = "geostore") => {
35+
Persistence.api = name;
36+
},
37+
/**
38+
* Add a new api implementation
39+
* @return {object} Current api
40+
*/
41+
getApi: () => {
42+
return ApiProviders[ConfigUtils.getConfigProp("persistenceApi") || Persistence.api];
43+
},
44+
/**
45+
* Retrieves a resource with data with all information about user's permission on that resource, attributes and data.
46+
* @param {number} id the id of the resource to get
47+
* @param {options} param1 `includeAttributes` and `withData` flags, both true by default
48+
* @return an observable that emits the requested resource
49+
*/
50+
getResource: (...args) => Persistence.getApi().getResource(...args),
51+
/**
52+
* Returns an observable for saving a "Resource" and it's linked resources.
53+
* Linked resources are geostore resources like thumbnail or details. The main resource contains a link
54+
* to that resources as attributes. (the URL is double encoded to avoid issues with conversions in other pieces of the API)
55+
* Required format of the resource object is:
56+
* ```
57+
* {
58+
* id: "id", // if present. Otherwise a new item will be created
59+
* category: "string",
60+
* metadata: {
61+
* name: "name",
62+
* description: "description",
63+
* attribute1: "value1",
64+
* attribute2: "value2"
65+
* }
66+
* permission: [{}] // permissions to save
67+
* data: {}
68+
* linkedResources: {
69+
* thumbnail: {
70+
* tail: '/raw?decode=datauri' // for thumbnails, this will be appended to the resource URL in the main resource
71+
* data: {}
72+
*
73+
* }
74+
* }
75+
* ```
76+
* }
77+
* @param {resource} param0 resource content
78+
* @return an observable that emits the id of the resource
79+
*/
80+
createResource: (...args) => Persistence.getApi().createResource(...args),
81+
/**
82+
* Updates a resource setting up permission and linked resources
83+
* @param {resource} param0 the resource to update (must contain the id)
84+
* @return an observable that emits the id of the updated resource
85+
*/
86+
updateResource: (...args) => Persistence.getApi().updateResource(...args),
87+
/**
88+
* Deletes a resource and its linked attributes
89+
* @param {object} resource the resource with the id
90+
* @param {object} options properties: deleteLinkedResources default true
91+
* @param {object} API the API to use
92+
* @return an observable that emits axios response for the deleted resource and for each of its deleted attributes
93+
*/
94+
deleteResource: (...args) => Persistence.getApi().deleteResource(...args)
95+
};
96+
97+
module.exports = Persistence;

web/client/components/resources/enhancers/resourceGrid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Rx = require('rxjs');
1010
const { compose, branch, withState, withHandlers, defaultProps, mapPropsStream, createEventHandler} = require('recompose');
1111
const handleSaveModal = require('../modals/enhancers/handleSaveModal');
1212
const handleResourceDownload = require('../modals/enhancers/handleResourceDownload');
13-
const {updateResource} = require('../../../observables/geostore');
13+
const {updateResource} = require('../../../api/persistence');
1414

1515
const handleSave = mapPropsStream(props$ => {
1616
const { handler: onSave, stream: saveEventStream$ } = createEventHandler();

web/client/components/resources/modals/enhancers/handleResourceDownload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
const Rx = require('rxjs');
10-
const { getResource } = require('../../../../observables/geostore');
10+
const { getResource } = require('../../../../api/persistence');
1111

1212
const { mapPropsStream } = require('recompose');
1313
module.exports = mapPropsStream(props$ => {

web/client/epics/dashboard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const {
5757
createResource,
5858
updateResource,
5959
getResource
60-
} = require('../observables/geostore');
60+
} = require('../api/persistence');
6161
const {
6262
wrapStartStop
6363
} = require('../observables/epics');

web/client/epics/dashboards.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const GeoStoreApi = require('../api/GeoStoreDAO');
1313
const { wrapStartStop } = require('../observables/epics');
1414
const {error} = require('../actions/notifications');
1515

16-
const {deleteResource} = require('../observables/geostore');
16+
const {deleteResource} = require('../api/persistence');
1717

1818
const calculateNewParams = state => {
1919
const totalCount = totalCountSelector(state);

web/client/observables/geostore.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const updateOtherLinkedResourcesPermissions = (id, linkedResources, permission,
158158
* @param {number} id the id of the resource to get
159159
* @param {options} param1 `includeAttributes` and `withData` flags, both true by default
160160
* @param {object} API the API to use
161-
* @return and observable that emits the resource
161+
* @return an observable that emits the resource
162162
*/
163163
const getResource = (id, { includeAttributes = true, withData = true } = {}, API = GeoStoreDAO) =>
164164
Rx.Observable.forkJoin([
@@ -237,6 +237,7 @@ const createResource = ({ data, category, metadata, permission: configuredPermis
237237
* Updates a resource setting up permission and linked resources
238238
* @param {resource} param0 the resource to update (must contain the id)
239239
* @param {object} API the API to use
240+
* @return an observable that emits the id of the updated resource
240241
*/
241242
const updateResource = ({ id, data, category, permission, metadata, linkedResources = {} } = {}, API = GeoStoreDAO) =>
242243
Rx.Observable.forkJoin([
@@ -262,10 +263,11 @@ const updateResource = ({ id, data, category, permission, metadata, linkedResour
262263
)
263264
]).map(() => id);
264265
/**
265-
* Deletes a resource and the linked resources
266+
* Deletes a resource and Its linked attributes
266267
* @param {object} resource the resource with the id
267-
* @param {object} options options
268+
* @param {object} options options deleteLinkedResources default true
268269
* @param {object} API the API to use
270+
* @return an observable that emits axios response for the deleted resource and for each of its deleted attributes
269271
*/
270272
const deleteResource = ({ id }, { deleteLinkedResources = true} = {}, API = GeoStoreDAO) =>
271273
(deleteLinkedResources

0 commit comments

Comments
 (0)