ResourceSupport resource = response.getBody();
List<Link> links = new ArrayList<Link>();
ControllerLinkBuilder linkBuilder = linkTo(methodOn(RepositoryPropertyReferenceController.class)
.followPropertyReference(repoRequest, id, property, assembler));
if (resource instanceof Resource) {
Object content = ((Resource<?>) resource).getContent();
if (content instanceof Iterable) {
for (Resource<?> res : (Iterable<Resource<?>>) content) {
links.add(linkBuilder.withRel(propertyMapping.getRel()));
}
} else if (content instanceof Map) {
Map<Object, Resource<?>> map = (Map<Object, Resource<?>>) content;
for (Entry<Object, Resource<?>> entry : map.entrySet()) {
Link l = new Link(entry.getValue().getLink("self").getHref(), entry.getKey().toString());
links.add(l);
}
}
} else {
links.add(linkBuilder.withRel(propertyMapping.getRel()));
}
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, new Resource<Object>(EMPTY_RESOURCE_LIST, links));
}