/** * 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); }
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; }
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()); }
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; }