public Node getNode() { if (node == null && container != null) { node = container.getParentNode(); } return node; }
public String generateVersion(NodeGraphFieldContainer container, String branchUuid, ContainerType type) { Node node = container.getParentNode(); Project project = node.getProject(); StringBuilder builder = new StringBuilder(); builder.append(container.getElementVersion()); builder.append("|"); builder.append(branchUuid); builder.append("|"); builder.append(type.name()); builder.append("|"); builder.append(project.getUuid() + project.getName()); builder.append("|"); builder.append(node.getElementVersion()); return ETag.hash(builder.toString()); }
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; }
/** * Return the document id for the container. * * @return */ default String getDocumentId() { return composeDocumentId(getParentNode().getUuid(), getLanguageTag()); }
public static Node mockNode(Node parentNode, Project project, User user, String languageTag, Tag tagA, Tag tagB) { Node node = mock(Node.class); when(node.getParentNode(anyString())).thenReturn(parentNode); when(node.getProject()).thenReturn(project); TraversalResult<? extends Tag> tagResult = new TraversalResult<>(Arrays.asList(tagA, tagB)); Mockito.<TraversalResult<? extends Tag>>when(node.getTags(any(Branch.class))).thenReturn(tagResult); SchemaContainer schemaContainer = mockSchemaContainer("content", user); SchemaContainerVersion latestVersion = schemaContainer.getLatestVersion(); when(latestVersion.getUuid()).thenReturn(UUID_2); when(node.getSchemaContainer()).thenReturn(schemaContainer); when(node.getCreator()).thenReturn(user); when(node.getUuid()).thenReturn(NODE_DELOREAN_UUID); when(node.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal()); when(node.getRolesWithPerm(GraphPermission.READ_PUBLISHED_PERM)).thenReturn(createEmptyTraversal()); NodeGraphFieldContainer container = mockContainer(languageTag, user); when(container.getSchemaContainerVersion()).thenReturn(latestVersion); when(container.getParentNode()).thenReturn(node); when(container.getElementVersion()).thenReturn(UUID_5); when(node.getLatestDraftFieldContainer(languageTag)).thenReturn(container); when(node.getElementVersion()).thenReturn(UUID_4); Mockito.<Iterable<? extends NodeGraphFieldContainer>> when(node.getDraftGraphFieldContainers()).thenReturn(createEmptyTraversal()); return node; }
/** * Deletes the container for the index in which it should reside. * * @param container * @param branchUuid * @param type * @return */ private Completable deleteContainer(NodeGraphFieldContainer container, String branchUuid, ContainerType type) { String projectUuid = container.getParentNode().getProject().getUuid(); return searchProvider.deleteDocument(container.getIndexName(projectUuid, branchUuid, type), container.getDocumentId()); }
/** * Generate an elasticsearch document object from the given container and stores it in the search index. * * @param container * @param branchUuid * @param type * @return Single with the bulk entry */ public Single<IndexBulkEntry> storeContainerForBulk(NodeGraphFieldContainer container, String branchUuid, ContainerType type) { JsonObject doc = transformer.toDocument(container, branchUuid, type); String projectUuid = container.getParentNode().getProject().getUuid(); String indexName = NodeGraphFieldContainer.composeIndexName(projectUuid, branchUuid, container.getSchemaContainerVersion().getUuid(), type); if (log.isDebugEnabled()) { log.debug("Storing node {" + container.getParentNode().getUuid() + "} into index {" + indexName + "}"); } String languageTag = container.getLanguageTag(); String documentId = NodeGraphFieldContainer.composeDocumentId(container.getParentNode().getUuid(), languageTag); return Single.just(new IndexBulkEntry(indexName, documentId, doc, searchProvider.hasIngestPipelinePlugin())); }
/** * Generate an elasticsearch document object from the given container and stores it in the search index. * * @param container * @param branchUuid * @param type * @return Single with affected index name */ public Single<String> storeContainer(NodeGraphFieldContainer container, String branchUuid, ContainerType type) { JsonObject doc = transformer.toDocument(container, branchUuid, type); String projectUuid = container.getParentNode().getProject().getUuid(); String indexName = NodeGraphFieldContainer.composeIndexName(projectUuid, branchUuid, container.getSchemaContainerVersion().getUuid(), type); if (log.isDebugEnabled()) { log.debug("Storing node {" + container.getParentNode().getUuid() + "} into index {" + indexName + "}"); } String languageTag = container.getLanguageTag(); String documentId = NodeGraphFieldContainer.composeDocumentId(container.getParentNode().getUuid(), languageTag); return searchProvider.storeDocument(indexName, documentId, doc).andThen(Single.just(indexName)); }
public Observable<? extends BulkEntry> moveForBulk(MoveDocumentEntry entry) { MoveEntryContext context = entry.getContext(); ContainerType type = context.getContainerType(); String releaseUuid = context.getBranchUuid(); NodeGraphFieldContainer oldContainer = context.getOldContainer(); String oldProjectUuid = oldContainer.getParentNode().getProject().getUuid(); String oldIndexName = NodeGraphFieldContainer.composeIndexName(oldProjectUuid, releaseUuid, oldContainer.getSchemaContainerVersion().getUuid(), type); String oldLanguageTag = oldContainer.getLanguageTag(); String oldDocumentId = NodeGraphFieldContainer.composeDocumentId(oldContainer.getParentNode().getUuid(), oldLanguageTag); DeleteBulkEntry deleteEntry = new DeleteBulkEntry(oldIndexName, oldDocumentId); NodeGraphFieldContainer newContainer = context.getNewContainer(); String newProjectUuid = newContainer.getParentNode().getProject().getUuid(); String newIndexName = NodeGraphFieldContainer.composeIndexName(newProjectUuid, releaseUuid, newContainer.getSchemaContainerVersion().getUuid(), type); String newLanguageTag = newContainer.getLanguageTag(); String newDocumentId = NodeGraphFieldContainer.composeDocumentId(newContainer.getParentNode().getUuid(), newLanguageTag); JsonObject doc = transformer.toDocument(newContainer, releaseUuid, type); IndexBulkEntry addEntry = new IndexBulkEntry(newIndexName, newDocumentId, doc, searchProvider.hasIngestPipelinePlugin()); return Observable.fromArray(addEntry, deleteEntry); }
Node node = container.getParentNode(); JsonObject document = new JsonObject(); document.put("uuid", node.getUuid());
Node nodeOfContainer = container.getParentNode(); nodeOfContainer = gc.requiresPerm(nodeOfContainer, READ_PERM, READ_PUBLISHED_PERM); return new NodeContent(nodeOfContainer, container, Arrays.asList(container.getLanguageTag()));
String branchUuid = gc.getBranch().getUuid(); String languageTag = container.getLanguageTag(); return container.getParentNode().getPath(gc, branchUuid, containerType, languageTag); }));