use of dk.dbc.vipcore.marshallers.LibraryRules in project dataio by DBCDK.
the class LHRRetriever method getLibraryRules.
private AddiMetaData.LibraryRules getLibraryRules(long agencyId) throws VipCoreException {
if (libraryRulesCache.containsKey(agencyId)) {
return libraryRulesCache.get(agencyId);
}
final LibraryRules libraryRules = vipCoreLibraryRulesConnector.getLibraryRulesByAgencyId(Long.toString(agencyId));
final List<LibraryRule> libraryRuleList = libraryRules.getLibraryRule();
final AddiMetaData.LibraryRules metadataRules = new AddiMetaData.LibraryRules();
libraryRuleList.stream().filter(entry -> entry.getBool() != null).forEach(entry -> metadataRules.withLibraryRule(entry.getName(), entry.getBool()));
metadataRules.withAgencyType(libraryRules.getAgencyType());
libraryRulesCache.put(agencyId, metadataRules);
return metadataRules;
}
use of dk.dbc.vipcore.marshallers.LibraryRules in project dataio by DBCDK.
the class VipCoreConnectionTest method getLibraryRules_connectorReturnsNonEmptyResponse_returnsLibraryRules.
@Test
public void getLibraryRules_connectorReturnsNonEmptyResponse_returnsLibraryRules() throws VipCoreException {
final LibraryRule firstLibraryRule = new LibraryRule();
firstLibraryRule.setName("1st rule");
firstLibraryRule.setBool(true);
final LibraryRule secondLibraryRule = new LibraryRule();
secondLibraryRule.setName("2nd rule");
secondLibraryRule.setBool(false);
final LibraryRule thirdLibraryRule = new LibraryRule();
thirdLibraryRule.setName("3rd rule");
thirdLibraryRule.setString("value");
final LibraryRules libraryRules = new LibraryRules();
libraryRules.setAgencyType("myType");
libraryRules.setLibraryRule(Arrays.asList(firstLibraryRule, secondLibraryRule, thirdLibraryRule));
final AddiMetaData.LibraryRules expectedLibraryRules = new AddiMetaData.LibraryRules().withAgencyType(libraryRules.getAgencyType()).withLibraryRule(firstLibraryRule.getName(), firstLibraryRule.getBool()).withLibraryRule(secondLibraryRule.getName(), secondLibraryRule.getBool()).withLibraryRule(thirdLibraryRule.getName(), thirdLibraryRule.getString());
when(connector.getLibraryRulesByAgencyId(anyString(), anyString())).thenReturn(libraryRules);
assertThat(newVipCoreConnection().getLibraryRules(123456, "test"), is(expectedLibraryRules));
}
use of dk.dbc.vipcore.marshallers.LibraryRules in project dataio by DBCDK.
the class VipCoreConnectionTest method getLibraryRules_connectorReturnsNonEmptyResponse_cachesLibraryRules.
@Test
public void getLibraryRules_connectorReturnsNonEmptyResponse_cachesLibraryRules() throws VipCoreException {
final LibraryRules emptyLibraryRules = new LibraryRules();
emptyLibraryRules.setLibraryRule(new ArrayList<>());
when(connector.getLibraryRulesByAgencyId("123456", null)).thenReturn(emptyLibraryRules);
final VipCoreConnection vipCoreConnection = newVipCoreConnection();
assertSame(vipCoreConnection.getLibraryRules(123456, null), vipCoreConnection.getLibraryRules(123456, null));
verify(connector, times(1)).getLibraryRulesByAgencyId("123456", null);
}
use of dk.dbc.vipcore.marshallers.LibraryRules 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.LibraryRules in project dataio by DBCDK.
the class VipCoreConnection method getLibraryRules.
/**
* Retrieves library rules for given agency ID.
* <p>
* All non-null rule sets are cached. All subsequent requests for the same agency ID
* will return the result from the cache.
* </p>
*
* @param agencyId agency ID
* @param trackingId tracking ID used in web-service call, can be null
* @return library rules or null if no rules could be found.
* @throws IllegalStateException on error communicating with the vipcore web-service
*/
public AddiMetaData.LibraryRules getLibraryRules(int agencyId, String trackingId) throws IllegalStateException {
return libraryRulesCache.computeIfAbsent(agencyId, id -> {
try {
final LibraryRules libraryRules = connector.getLibraryRulesByAgencyId(Integer.toString(agencyId), trackingId);
final AddiMetaData.LibraryRules addiMetaDatalibraryRules = new AddiMetaData.LibraryRules();
libraryRules.getLibraryRule().forEach(entry -> addiMetaDatalibraryRules.withLibraryRule(entry.getName(), entry.getBool() != null ? entry.getBool() : entry.getString()));
return addiMetaDatalibraryRules.withAgencyType(libraryRules.getAgencyType());
} catch (AgencyNotFoundException e) {
return null;
} catch (VipCoreException e) {
throw new IllegalStateException("Error while looking up library rules for agency ID " + agencyId, e);
}
});
}
Aggregations