Skip to content

Commit

Permalink
Made export resilient to errors due to natural order issues
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Aug 2, 2017
1 parent 5d09fdc commit f022ff5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions web/client/epics/wfsdownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FilterUtils = require('../utils/FilterUtils');
const {getByOutputFormat} = require('../utils/FileFormatUtils');

const getWFSFeature = ({url, filterObj = {}, downloadOptions= {}} = {}) => {
const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion);
const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion, filterObj.sortOptions);
return Rx.Observable.defer( () =>
axios.post(url + `?service=WFS&outputFormat=${downloadOptions.selectedFormat}`, data, {
timeout: 60000,
Expand All @@ -25,6 +25,12 @@ const getFileName = action => {
}
return name;
};
const getDefaultSortOptions = (attribute) => {
return attribute ? { sortBy: attribute, sortOrder: 'A'} : {};
};
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 str2bytes = (str) => {
var bytes = new Uint8Array(str.length);
Expand All @@ -35,7 +41,7 @@ const str2bytes = (str) => {
};
*/
module.exports = {
startFeatureExportDownload: action$ =>
startFeatureExportDownload: (action$, store) =>
action$.ofType(DOWNLOAD_FEATURES).switchMap(action =>
getWFSFeature({
url: action.url,
Expand All @@ -52,6 +58,26 @@ module.exports = {
throw xml;
}
}
})
.catch( () => {
return getWFSFeature({
url: action.url,
downloadOptions: action.downloadOptions,
filterObj: {
...action.filterObj,
pagination: get(action, "downloadOptions.singlePage") ? action.filterObj.pagination : null,
sortOptions: getDefaultSortOptions(getFirstAttribute(store.getState()))
}
}).do(({data, headers}) => {
if (headers["content-type"] === "application/xml") { // TODO add expected mimetypes in the case you want application/dxf
let xml = String.fromCharCode.apply(null, new Uint8Array(data));
if (xml.indexOf("<ows:ExceptionReport") === 0 ) {
throw xml;
}
}
saveAs(new Blob([data], {type: headers && headers["content-type"]}), getFileName(action));
});
}).do(({data, headers}) => {
saveAs(new Blob([data], {type: headers && headers["content-type"]}), getFileName(action));
})
.map( () => onDownloadFinished() )
Expand Down

0 comments on commit f022ff5

Please sign in to comment.