Skip to content

Commit

Permalink
Fix 4009 add_layers from catalog (#4017)
Browse files Browse the repository at this point in the history
* Fix 4009 add layers from catalog

* update dev guide
* removed unused thunk
* added more comments
* changed names of action creator and its constants
* Update web/client/actions/catalog.js
* changed layerSearch to textSearch
* removed references in test resource
* change name of the epic that searches records in catalog
* fix failing test
  • Loading branch information
MV88 authored Aug 20, 2019
1 parent 7e5deeb commit c6e014a
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 52 deletions.
20 changes: 20 additions & 0 deletions docs/developer-guide/map-query-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ The MapStore invocation URL above executes the following operations:
- Execution of a map zoom to the provided extent

For more details check out the [searchLayerWithFilter](https://mapstore2.geo-solutions.it/mapstore/docs/#actions.search.exports.searchLayerWithFilter) in the framework documentation


#### Add Layers

This action allows to add layers from catalog present in the map

Requirements:
- the number of values must be even
- catalog name must be present in the map


Example:
```
{
"type": "CATALOG:ADD_LAYERS_FROM_CATALOGS",
"layers": ["layer1", "layer2"],
"sources": ["catalog1", "catalog2"]
}
?actions=[{"type":"CATALOG:ADD_LAYERS_FROM_CATALOGS","layers":["layer1", "layer2"],"sources":["catalog1", "catalog2"]}]
```
33 changes: 31 additions & 2 deletions web/client/actions/__tests__/catalog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const service = {
};
const expect = require('expect');
const LayersUtils = require('../../utils/LayersUtils');
const {getRecords, addLayerError, addLayer, ADD_LAYER_ERROR, changeCatalogFormat, CHANGE_CATALOG_FORMAT, changeSelectedService, CHANGE_SELECTED_SERVICE,
focusServicesList, FOCUS_SERVICES_LIST, changeCatalogMode, CHANGE_CATALOG_MODE, changeTitle, CHANGE_TITLE,
const {
addLayersMapViewerUrl, ADD_LAYERS_FROM_CATALOGS, textSearch, TEXT_SEARCH, getRecords, addLayerError, addLayer, ADD_LAYER_ERROR, changeCatalogFormat, CHANGE_CATALOG_FORMAT, changeSelectedService, CHANGE_SELECTED_SERVICE,
focusServicesList, FOCUS_SERVICES_LIST, changeCatalogMode, CHANGE_CATALOG_MODE, changeTitle, CHANGE_TITLE,
changeUrl, CHANGE_URL, changeType, CHANGE_TYPE, addService, ADD_SERVICE, addCatalogService, ADD_CATALOG_SERVICE, resetCatalog, RESET_CATALOG,
changeAutoload, CHANGE_AUTOLOAD, deleteCatalogService, DELETE_CATALOG_SERVICE, deleteService, DELETE_SERVICE, savingService,
SAVING_SERVICE, DESCRIBE_ERROR, initCatalog, CATALOG_INITED, changeText, CHANGE_TEXT,
Expand All @@ -25,6 +26,34 @@ const {getRecords, addLayerError, addLayer, ADD_LAYER_ERROR, changeCatalogFormat
const {CHANGE_LAYER_PROPERTIES, ADD_LAYER} = require('../layers');
describe('Test correctness of the catalog actions', () => {

it('addLayersMapViewerUrl', () => {
const layers = ["layer name"];
const sources = ["catalog name"];
const retval = addLayersMapViewerUrl(layers, sources);

expect(retval).toExist();
expect(retval.type).toBe(ADD_LAYERS_FROM_CATALOGS);
expect(retval.layers).toEqual(layers);
expect(retval.sources).toEqual(sources);
});
it('textSearch', () => {
const format = "csw";
const urlValue = "url";
const startPosition = 1;
const maxRecords = 1;
const text = "text";
const options = {};
const retval = textSearch({format, url: urlValue, startPosition, maxRecords, text, options});

expect(retval).toExist();
expect(retval.type).toBe(TEXT_SEARCH);
expect(retval.format).toBe(format);
expect(retval.url).toBe(urlValue);
expect(retval.startPosition).toBe(startPosition);
expect(retval.maxRecords).toBe(maxRecords);
expect(retval.text).toBe(text);
expect(retval.options).toEqual(options);
});
it('deleteCatalogService', () => {
var retval = deleteCatalogService(service);

Expand Down
77 changes: 48 additions & 29 deletions web/client/actions/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
*/

import csw from '../api/CSW';
import wms from '../api/WMS';
import wmts from '../api/WMTS';
var API = {
csw: require('../api/CSW'),
wms: require('../api/WMS'),
wmts: require('../api/WMTS')
csw,
wms,
wmts
};

const {addLayer: addNewLayer, changeLayerProperties} = require('./layers');
import {addLayer as addNewLayer, changeLayerProperties} from './layers';

const LayersUtils = require('../utils/LayersUtils');
const ConfigUtils = require('../utils/ConfigUtils');
const {find} = require('lodash');
const {authkeyParamNameSelector} = require('../selectors/catalog');
import * as LayersUtils from '../utils/LayersUtils';
import * as ConfigUtils from '../utils/ConfigUtils';
import {find} from 'lodash';
import {authkeyParamNameSelector} from '../selectors/catalog';

export const ADD_LAYERS_FROM_CATALOGS = 'CATALOG:ADD_LAYERS_FROM_CATALOGS';
export const TEXT_SEARCH = 'CATALOG:TEXT_SEARCH';
export const RECORD_LIST_LOADED = 'CATALOG:RECORD_LIST_LOADED';
export const RESET_CATALOG = 'CATALOG:RESET_CATALOG';
export const RECORD_LIST_LOAD_ERROR = 'CATALOG:RECORD_LIST_LOAD_ERROR';
Expand Down Expand Up @@ -46,6 +51,39 @@ export const TOGGLE_TEMPLATE = 'CATALOG:TOGGLE_TEMPLATE';
export const TOGGLE_THUMBNAIL = 'CATALOG:TOGGLE_THUMBNAIL';
export const TOGGLE_ADVANCED_SETTINGS = 'CATALOG:TOGGLE_ADVANCED_SETTINGS';

/**
* Adds a list of layers from the given catalogs to the map
* @param {string[]} layers list with workspace to be added in the map
* @param {string[]} sources catalog names related to each layer
*/
export function addLayersMapViewerUrl(layers = [], sources = []) {
return {
type: ADD_LAYERS_FROM_CATALOGS,
layers,
sources
};
}
/**
* Searches for a layer in the related catalog
* @param {object} params
* @param {string} params.format format of the catalog
* @param {string} params.url catalog url
* @param {number} params.startPosition initial position to start search, default 1
* @param {number} params.maxRecords max number of records returned
* @param {string} params.text layer name
* @param {object} params.options layer name
*/
export function textSearch({format, url, startPosition, maxRecords, text, options} = {}) {
return {
type: TEXT_SEARCH,
format,
url,
startPosition,
maxRecords,
text,
options
};
}
export function recordsLoaded(options, result) {
return {
type: RECORD_LIST_LOADED,
Expand Down Expand Up @@ -191,26 +229,7 @@ export function getRecords(format, url, startPosition = 1, maxRecords, filter, o
});
};
}
export function textSearch(format, url, startPosition, maxRecords, text, options) {
return (dispatch /* , getState */) => {
// TODO auth (like) let opts = GeoStoreApi.getAuthOptionsFromState(getState(), {params: {start: 0, limit: 20}, baseURL: geoStoreUrl });
dispatch(setLoading(true));
API[format].textSearch(url, startPosition, maxRecords, text, options).then((result) => {
if (result.error) {
dispatch(recordsLoadError(result));
} else {
dispatch(recordsLoaded({
url,
startPosition,
maxRecords,
text
}, result));
}
}).catch((e) => {
dispatch(recordsLoadError(e));
});
};
}

export function describeError(layer, error) {
return {
type: DESCRIBE_ERROR,
Expand Down
189 changes: 185 additions & 4 deletions web/client/epics/__tests__/catalog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@

import expect from 'expect';
import csw from '../../api/CSW';
import wmts from '../../api/WMTS';
const API = {
csw
csw,
wmts
};
import catalog from '../catalog';
const {getMetadataRecordById} = catalog(API);
const {
addLayersFromCatalogsEpic,
getMetadataRecordById,
autoSearchEpic,
openCatalogEpic,
recordSearchEpic
} = catalog(API);
import {SHOW_NOTIFICATION} from '../../actions/notifications';
import {testEpic} from './epicTestUtils';
import {getMetadataRecordById as initAction} from '../../actions/catalog';
import {CLOSE_FEATURE_GRID} from '../../actions/featuregrid';
import {setControlProperty} from '../../actions/controls';
import {ADD_LAYER} from '../../actions/layers';
import {PURGE_MAPINFO_RESULTS, HIDE_MAPINFO_MARKER} from '../../actions/mapInfo';
import {testEpic, addTimeoutEpic, TEST_TIMEOUT} from './epicTestUtils';
import {
addLayersMapViewerUrl,
getMetadataRecordById as initAction,
changeText,
textSearch, TEXT_SEARCH,
RECORD_LIST_LOADED,
RECORD_LIST_LOAD_ERROR,
SET_LOADING
} from '../../actions/catalog';

describe('catalog Epics', () => {
it('getMetadataRecordById', (done) => {
Expand All @@ -34,7 +54,168 @@ describe('catalog Epics', () => {
}]
}
});
});

it('autoSearchEpic', (done) => {
const NUM_ACTIONS = 1;
testEpic(autoSearchEpic, NUM_ACTIONS, changeText(""), (actions) => {
expect(actions.length).toBe(NUM_ACTIONS);
expect(actions[0].type).toBe(TEXT_SEARCH);
done();
}, {
catalog: {
delayAutoSearch: 50,
selectedService: "cswCatalog",
services: {
"cswCatalog": {
type: "csw",
url: "url"
}
},
pageSize: 2
},
layers: {
selected: ["TEST"],
flat: [{
id: "TEST",
catalogURL: "base/web/client/test-resources/csw/getRecordsResponseException.xml"
}]
}
});
});
it('openCatalogEpic', (done) => {
const NUM_ACTIONS = 3;
testEpic(openCatalogEpic, NUM_ACTIONS, setControlProperty("metadataexplorer", "enabled", true), (actions) => {
expect(actions.length).toBe(NUM_ACTIONS);
expect(actions[0].type).toBe(CLOSE_FEATURE_GRID);
expect(actions[1].type).toBe(PURGE_MAPINFO_RESULTS);
expect(actions[2].type).toBe(HIDE_MAPINFO_MARKER);
done();
}, { });
});

it('recordSearchEpic with two layers', (done) => {
const NUM_ACTIONS = 2;
testEpic(addTimeoutEpic(recordSearchEpic), NUM_ACTIONS, textSearch({
format: "csw",
url: "base/web/client/test-resources/csw/getRecordsResponseDC.xml",
startPosition: 1,
maxRecords: 1,
text: "a",
options: {}
}), (actions) => {
expect(actions.length).toBe(NUM_ACTIONS);
actions.map((action) => {
switch (action.type) {
case SET_LOADING:
expect(action.loading).toBe(true);
break;
case RECORD_LIST_LOADED:
expect(action.result.records.length).toBe(2);
break;
case TEST_TIMEOUT:
break;
default:
expect(true).toBe(false);
}
});
done();
}, { });
});
it('recordSearchEpic with exception', (done) => {
const NUM_ACTIONS = 2;
testEpic(addTimeoutEpic(recordSearchEpic), NUM_ACTIONS, textSearch({
format: "csw",
url: "base/web/client/test-resources/csw/getRecordsResponseEsxception.xml",
startPosition: 1,
maxRecords: 1,
text: "a",
options: {}
}), (actions) => {
expect(actions.length).toBe(NUM_ACTIONS);
actions.map((action) => {
switch (action.type) {
case SET_LOADING:
expect(action.loading).toBe(true);
break;
case RECORD_LIST_LOAD_ERROR:
expect(action.error.status).toBe(404);
expect(action.error.statusText).toBe("Not Found");
break;
case TEST_TIMEOUT:
break;
default:
expect(true).toBe(false);
}
});
done();
}, { });
});

it('addLayersFromCatalogsEpic csw', (done) => {
const NUM_ACTIONS = 2;
testEpic(addTimeoutEpic(addLayersFromCatalogsEpic, 0), NUM_ACTIONS, addLayersMapViewerUrl(["gs:us_states"], ["cswCatalog"]), (actions) => {
expect(actions.length).toBe(NUM_ACTIONS);
actions.map((action) => {
switch (action.type) {
case ADD_LAYER:
expect(action.layer.name).toBe("gs:us_states");
expect(action.layer.title).toBe("States of US");
expect(action.layer.type).toBe("wms");
expect(action.layer.url).toBe("https://sample.server/geoserver/wms");
break;
case TEST_TIMEOUT:
break;
default:
expect(true).toBe(false);
}
});
done();
}, {
catalog: {
delayAutoSearch: 50,
selectedService: "cswCatalog",
services: {
"cswCatalog": {
type: "csw",
url: "base/web/client/test-resources/csw/getRecordsResponse-gs-us_states.xml"
}
},
pageSize: 2
}
});
});
it('addLayersFromCatalogsEpic wmts', (done) => {
const NUM_ACTIONS = 2;
testEpic(addTimeoutEpic(addLayersFromCatalogsEpic, 0), NUM_ACTIONS, addLayersMapViewerUrl(["topp:tasmania_cities_hidden"], ["cswCatalog"]), (actions) => {
expect(actions.length).toBe(NUM_ACTIONS);
actions.map((action) => {
switch (action.type) {
case ADD_LAYER:
expect(action.layer.name).toBe("topp:tasmania_cities_hidden");
expect(action.layer.title).toBe("tasmania_cities");
expect(action.layer.type).toBe("wmts");
expect(action.layer.url).toBe("http://sample.server/geoserver/gwc/service/wmts");
break;
case TEST_TIMEOUT:
break;
default:
expect(true).toBe(false);
}
});
done();
}, {
catalog: {
delayAutoSearch: 50,
selectedService: "cswCatalog",
services: {
"cswCatalog": {
type: "wmts",
url: "base/web/client/test-resources/wmts/GetCapabilities-1.0.0.xml"
}
},
pageSize: 2
}
});
});
});
Loading

0 comments on commit c6e014a

Please sign in to comment.