private Representation processRedirects(ReferencedSite site, Representation rep, Collection<String> fields) {
Iterator<Reference> redirects = rep.getReferences(NamespaceEnum.rdfs+"seeAlso");
switch (redirectState == null ? RedirectProcessingState.IGNORE : redirectState) {
case ADD_VALUES:
while(redirects.hasNext()){
Reference redirect = redirects.next();
if(redirect != null){
try {
Entity redirectedEntity = site != null ?
site.getEntity(redirect.getReference()) :
entityhub.getEntity(redirect.getReference());
if(redirectedEntity != null){
for(String field: fields){
rep.add(field, redirectedEntity.getRepresentation().get(field));
}
}
} catch (EntityhubException e) {
log.info(String.format("Unable to follow redirect to '%s' for Entity '%s'",
redirect.getReference(),rep.getId()),e);
}
}
}
return rep;
case FOLLOW:
while(redirects.hasNext()){
Reference redirect = redirects.next();
if(redirect != null){
try {
Entity redirectedEntity = site != null ?
site.getEntity(redirect.getReference()) :
entityhub.getEntity(redirect.getReference());
if(redirectedEntity != null){
return redirectedEntity.getRepresentation();
}
} catch (EntityhubException e) {
log.info(String.format("Unable to follow redirect to '%s' for Entity '%s'",
redirect.getReference(),rep.getId()),e);
}
}
}
return rep; //no redirect found
default: