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

geosolutions-it / MapStore2 / 19710972030

26 Nov 2025 03:38PM UTC coverage: 76.665% (-0.3%) from 76.929%
19710972030

Pull #11119

github

web-flow
Fix maven publish (#11739)
Pull Request #11119: Layer Selection Plugin on ArcGIS, WFS & WMS layers

32272 of 50209 branches covered (64.28%)

3 of 3 new or added lines in 2 files covered. (100.0%)

3018 existing lines in 249 files now uncovered.

40157 of 52380 relevant lines covered (76.66%)

37.9 hits per line

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

96.3
/web/client/utils/ogc/WFS/base.js
1
/*
2
 * Copyright 2017, 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

9
import head from 'lodash/head';
10
import get  from 'lodash/get';
11
export {processOGCGeometry} from "../GML";
12
import {processOGCGeometry} from "../GML";
13
import { notPrimaryGeometryFields } from '../../FeatureTypeUtils';
14
/**
15
 * Base utilities for WFS.
16
 * @name WFS
17
 * @memberof utils.ogc
18
 * @module
19
 */
20

21

22
// TODO missing escape of cdata entries (you should split the ]]> and put the two parts of it in adjacent CDATA sections).
23
// e.g.
24
// <![CDATA[Certain tokens like ]]> can be difficult and <invalid>]]>
25
// should be written as
26
// <![CDATA[Certain tokens like ]]]]><![CDATA[> can be difficult and <valid>]]>
27
const toCData = (value) => /[<>&'"]/.test(value) ? `<![CDATA[${value}]]>` : value;
38!
28

29
const WFS_TO_GML = {
1✔
30
    "1.0.0": "2.0",
31
    "1.1.0": "3.1.1",
32
    "2.0": "3.2",
33
    "2.0.0": "3.2"
34
};
35
/**
36
 * retrieve default GML version from WFS version
37
 * @param  {string} v WFS version
38
 * @return {string}   GML version
39
 */
40
export const wfsToGmlVersion = (v = "1.1.0") => WFS_TO_GML[v];
80!
41
/**
42
 * Provides the array of featureType properties
43
 * @param  {object} describeFeatureType the describeFeatureType object
44
 * @return {object[]}                     The array of featuretypes properties
45
 */
46
export const getFeatureTypeProperties = (describeFeatureType) => get(describeFeatureType, "featureTypes[0].properties");
582✔
47

48
export const isGeometryType = (pd) => pd.type.indexOf("gml:") === 0 || pd.type === "xsd:Geometry" || !!(notPrimaryGeometryFields[pd.type]);
647✔
49
/**
50
 * Provides the first geometry type found
51
 * @param  {object} describeFeatureType the describeFeatureType object
52
 * @return {object}                     the featureType property
53
 */
54
export const findGeometryProperty = (describeFeatureType) => head((getFeatureTypeProperties(describeFeatureType) || []).filter( isGeometryType ));
61✔
55
/**
56
 * Retrives the descriptor for a property in the describeFeatureType (supports single featureTypes)
57
 * @memberof utils.ogc.WFS
58
 * @param  {string} propName            the name of the property to get
59
 * @param  {object} describeFeatureType the describeFeatureType object
60
 * @return {object}                     the property descriptor
61
 */
62
export const getPropertyDescriptor = (propName, describeFeatureType) =>
1✔
63
    head(
463✔
64
        (getFeatureTypeProperties(describeFeatureType) || []).filter(d => d.name === propName)
7,093!
65
    );
66
/**
67
 * @name schemaLocation
68
 * @memberof utils.ogc.WFS
69
 * @param  {object} describeFeatureType schemaLocation
70
 * @return {string}   url of the schemaLocation
71
 */
72
export const schemaLocation = (d) => d.targetNamespace;
14✔
73
export const isValidValue = (v, pd) =>
1✔
74
    pd === undefined
77!
75
    || pd === null
76
    || pd && pd.nillable === true
77
    || pd && pd.nillable === false && v !== undefined && v !== null; // TODO validate type
78
export const isValidProperty = ({geom, properties} = {}, pd) => isValidValue(isGeometryType(pd) ? geom : properties[pd.name], pd);
4!
79

80
/**
81
 * retrieves the featureTypeSchema entry for XML from describeFeatureType
82
 * @param  {object} d describeFeatureType
83
 * @return {string}   the attribute. e.g. xmlns:topp="http://example.com/topp"
84
 */
85
export const featureTypeSchema = (d) => `xmlns:${d.targetPrefix}="${schemaLocation(d)}"`;
14✔
86
/**
87
 * Retrieve the value of the feature in GeoJSON to output the Geometry
88
 * @param  {object|number|string} value               the value
89
 * @param  {string} key                 the attribute name
90
 * @param  {object} describeFeatureType the describeFeatureType object
91
 * @return {string}                     the attribute value or a gml geometry
92
 */
93
export const getValue = (value, key, describeFeatureType, version = "1.1.0") => {
1✔
94
    // TODO implement normal attributes;
95
    const isGeom = isGeometryType(getPropertyDescriptor(key, describeFeatureType));
159✔
96
    if (isGeom) {
159✔
97
        return value ? processOGCGeometry(version, {
10!
98
            type: value.type,
99
            coordinates: value.coordinates
100
        }) : "";
101
    }
102
    if (value === null || value === undefined) {
149!
UNCOV
103
        return "";
×
104
    } if (typeof value === 'string') {
149✔
105
        return toCData(value);
38✔
106
    }
107
    return value;
111✔
108
};
109

110
/**
111
 * retrieves the featureTypeName from the describeFeatureType json object.
112
 * It prepends the targetPrefix to the first typename found in the featureTypes array.
113
 * Doesn't support multiple feature types
114
 * @param  {object} describeFeatureType the json object for describeFeatureType
115
 * @return {string} the prefixed typenName
116
 * @example
117
 * getTypeName({targetPrefix: "topp",featureTypes: [{typeName: "states"}]}); // --> topp:states
118
 */
119
export const getTypeName = (dft) => dft.targetPrefix ? dft.targetPrefix + ":" + dft.featureTypes[0].typeName : dft.featureTypes[0].typeName;
11!
120

121
export const isValid = (f, describe) => getFeatureTypeProperties(describe).map( pd => isValidProperty(f, pd));
4✔
122
export const isValidValueForPropertyName = (v, name, desc) => isValidValue(v, getPropertyDescriptor(name, desc));
73✔
123

124

125
/**
126
 * Gets all properties that are not a geometry
127
 * @param {object} describeFeatureType the describeFeatureType object
128
 * @return {object[]} the featureType properties
129
 * @example
130
 * describeFeatureType: {
131
 *   featureTypes: [{
132
 *     properties:[{
133
 *       localType: "string",
134
 *       maxOccurs: 1,
135
 *       minOccurs: 0,
136
 *       name: "id",
137
 *       nillable: true,
138
 *       type: "xsd:string"
139
 *     }]
140
 * }]
141
 */
142
export const findNonGeometryProperty = (describeFeatureType) => (getFeatureTypeProperties(describeFeatureType) || []).filter( d => !isGeometryType(d));
12!
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

© 2025 Coveralls, Inc