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",
id, siteConfiguration.getAccessUri(), siteConfiguration.getEntityDereferencerType()), e);
}
// representation loaded from remote site and cache is available
if (rep != null) {
Boolean cachedVersion = Boolean.FALSE;
if (cache != null) {// -> cache the representation
try {
start = System.currentTimeMillis();
// return the the cached version
rep = cache.store(rep);
cachedVersion = Boolean.TRUE;
log.debug(" - cached Representation {} in {} ms", id,
(System.currentTimeMillis() - start));
} catch (YardException e) {
log.warn(String.format(
"Unable to cache Represetnation %s in Cache %s! Representation not cached!", id,
siteConfiguration.getCacheId()), e);
}
}
entity = new EntityImpl(getId(), rep, null);
initEntityMetadata(entity, siteMetadata,
singletonMap(RdfResourceEnum.isChached.getUri(), (Object) cachedVersion));
}
} else {
log.debug(" - loaded Representation {} from Cache in {} ms", id,