use of dk.dbc.search.solrdocstore.updater.SolrCollection in project solr-document-store by DBCDK.
the class DocTest method format.
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("format/{agencyId : \\d+}/{classifier}/{bibliographicRecordId : .*$}")
public Response format(@PathParam("agencyId") int agencyId, @PathParam("classifier") String classifier, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("collection") String collection) throws InterruptedException, ExecutionException, IOException {
log.debug("agencyId = {}; bibliographicRecordId = {}", agencyId, bibliographicRecordId);
try {
SolrDocStoreResponse sourceDoc = docProducer.fetchSourceDoc(QueueJob.manifestation(agencyId, classifier, bibliographicRecordId));
if (sourceDoc.bibliographicRecord.deleted) {
return Response.noContent().build();
}
Set<SolrCollection> solrCollections = config.getSolrCollections();
Optional<SolrCollection> solrCollection;
if (collection == null) {
solrCollection = solrCollections.stream().findAny();
} else {
solrCollection = solrCollections.stream().filter(c -> c.getName().equalsIgnoreCase(collection)).findAny();
}
if (!solrCollection.isPresent())
throw new InternalServerErrorException("Cannot find collection");
SolrInputDocument document = docProducer.createSolrDocument(sourceDoc, solrCollection.get());
String xml = ClientUtils.toXML(document);
return Response.ok(xml, MediaType.APPLICATION_XML_TYPE).build();
} catch (IOException | RuntimeException ex) {
log.error("Exception: {}", ex.getMessage());
log.debug("Exception:", ex);
return Response.ok(ex.getMessage(), MediaType.TEXT_PLAIN).build();
}
}
Aggregations