@Override public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) { if (collectionTerminalState.isPresent()) { return collectionTerminalState.get().handlePost(state); } throw new InvalidOperationException("Cannot POST to a record."); }
Optional<MultivaluedMap<String, String>> queryParams = requestScope.getQueryParams(); Set<PersistentResource> collection = getResourceCollection(requestScope); jsonApiDocument.setData(getData(collection));
@Override public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) { String entityName = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty())); }
@Override public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) { RequestScope requestScope = state.getRequestScope(); JsonApiMapper mapper = requestScope.getMapper(); newObject = createObject(requestScope); parent.ifPresent(persistentResource -> persistentResource.addRelation(relationName.get(), newObject)); return () -> { JsonApiDocument returnDoc = new JsonApiDocument(); returnDoc.setData(new Data(newObject.toResource())); JsonNode responseBody = mapper.getObjectMapper().convertValue(returnDoc, JsonNode.class); return Pair.of(HttpStatus.SC_CREATED, responseBody); }; }
Optional<MultivaluedMap<String, String>> queryParams = requestScope.getQueryParams(); Set<PersistentResource> collection = getResourceCollection(requestScope); jsonApiDocument.setData(getData(collection));
@Override public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) { String entityName = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty())); }
@Override public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) { RequestScope requestScope = state.getRequestScope(); JsonApiMapper mapper = requestScope.getMapper(); newObject = createObject(requestScope); parent.ifPresent(persistentResource -> persistentResource.addRelation(relationName.get(), newObject)); return () -> { JsonApiDocument returnDoc = new JsonApiDocument(); returnDoc.setData(new Data(newObject.toResource())); JsonNode responseBody = mapper.getObjectMapper().convertValue(returnDoc, JsonNode.class); return Pair.of(HttpStatus.SC_CREATED, responseBody); }; }
new CollectionTerminalState(entityClass, Optional.of(resource), Optional.of(subCollection)); Set<PersistentResource> collection = null; if (type.isToOne()) {
@Override public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) { if (collectionTerminalState.isPresent()) { return collectionTerminalState.get().handlePost(state); } throw new InvalidOperationException("Cannot POST to a record."); }
new CollectionTerminalState(entityClass, Optional.of(resource), Optional.of(subCollection)); Set<PersistentResource> collection = null; if (type.isToOne()) {