/** * Scan through the {@link Affordance}s and * @param resource * @return */ private static CollectionJsonTemplate findTemplate(ResourceSupport resource) { List<CollectionJsonTemplate> templates = new ArrayList<>(); if (resource.hasLink(IanaLinkRelation.SELF.value())) { resource.getRequiredLink(IanaLinkRelation.SELF.value()).getAffordances().forEach(affordance -> { CollectionJsonAffordanceModel model = affordance.getAffordanceModel(MediaTypes.COLLECTION_JSON); /** * For Collection+JSON, "templates" are made of any non-GET affordances. */ if (!(model.getHttpMethod() == HttpMethod.GET)) { CollectionJsonTemplate template = new CollectionJsonTemplate() // .withData(model.getInputProperties()); templates.add(template); } }); } /** * Collection+JSON can only have one template, so grab the first one. */ return templates.stream() .findFirst() .orElse(null); }
.flatMap(link -> link.getAffordances().stream()) .map(affordance -> (UberAffordanceModel) affordance.getAffordanceModel(MediaTypes.UBER_JSON)) .map(model -> {
/** * Scan through the {@link Affordance}s and find any {@literal GET} calls against non-self URIs. * * @param resource * @return */ private static List<CollectionJsonQuery> findQueries(ResourceSupport resource) { List<CollectionJsonQuery> queries = new ArrayList<>(); if (resource.hasLink(IanaLinkRelation.SELF.value())) { Link selfLink = resource.getRequiredLink(IanaLinkRelation.SELF.value()); selfLink.getAffordances().forEach(affordance -> { CollectionJsonAffordanceModel model = affordance.getAffordanceModel(MediaTypes.COLLECTION_JSON); /** * For Collection+JSON, "queries" are only collected for GET affordances where the URI is NOT a self link. */ if (model.getHttpMethod() == HttpMethod.GET && !model.getURI().equals(selfLink.getHref())) { queries.add(new CollectionJsonQuery() .withRel(model.getName()) .withHref(model.getURI()) .withData(model.getQueryProperties())); } }); } return queries; }