use of org.codice.ddf.confluence.api.SearchResource in project ddf by codice.
the class ConfluenceSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
Query query = request.getQuery();
ConfluenceFilterDelegate confluenceDelegate = new ConfluenceFilterDelegate();
String cql = filterAdapter.adapt(query, confluenceDelegate);
if (!confluenceDelegate.isConfluenceQuery() || (StringUtils.isEmpty(cql) && (confluenceSpaces.isEmpty() || !confluenceDelegate.isWildCardQuery()))) {
return new SourceResponseImpl(request, Collections.emptyList());
}
cql = getSortedQuery(query.getSortBy(), getSpaceQuery(cql));
LOGGER.debug(cql);
String finalExpandedSections = expandedSections;
if (includePageContent) {
finalExpandedSections += ",body.view";
}
SearchResource confluence = getClientFactory().getClient();
String cqlContext = null;
String excerpt = null;
Response confluenceResponse = confluence.search(cql, cqlContext, excerpt, finalExpandedSections, query.getStartIndex() - 1, query.getPageSize(), includeArchivedSpaces);
InputStream stream = null;
Object entityObj = confluenceResponse.getEntity();
if (entityObj != null) {
stream = (InputStream) entityObj;
}
if (Response.Status.OK.getStatusCode() != confluenceResponse.getStatus()) {
String error = "";
try {
if (stream != null) {
error = IOUtils.toString(stream);
}
} catch (IOException ioe) {
LOGGER.debug("Could not convert error message to a string for output.", ioe);
}
throw new UnsupportedQueryException(String.format("Received error code from remote source (status %s ): %s", confluenceResponse.getStatus(), error));
}
try {
List<Result> results = transformer.transformConfluenceResponse(stream).stream().map(this::getUpdatedResult).collect(Collectors.toList());
return new SourceResponseImpl(request, results);
} catch (IOException | CatalogTransformerException e) {
throw new UnsupportedQueryException("Exception processing results from Confluence");
}
}
Aggregations