/** * Iterate the version chain from the back in order to find the given version. * * @param languageTag * @param branchUuid * @param version * @return Found version or null when no version could be found. */ default NodeGraphFieldContainer findVersion(String languageTag, String branchUuid, String version) { return findVersion(Arrays.asList(languageTag), branchUuid, version); }
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()); }
/** * Find a node field container that matches the nearest possible value for the language parameter. * * @param ac * @param languageTags * @return Next matching field container or null when no language matches */ default NodeGraphFieldContainer findVersion(InternalActionContext ac, List<String> languageTags) { return findVersion(languageTags, ac.getBranch().getUuid(), ac.getVersioningParameters().getVersion()); }
/** * 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; }
NodeGraphFieldContainer itemContainer = node.findVersion(gc, languageTags); return new NodeContent(node, itemContainer, languageTags); });
/** * 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); }
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); }
NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags);
NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); }).collect(Collectors.toList());
/** * 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(); }
).spliterator(), false) .map(node -> { NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); });
.map(item -> new NodeContent(item, item.findVersion(gc, languageTags), languageTags)) .filter(item -> item.getContainer() != null);