use of dk.dbc.solrdocstore.updater.businesslogic.VipCoreProfile 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");
}
use of dk.dbc.solrdocstore.updater.businesslogic.VipCoreProfile in project solr-document-store by DBCDK.
the class ProfileProviderBean method profileFor.
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@CacheResult(cacheName = "vipProfile", exceptionCacheName = "vipProfileError", cachedExceptions = { IllegalStateException.class, ClientErrorException.class, ServerErrorException.class })
public VipCoreProfile profileFor(String agencyId, String profile) {
try {
String vipCoreResponse = vipCoreHttpClient.getFromVipCore(config.getVipCoreEndpoint(), VipCoreHttpClient.PROFILE_SERVICE_PATH + "/search/" + agencyId + "/" + profile);
log.debug("vipCoreResponse was: {}", vipCoreResponse);
ProfileServiceResponse profileServiceResponse = O.readValue(vipCoreResponse, ProfileServiceResponse.class);
if (profileServiceResponse.getError() != null)
throw new IllegalStateException("profile service: " + profileServiceResponse.getError().value());
return new VipCoreProfile(profileServiceResponse);
} catch (OpenAgencyException ex) {
log.error("Error when fetching profile {} for agencyId {}", profile, agencyId);
throw new IllegalStateException("profile service: " + ex.getMessage());
} catch (JsonProcessingException ex) {
log.error("Error when processing response from VipCore profileservice for agency {} and profile {}: {}", agencyId, profile, ex.getMessage());
log.debug("Error when processing response from VipCore profileservice for agency {} and profile {}: {}", agencyId, profile, ex);
throw new IllegalStateException("profile service: " + ex.getMessage());
}
}
Aggregations