From 74c78b34480e4b675af7eeb3c6d6f61de6c7850f Mon Sep 17 00:00:00 2001 From: allyoucanmap Date: Thu, 4 Jul 2024 18:40:07 +0200 Subject: [PATCH] Fix #4675 Remove ogc-schemas, w3c-schemas and jsonix dependencies --- build/buildConfig.js | 1 - build/testConfig.js | 1 - package.json | 3 - web/client/api/CSW.js | 395 ++++++++---------- web/client/api/WFS.js | 24 -- web/client/api/__tests__/CSW-test.js | 2 +- .../editor/AdvancedSettings/CSWFilters.jsx | 3 +- web/client/utils/__tests__/SLDUtils-test.js | 89 ---- web/client/utils/ogc/CSW.js | 128 ------ web/client/utils/ogc/DC_1_1_full.js | 145 ------- web/client/utils/ogc/Filter/index.js | 116 ----- web/client/utils/ogc/WFS/index.js | 46 -- web/client/utils/ogc/__tests__/CSW-test.js | 65 --- web/client/utils/ogc/__tests__/Filter-test.js | 75 ---- 14 files changed, 187 insertions(+), 906 deletions(-) delete mode 100644 web/client/utils/__tests__/SLDUtils-test.js delete mode 100644 web/client/utils/ogc/CSW.js delete mode 100644 web/client/utils/ogc/DC_1_1_full.js delete mode 100644 web/client/utils/ogc/Filter/index.js delete mode 100644 web/client/utils/ogc/WFS/index.js delete mode 100644 web/client/utils/ogc/__tests__/CSW-test.js delete mode 100644 web/client/utils/ogc/__tests__/Filter-test.js diff --git a/build/buildConfig.js b/build/buildConfig.js index e25128c1b9..68f2b41f9b 100644 --- a/build/buildConfig.js +++ b/build/buildConfig.js @@ -192,7 +192,6 @@ module.exports = (...args) => mapArgumentsToObject(args, ({ }, extensions: [".js", ".jsx"], alias: assign({}, { - jsonix: '@boundlessgeo/jsonix', // next libs are added because of this issue https://github.com/geosolutions-it/MapStore2/issues/4569 proj4: '@geosolutions/proj4', "react-joyride": '@geosolutions/react-joyride' diff --git a/build/testConfig.js b/build/testConfig.js index 2890f7d6c3..574e12f55b 100644 --- a/build/testConfig.js +++ b/build/testConfig.js @@ -140,7 +140,6 @@ module.exports = ({browsers = [ 'ChromeHeadless' ], files, path, testFile, singl zlib: false }, alias: assign({}, { - jsonix: '@boundlessgeo/jsonix', // next libs are added because of this issue https://github.com/geosolutions-it/MapStore2/issues/4569 proj4: '@geosolutions/proj4', "react-joyride": '@geosolutions/react-joyride' diff --git a/package.json b/package.json index 450999cd80..5f9edf287b 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,6 @@ "webpack-dev-server": "3.11.0" }, "dependencies": { - "@boundlessgeo/jsonix": "2.4.3", "@carnesen/redux-add-action-listener-enhancer": "0.0.1", "@geosolutions/geostyler-geocss-parser": "1.0.0", "@geosolutions/geostyler-sld-parser": "2.0.1-1", @@ -228,7 +227,6 @@ "node-geo-distance": "1.2.0", "object-assign": "4.1.1", "object-fit-images": "3.2.4", - "ogc-schemas": "2.6.1", "ol": "7.4.0", "pdfmake": "0.2.7", "pdfviewer": "0.3.2", @@ -309,7 +307,6 @@ "util": "0.12.3", "uuid": "3.0.1", "vis": "4.21.0", - "w3c-schemas": "1.3.1", "web-ifc": "0.0.50", "webfontloader": "1.6.28", "wellknown": "0.5.0", diff --git a/web/client/api/CSW.js b/web/client/api/CSW.js index a9572c696b..f59d37e90d 100644 --- a/web/client/api/CSW.js +++ b/web/client/api/CSW.js @@ -10,7 +10,7 @@ import urlUtil from 'url'; import { get, head, last, template, isNil, castArray, isEmpty } from 'lodash'; import assign from 'object-assign'; - +import xml2js from 'xml2js'; import axios from '../libs/ajax'; import { cleanDuplicatedQuestionMarks } from '../utils/ConfigUtils'; import { extractCrsFromURN, makeBboxFromOWS, makeNumericEPSG, getExtentFromNormalized } from '../utils/CoordinatesUtils'; @@ -45,14 +45,14 @@ const defaultDynamicFilter = "%${searchText}% " + " "; -export const sortBy = "" + +const sortByXml = ({ name, order }) => "" + "" + - "${name}" + - "${order}" + + `${name}` + + `${order}` + "" + ""; -export const cswGetRecordsXml = ' ' ' + - ' ' + - 'full ' + - ' ' + - ' ' + - '${filterXml} ' + - ' ' + - ' ' + - '${sortBy} ' + - ' ' + + `xmlns:ows="http://www.opengis.net/ows" service="CSW" version="2.0.2" resultType="results" startPosition="${options.startPosition}" maxRecords="${options.maxRecords}">` + + '' + + 'full' + + '' + + '' + + (options.filterXml || '') + + '' + + '' + + (options.sortBy || '') + + '' + ''; +const getCRSFromCSWBoundingBox = (boundingBox) => { + const crsValue = boundingBox?.$?.crs ?? ''; + const urn = crsValue.match(/[\w-]*:[\w-]*:[\w-]*:[\w-]*:[\w-]*:[^:]*:(([\w-]+\s[\w-]+)|[\w-]*)/)?.[0]; + const epsg = makeNumericEPSG(crsValue.match(/EPSG:[0-9]+/)?.[0]); + const extractedCrs = epsg || (extractCrsFromURN(urn) || last(crsValue.split(':'))); + if (!extractedCrs) { + return { crs: 'EPSG:4326', extractedCrs }; + } + if (extractedCrs.slice(0, 5) === 'EPSG:') { + return { crs: makeNumericEPSG(extractedCrs), extractedCrs }; + } + return { crs: makeNumericEPSG(`EPSG:${extractedCrs}`), extractedCrs }; +}; + +const getBoundingBoxFromCSWRecord = (cswRecord) => { + if (cswRecord?.['ows:BoundingBox']) { + const boundingBox = castArray(cswRecord['ows:BoundingBox'])[0]; + const { crs, extractedCrs } = getCRSFromCSWBoundingBox(boundingBox); + let lc = (boundingBox?.['ows:LowerCorner'] || '-180 -90').split(' ').map(parseFloat); + let uc = (boundingBox?.['ows:UpperCorner'] || '180 90').split(' ').map(parseFloat); + // Usually switched, GeoServer sometimes doesn't. + // See https://docs.geoserver.org/latest/en/user/services/wfs/axis_order.html#axis-ordering + if (crs === 'EPSG:4326' && extractedCrs !== 'CRS84' && extractedCrs !== 'OGC:CRS84') { + lc = [lc[1], lc[0]]; + uc = [uc[1], uc[0]]; + } + return { + extent: makeBboxFromOWS(lc, uc), + crs: 'EPSG:4326' + }; + } + return null; +}; + +const getDCFromCSWRecord = (cswRecord) => { + // extract each dc or dct tag item in the XML + const dc = Object.keys(cswRecord || {}).reduce((acc, key) => { + const isDCElement = key.indexOf('dc:') === 0; + const isDCTElement = key.indexOf('dct:') === 0; + if (isDCElement || isDCTElement) { + const name = isDCElement ? key.replace('dc:', '') : key.replace('dct:', ''); + let value = cswRecord[key]; + if (name === 'references') { + value = castArray(cswRecord[key]).map((reference) => { + return { + value: cleanDuplicatedQuestionMarks(reference?._), + scheme: reference?.$?.scheme + }; + }); + } + if (name === 'URI') { + value = castArray(cswRecord[key]).map((uri) => { + return { + description: uri?.$?.description, + name: uri?.$?.name, + protocol: uri?.$?.protocol, + value: uri?._ + }; + }); + } + return { + ...acc, + [name]: value + }; + } + return acc; + }, {}); + return isEmpty(dc) ? null : dc; +}; + +const getCSWError = (json) => { + const exceptionReport = json?.['ows:ExceptionReport']; + if (exceptionReport) { + const exceptionText = exceptionReport?.['ows:Exception']?.['ows:ExceptionText']; + return exceptionText || 'GenericError'; + } + return null; +}; + +const parseCSWResponse = (response) => { + if (!response) { + return null; + } + let json; + xml2js.parseString(response.data, { explicitArray: false }, (ignore, result) => { + json = result; + }); + const searchResults = json?.['csw:GetRecordsResponse']?.['csw:SearchResults']; + if (searchResults) { + const cswRecords = searchResults?.['csw:Record'] || searchResults?.['gmd:MD_Metadata']; + const records = !cswRecords ? null : castArray(cswRecords).map((cswRecord) => { + const boundingBox = getBoundingBoxFromCSWRecord(cswRecord); + const dc = getDCFromCSWRecord(cswRecord); + return { + dateStamp: cswRecord?.['gmd:dateStamp']?.['gco:Date'], + fileIdentifier: cswRecord?.['gmd:fileIdentifier']?.['gco:CharacterString'], + identificationInfo: cswRecord?.['gmd:identificationInfo']?.['gmd:AbstractMD_Identification'], + ...(boundingBox && { boundingBox }), + ...(dc && { dc }) + }; + }); + const _dcRef = records ? records.map(({ dc = {} }) => { + const URIs = castArray(dc?.references?.length > 0 ? dc.references : dc.URI); + return URIs; + }).flat() : undefined; + return { + result: { + numberOfRecordsMatched: parseFloat(searchResults?.$?.numberOfRecordsMatched), + numberOfRecordsReturned: parseFloat(searchResults?.$?.numberOfRecordsReturned), + nextRecord: parseFloat(searchResults?.$?.nextRecord), + ...(records && { records }) + }, + _dcRef + }; + } + const error = getCSWError(json); + if (error) { + return { error }; + } + return null; +}; + /** * Construct XML body to get records from the CSW service * @param {object} [options] the options to pass to withIntersectionObserver enhancer. @@ -90,8 +212,8 @@ export const constructXMLBody = (startPosition, maxRecords, searchText, { option ${template(filter?.dynamicFilter || defaultDynamicFilter)({ searchText })} ${staticFilter} `; - const sortExp = sortObj?.name ? template(sortBy)({ name: sortObj?.name, order: sortObj?.order ?? "ASC"}) : ''; - return template(cswGetRecordsXml)({ filterXml: !searchText ? staticFilter : dynamicFilter, startPosition, maxRecords, sortBy: sortExp}); + const sortExp = sortObj?.name ? sortByXml({ name: sortObj?.name, order: sortObj?.order ?? "ASC"}) : ''; + return cswGetRecordsXml({ filterXml: !searchText ? staticFilter : dynamicFilter, startPosition, maxRecords, sortBy: sortExp}); }; // Extract the relevant information from the wms URL for (RNDT / INSPIRE) @@ -335,193 +457,42 @@ const getBboxFor3DLayersToRecords = async(result)=> { const Api = { parseUrl, getRecordById: function(catalogURL) { - return new Promise((resolve) => { - require.ensure(['../utils/ogc/CSW'], () => { - resolve(axios.get(catalogURL) - .then((response) => { - if (response) { - const { unmarshaller } = require('../utils/ogc/CSW'); - const json = unmarshaller.unmarshalString(response.data); - if (json && json.name && json.name.localPart === "GetRecordByIdResponse" && json.value && json.value.abstractRecord) { - let dcElement = json.value.abstractRecord[0].value.dcElement; - if (dcElement) { - let dc = { - references: [] - }; - for (let j = 0; j < dcElement.length; j++) { - let dcel = dcElement[j]; - let elName = dcel.name.localPart; - let finalEl = {}; - /* Some services (e.g. GeoServer) support http://schemas.opengis.net/csw/2.0.2/record.xsd only - * Usually they publish the WMS URL at dct:"references" with scheme=OGC:WMS - * So we place references as they are. - */ - if (elName === "references" && dcel.value) { - let urlString = dcel.value.content && cleanDuplicatedQuestionMarks(dcel.value.content[0]) || dcel.value.content || dcel.value; - finalEl = { - value: urlString, - scheme: dcel.value.scheme - }; - } else { - finalEl = dcel.value.content && dcel.value.content[0] || dcel.value.content || dcel.value; - } - if (dc[elName] && Array.isArray(dc[elName])) { - dc[elName].push(finalEl); - } else if (dc[elName]) { - dc[elName] = [dc[elName], finalEl]; - } else { - dc[elName] = finalEl; - } - } - return { dc }; - } - } else if (json && json.name && json.name.localPart === "ExceptionReport") { - return { - error: json.value.exception && json.value.exception.length && json.value.exception[0].exceptionText || 'GenericError' - }; - } - return null; - } - return null; - })); - }); - }); - }, - getRecords: function(url, startPosition, maxRecords, filter, options) { - return new Promise((resolve) => { - require.ensure(['../utils/ogc/CSW', '../utils/ogc/Filter'], () => { - const { CSW, marshaller, unmarshaller } = require('../utils/ogc/CSW'); - let body = marshaller.marshalString({ - name: "csw:GetRecords", - value: CSW.getRecords(startPosition, maxRecords, typeof filter !== "string" && filter) - }); - if (!filter || typeof filter === "string") { - body = constructXMLBody(startPosition, maxRecords, filter, options); - } - resolve(axios.post(parseUrl(url), body, { - headers: { - 'Content-Type': 'application/xml' + return axios.get(catalogURL) + .then((response) => { + if (response) { + let json; + xml2js.parseString(response.data, { explicitArray: false }, (ignore, result) => { + json = result; + }); + const record = json?.['csw:GetRecordByIdResponse']?.['csw:Record']; + const dc = getDCFromCSWRecord(record); + if (dc) { + return { dc }; } - }).then((response) => { - if (response) { - let json = unmarshaller.unmarshalString(response.data); - if (json && json.name && json.name.localPart === "GetRecordsResponse" && json.value && json.value.searchResults) { - let rawResult = json.value; - let rawRecords = rawResult.searchResults.abstractRecord || rawResult.searchResults.any; - let result = { - numberOfRecordsMatched: rawResult.searchResults.numberOfRecordsMatched, - numberOfRecordsReturned: rawResult.searchResults.numberOfRecordsReturned, - nextRecord: rawResult.searchResults.nextRecord - // searchStatus: rawResult.searchStatus - }; - let records = []; - let _dcRef; - if (rawRecords) { - for (let i = 0; i < rawRecords.length; i++) { - let rawRec = rawRecords[i].value; - let obj = { - dateStamp: rawRec.dateStamp && rawRec.dateStamp.date, - fileIdentifier: rawRec.fileIdentifier && rawRec.fileIdentifier.characterString && rawRec.fileIdentifier.characterString.value, - identificationInfo: rawRec.abstractMDIdentification && rawRec.abstractMDIdentification.value - }; - if (rawRec.boundingBox) { - let bbox; - let crs; - let el; - if (Array.isArray(rawRec.boundingBox)) { - el = head(rawRec.boundingBox); - } else { - el = rawRec.boundingBox; - } - if (el && el.value) { - const crsValue = el.value?.crs ?? ''; - const urn = crsValue.match(/[\w-]*:[\w-]*:[\w-]*:[\w-]*:[\w-]*:[^:]*:(([\w-]+\s[\w-]+)|[\w-]*)/)?.[0]; - const epsg = makeNumericEPSG(crsValue.match(/EPSG:[0-9]+/)?.[0]); - - let lc = el.value.lowerCorner; - let uc = el.value.upperCorner; - - const extractedCrs = epsg || (extractCrsFromURN(urn) || last(crsValue.split(':'))); - - if (!extractedCrs) { - crs = 'EPSG:4326'; - } else if (extractedCrs.slice(0, 5) === 'EPSG:') { - crs = makeNumericEPSG(extractedCrs); - } else { - crs = makeNumericEPSG(`EPSG:${extractedCrs}`); - } - - // Usually switched, GeoServer sometimes doesn't. See https://docs.geoserver.org/latest/en/user/services/wfs/axis_order.html#axis-ordering - if (crs === 'EPSG:4326' && extractedCrs !== 'CRS84' && extractedCrs !== 'OGC:CRS84') { - lc = [lc[1], lc[0]]; - uc = [uc[1], uc[0]]; - } - bbox = makeBboxFromOWS(lc, uc); - } - obj.boundingBox = { - extent: bbox, - crs: 'EPSG:4326' - }; - } - // dcElement is an array of objects, each item is a dc tag in the XML - let dcElement = rawRec.dcElement; - if (dcElement) { - let dc = { - references: [] - }; - for (let j = 0; j < dcElement.length; j++) { - let dcel = dcElement[j]; - // here the element name is taken (i.e. "URI", "title", "description", etc) - let elName = dcel.name.localPart; - let finalEl = {}; - /* Some services (e.g. GeoServer) support http://schemas.opengis.net/csw/2.0.2/record.xsd only - * Usually they publish the WMS URL at dct:"references" with scheme=OGC:WMS - * So we place references as they are. - */ - if (elName === "references" && dcel.value) { - let urlString = dcel.value.content && cleanDuplicatedQuestionMarks(dcel.value.content[0]) || dcel.value.content || dcel.value; - finalEl = { - value: urlString, - scheme: dcel.value.scheme - }; - } else { - finalEl = dcel.value.content && dcel.value.content[0] || dcel.value.content || dcel.value; - } - /** - grouping all tags with same property together (i.e mobilità traffico) - will become { subject: ["mobilità", "traffico"] } - **/ - if (dc[elName] && Array.isArray(dc[elName])) { - dc[elName].push(finalEl); - } else if (dc[elName]) { - dc[elName] = [dc[elName], finalEl]; - } else { - dc[elName] = finalEl; - } - } - const URIs = castArray(dc.references.length > 0 ? dc.references : dc.URI); - if (!_dcRef) { - _dcRef = URIs; - } else { - _dcRef = _dcRef.concat(URIs); - } - obj.dc = dc; - } - records.push(obj); - } - } - result.records = records; - return addCapabilitiesToRecords(_dcRef, result, options); - } else if (json && json.name && json.name.localPart === "ExceptionReport") { - return { - error: json.value.exception && json.value.exception.length && json.value.exception[0].exceptionText || 'GenericError' - }; - } + const error = getCSWError(json); + if (error) { + return { error }; } - return null; - }).then(results => getBboxFor3DLayersToRecords(results))); // handle getting bbox from capabilities in case of 3D tile layer + } + return null; }); - }); + }, + getRecords: function(url, startPosition, maxRecords, text, options) { + const body = constructXMLBody(startPosition, maxRecords, text, options); + return axios.post(parseUrl(url), body, { + headers: { + 'Content-Type': 'application/xml' + } + }).then((response) => { + const { error, _dcRef, result } = parseCSWResponse(response) || {}; + if (result) { + return addCapabilitiesToRecords(_dcRef, result, options); + } + if (error) { + return { error }; + } + return null; + }).then(results => getBboxFor3DLayersToRecords(results)); // handle getting bbox from capabilities in case of 3D tile layer }, textSearch: function(url, startPosition, maxRecords, text, options) { return new Promise((resolve) => { @@ -529,15 +500,19 @@ const Api = { }); }, workspaceSearch: function(url, startPosition, maxRecords, text, workspace) { - return new Promise((resolve) => { - require.ensure(['../utils/ogc/CSW', '../utils/ogc/Filter'], () => { - const { Filter } = require('../utils/ogc/Filter'); - const workspaceTerm = workspace || "%"; - const layerNameTerm = text && "%" + text + "%" || "%"; - const ops = Filter.propertyIsLike("dc:identifier", workspaceTerm + ":" + layerNameTerm); - const filter = Filter.filter(ops); - resolve(Api.getRecords(url, startPosition, maxRecords, filter)); - }); + const workspaceTerm = workspace || "%"; + const layerNameTerm = text && "%" + text + "%" || "%"; + return Api.getRecords(url, startPosition, maxRecords, '', { + options: { + service: { + filter: { + staticFilter: "" + + "dc:identifier" + + `${workspaceTerm + ":" + layerNameTerm}` + + "" + } + } + } }); }, reset: () => { } diff --git a/web/client/api/WFS.js b/web/client/api/WFS.js index e0fa068c26..2410b1b263 100644 --- a/web/client/api/WFS.js +++ b/web/client/api/WFS.js @@ -152,30 +152,6 @@ export const getCapabilities = function(url) { return json; }); }; -/** - * @deprecated - */ -export const describeFeatureTypeOGCSchemas = function(url, typeName) { - const parsed = urlUtil.parse(getDefaultUrl(url), true); - const describeLayerUrl = urlUtil.format(assign({}, parsed, { - query: assign({ - service: "WFS", - version: "1.1.0", - typeName: typeName, - request: "DescribeFeatureType" - }, parsed.query) - })); - return new Promise((resolve) => { - require.ensure(['../utils/ogc/WFS'], () => { - const {unmarshaller} = require('../utils/ogc/WFS'); - resolve(axios.get(describeLayerUrl).then((response) => { - let json = unmarshaller.unmarshalString(response.data); - return json && json.value; - - })); - }); - }); -}; export const describeFeatureType = function(url, typeName) { return axios.get(toDescribeURL(url, typeName)).then(({data}) => data); diff --git a/web/client/api/__tests__/CSW-test.js b/web/client/api/__tests__/CSW-test.js index 5856bea050..6ffec24f67 100644 --- a/web/client/api/__tests__/CSW-test.js +++ b/web/client/api/__tests__/CSW-test.js @@ -208,7 +208,7 @@ describe('tests with mockedActions', () => { expect(data.records).toExist(); expect(data.records.length).toBe(4); done(); - }); + }).catch(done); }); }); describe("getRecords for 3D layers", () => { diff --git a/web/client/components/catalog/editor/AdvancedSettings/CSWFilters.jsx b/web/client/components/catalog/editor/AdvancedSettings/CSWFilters.jsx index 1705a80aa5..97a5591119 100644 --- a/web/client/components/catalog/editor/AdvancedSettings/CSWFilters.jsx +++ b/web/client/components/catalog/editor/AdvancedSettings/CSWFilters.jsx @@ -7,7 +7,6 @@ import { HelpBlock } from "react-bootstrap"; import CodeMirror from '../../../../libs/codemirror/react-codemirror-suspense'; -import template from "lodash/template"; import isEqual from "lodash/isEqual"; import { cswGetRecordsXml } from "../../../../api/CSW"; import OverlayTrigger from "../../../misc/OverlayTrigger"; @@ -88,7 +87,7 @@ export default ({ const cmProps = { code, setCode, error }; const isValid = value => { - const _filter = template(cswGetRecordsXml)({ + const _filter = cswGetRecordsXml({ filterXml: value, startPosition: 1, maxRecords: 4, diff --git a/web/client/utils/__tests__/SLDUtils-test.js b/web/client/utils/__tests__/SLDUtils-test.js deleted file mode 100644 index 3afe7d27bb..0000000000 --- a/web/client/utils/__tests__/SLDUtils-test.js +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ -import expect from 'expect'; - -import { jsonToSLD, vecStyleToSLD } from '../SLDUtils'; - -const rasterstylerstate = { - redband: {band: '1', contrast: 'GammaValue', algorithm: "none", gammaValue: 1, min: 1, max: 255}, - blueband: {band: '3', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255}, - greenband: {band: '2', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255}, - grayband: {band: '1', contrast: 'none', algorithm: "none", gammaValue: 1, min: 1, max: 255}, - pseudocolor: {colorMapEntry: [{color: "#eff3ff", quantity: 0, label: "0.00"}], type: "ramp", opacity: "1.00"}, - pseudoband: {band: "1", contrast: "Normalize", algorithm: "ClipToMinimumMaximum", min: 1, max: 255} -}; -const layer = {name: "sde:HYP_HR_SR_OB_DR"}; - - -describe('SLDUtils', () => { - - it('convert rasterlayer state to sld strings', () => { - let pseudo = jsonToSLD({ - styletype: "pseudo", - opacity: "0.50", - state: rasterstylerstate, - layer: layer}); - expect(pseudo).toExist(); - let rgb = jsonToSLD( - { - styletype: "rgb", - opacity: "0.50", - state: rasterstylerstate, - layer: layer - }); - expect(rgb).toExist(); - let gray = jsonToSLD({ - styletype: "gray", - opacity: "0.50", - state: rasterstylerstate, - layer: layer - }); - expect(gray).toExist(); - }); - it('test vectorlayer state to sld strings', () => { - let rules = [ - { - "id": "bd8587a0-543a-11e6-a812-3f41916af8df", - "symbol": { - "type": "Point", - "color": {"r": 0, "g": 0, "b": 255, "a": 1}, - "width": 3, - "fill": {"r": 0, "g": 0, "b": 255, "a": 0.1}, - "radius": 10, - "marker": false, - "markName": "circle" - }, - "name": "Test Name"}, - { - "id": "dfcce690-543b-11e6-a812-3f41916af8df", - "symbol": { - "type": "Polygon", - "color": {"r": 0, "g": 0, "b": 255, "a": 1}, - "width": 3, - "fill": {"r": 0, "g": 0, "b": 255, "a": 0.1} - }, - "name": "Test Name"}, - { - "id": "406d88b0-543c-11e6-a812-3f41916af8df", - "symbol": { - "type": "Line", - "color": {"r": 0, "g": 0, "b": 255, "a": 1}, - "width": 3 - }, - "name": "Test Name", - "minDenominator": 73957338.86364141, - "maxDenominator": 295829355.45456564} - ]; - let result = `sde:HYP_HR_SR_OB_DRcircle#0000ff0.1#0000ff1310#0000ff0.1#0000ff1373957338.86364141295829355.45456564#0000ff13`; - let sld = vecStyleToSLD({ - rules, - layer}); - expect(sld).toExist(); - expect(sld).toEqual(result); - }); -}); diff --git a/web/client/utils/ogc/CSW.js b/web/client/utils/ogc/CSW.js deleted file mode 100644 index 69d7abb28d..0000000000 --- a/web/client/utils/ogc/CSW.js +++ /dev/null @@ -1,128 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ -// Disable ESLint because some of the names to include are not in camel case -/* eslint-disable */ -// include base schemas and name spaces -const { - OWS_1_0_0, - // DC_1_1, - DCT, - SMIL_2_0, - SMIL_2_0_Language, - GML_3_1_1, - Filter_1_1_0, - CSW_2_0_2, - GML_3_2_0, - GML_3_2_1, - ISO19139_GCO_20070417, - ISO19139_GMD_20070417, - ISO19139_GMX_20070417, - ISO19139_GSS_20070417, - ISO19139_GTS_20070417, - ISO19139_GSR_20070417, - ISO19139_2_GMI_1_0 -} = require('ogc-schemas'); -const DC_1_1 = require('./DC_1_1_full'); -var XLink_1_0 = require('w3c-schemas').XLink_1_0; -const {Jsonix} = require('jsonix'); -const context = new Jsonix.Context([ - OWS_1_0_0, - DC_1_1, - DCT, - XLink_1_0, - SMIL_2_0, - SMIL_2_0_Language, - GML_3_1_1, - Filter_1_1_0, - CSW_2_0_2, - GML_3_2_0, - GML_3_2_1, - ISO19139_GCO_20070417, - ISO19139_GMD_20070417, - ISO19139_GMX_20070417, - ISO19139_GSS_20070417, - ISO19139_GTS_20070417, - ISO19139_GSR_20070417, - ISO19139_2_GMI_1_0], { - namespacePrefixes: { - "http://www.opengis.net/cat/csw/2.0.2": "csw", - "http://www.opengis.net/ogc": 'ogc', - "http://www.opengis.net/gml": "gml", - "http://purl.org/dc/elements/1.1/": "dc", - "http://purl.org/dc/terms/": "dct", - "http://www.isotc211.org/2005/gmd": "gmd", - "http://www.isotc211.org/2005/gco": "gco", - "http://www.isotc211.org/2005/gmi": "gmi", - "http://www.opengis.net/ows": "ows" - } -}); -/* eslint-enable */ -const marshaller = context.createMarshaller(); -const unmarshaller = context.createUnmarshaller(); -const CSW = { - getRecords: function(startPosition, maxRecords, query, outputSchema) { - let body = { - startPosition: startPosition, - maxRecords: maxRecords, - abstractQuery: CSW.query("full", query && CSW.constraint(query)), - resultType: "results", - service: "CSW", - version: "2.0.2" - }; - if (outputSchema) { - body.outputSchema = outputSchema; - } - return body; - }, - getRecordById: function(ids) { - return { - TYPE_NAME: "CSW_2_0_2.GetRecordByIdType", - elementSetName: { - ObjectTYPE_NAME: "CSW_2_0_2.ElementSetNameType", - value: "full" - }, - id: Array.isArray(ids) ? ids : [ids], - service: "CSW", - version: "2.0.2" - }; - }, - query: function(elementSetName = "full", constraint) { - let query = { - "csw:Query": { - TYPE_NAME: "CSW_2_0_2.QueryType", - elementSetName: { - TYPE_NAME: "CSW_2_0_2.ElementSetNameType", - value: elementSetName - }, - typeNames: [ - { - key: "{http://www.opengis.net/cat/csw/2.0.2}Record", - localPart: "Record", - namespaceURI: "http://www.opengis.net/cat/csw/2.0.2", - prefix: "csw", - string: "{http://www.opengis.net/cat/csw/2.0.2}csw:Record" - } - ] - } - }; - if (constraint) { - query['csw:Query'].constraint = constraint; - } - return query; - }, - constraint: (ogcfilter) => { - return { - TYPE_NAME: "CSW_2_0_2.QueryConstraintType", - version: "1.1.0", - "filter": ogcfilter - }; - } -}; - - -module.exports = {CSW, marshaller, unmarshaller}; diff --git a/web/client/utils/ogc/DC_1_1_full.js b/web/client/utils/ogc/DC_1_1_full.js deleted file mode 100644 index abe05e727b..0000000000 --- a/web/client/utils/ogc/DC_1_1_full.js +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ -/** - * This definition of DC add the dc:URI to the possible Dublin core elements - * originally available in the ogc-schemas mappings. - */ -module.exports = { - n: 'DC_1_1', - dens: 'http:\/\/purl.org\/dc\/elements\/1.1\/', - tis: [{ - ln: 'ElementContainer', - tn: 'elementContainer', - ps: [{ - n: 'dcElement', - mno: 0, - col: true, - mx: false, - dom: false, - en: 'DC-element', - ti: '.SimpleLiteral', - t: 'er' - }, { - n: 'dcElement', - mno: 0, - col: true, - mx: false, - dom: false, - en: 'DC-element', - ti: '.URI', - t: 'er' - }] - }, { - ln: 'SimpleLiteral', - ps: [{ - n: 'content', - col: true, - dom: false, - t: 'ers' - }, { - n: 'scheme', - an: { - lp: 'scheme' - }, - t: 'a' - }] - }, { - ln: 'URI', - ti: 'URI', - sh: 'DC-element', - collection: true, - propertyInfos: [ { - type: 'attribute', - name: 'name', - attributeName: 'name', - typeInfo: 'String' - }, { - type: 'attribute', - name: 'description', - attributeName: 'description', - typeInfo: 'String' - }, { - type: 'attribute', - name: 'protocol', - attributeName: 'protocol', - typeInfo: 'String' - }, { - type: 'value', - name: 'value', - typeInfo: 'String' - }] - }], - eis: [{ - en: 'identifier', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'relation', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'format', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'title', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'description', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'source', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'date', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'type', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'language', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'DC-element', - ti: '.SimpleLiteral' - }, { - en: 'rights', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'creator', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'publisher', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'contributor', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'subject', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'coverage', - ti: '.SimpleLiteral', - sh: 'DC-element' - }, { - en: 'URI', - ti: '.URI', - sh: 'DC-element' - }] -}; diff --git a/web/client/utils/ogc/Filter/index.js b/web/client/utils/ogc/Filter/index.js deleted file mode 100644 index 46c24e3a99..0000000000 --- a/web/client/utils/ogc/Filter/index.js +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ -// Disable ESLint because some of the names to include are not in camel case -/* eslint-disable */ -// include base schemas and name spaces -const { - OWS_1_0_0, - DC_1_1, - DCT, - SMIL_2_0, - SMIL_2_0_Language, - GML_3_1_1, - Filter_1_1_0, - CSW_2_0_2 -} = require('ogc-schemas'); -var XLink_1_0 = require('w3c-schemas').XLink_1_0; -const {Jsonix} = require('jsonix'); -const context = new Jsonix.Context([ - OWS_1_0_0, - DC_1_1, - DCT, - XLink_1_0, - SMIL_2_0, - SMIL_2_0_Language, - GML_3_1_1, - Filter_1_1_0, - CSW_2_0_2], { - namespacePrefixes: { - 'http://www.opengis.net/cat/csw/2.0.2': 'csw', - "http://www.opengis.net/ogc": 'ogc', - "http://www.opengis.net/gml": "gml", - "http://www.opengis.net/ows": "ows" - } -}); -/* eslint-enable */ -const marshaller = context.createMarshaller(); -const unmarshaller = context.createUnmarshaller(); -const Filter = { - propertyName: function(propertyName) { - return { - PropertyName: propertyName - }; - }, - propertyIsLike: function(propertyName, value) { - return { - 'ogc:PropertyIsLike': { - TYPE_NAME: "Filter_1_1_0.PropertyIsLikeType", - escapeChar: "\\\\", - singleChar: "_", - wildCard: "%", - literal: { - TYPE_NAME: "Filter_1_1_0.LiteralType", - content: [value] - }, - propertyName: { - TYPE_NAME: "Filter_1_1_0.PropertyNameType", - content: [propertyName] - } - } - }; - }, - bbox: function(llat, llon, ulat, ulon, srsName) { - return { - 'ows:BBOX': { - TYPE_NAME: "Filter_1_1_0.BBOXType", - envelope: { - 'gml:Envelope': { - TYPE_NAME: "GML_3_1_1.EnvelopeType", - lowerCorner: { - TYPE_NAME: "GML_3_1_1.DirectPositionType", - value: [llat, llon] - }, - upperCorner: { - TYPE_NAME: "GML_3_1_1.DirectPositionType", - value: [ulat, ulon] - }, - srsName: srsName - } - } - } - }; - }, - and: function( opts ) { - return { - 'ogc:And': { - TYPE_NAME: "Filter_1_1_0.BinaryLogicOpType", - ops: opts - } - }; - }, - or: function( opts ) { - return { - 'ogc:Or': { - TYPE_NAME: "Filter_1_1_0.BinaryLogicOpType", - ops: opts - } - }; - }, - filter(logicOps, spatialOps) { - return { - "ogc:Filter": { - TYPE_NAME: "Filter_1_1_0.FilterType", - logicOps: logicOps, - spatialOps: spatialOps - } - }; - } -}; - - -module.exports = {Filter, marshaller, unmarshaller}; diff --git a/web/client/utils/ogc/WFS/index.js b/web/client/utils/ogc/WFS/index.js deleted file mode 100644 index c9d3a9ea44..0000000000 --- a/web/client/utils/ogc/WFS/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ -// Disable ESLint because some of the names to include are not in camel case -/* eslint-disable */ -// include base schemas and name spaces -const { - OWS_1_0_0, - Filter_1_1_0, - GML_3_1_1, - SMIL_2_0, - SMIL_2_0_Language, - WFS_1_1_0 -} = require('ogc-schemas'); - -const {XLink_1_0, XSD_1_0} = require('w3c-schemas'); -const {Jsonix} = require('jsonix'); -const context = new Jsonix.Context([ - XLink_1_0, - XSD_1_0, - OWS_1_0_0, - Filter_1_1_0, - GML_3_1_1, - SMIL_2_0, - SMIL_2_0_Language, - WFS_1_1_0 -],{ - namespacePrefixes: { - "http://www.opengis.net/ogc": 'ogc', - "http://www.opengis.net/wms": "wfs", - "http://www.opengis.net/ows": "ows", - "http://www.w3.org/2001/XMLSchema" : "xsd" - } -}); -/* eslint-enable */ -const marshaller = context.createMarshaller(); -const unmarshaller = context.createUnmarshaller(); -const WFS = { -}; - - -module.exports = {WFS, marshaller, unmarshaller}; diff --git a/web/client/utils/ogc/__tests__/CSW-test.js b/web/client/utils/ogc/__tests__/CSW-test.js deleted file mode 100644 index 72628d09b5..0000000000 --- a/web/client/utils/ogc/__tests__/CSW-test.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -const expect = require('expect'); -const {CSW, marshaller, unmarshaller} = require('../CSW'); -const {Filter} = require('../Filter'); -/** - * Validates CSW tag trying to unmarshal that - */ -const validate = function(body, localPart) { - const doc = unmarshaller.unmarshalDocument(body); - expect(doc).toExist(); - expect(doc.name && doc.name.localPart).toBe(localPart); - return doc; -}; -describe('Test CSW request/response generation/parsing', () => { - - it('getRecords', () => { - expect(CSW.getRecords).toExist(); - let jsonBody = CSW.getRecords(0, 1); - expect(jsonBody).toExist(); - const doc = marshaller.marshalDocument( { name: "csw:GetRecords", value: jsonBody}); - expect(doc).toExist(); - validate(doc, "GetRecords"); - }); - - it('getRecords with Filters', () => { - expect(CSW.getRecords).toExist(); - - // create a filter - let json1 = Filter.propertyIsLike("propName", "%propValueLike%"); - expect(json1).toExist(); - let json2 = Filter.bbox(0, 0, 1, 1, "EPSG:4326"); - let or = Filter.or([json1, json2]); - let filter = Filter.filter(or); - - // create a getRecords with the filter - let jsonBody = CSW.getRecords(0, 1, filter); - expect(jsonBody).toExist(); - - // marshal and unmarshal - const doc = marshaller.marshalDocument( { name: "csw:GetRecords", value: jsonBody}); - expect(doc).toExist(); - let jsonOut = validate(doc, "GetRecords").value; - - // check if the filter exists in the unmarshalled object - expect(jsonOut).toExist(); - expect(jsonOut.abstractQuery).toExist(); - expect(jsonOut.abstractQuery.value.constraint).toExist(); - expect(jsonOut.abstractQuery.value.constraint.filter).toExist(); - }); - it('getRecordById', () => { - expect(CSW.getRecordById).toExist(); - let jsonBody = CSW.getRecordById("TEST_ID"); - expect(jsonBody).toExist(); - const doc = marshaller.marshalDocument( { name: "csw:GetRecordById", value: jsonBody}); - expect(doc).toExist(); - validate(doc, "GetRecordById"); - }); -}); diff --git a/web/client/utils/ogc/__tests__/Filter-test.js b/web/client/utils/ogc/__tests__/Filter-test.js deleted file mode 100644 index c4d0a0b1b6..0000000000 --- a/web/client/utils/ogc/__tests__/Filter-test.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2016, GeoSolutions Sas. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -const expect = require('expect'); -const {Filter, marshaller, unmarshaller} = require('../Filter'); -/** - * Validates CSW tag trying to unmarshal that - */ -const validate = function(body, localPart) { - const doc = unmarshaller.unmarshalDocument(body); - expect(doc).toExist(); - expect(doc.name && doc.name.localPart).toBe(localPart); - return doc; -}; -describe('Test Filter generation/parsing', () => { - - it('propertyIsLike', () => { - expect(Filter.propertyIsLike).toExist(); - let jsonBody = Filter.propertyIsLike("propName", "%propValueLike%"); - expect(jsonBody).toExist(); - const doc = marshaller.marshalDocument( { name: "ogc:PropertyIsLike", value: jsonBody}); - expect(doc).toExist(); - let outJson = validate(doc, "PropertyIsLike"); - expect(outJson).toExist(); - }); - - it('BBox', () => { - expect(Filter.propertyIsLike).toExist(); - let jsonBody = Filter.bbox(0, 0, 1, 1, "EPSG:4326"); - expect(jsonBody).toExist(); - const doc = marshaller.marshalDocument( { name: "ogc:BBOX", value: jsonBody}); - expect(doc).toExist(); - validate(doc, "BBOX"); - }); - it('and', () => { - expect(Filter.propertyIsLike).toExist(); - let json1 = Filter.propertyIsLike("propName", "%propValueLike%"); - expect(json1).toExist(); - let json2 = Filter.bbox(0, 0, 1, 1, "EPSG:4326"); - let and = Filter.and([json1, json2]); - const doc = marshaller.marshalDocument( and ); - expect(doc).toExist(); - let outJson = validate(doc, "And"); - expect(outJson).toExist(); - }); - it('or', () => { - expect(Filter.propertyIsLike).toExist(); - let json1 = Filter.propertyIsLike("propName", "%propValueLike%"); - expect(json1).toExist(); - let json2 = Filter.bbox(0, 0, 1, 1, "EPSG:4326"); - let or = Filter.or([json1, json2]); - const doc = marshaller.marshalDocument( or ); - expect(doc).toExist(); - let outJson = validate(doc, "Or"); - expect(outJson).toExist(); - }); - it('Filter', () => { - expect(Filter.propertyIsLike).toExist(); - let json1 = Filter.propertyIsLike("propName", "%propValueLike%"); - expect(json1).toExist(); - let json2 = Filter.bbox(0, 0, 1, 1, "EPSG:4326"); - let or = Filter.or([json1, json2]); - let filter = Filter.filter(or); - const doc = marshaller.marshalDocument( filter ); - expect(doc).toExist(); - let outJson = validate(doc, "Filter"); - expect(outJson).toExist(); - }); - -});