use of dk.dbc.vipcore.marshallers.LibraryRulesResponse in project solr-document-store by DBCDK.
the class LibraryRuleProviderBean method libraryRulesFor.
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@CacheResult(cacheName = "vipLibraryRules", exceptionCacheName = "vipLibraryRulesError", cachedExceptions = { IllegalStateException.class, ClientErrorException.class, ServerErrorException.class })
public VipCoreLibraryRule libraryRulesFor(String agencyId) {
try {
String vipCoreResponse = vipCoreHttpClient.getFromVipCore(config.getVipCoreEndpoint(), VipCoreHttpClient.LIBRARY_RULES_PATH + "/" + agencyId);
if (vipCoreResponse.startsWith("{")) {
log.debug("vipCoreResponse was: {}", vipCoreResponse);
LibraryRulesResponse libraryRulesResponse = O.readValue(vipCoreResponse, LibraryRulesResponse.class);
if (libraryRulesResponse.getError() != null)
throw new IllegalStateException("library rules: " + libraryRulesResponse.getError().value());
return new VipCoreLibraryRule(libraryRulesResponse);
} else {
throw new ClientErrorException("Vipcore said: " + vipCoreResponse.substring(Integer.max(0, vipCoreResponse.length() - 50)), Response.Status.BAD_REQUEST);
}
} catch (OpenAgencyException ex) {
log.error("Error when fetching libraryrules for agencyId {}", agencyId);
throw new IllegalStateException("library rules: " + ex.getMessage());
} catch (JsonProcessingException ex) {
log.error("Error when processing response from VipCore libraryrules for agency {}: {}", agencyId, ex.getMessage());
log.debug("Error when processing response from VipCore libraryrules for agency {}: {}", agencyId, ex);
throw new IllegalStateException("library rules: " + ex.getMessage());
}
}
use of dk.dbc.vipcore.marshallers.LibraryRulesResponse in project solr-document-store by DBCDK.
the class OpenAgencyProxyBean method loadOpenAgencyEntry.
@Timed
public OpenAgencyEntity loadOpenAgencyEntry(int agencyId) {
try {
LibraryRulesResponse libraryRulesResponse = getLibraryRuleResponse(agencyId);
if (libraryRulesResponse.getError() != null) {
return new OpenAgencyEntity(agencyId, LibraryType.Missing, false, false, false);
}
final List<LibraryRules> libraryRuleList = libraryRulesResponse.getLibraryRules();
if (libraryRuleList == null || libraryRuleList.isEmpty()) {
return null;
} else {
return new OpenAgencyEntity(libraryRuleList.get(0));
}
} catch (JsonProcessingException e) {
log.error("Unable to unmarshall response from vipCore from agency {}, error: {}", agencyId, e.getMessage());
log.debug("Unable to unmarshall response from vipCore from agency {}, error: {}", agencyId, e);
throw new EJBException(e);
} catch (RuntimeException | OpenAgencyException | IOException e) {
log.error("Error happened while fetching vipCore library rules for agency {}: {}", agencyId, e.getMessage());
throw new EJBException(e);
}
}
use of dk.dbc.vipcore.marshallers.LibraryRulesResponse in project solr-document-store by DBCDK.
the class VipCoreLibraryRuleTest method testLibraryRuleFromVip.
@Test(timeout = 2_000L)
public void testLibraryRuleFromVip() throws Exception {
System.out.println("testLibraryRuleFromVip");
String content = "{'libraryRules':[{'agencyId':'number','agencyType':'Skolebibliotek','libraryRule':[{'name':'create_enrichments','bool':true},{'name':'use_enrichments','bool':true},{'name':'auth_root','bool':false},{'name':'auth_common_subjects','bool':false},{'name':'auth_common_notes','bool':false},{'name':'auth_dbc_records','bool':false},{'name':'auth_public_lib_common_record','bool':false},{'name':'auth_ret_record','bool':false},{'name':'auth_agency_common_record','bool':true},{'name':'auth_export_holdings','bool':false},{'name':'use_localdata_stream','bool':false},{'name':'use_holdings_item','bool':true},{'name':'part_of_bibliotek_dk','bool':false},{'name':'auth_create_common_record','bool':false},{'name':'ims_library','bool':false},{'name':'worldcat_synchronize','bool':true},{'name':'worldcat_resource_sharing','bool':false},{'name':'cataloging_template_set','string':'dbc'},{'name':'part_of_danbib','bool':false},{'name':'auth_add_dk5_to_phd','bool':false},{'name':'auth_metacompass','bool':false},{'name':'view_metacompass','bool':false},{'name':'use_central_faust','bool':true}]}]}";
LibraryRulesResponse libraryRulesResponse = O.readValue(content.replaceAll("'", "\""), LibraryRulesResponse.class);
VipCoreLibraryRule libraryRule = new VipCoreLibraryRule(libraryRulesResponse);
assertThat(libraryRule.isPartOfBibdk(), is(false));
assertThat(libraryRule.usesHoldingsItem(), is(true));
assertThat(libraryRule.isFbsLibrary(), is(true));
assertThat(libraryRule.isResearchLibrary(), is(false));
}
Aggregations