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());
}
}
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());
}
}
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);
}
}
Aggregations