Search in sources :

Example 1 with SolrDocStoreResponse

use of dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse in project solr-document-store by DBCDK.

the class DocProducerIT method deployAndSearch.

private void deployAndSearch(int agencyId, DocProducer docProducer, SolrCollection solrCollection, int expected) throws SolrServerException, IOException, PostponedNonFatalQueueError {
    SolrDocStoreResponse sourceDoc = docProducer.fetchSourceDoc(QueueJob.manifestation(agencyId, "clazzifier", "23645564"));
    SolrInputDocument doc = docProducer.createSolrDocument(sourceDoc, solrCollection);
    String bibliographicShardId = DocProducer.bibliographicShardId(sourceDoc);
    docProducer.deleteSolrDocuments(bibliographicShardId, solrCollection);
    docProducer.deploy(doc, solrCollection);
    SolrClient solrClient = solrCollection.getSolrClient();
    solrClient.commit(true, true);
    QueryResponse response = solrClient.query(new SolrQuery("*:*"));
    System.out.println("response = " + response);
    System.out.println("response = " + response.getResults());
    assertEquals(expected, response.getResults().getNumFound());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocStoreResponse(dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse) SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 2 with SolrDocStoreResponse

use of dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse in project solr-document-store by DBCDK.

the class DocProducerTest method test.

@Test
public void test() throws Exception {
    System.out.println("test");
    Config config = new Config("solrUrl=Not-Relevant", "zookeeperUrl=Not-Relevant", "profileServiceUrl=Not-Relevant", "solrDocStoreUrl=Not-Relevant", "solrAppId=Not-Relevant", "queues=Not-Relevant", "openAgencyUrl=Not-Relevant", "vipCoreEndpoint=Not-Relevant", "workPresentationUrl=not-relevant", "scanProfiles=102030-magic,123456-basic", "scanDefaultFields=abc,def") {

        @Override
        protected Set<SolrCollection> makeSolrCollections(Client client) throws IllegalArgumentException {
            return Collections.EMPTY_SET;
        }

        @Override
        public Client getClient() {
            return CLIENT;
        }
    };
    DocProducer docProducer = new DocProducer() {

        @Override
        public SolrDocStoreResponse fetchSourceDoc(QueueJob job) throws IOException {
            String file = "DocProducerTest/" + job.getAgencyId() + "-" + job.getBibliographicRecordId() + ".json";
            System.out.println("file = " + file);
            try (InputStream stream = DocProducerTest.class.getClassLoader().getResourceAsStream(file)) {
                return OBJECT_MAPPER.readValue(stream, SolrDocStoreResponse.class);
            }
        }
    };
    docProducer.config = config;
    docProducer.libraryRuleProvider = new LibraryRuleProviderBean() {

        @Override
        public VipCoreLibraryRule libraryRulesFor(String agencyId) {
            return new VipCoreLibraryRuleMockResponse(true, true, true, true, false, true);
        }
    };
    docProducer.persistentWorkIdProvider = new PersistentWorkIdProviderBean() {

        @Override
        public String persistentWorkIdFor(String corepoWorkId) {
            return "persistent-for-" + corepoWorkId;
        }
    };
    docProducer.profileProvider = new ProfileProviderBean() {

        @Override
        public VipCoreProfile profileFor(String agencyId, String profile) {
            switch(agencyId + "-" + profile) {
                case "102030-magic":
                    return new VipCoreProfile(true, "220000-katalog");
                case "123456-basic":
                    return new VipCoreProfile(false, "220000-katalog");
                default:
                    throw new AssertionError();
            }
        }
    };
    SolrDocStoreResponse node = docProducer.fetchSourceDoc(QueueJob.manifestation(300101, "clazzifier", "23645564"));
    System.out.println("node = " + node);
    SolrCollection solrCollection = new SolrCollection() {

        @Override
        public FeatureSwitch getFeatures() {
            return new FeatureSwitch("all");
        }

        @Override
        public KnownSolrFields getSolrFields() {
            try (InputStream is = getClass().getClassLoader().getResourceAsStream("schema.xml")) {
                return new KnownSolrFields(is);
            } catch (IOException | SAXException ex) {
                throw new RuntimeException(ex);
            }
        }
    };
    SolrInputDocument document = docProducer.createSolrDocument(node, solrCollection);
    System.out.println("document = " + document);
    assertTrue(document.containsKey("dkcclterm.po"));
    assertFalse(document.containsKey("unknown.field"));
    assertEquals(3, document.get("rec.holdingsAgencyId").getValues().size());
    assertTrue(document.get("rec.holdingsAgencyId").getValues().contains("300101"));
    assertTrue(document.get("rec.holdingsAgencyId").getValues().contains("300102"));
    assertTrue(document.get("rec.holdingsAgencyId").getValues().contains("300104"));
    assertTrue(document.get("rec.repositoryId").getValues().contains("870970-basis:23645564"));
    assertTrue(document.containsKey("dkcclterm.ln"));
    assertTrue(document.get("dkcclterm.ln").getValues().contains("777777"));
    System.out.println("OK");
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) VipCoreLibraryRule(dk.dbc.solrdocstore.updater.businesslogic.VipCoreLibraryRule) VipCoreProfile(dk.dbc.solrdocstore.updater.businesslogic.VipCoreProfile) SAXException(org.xml.sax.SAXException) FeatureSwitch(dk.dbc.solrdocstore.updater.businesslogic.FeatureSwitch) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocStoreResponse(dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse) KnownSolrFields(dk.dbc.solrdocstore.updater.businesslogic.KnownSolrFields) Client(javax.ws.rs.client.Client) QueueJob(dk.dbc.search.solrdocstore.queue.QueueJob) Test(org.junit.Test)

Example 3 with SolrDocStoreResponse

use of dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse 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

SolrDocStoreResponse (dk.dbc.solrdocstore.updater.businesslogic.SolrDocStoreResponse)3 SolrInputDocument (org.apache.solr.common.SolrInputDocument)3 IOException (java.io.IOException)2 QueueJob (dk.dbc.search.solrdocstore.queue.QueueJob)1 SolrCollection (dk.dbc.search.solrdocstore.updater.SolrCollection)1 FeatureSwitch (dk.dbc.solrdocstore.updater.businesslogic.FeatureSwitch)1 KnownSolrFields (dk.dbc.solrdocstore.updater.businesslogic.KnownSolrFields)1 VipCoreLibraryRule (dk.dbc.solrdocstore.updater.businesslogic.VipCoreLibraryRule)1 VipCoreProfile (dk.dbc.solrdocstore.updater.businesslogic.VipCoreProfile)1 InputStream (java.io.InputStream)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 Client (javax.ws.rs.client.Client)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 Test (org.junit.Test)1 SAXException (org.xml.sax.SAXException)1