public Object breadcrumbFetcher(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); NodeContent content = env.getSource(); if (content == null) { return null; } return content.getNode().getBreadcrumbNodes(gc).stream().map(node -> { List<String> languageTags = getLanguageArgument(env, content); return new NodeContent(node, node.findVersion(gc, languageTags), languageTags); }).collect(Collectors.toList()); }
public Object languagesFetcher(DataFetchingEnvironment env) { NodeContent content = env.getSource(); if (content == null) { return null; } GraphQLContext gc = env.getContext(); Branch branch = gc.getBranch(); ContainerType type = ContainerType.forVersion(gc.getVersioningParameters().getVersion()); Stream<? extends NodeGraphFieldContainer> stream = StreamSupport .stream(content.getNode().getGraphFieldContainersIt(branch, type).spliterator(), false); return stream.map(item -> { return new NodeContent(content.getNode(), item, content.getLanguageFallback()); }).collect(Collectors.toList()); }
/** * Fetches nodes and applies filters * * @param env * the environment of the request * @return the filtered nodes */ protected DynamicStreamPageImpl<NodeContent> fetchFilteredNodes(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); NodeRoot nodeRoot = gc.getProject().getNodeRoot(); List<String> languageTags = getLanguageArgument(env); Stream<NodeContent> contents = nodeRoot.findAllStream(gc) // Now lets try to load the containers for those found nodes - apply the language fallback .map(node -> new NodeContent(node, node.findVersion(gc, languageTags), languageTags)) // Filter nodes without a container .filter(content -> content.getContainer() != null); return applyNodeFilter(env, contents); }
/** * Fetcher for the project base node. * * @param env * @return */ private NodeContent baseNodeFetcher(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Project project = env.getSource(); Node node = project.getBaseNode(); gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM); List<String> languageTags = getLanguageArgument(env); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); }
/** * Data fetcher for the root node of the current project. * * @param env * @return */ public Object rootNodeFetcher(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Project project = gc.getProject(); if (project != null) { Node node = project.getBaseNode(); gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM); List<String> languageTags = getLanguageArgument(env); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); } return null; }
return new NodeContent(node, itemContainer, languageTags); }); if (filterArgument != null) {
List<String> languageTags = getLanguageArgument(env); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); Node nodeOfContainer = container.getParentNode(); nodeOfContainer = gc.requiresPerm(nodeOfContainer, READ_PERM, READ_PUBLISHED_PERM); return new NodeContent(nodeOfContainer, container, Arrays.asList(container.getLanguageTag()));
/** * Fetcher for the parent node reference of a node. * * @param env * @return */ public Object parentNodeFetcher(DataFetchingEnvironment env) { NodeContent content = env.getSource(); if (content == null) { return null; } GraphQLContext gc = env.getContext(); String uuid = gc.getBranch().getUuid(); Node parentNode = content.getNode().getParentNode(uuid); // The project root node can have no parent. Lets check this and exit early. if (parentNode == null) { return null; } gc.requiresPerm(parentNode, READ_PERM, READ_PUBLISHED_PERM); List<String> languageTags = getLanguageArgument(env, content); return new NodeContent(parentNode, parentNode.findVersion(gc, languageTags), languageTags); }
elementList.add(new NodeContent(element, container, Arrays.asList(languageTag))); } else { totalCount--;
public Object nodeLanguageFetcher(DataFetchingEnvironment env) { NodeContent content = env.getSource(); if (content == null) { return null; } List<String> languageTags = getLanguageArgument(env); GraphQLContext gc = env.getContext(); Node node = content.getNode(); Branch branch = gc.getBranch(); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); // There might not be a container for the selected language (incl. fallback language) if (container == null) { return null; } // Check whether the user is allowed to read the published container boolean isPublished = container.isPublished(branch.getUuid()); if (isPublished) { gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM); } else { // Otherwise the container is a draft and we need to use the regular read permission gc.requiresPerm(node, READ_PERM); } return new NodeContent(node, container, languageTags); }
return new NodeContent(node, container, languageTags); }).collect(Collectors.toList()); return new WrappedPageImpl<NodeContent>(contents, nodes);
/** * Generate a new node field definition using the provided field schema. * * @param schema * @return */ public GraphQLFieldDefinition createNodeDef(FieldSchema schema) { return newFieldDefinition().name(schema.getName()).argument(createLanguageTagArg(false)).description(schema.getLabel()) .type(new GraphQLTypeReference(NODE_TYPE_NAME)).dataFetcher(env -> { GraphQLContext gc = env.getContext(); GraphFieldContainer source = env.getSource(); // TODO decide whether we want to reference the default content by default NodeGraphField nodeField = source.getNode(schema.getName()); if (nodeField != null) { Node node = nodeField.getNode(); if (node != null) { //Note that we would need to check for micronodes which are not language specific! List<String> languageTags = getLanguageArgument(env, source); // Check permissions for the linked node gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); } } return null; }).build(); }
.map(node -> { NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); });
return new NodeContent(null, container, Arrays.asList(container.getLanguageTag())); .map(item -> new NodeContent(item, item.findVersion(gc, languageTags), languageTags)) .filter(item -> item.getContainer() != null);