/** * 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 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()); }
/** * Return the document id for the container. * * @return */ default String getDocumentId() { return composeDocumentId(getParentNode().getUuid(), getLanguageTag()); }
/** * Return the index name for the given parameters. * * @param projectUuid * @param branchUuid * @param type * @return */ default String getIndexName(String projectUuid, String branchUuid, ContainerType type) { return composeIndexName(projectUuid, branchUuid, getSchemaContainerVersion().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; }
public static NodeGraphFieldContainer mockContainer(String languageTag, User user) { NodeGraphFieldContainer container = mock(NodeGraphFieldContainer.class); when(container.getLanguageTag()).thenReturn(languageTag); when(container.getEditor()).thenReturn(user); when(container.getString("string")).thenReturn(stringField); when(container.getNumber("number")).thenReturn(numberField); when(container.getDate("date")).thenReturn(dateField); when(container.getBoolean("boolean")).thenReturn(booleanField); Node nodeRef = mockNodeBasic("folder", user); when(nodeField.getNode()).thenReturn(nodeRef); when(container.getNode("node")).thenReturn(nodeField); when(container.getHtml("html")).thenReturn(htmlField); Micronode micronode = mockMicronode("geolocation", user); when(micronodeField.getMicronode()).thenReturn(micronode); when(container.getMicronode("micronode")).thenReturn(micronodeField); when(container.getNodeList("nodeList")).thenReturn(nodeListField); when(container.getStringList("stringList")).thenReturn(stringListField); Mockito.<List<? extends BooleanGraphField>> when(booleanListField.getList()) .thenReturn(Arrays.asList(booleanField, booleanField, booleanField));
Node node = container.getParentNode(); JsonObject document = new JsonObject(); document.put("uuid", node.getUuid()); addUser(document, "editor", container.getEditor()); document.put("edited", toISO8601(container.getLastEditedTimestamp())); addUser(document, "creator", node.getCreator()); document.put("created", toISO8601(node.getCreationTimestamp())); String language = container.getLanguageTag(); document.put("language", language); addSchema(document, container.getSchemaContainerVersion()); addFields(document, "fields", container, container.getSchemaContainerVersion().getSchema().getFields()); if (log.isTraceEnabled()) { String json = document.toString(); displayField.put("key", container.getSchemaContainerVersion().getSchema().getDisplayField()); displayField.put("value", container.getDisplayFieldValue()); document.put("displayField", displayField); document.put(VERSION_KEY, generateVersion(container, branchUuid, type));
return new NodeContent(null, container, Arrays.asList(container.getLanguageTag())); String languageTag = container.getLanguageTag(); return container.getParentNode().getPath(gc, branchUuid, containerType, languageTag); })); return null; return container.getLastEditedDate(); })); return container.getSchemaContainerVersion(); })); return container.isPublished(gc.getBranch().getUuid()); })); return container.isDraft(gc.getBranch().getUuid()); })); return container.getVersion().getFullVersion(); })); return container.getLanguageTag(); })); return container.getDisplayFieldValue(); }));
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; }
Node nodeOfContainer = container.getParentNode(); nodeOfContainer = gc.requiresPerm(nodeOfContainer, READ_PERM, READ_PUBLISHED_PERM); return new NodeContent(nodeOfContainer, container, Arrays.asList(container.getLanguageTag()));
/** * 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()); }
@Override public Set<String> filterUnknownIndices(Set<String> indices) { Set<String> activeIndices = new HashSet<>(); db.tx(() -> { for (Project currentProject : boot.meshRoot().getProjectRoot().findAll()) { for (Branch branch : currentProject.getBranchRoot().findAll()) { for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { Arrays.asList(ContainerType.DRAFT, ContainerType.PUBLISHED).forEach(type -> { activeIndices .add(NodeGraphFieldContainer.composeIndexName(currentProject.getUuid(), branch.getUuid(), version.getUuid(), type)); }); } } } }); if (log.isDebugEnabled()) { for (String name : activeIndices) { log.debug("Active index: {" + name + "}"); } } return indices.stream() // Only handle indices of the handler's type .filter(i -> i.startsWith(getType())) // Filter out indices which are active .filter(i -> !activeIndices.contains(i)) .collect(Collectors.toSet()); }
/** * 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; }
/** * Assert that the field uses the given schema. * * @param schemaVersion * schema container * @return fluent API */ public NodeGraphFieldContainerAssert isOf(SchemaContainerVersion schemaVersion) { assertThat(actual.getSchemaContainerVersion().getVersion()).as("Schema version").isEqualTo(schemaVersion.getVersion()); assertThat(actual.getSchemaContainerVersion().getUuid()).as("Schema version Uuid").isEqualTo(schemaVersion.getUuid()); return this; }
public Node getNode() { if (node == null && container != null) { node = container.getParentNode(); } return node; }
@Override protected List<FilterField<NodeContent, ?>> getFilters() { List<FilterField<NodeContent, ?>> filters = new ArrayList<>(); filters.add(new MappedFilter<>("uuid", "Filters by uuid", StringFilter.filter(), content -> content.getNode().getUuid())); filters .add(new MappedFilter<>("schema", "Filters by schema", SchemaFilter.filter(context), content -> content.getNode().getSchemaContainer())); filters.add(new MappedFilter<>("created", "Filters by node creation timestamp", DateFilter.filter(), content -> content.getNode().getCreationTimestamp())); filters.add(new MappedFilter<>("creator", "Filters by creator", UserFilter.filter(), content -> content.getNode().getCreator())); filters.add(new MappedFilter<>("edited", "Filters by node update timestamp", DateFilter.filter(), content -> content.getContainer().getLastEditedTimestamp())); filters.add(new MappedFilter<>("editor", "Filters by editor", UserFilter.filter(), content -> content.getContainer().getEditor())); filters.add(new MappedFilter<>("fields", "Filters by fields", createAllFieldFilters(), Function.identity())); return filters; }
@Override protected String composeDocumentIdFromEntry(UpdateDocumentEntry entry) { return NodeGraphFieldContainer.composeDocumentId(entry.getElementUuid(), entry.getContext().getLanguageTag()); }
public Object editorFetcher(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); NodeContent content = env.getSource(); if (content == null) { return null; } User user = content.getContainer().getEditor(); return gc.requiresPerm(user, READ_PERM); }
/** * Assert that the field container is of the version * * @param version * @return */ public NodeGraphFieldContainerAssert hasVersion(String version) { assertThat(actual.getVersion()).as(descriptionText() + " version").isNotNull().hasToString(version); return this; }
@Override protected String composeIndexNameFromEntry(UpdateDocumentEntry entry) { GenericEntryContext context = entry.getContext(); String projectUuid = context.getProjectUuid(); String branchUuid = context.getBranchUuid(); String schemaContainerVersionUuid = context.getSchemaContainerVersionUuid(); ContainerType type = context.getContainerType(); return NodeGraphFieldContainer.composeIndexName(projectUuid, branchUuid, schemaContainerVersionUuid, type); }