/** * Replaces the site name(s) of {@link FederatedSource}s in the {@link QueryResponse} with the * fanout's site name to keep info about the {@link FederatedSource}s hidden from the external * client. * * @param queryResponse the original {@link QueryResponse} from the query request * @return the updated {@link QueryResponse} with all site names replaced with fanout's site name */ public QueryResponse replaceSourceId(QueryResponse queryResponse) { LOGGER.trace("ENTERING: replaceSourceId()"); List<Result> results = queryResponse.getResults(); QueryResponseImpl newResponse = new QueryResponseImpl(queryResponse.getRequest(), queryResponse.getProperties()); for (Result result : results) { MetacardImpl newMetacard = new MetacardImpl(result.getMetacard()); newMetacard.setSourceId(this.getId()); ResultImpl newResult = new ResultImpl(newMetacard); // Copy over scores newResult.setDistanceInMeters(result.getDistanceInMeters()); newResult.setRelevanceScore(result.getRelevanceScore()); newResponse.addResult(newResult, false); } newResponse.setHits(queryResponse.getHits()); newResponse.closeResultQueue(); LOGGER.trace("EXITING: replaceSourceId()"); return newResponse; }
private QueryResponse injectAttributes(QueryResponse response) { List<Result> results = response .getResults() .stream() .map( result -> { Metacard original = result.getMetacard(); Metacard metacard = opsMetacardSupport.applyInjectors( original, frameworkProperties.getAttributeInjectors()); ResultImpl newResult = new ResultImpl(metacard); newResult.setDistanceInMeters(result.getDistanceInMeters()); newResult.setRelevanceScore(result.getRelevanceScore()); return newResult; }) .collect(Collectors.toList()); return new QueryResponseImpl( response.getRequest(), results, true, response.getHits(), response.getProperties()); }