Search in sources :

Example 1 with SolrCollection

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();
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocStoreResponse(dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse) SolrCollection(dk.dbc.search.solrdocstore.updater.SolrCollection) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

SolrCollection (dk.dbc.search.solrdocstore.updater.SolrCollection)1 SolrDocStoreResponse (dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse)1 IOException (java.io.IOException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1