/** * 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); }
/** * Tests if the node has at least one content that is published. * @param branchUuid */ default boolean hasPublishedContent(String branchUuid) { return getGraphFieldContainersIt(branchUuid, ContainerType.PUBLISHED).iterator().hasNext(); }
/** * Return the draft field containers of the node in the latest branch. * * @return */ default TraversalResult<? extends NodeGraphFieldContainer> getDraftGraphFieldContainers() { // FIX ME: We should not rely on specific branches. return getGraphFieldContainersIt(getProject().getLatestBranch(), DRAFT); }
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()); }
/** * Step 3 - Check whether we need to handle all languages. * * Invoke store for the possible set of containers. Utilise the given context settings as much as possible. * * @param obs * @param node * @param branchUuid * @param type * @param context */ private void store(Set<Single<String>> obs, Node node, String branchUuid, ContainerType type, GenericEntryContext context) { if (context.getLanguageTag() != null) { NodeGraphFieldContainer container = node.getGraphFieldContainer(context.getLanguageTag(), branchUuid, type); if (container == null) { log.warn("Node {" + node.getUuid() + "} has no language container for languageTag {" + context.getLanguageTag() + "}. I can't store the search index document. This may be normal in cases if mesh is handling an outdated search queue batch entry."); } else { obs.add(storeContainer(container, branchUuid, type)); } } else { for (NodeGraphFieldContainer container : node.getGraphFieldContainersIt(branchUuid, type)) { obs.add(storeContainer(container, branchUuid, type)); } } }
/** * 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); } }
/** * Step 3 - Check whether we need to handle all languages. * * Invoke store for the possible set of containers. Utilise the given context settings as much as possible. * * @param node * @param branchUuid * @param type * @param context * @return */ private Observable<IndexBulkEntry> storeForBulk(Node node, String branchUuid, ContainerType type, GenericEntryContext context) { if (context.getLanguageTag() != null) { NodeGraphFieldContainer container = node.getGraphFieldContainer(context.getLanguageTag(), branchUuid, type); if (container == null) { log.warn("Node {" + node.getUuid() + "} has no language container for languageTag {" + context.getLanguageTag() + "}. I can't store the search index document. This may be normal in cases if mesh is handling an outdated search queue batch entry."); } else { return storeContainerForBulk(container, branchUuid, type).toObservable(); } } else { Set<Observable<IndexBulkEntry>> obs = new HashSet<>(); for (NodeGraphFieldContainer container : node.getGraphFieldContainersIt(branchUuid, type)) { obs.add(storeContainerForBulk(container, branchUuid, type).toObservable()); } return Observable.merge(obs); } return Observable.empty(); }