• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 13456178088

21 Feb 2025 11:49AM UTC coverage: 76.734% (+0.05%) from 76.688%
13456178088

Pull #10813

github

web-flow
Merge 7ffa6d126 into 1e493c5d2
Pull Request #10813: Fix #10805 JAXBException while updating an existing dashboard

31263 of 48901 branches covered (63.93%)

5 of 8 new or added lines in 2 files covered. (62.5%)

318 existing lines in 24 files now uncovered.

38808 of 50575 relevant lines covered (76.73%)

34.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.56
/web/client/api/WFS.js
1
/**
2
 * Copyright 2016, 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
import axios from '../libs/ajax';
9
import urlUtil from 'url';
10
import assign from 'object-assign';
11
import xml2js from 'xml2js';
12
import ConfigUtils from '../utils/ConfigUtils';
13
import requestBuilder from '../utils/ogc/WFS/RequestBuilder';
14
import {toOGCFilterParts} from '../utils/FilterUtils';
15
import { getDefaultUrl } from '../utils/URLUtils';
16
import { castArray } from 'lodash';
17
import { isValidGetFeatureInfoFormat } from '../utils/WMSUtils';
18

19
const capabilitiesCache = {};
1✔
20

21
export const toDescribeURL = (url, typeName) => {
1✔
22
    const parsed = urlUtil.parse(getDefaultUrl(url), true);
6✔
23
    return urlUtil.format(
6✔
24
        {
25
            ...parsed,
26
            search: undefined, // this allows to merge parameters correctly
27
            query: {
28
                ...parsed.query,
29

30
                service: "WFS",
31
                version: "1.1.0",
32
                typeName,
33
                outputFormat: 'application/json',
34
                request: "DescribeFeatureType"
35
            }
36
        });
37
};
38
/**
39
 * Simple getFeature using http GET method with json format
40
 */
41
export const getFeatureSimple = function(baseUrl, params) {
1✔
42
    return axios.get(baseUrl + '?service=WFS&version=1.1.0&request=GetFeature', {
21✔
43
        params: assign({
44
            outputFormat: "application/json"
45
        }, params)
46
    }).then((response) => {
47
        if (typeof response.data !== 'object') {
20!
48
            return JSON.parse(response.data);
×
49
        }
50
        return response.data;
20✔
51
    });
52
};
53

54
export const getCapabilitiesURL = (url, {version = "1.1.0"} = {}) => {
1✔
55
    const parsed = urlUtil.parse(getDefaultUrl(url), true);
7✔
56
    return urlUtil.format(assign({}, parsed, {
7✔
57
        search: undefined, // this allows to merge parameters correctly
58
        query: assign({
59
            version,
60
            ...parsed.query,
61
            service: "WFS",
62
            request: "GetCapabilities"
63
        })
64
    }));
65
};
66

67
export const getFeatureURL = (url, typeName, { version = "1.1.0", ...params } = {}) => {
1✔
68
    const parsed = urlUtil.parse(getDefaultUrl(url), true);
19✔
69
    return urlUtil.format(assign({}, parsed, {
19✔
70
        search: undefined, // this allows to merge parameters correctly
71
        query: assign({
72
            typeName,
73
            version,
74
            ...parsed.query,
75
            service: "WFS",
76
            request: "GetFeature",
77
            ...params
78
        })
79
    }));
80
};
81
/**
82
 * Performs a getFeature request (using axios POST) to a WFS service for a given MapStore layer WFS layer object.
83
 * @param {object} layer MapStore layer object
84
 * @param {object} requestOptions additional request options. Can include:
85
 * - `version`: WFS version. Default: `1.1.0`
86
 * - `filter`: optional array of mapstore filters. If the layer has a `layerFilter` property or filterObj, it will be added to the filter in a logic AND.
87
 * - `proj`: projection string
88
 * - `outputFormat`: output format string. Default: `application/json`
89
 * - `resultType`: result type string. Default: `results`
90
 * @param {object} config axios request config (headers, etc...)
91
 * @returns
92
 */
