Search in sources :

Example 1 with OpenAgencyException

use of dk.dbc.openagency.http.OpenAgencyException 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 OpenAgencyException

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

Example 3 with OpenAgencyException

use of dk.dbc.openagency.http.OpenAgencyException 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)

Aggregations

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