/** * Merges the results of the request subparts into one feature collection. * * @param fcid id of the new (result) feature collection * @param finishedEvents * @return feature collection containing all features from all responses * @throws OGCWebServiceException */ private FeatureCollection mergeResults( String fcid, List<ExecutionFinishedEvent<FeatureCollection>> finishedEvents) throws OGCWebServiceException { FeatureCollection result = null; try { for (ExecutionFinishedEvent<FeatureCollection> event : finishedEvents) { if (result == null) { result = event.getResult(); } else { result.addAll(event.getResult()); } } } catch (CancellationException e) { String msg = Messages.getMessage("WFS_GET_FEATURE_TIMEOUT"); LOG.logInfo(msg); throw new OGCWebServiceException(this.getClass().getName(), msg); } catch (Throwable t) { String msg = Messages.getMessage("WFS_GET_FEATURE_BACKEND", t.getMessage()); LOG.logError(msg, t); throw new OGCWebServiceException(this.getClass().getName(), msg); } result.setId(fcid); result.setAttribute("numberOfFeatures", "" + result.size()); return result; }
/** * Merges the results of the request subparts into one feature collection. * * <p>This method is used if only the HITS have been requested, i.e. the number of features. * * <p>TODO: Do this a better way (maybe change feature model). * * @param fcid id of the new (result) feature collection * @param finishedEvents * @return empty feature collection with "numberOfFeatures" attribute * @throws OGCWebServiceException */ private FeatureCollection mergeHits( String fcid, List<ExecutionFinishedEvent<FeatureCollection>> finishedEvents) throws OGCWebServiceException { FeatureCollection result = null; int numberOfFeatures = 0; try { for (ExecutionFinishedEvent<FeatureCollection> event : finishedEvents) { FeatureCollection fc = event.getResult(); try { numberOfFeatures += Integer.parseInt((fc.getAttribute("numberOfFeatures"))); } catch (NumberFormatException e) { String msg = "Internal error. Could not parse 'numberOfFeatures' attribute " + "of sub-result as an integer value."; throw new OGCWebServiceException(this.getClass().getName(), msg); } if (result == null) { result = fc; } else { result.addAll(fc); } } } catch (CancellationException e) { String msg = Messages.getMessage("WFS_GET_FEATURE_TIMEOUT"); LOG.logInfo(msg); throw new OGCWebServiceException(this.getClass().getName(), msg); } catch (Throwable t) { String msg = Messages.getMessage("WFS_GET_FEATURE_BACKEND", t.getMessage()); LOG.logError(msg); throw new OGCWebServiceException(this.getClass().getName(), msg); } result.setId(fcid); result.setAttribute("numberOfFeatures", "" + numberOfFeatures); return result; }