93
export const getFeatureLayer = (layer, {version =  "1.1.0", filters, proj, outputFormat = 'application/json', resultType = 'results'} = {}, config) => {
1✔
94
    const {url, name: typeName, params } = layer;
7✔
95
    const {layerFilter, filterObj: featureGridFilter} = layer; // TODO: add
7✔
96
    const {getFeature: wfsGetFeature, query, filter, and} = requestBuilder({wfsVersion: version});
7✔
97
    const allFilters = []
7✔
98
        .concat(filters ?? [])
9✔
99
        .concat(layerFilter ? layerFilter : [])
7✔
100
        .concat(featureGridFilter ? featureGridFilter : []);
7!
101
    const reqBody = wfsGetFeature(query(
7✔
102
        typeName,
103
        // TODO: insert propertyName before filter to limit attributes to return
104
        allFilters.length > 0
7✔
105
            ? filter(
106
                and(
107
                    allFilters
108
                        .map(f => toOGCFilterParts(f, version, "ogc"))
6✔
109
                )
110

111
            ) : "",
112
        {srsName: proj} // 3rd for query is optional
113
    ),
114
    {outputFormat, resultType}
115
    );
116
    return axios.post(url, reqBody, {
7✔
117
        ...config,
118
        params,
119
        headers: {
120
            ...config?.headers,
121
            'Content-Type': 'application/xml'
122
        }
123
    });
124
};
125

126
/**
127
 * Performs a WFS GetFeature request (using axios GET) with the given parameters.
128
 * @param {string} url URL of the WFS service
129
 * @param {string} typeName layer name
130
 * @param {object} params the params to add to the request
131
 * @param {object} config axios request config (headers, etc...)
132
 * @returns {Promise} the axios promise
133
 */
134
export const getFeature = (url, typeName, params, config) => {
1✔
135
    return axios.get(getFeatureURL(url, typeName, params), config);
16✔
136
};
137

138
export const getCapabilities = function(url) {
1✔
139
    const cached = capabilitiesCache[url];
8✔
140
    if (cached && new Date().getTime() < cached.timestamp + (ConfigUtils.getConfigProp('cacheExpire') || 60) * 1000) {
8✔
141
        return Promise.resolve(cached.data);
2✔
142
    }
143
    return axios.get(getCapabilitiesURL(url))
6✔
144
        .then((response) => {
145
            let json;
146
            xml2js.parseString(response.data, { explicitArray: false, stripPrefix: true }, (ignore, result) => {
5✔
147
                json = { ...result, url };
5✔
148
            });
149
            capabilitiesCache[url] = {
5✔
150
                timestamp: new Date().getTime(),
151
                data: json
152
            };
153
            return json;
5✔
154
        });
155
};
156

157
export const describeFeatureType = function(url, typeName) {
1✔
158
    return axios.get(toDescribeURL(url, typeName)).then(({data}) => data);
5✔
159
};
160

161
/**
162
 * Fetch the supported formats of the WFS service
163
 * @param url
164
 * @return {object} { infoFormats }
165
 */
166
export const getSupportedFormat = (url) => {
1✔
167
    return getCapabilities(url)
3✔
168
        .then((response) => {
169
            const operations = castArray(response?.['wfs:WFS_Capabilities']?.['ows:OperationsMetadata']?.['ows:Operation'] || []);
3✔
170
            const getFeatureOperation = operations.find(operation => operation?.$?.name === 'GetFeature');
3✔
171
            const parameters = castArray(getFeatureOperation?.['ows:Parameter'] || []);
3✔
172
            const outputFormats = parameters.find((parameter) => parameter?.$?.name === 'outputFormat')?.['ows:Value'] || [];
3✔
173
            const infoFormats = outputFormats.filter(isValidGetFeatureInfoFormat);
3✔
174
            return {
3✔
175
                infoFormats: infoFormats?.length ? infoFormats : ['application/json']
3✔
176
            };
177
        })
UNCOV
178
        .catch(() => ({ infoFormats: ['application/json'] }));
×
179
};
180

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc