-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1737 Query panel search fails if an id is not defined #1792
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63aa18d
Added query epic to handle WFS error
allyoucanmap cf20f90
Fixed structure of query epic
allyoucanmap 2227652
Merge branch 'master' into id-fails
allyoucanmap 592533e
Added documentation to wfsquery epic
allyoucanmap 869016a
Fixed indent and documentationof wfsquery
allyoucanmap f513469
Merge branch 'master' into id-fails
allyoucanmap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,21 @@ | |
const Rx = require('rxjs'); | ||
const axios = require('../libs/ajax'); | ||
const {changeSpatialAttribute} = require('../actions/queryform'); | ||
const {FEATURE_TYPE_SELECTED, featureTypeLoaded, featureTypeError} = require('../actions/wfsquery'); | ||
const {FEATURE_TYPE_SELECTED, QUERY, featureTypeLoaded, featureTypeError, createQuery, querySearchResponse, queryError, featureClose} = require('../actions/wfsquery'); | ||
const FilterUtils = require('../utils/FilterUtils'); | ||
const assign = require('object-assign'); | ||
const {isString} = require('lodash'); | ||
const {TOGGLE_CONTROL, setControlProperty} = require('../actions/controls'); | ||
|
||
const types = { | ||
'xsd:string': 'string', | ||
'xsd:dateTime': 'date', | ||
'xsd:number': 'number', | ||
'xsd:int': 'number' | ||
}; | ||
|
||
const fieldConfig = {}; | ||
|
||
const extractInfo = (data) => { | ||
return { | ||
geometry: data.featureTypes[0].properties | ||
|
@@ -51,6 +57,62 @@ const extractInfo = (data) => { | |
}; | ||
}; | ||
|
||
const getWFSFilterData = (filterObj) => { | ||
let data; | ||
if (typeof filterObj === 'string') { | ||
data = filterObj; | ||
} else { | ||
data = filterObj.filterType === "OGC" ? | ||
FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion, filterObj.sortOptions, filterObj.hits) : | ||
FilterUtils.toCQLFilter(filterObj); | ||
} | ||
return data; | ||
}; | ||
|
||
const getWFSFeature = (searchUrl, filterObj) => { | ||
const data = getWFSFilterData(filterObj); | ||
return Rx.Observable.defer( () => | ||
axios.post(searchUrl + '?service=WFS&outputFormat=json', data, { | ||
timeout: 60000, | ||
headers: {'Accept': 'application/json', 'Content-Type': 'application/json'} | ||
})); | ||
}; | ||
|
||
const getWFSResponseException = (response, code) => { | ||
const {unmarshaller} = require('../utils/ogc/WFS'); | ||
const json = isString(response.data) ? unmarshaller.unmarshalString(response.data) : null; | ||
return json && json.value && json.value.exception && json.value.exception[0] && json.value.exception[0].TYPE_NAME === 'OWS_1_0_0.ExceptionType' && json.value.exception[0].exceptionCode === code; | ||
}; | ||
|
||
const getFirstAttribute = (state)=> { | ||
return state.query && state.query.featureTypes && state.query.featureTypes[state.query.typeName] && state.query.featureTypes[state.query.typeName].attributes && state.query.featureTypes[state.query.typeName].attributes[0] && state.query.featureTypes[state.query.typeName].attributes[0].attribute || null; | ||
}; | ||
|
||
const getDefaultSortOptions = (attribute) => { | ||
return attribute ? { sortBy: attribute, sortOrder: 'A'} : {}; | ||
}; | ||
|
||
const retryWithForcedSortOptions = (action, store) => { | ||
const sortOptions = getDefaultSortOptions(getFirstAttribute(store.getState())); | ||
return getWFSFeature(action.searchUrl, assign(action.filterObj, { | ||
sortOptions | ||
})) | ||
.map((newResponse) => { | ||
const newError = getWFSResponseException(newResponse, 'NoApplicableCode'); | ||
return !newError ? querySearchResponse(newResponse.data, action.searchUrl, action.filterObj) : queryError('No sortable request'); | ||
}) | ||
.catch((e) => { | ||
return Rx.Observable.of(queryError(e)); | ||
}); | ||
}; | ||
|
||
/** | ||
* Gets the WFS feature type attributes and geometry when the feature has been selected | ||
* @param {Observable} action$ manages `FEATURE_TYPE_SELECTED` | ||
* @memberof epics.wfsquery | ||
* @return {Observable} | ||
*/ | ||
|
||
const featureTypeSelectedEpic = action$ => | ||
action$.ofType(FEATURE_TYPE_SELECTED).switchMap(action => { | ||
return Rx.Observable.defer( () => | ||
|
@@ -72,6 +134,55 @@ const featureTypeSelectedEpic = action$ => | |
.catch(e => Rx.Observable.of(featureTypeError(action.typeName, e.message))); | ||
}); | ||
|
||
/** | ||
* Sends a WFS query, returns a response or handles request error | ||
* in particular the NoApplicableCode WFS error with a forced sort option on the first attribute | ||
* @param {Observable} action$ manages `QUERY` | ||
* @memberof epics.wfsquery | ||
* @return {Observable} | ||
*/ | ||
|
||
const wfsQueryEpic = (action$, store) => | ||
action$.ofType(QUERY).switchMap(action => { | ||
|
||
return Rx.Observable.merge( | ||
Rx.Observable.of(createQuery(action.searchUrl, action.filterObj)), | ||
Rx.Observable.of(setControlProperty('drawer', 'enabled', false)), | ||
getWFSFeature(action.searchUrl, action.filterObj) | ||
.switchMap((response) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent |
||
// try to guess if it was a missing id error and try to search again with forced sortOptions | ||
const error = getWFSResponseException(response, 'NoApplicableCode'); | ||
if (error) { | ||
return retryWithForcedSortOptions(action, store); | ||
} | ||
return Rx.Observable.of(querySearchResponse(response.data, action.searchUrl, action.filterObj)); | ||
}) | ||
.catch((e) => { | ||
return Rx.Observable.of(queryError(e)); | ||
}) | ||
); | ||
}); | ||
|
||
/** | ||
* Closes the feature grid when the drawer menu button has been toggled | ||
* @param {Observable} action$ manages `TOGGLE_CONTROL` | ||
* @memberof epics.wfsquery | ||
* @return {Observable} | ||
*/ | ||
|
||
const closeFeatureEpic = action$ => | ||
action$.ofType(TOGGLE_CONTROL).switchMap(action => { | ||
return action.control && action.control === 'drawer' ? Rx.Observable.of(featureClose()) : Rx.Observable.empty(); | ||
}); | ||
|
||
/** | ||
* Epics for WFS query requests | ||
* @name epics.wfsquery | ||
* @type {Object} | ||
*/ | ||
|
||
module.exports = { | ||
featureTypeSelectedEpic | ||
featureTypeSelectedEpic, | ||
wfsQueryEpic, | ||
closeFeatureEpic | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
external:Observable see other epics.