Package org.springframework.hateoas.mvc

Examples of org.springframework.hateoas.mvc.ControllerLinkBuilder


    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));
  }
View Full Code Here


    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));
  }
View Full Code Here

TOP

Related Classes of org.springframework.hateoas.mvc.ControllerLinkBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.