public static SchemaContainer mockSchemaContainer(String name, User user) { SchemaContainer container = mock(SchemaContainer.class); when(container.getName()).thenReturn(name); when(container.getUuid()).thenReturn(SCHEMA_VEHICLE_UUID); SchemaContainerVersion latestVersion = mock(SchemaContainerVersion.class); when(latestVersion.getSchemaContainer()).thenReturn(container); when(latestVersion.getSchema()).thenReturn(mockContentSchema()); when(latestVersion.getName()).thenReturn(name); when(container.getLatestVersion()).thenReturn(latestVersion); when(container.getCreator()).thenReturn(user); when(container.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD); when(container.getEditor()).thenReturn(user); when(container.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW); when(container.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal()); return container; }
/** * 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()); }
public SchemaCreateRequestAssert matches(SchemaContainerVersion version) { assertNotNull(version); assertNotNull(actual); SchemaCreateRequest storedSchema = JsonUtil.readValue(version.getJson(), SchemaCreateRequest.class); matches(storedSchema); SchemaContainer container = version.getSchemaContainer(); matches(container); return this; }
/** * Transform the given schema and add it to the source map. * * @param document * @param schemaContainerVersion */ private void addSchema(JsonObject document, SchemaContainerVersion schemaContainerVersion) { String name = schemaContainerVersion.getName(); String uuid = schemaContainerVersion.getSchemaContainer().getUuid(); Map<String, String> schemaFields = new HashMap<>(); schemaFields.put(NAME_KEY, name); schemaFields.put(UUID_KEY, uuid); schemaFields.put(VERSION_KEY, schemaContainerVersion.getVersion()); document.put("schema", schemaFields); }
/** * 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; }
/** * 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); }
@Override public JsonObject toDocument(SchemaContainer container) { JsonObject document = new JsonObject(); document.put(NAME_KEY, container.getName()); document.put(DESCRIPTION_KEY, container.getLatestVersion().getSchema().getDescription()); addBasicReferences(document, container); addPermissionInfo(document, container); document.put(VERSION_KEY, generateVersion(container)); return document; }
public SchemaResponseAssert matches(SchemaContainerVersion version) { assertNotNull(version); assertNotNull(actual); Schema storedSchema = version.getSchema(); matches(storedSchema); SchemaContainer container = version.getSchemaContainer(); matches(container); return this; }
protected MeshVertex handleBranchSchema(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Branch branch = env.getSource(); Stream<? extends SchemaContainerVersion> schemas = StreamSupport.stream(branch.findActiveSchemaVersions().spliterator(), false); // We need to handle permissions dedicately since we check the schema container perm and not the schema container version perm. return handleUuidNameArgsNoPerm(env, uuid -> schemas.filter(schema -> { SchemaContainer container = schema.getSchemaContainer(); return container.getUuid().equals(uuid) && gc.getUser().hasPermission(container, READ_PERM); }).findFirst().get(), name -> schemas.filter(schema -> schema.getName().equals(name) && gc.getUser().hasPermission(schema .getSchemaContainer(), READ_PERM)).findFirst().get()); }
protected Page<SchemaContainerVersion> handleBranchSchemas(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Branch branch = env.getSource(); Stream<? extends SchemaContainerVersion> schemas = StreamSupport.stream(branch.findActiveSchemaVersions().spliterator(), false).filter( schema -> gc.getUser().hasPermission(schema.getSchemaContainer(), READ_PERM)); return new DynamicStreamPageImpl<>(schemas, getPagingInfo(env)); }
public GraphQLUnionType getSchemaFieldsType(GraphQLContext context) { Map<String, GraphQLObjectType> types = generateSchemaFieldType(context); GraphQLObjectType[] typeArray = types.values().toArray(new GraphQLObjectType[types.values().size()]); GraphQLUnionType fieldType = newUnionType().name(NODE_FIELDS_TYPE_NAME).possibleTypes(typeArray).description("Fields of the node.") .typeResolver(env -> { Object object = env.getObject(); if (object instanceof NodeGraphFieldContainer) { NodeGraphFieldContainer fieldContainer = (NodeGraphFieldContainer) object; String schemaName = fieldContainer.getSchemaContainerVersion().getName(); GraphQLObjectType foundType = types.get(schemaName); if (foundType == null) { throw new GraphQLException("The type for the schema with name {" + schemaName + "} could not be found. Maybe the schema is not linked to the project."); } return foundType; } return null; }).build(); return fieldType; }
private SchemaModel getLatestVersion(SchemaContainer schema) { return JsonUtil.readValue(schema.getLatestVersion().getJson(), SchemaModelImpl.class); } }
public String generateVersion(SchemaContainer container) { StringBuilder builder = new StringBuilder(); builder.append(container.getElementVersion()); builder.append("|"); builder.append(container.getLatestVersion().getElementVersion()); // No need to add users since the creator/editor edge affects the schema version return ETag.hash(builder.toString()); }
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; }
private FilterField<NodeContent, ?> createFieldFilter(SchemaContainer schema) { return new MappedFilter<>(schema.getName(), "Filters by fields of the " + schema.getName() + " schema", FieldFilter.filter(context, schema.getLatestVersion().getSchema()), NodeContent::getContainer); } }
element = ((NodeContent) source).getNode(); } else if (source instanceof SchemaContainerVersion) { element = ((SchemaContainerVersion) source).getSchemaContainer(); } else { element = env.getSource(); vertex = ((NodeContent) source).getNode(); } else if (source instanceof SchemaContainerVersion) { vertex = ((SchemaContainerVersion) source).getSchemaContainer(); } else { vertex = env.getSource(); vertex = ((NodeContent) source).getNode(); } else if (source instanceof SchemaContainerVersion) { vertex = ((SchemaContainerVersion) source).getSchemaContainer(); } else { vertex = env.getSource(); Object source = env.getSource(); if (source instanceof SchemaContainerVersion) { source = ((SchemaContainerVersion) source).getSchemaContainer(); Object source = env.getSource(); if (source instanceof SchemaContainerVersion) { source = ((SchemaContainerVersion) source).getSchemaContainer();
private SchemaModel loadModelWithFallback(DataFetchingEnvironment env) { Object source = env.getSource(); if (source instanceof SchemaContainer) { SchemaContainer schema = env.getSource(); SchemaModel model = JsonUtil.readValue(schema.getLatestVersion().getJson(), SchemaModelImpl.class); return model; } if (source instanceof SchemaContainerVersion) { SchemaContainerVersion schema = env.getSource(); SchemaModel model = JsonUtil.readValue(schema.getJson(), SchemaModelImpl.class); return model; } log.error("Invalid type {" + source + "}."); return null; } }
.getUuid(), DRAFT); String publishIndexName = NodeGraphFieldContainer.composeIndexName(project.getUuid(), branch.getUuid(), containerVersion .getUuid(), PUBLISHED); if (log.isDebugEnabled()) { log.debug("Adding index to map of known indices {" + draftIndexName + "}"); SchemaModel schema = containerVersion.getSchema(); JsonObject mapping = getMappingProvider().getMapping(schema, branch); JsonObject settings = schema.getElasticsearch();
@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()); }
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);