Search in sources :

Example 1 with LibraryRulesResponse

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());
    }
}
Also used : ClientErrorException(javax.ws.rs.ClientErrorException) LibraryRulesResponse(dk.dbc.vipcore.marshallers.LibraryRulesResponse) OpenAgencyException(dk.dbc.openagency.http.OpenAgencyException) VipCoreLibraryRule(dk.dbc.solrdocstore.updater.businesslogic.VipCoreLibraryRule) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TransactionAttribute(javax.ejb.TransactionAttribute) CacheResult(javax.cache.annotation.CacheResult)

Example 2 with LibraryRulesResponse

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);
    }
}
Also used : LibraryRules(dk.dbc.vipcore.marshallers.LibraryRules) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) LibraryRulesResponse(dk.dbc.vipcore.marshallers.LibraryRulesResponse) OpenAgencyException(dk.dbc.openagency.http.OpenAgencyException) IOException(java.io.IOException) EJBException(javax.ejb.EJBException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Timed(org.eclipse.microprofile.metrics.annotation.Timed)

Example 3 with LibraryRulesResponse

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));
}
Also used : LibraryRulesResponse(dk.dbc.vipcore.marshallers.LibraryRulesResponse) Test(org.junit.Test)

Aggregations

LibraryRulesResponse (dk.dbc.vipcore.marshallers.LibraryRulesResponse)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 OpenAgencyException (dk.dbc.openagency.http.OpenAgencyException)2 OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)1 VipCoreLibraryRule (dk.dbc.solrdocstore.updater.businesslogic.VipCoreLibraryRule)1 LibraryRules (dk.dbc.vipcore.marshallers.LibraryRules)1 IOException (java.io.IOException)1 CacheResult (javax.cache.annotation.CacheResult)1 EJBException (javax.ejb.EJBException)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Timed (org.eclipse.microprofile.metrics.annotation.Timed)1 Test (org.junit.Test)1