/** * Return containers of the given type and branch. * * @param branch * @param type * @return */ default TraversalResult<? extends NodeGraphFieldContainer> getGraphFieldContainersIt(Branch branch, ContainerType type) { return getGraphFieldContainersIt(branch.getUuid(), type); }
/** * Return a traversal of graph field containers of given type for the node in the given branch. * * @param branch * @param type * @return */ default TraversalResult<? extends NodeGraphFieldContainer> getGraphFieldContainers(Branch branch, ContainerType type) { return getGraphFieldContainers(branch.getUuid(), type); }
private Map<String, String> loadVersionsFromGraph(Branch branch, SchemaContainerVersion version, ContainerType type) { Map<String, String> versions = new HashMap<>(); String branchUuid = branch.getUuid(); version.getFieldContainers(branchUuid) .filter(c -> c.getSchemaContainerVersion().equals(version)) .filter(c -> c.isType(type, branchUuid)) .forEach(c -> { String v = generateVersion(c, branchUuid, type); versions.put(c.getParentNode().getUuid() + "-" + c.getLanguageTag(), v); }); return versions; }
/** * Assert that the node has no children in the branch. * * @param branch * branch * @return fluent API */ public NodeAssert hasNoChildren(Branch branch) { Stream<Node> stream = StreamSupport.stream(actual.getChildren(branch.getUuid()).spliterator(), false); List<Node> list = stream.collect(Collectors.toList()); assertThat(list).as(descriptionText() + " children").hasSize(0); return this; }
/** * Assert that the node has only the given nodes as children in the branch. * * @param branch * branch * @param nodes * list of nodes * @return fluent API */ public NodeAssert hasOnlyChildren(Branch branch, Node... nodes) { Stream<Node> stream = StreamSupport.stream(actual.getChildren(branch.getUuid()).spliterator(), false); List<Node> list = stream.collect(Collectors.toList()); assertThat(list).as(descriptionText() + " children").usingElementComparatorOnFields("uuid").containsOnly(nodes); return this; }
/** * Assert that the node has the given nodes as children in the branch. * * @param branch * branch * @param nodes * list of nodes * @return fluent API */ public NodeAssert hasChildren(Branch branch, Node... nodes) { Stream<Node> stream = StreamSupport.stream(actual.getChildren(branch.getUuid()).spliterator(), false); List<Node> list = stream.collect(Collectors.toList()); assertThat(list).as(descriptionText() + " children").usingElementComparatorOnFields("uuid").contains(nodes); return this; }
/** * Assert that the branch has a not empty uuid. * * @return fluent API */ public BranchAssert hasUuid() { assertThat(actual.getUuid()).as(descriptionText() + " uuid").isNotEmpty(); return this; }
/** * 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()); }
/** * Add a new node index to the search database and construct the index name using the provided values. See * {@link NodeContainerEntry#composeIndexName(String, String, String, ContainerType)} for details. * * @param project * @param branch * @param version * @param type * @return Fluent API */ default SearchQueueBatch addNodeIndex(Project project, Branch branch, SchemaContainerVersion version, ContainerType type) { return createNodeIndex(project.getUuid(), branch.getUuid(), version.getUuid(), type, version.getSchema()); }
/** * Step 1 - Check whether we need to handle all branches. * * @param node * @param context * @return */ private Observable<IndexBulkEntry> storeForBulk(Node node, GenericEntryContext context) { if (context.getBranchUuid() == null) { Set<Observable<IndexBulkEntry>> obs = new HashSet<>(); for (Branch branch : node.getProject().getBranchRoot().findAll()) { obs.add(storeForBulk(node, branch.getUuid(), context)); } return Observable.merge(obs); } else { return storeForBulk(node, context.getBranchUuid(), context); } }
/** * Assert that the node has none of the given nodes as children in the branch. * * @param branch * branch * @param nodes * list of nodes * @return fluent API */ public NodeAssert hasNotChildren(Branch branch, Node... nodes) { assertThat(actual.getChildren(branch.getUuid())).as(descriptionText() + " children").usingElementComparatorOnFields("uuid").doesNotContain( nodes); return this; }
/** * Assert that the branch matches the given one * * @param branch * branch to match * @return fluent API */ public BranchAssert matches(Branch branch) { if (branch == null) { assertThat(actual).as(descriptionText()).isNull(); } else { assertThat(actual).as(descriptionText()).isNotNull(); assertThat(actual.getUuid()).as(descriptionText() + " uuid").isEqualTo(branch.getUuid()); assertThat(actual.getName()).as(descriptionText() + " name").isEqualTo(branch.getName()); } return this; }
/** * Step 1 - Check whether we need to handle all branches. * * @param obs * @param node * @param context */ private void store(Set<Single<String>> obs, Node node, GenericEntryContext context) { if (context.getBranchUuid() == null) { for (Branch branch : node.getProject().getBranchRoot().findAll()) { store(obs, node, branch.getUuid(), context); } } else { store(obs, node, context.getBranchUuid(), context); } }
/** * Assert that the node was stored in the index for given languages and DRAFT and PUBLISHED versions * * @param node * @param project * @param branch * @param languages * @return Fluent API */ public DummySearchProviderAssert storedAllContainers(Node node, Project project, Branch branch, String... languages) { for (ContainerType type : Arrays.asList(DRAFT, PUBLISHED)) { for (String lang : languages) { String projectUuid = project.getUuid(); String branchUuid = branch.getUuid(); String schemaVersionUuid = node.getSchemaContainer().getLatestVersion().getUuid(); assertThat(actual).hasStore(NodeGraphFieldContainer.composeIndexName(projectUuid, branchUuid, schemaVersionUuid, type), NodeGraphFieldContainer.composeDocumentId(node.getUuid(), lang)); } } return this; }
/** * We need to handle permission update requests for nodes here since the action must affect multiple documents in multiple indices . */ @Override public Observable<UpdateBulkEntry> updatePermissionForBulk(UpdateDocumentEntry entry) { String uuid = entry.getElementUuid(); Node node = getRootVertex().findByUuid(uuid); if (node == null) { throw error(INTERNAL_SERVER_ERROR, "error_element_for_document_type_not_found", uuid, DEFAULT_TYPE); } else { Project project = node.getProject(); List<UpdateBulkEntry> entries = new ArrayList<>(); // Determine which documents need to be updated. The node could have multiple documents in various indices. for (Branch branch : project.getBranchRoot().findAll()) { for (ContainerType type : Arrays.asList(DRAFT, PUBLISHED)) { JsonObject json = getTransformer().toPermissionPartial(node, type); for (NodeGraphFieldContainer container : node.getGraphFieldContainersIt(branch, type)) { String indexName = container.getIndexName(project.getUuid(), branch.getUuid(), type); String documentId = container.getDocumentId(); entries.add(new UpdateBulkEntry(indexName, documentId, json, true)); } } } return Observable.fromIterable(entries); } }
@Override public Set<String> getSelectedIndices(InternalActionContext ac) { return db.tx(() -> { Set<String> indices = new HashSet<>(); Project project = ac.getProject(); if (project != null) { Branch branch = ac.getBranch(); // Locate all schema versions which need to be taken into consideration when choosing the indices for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { indices.add(NodeGraphFieldContainer.composeIndexName(project.getUuid(), branch.getUuid(), version.getUuid(), ContainerType .forVersion(ac.getVersioningParameters().getVersion()))); } } else { // The project was not specified. Maybe a global search wants to know which indices must be searched. // In that case we just iterate over all projects and collect index names per branch. for (Project currentProject : boot.meshRoot().getProjectRoot().findAll()) { for (Branch branch : currentProject.getBranchRoot().findAll()) { for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { indices.add(NodeGraphFieldContainer.composeIndexName(currentProject.getUuid(), branch.getUuid(), version.getUuid(), ContainerType.forVersion(ac.getVersioningParameters().getVersion()))); } } } } return indices; }); }
/** * 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); }
public GraphQLFieldDefinition createHtmlDef(FieldSchema schema) { return newFieldDefinition().name(schema.getName()).description(schema.getLabel()).type(GraphQLString).argument(createLinkTypeArg()) .dataFetcher(env -> { GraphFieldContainer container = env.getSource(); HtmlGraphField htmlField = container.getHtml(schema.getName()); if (htmlField != null) { GraphQLContext gc = env.getContext(); LinkType type = getLinkType(env); String content = htmlField.getHTML(); return linkReplacer.replace(gc, gc.getBranch() .getUuid(), null, content, type, gc.getProject().getName(), Arrays.asList(container.getLanguageTag())); } return null; }).build(); }
public GraphQLFieldDefinition createStringDef(FieldSchema schema) { return newFieldDefinition().name(schema.getName()).description(schema.getLabel()).type(GraphQLString).argument(createLinkTypeArg()) .dataFetcher(env -> { GraphFieldContainer container = env.getSource(); StringGraphField field = container.getString(schema.getName()); if (field != null) { GraphQLContext gc = env.getContext(); LinkType type = getLinkType(env); String content = field.getString(); return linkReplacer.replace(gc, gc.getBranch() .getUuid(), null, content, type, gc.getProject().getName(), Arrays.asList(container.getLanguageTag())); } return null; }).build(); }