/** * Adds all the relation resources for a given relation path to the included block of the * JsonApiDocument. */ private void addResourcesForPath(JsonApiDocument jsonApiDocument, PersistentResource<?> rec, List<String> relationPath) { //Pop off a relation of relation path String relation = relationPath.remove(0); Optional<FilterExpression> filterExpression = rec.getRequestScope().getExpressionForRelation(rec, relation); Set<PersistentResource> collection; try { collection = rec.getRelationCheckedFiltered(relation, filterExpression, Optional.empty(), Optional.empty()); } catch (ForbiddenAccessException e) { return; } collection.forEach(resource -> { jsonApiDocument.addIncluded(resource.toResource()); //If more relations left in the path, process a level deeper if (!relationPath.isEmpty()) { //Use a copy of the relationPath to preserve the path for remaining branches of the relationship tree addResourcesForPath(jsonApiDocument, resource, new ArrayList<>(relationPath)); } }); }
/** * Adds all the relation resources for a given relation path to the included block of the * JsonApiDocument. */ private void addResourcesForPath(JsonApiDocument jsonApiDocument, PersistentResource<?> rec, List<String> relationPath) { //Pop off a relation of relation path String relation = relationPath.remove(0); Optional<FilterExpression> filterExpression = rec.getRequestScope().getExpressionForRelation(rec, relation); Set<PersistentResource> collection; try { collection = rec.getRelationCheckedFiltered(relation, filterExpression, Optional.empty(), Optional.empty()); } catch (ForbiddenAccessException e) { return; } collection.forEach(resource -> { jsonApiDocument.addIncluded(resource.toResource()); //If more relations left in the path, process a level deeper if (!relationPath.isEmpty()) { //Use a copy of the relationPath to preserve the path for remaining branches of the relationship tree addResourcesForPath(jsonApiDocument, resource, new ArrayList<>(relationPath)); } }); }