/** * Get relationship mappings. * * @return Relationship mapping */ protected Map<String, Relationship> getRelationships() { return getRelationshipsWithRelationshipFunction((relationName) -> { Optional<FilterExpression> filterExpression = requestScope.getExpressionForRelation(this, relationName); return getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); }); }
/** * Get relationship mappings. * * @return Relationship mapping */ protected Map<String, Relationship> getRelationships() { return getRelationshipsWithRelationshipFunction((relationName) -> { Optional<FilterExpression> filterExpression = requestScope.getExpressionForRelation(this, relationName); return getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); }); }
/** * Get relationship mappings. * * @return Relationship mapping */ protected Map<String, Relationship> getRelationshipsWithSortingAndPagination() { return getRelationshipsWithRelationshipFunction((relationName) -> { Optional<FilterExpression> filterExpression = requestScope.getExpressionForRelation(this, relationName); Optional<Sorting> sorting = Optional.ofNullable(requestScope.getSorting()); Optional<Pagination> pagination = Optional.ofNullable(requestScope.getPagination()); return getRelationCheckedFiltered(relationName, filterExpression, sorting, pagination); }); }
private Set<PersistentResource> getResourceCollection(RequestScope requestScope) { final Set<PersistentResource> collection; // TODO: In case of join filters, apply pagination after getting records // instead of passing it to the datastore Optional<Pagination> pagination = Optional.ofNullable(requestScope.getPagination()); Optional<Sorting> sorting = Optional.ofNullable(requestScope.getSorting()); if (parent.isPresent()) { Optional<FilterExpression> filterExpression = requestScope.getExpressionForRelation(parent.get(), relationName.get()); collection = parent.get().getRelationCheckedFiltered( relationName.get(), filterExpression, sorting, pagination); } else { Optional<FilterExpression> filterExpression = requestScope.getLoadFilterExpression(entityClass); collection = PersistentResource.loadRecords( entityClass, new ArrayList<>(), //Empty list of IDs filterExpression, sorting, pagination, requestScope); } return collection; }
/** * 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)); } }); }
/** * Get relationship mappings. * * @return Relationship mapping */ protected Map<String, Relationship> getRelationshipsWithSortingAndPagination() { return getRelationshipsWithRelationshipFunction((relationName) -> { Optional<FilterExpression> filterExpression = requestScope.getExpressionForRelation(this, relationName); Optional<Sorting> sorting = Optional.ofNullable(requestScope.getSorting()); Optional<Pagination> pagination = Optional.ofNullable(requestScope.getPagination()); return getRelationCheckedFiltered(relationName, filterExpression, sorting, pagination); }); }
private Set<PersistentResource> getResourceCollection(RequestScope requestScope) { final Set<PersistentResource> collection; // TODO: In case of join filters, apply pagination after getting records // instead of passing it to the datastore Optional<Pagination> pagination = Optional.ofNullable(requestScope.getPagination()); Optional<Sorting> sorting = Optional.ofNullable(requestScope.getSorting()); if (parent.isPresent()) { Optional<FilterExpression> filterExpression = requestScope.getExpressionForRelation(parent.get(), relationName.get()); collection = parent.get().getRelationCheckedFiltered( relationName.get(), filterExpression, sorting, pagination); } else { Optional<FilterExpression> filterExpression = requestScope.getLoadFilterExpression(entityClass); collection = PersistentResource.loadRecords( entityClass, new ArrayList<>(), //Empty list of IDs filterExpression, sorting, pagination, requestScope); } return collection; }
/** * 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)); } }); }
@Override public void handle(StateContext state, RootCollectionRelationshipContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(record, relationName); record.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(record, relationName)); }
@Override public void handle(StateContext state, RootCollectionRelationshipContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(record, relationName); record.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(record, relationName)); }
relations = parentResource.getRelation(fieldName, ids.get(), filter, sorting, pagination); } else { relations = parentResource.getRelationCheckedFiltered(fieldName, filter, sorting, pagination);
relations = parentResource.getRelation(fieldName, ids.get(), filter, sorting, pagination); } else { relations = parentResource.getRelationCheckedFiltered(fieldName, filter, sorting, pagination);
@Override public void handle(StateContext state, SubCollectionRelationshipContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); PersistentResource childRecord; try { childRecord = resource.getRelation(subCollection, id); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); childRecord.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(childRecord, relationName)); } }
Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); collection = resource.getRelationCheckedFiltered(subCollection, filterExpression, Optional.empty(), Optional.empty());
@Override public void handle(StateContext state, SubCollectionRelationshipContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); PersistentResource childRecord; try { childRecord = resource.getRelation(subCollection, id); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); childRecord.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(childRecord, relationName)); } }
Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); collection = resource.getRelationCheckedFiltered(subCollection, filterExpression, Optional.empty(), Optional.empty());