Cache cache = getCache();
Entity entity = null;
long start = System.currentTimeMillis();
if (cache != null) {
try {
Representation rep = cache.getRepresentation(id);
if (rep != null) {
entity = new EntityImpl(getId(), rep, null);
initEntityMetadata(entity, siteMetadata,
singletonMap(RdfResourceEnum.isChached.getUri(), (Object) Boolean.TRUE));
} else if (siteConfiguration.getCacheStrategy() == CacheStrategy.all) {
return null; // do no remote lokkups on CacheStrategy.all!!
}
} catch (YardException e) {
if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
throw new SiteException(String.format("Unable to get Represetnation %s form Cache %s",
id, siteConfiguration.getCacheId()), e);
} else {
log.warn(
String.format(
"Unable to get Represetnation %s form Cache %s. Will dereference from remote site %s",
id, siteConfiguration.getCacheId(), siteConfiguration.getAccessUri()), e);
}
}
} else {
if (siteConfiguration.getEntityDereferencerType() == null || isOfflineMode()) {
throw new SiteException(String.format(
"Unable to get Represetnation %s because configured Cache %s is currently not available",
id, siteConfiguration.getCacheId()));
} else {
log.warn(String.format(
"Cache %s is currently not available. Will use remote site %s to load Representation %s",
siteConfiguration.getCacheId(), siteConfiguration.getEntityDereferencerType(), id));
}
}
if (entity == null) { // no cache or not found in cache
if (dereferencer == null) {
throw new SiteException(String.format(
"Entity Dereferencer %s for accessing remote site %s is not available",
siteConfiguration.getEntityDereferencerType(), siteConfiguration.getAccessUri()));
}
ensureOnline(siteConfiguration.getAccessUri(), dereferencer.getClass());
Representation rep = null;
try {
rep = dereferencer.dereference(id);
} catch (IOException e) {
throw new SiteException(String.format(
"Unable to load Representation for entity %s form remote site %s with dereferencer %s",