Package com.linkedin.data.schema

Examples of com.linkedin.data.schema.NamedDataSchema


    for (Object[] row : inputs)
    {
      String schemaText = (String) row[0];
      Predicate predicate = (Predicate) row[1];
      String expected = (String) row[2];
      NamedDataSchema schema = dataSchemaFromString(schemaText, isAvroUnionMode);

      DataSchema filteredSchema = null;
      SchemaParser parser = new SchemaParser();
      parser.getValidationOptions().setAvroUnionMode(isAvroUnionMode);
      filteredSchema = Filters.removeByPredicate(schema, predicate, parser);
View Full Code Here


  @Test
  public void testConvertDataSchemaToDataMap() throws IOException
  {
    for (String good : goodInputs)
    {
      NamedDataSchema dataSchema = (NamedDataSchema) TestUtil.dataSchemaFromString(good);

      DataMap mapFromSchema = Conversions.dataSchemaToDataMap(dataSchema);
      DataMap mapFromString = TestUtil.dataMapFromString(good);

      assertEquals(mapFromSchema, mapFromString);
View Full Code Here

  @Test
  public void testConvertDataMapToDataSchema() throws IOException
  {
    for (String good : goodInputs)
    {
      NamedDataSchema dataSchema = (NamedDataSchema) TestUtil.dataSchemaFromString(good);

      DataMap mapFromString = TestUtil.dataMapFromString(good);
      SchemaParser parser = new SchemaParser();
      DataSchema schemaFromMap = Conversions.dataMapToDataSchema(mapFromString, parser);
View Full Code Here

        }

      case FIXED:
      case RECORD:
      case ENUM:
        NamedDataSchema namedSchema = (NamedDataSchema) dereferencedDataSchema;
        return new ClassInfo(namedSchema.getNamespace(), capitalize(namedSchema.getName()));

      case BOOLEAN:
        return new ClassInfo(_templatePackageName, "Boolean");

      case INT:
View Full Code Here

  {
    final Map<String, NamedDataSchema> parsedModels = new HashMap<String, NamedDataSchema>();

    for (Object modelObj : models)
    {
      NamedDataSchema dataSchema;
      if (modelObj instanceof DataMap)
      {
        DataMap model = (DataMap)modelObj;
        dataSchema = (NamedDataSchema) RestSpecCodec.textToSchema(_dataCodec.mapToString(model), _dataSchemaResolver);
      }
      else if (modelObj instanceof String)
      {
        String str = (String)modelObj;
        dataSchema = (NamedDataSchema) RestSpecCodec.textToSchema(str, _dataSchemaResolver);
      }
      else
      {
        throw new IOException("Found " + modelObj.getClass() + " in models list; Models must be strings or DataMaps.");
      }
      parsedModels.put(dataSchema.getFullName(), dataSchema);
    }

    return parsedModels;
  }
View Full Code Here

  private void recordType(DataSchema schema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder)
  {
    if (schema instanceof NamedDataSchema)
    {
      NamedDataSchema namedDataSchema = (NamedDataSchema) schema;

      if (!foundTypes.containsKey(namedDataSchema.getFullName()))
      {
        foundTypes.put(namedDataSchema.getFullName(), namedDataSchema);

        if (schema instanceof RecordDataSchema) // recurse into record, record any contained types.
        {
          RecordDataSchema recordDataSchema = (RecordDataSchema)schema;
          for (NamedDataSchema includedSchema : recordDataSchema.getInclude())
View Full Code Here

  {
    if (_schemaParser == null)
    {
      // 'online mode': resolve data schema from RecordTemplate Class SCHEMA field
      final StringBuilder errorMessage = new StringBuilder();
      final NamedDataSchema schema = _schemaResolver.findDataSchema(className, errorMessage);
      if (errorMessage.length() > 0)
      {
        return null;
      }
View Full Code Here

      {
        final String schema = resourceSchema.getSchema();
        // ActionSet resources do not have a schema
        if (schema != null)
        {
          final NamedDataSchema schemaSchema = extractSchema(schema);
          if (schemaSchema != null)
          {
            connectSchemaToResource(visitContext, schemaSchema);
          }
        }
      }

      @Override
      public void visitCollectionResource(VisitContext visitContext,
                                          CollectionSchema collectionSchema)
      {
        final IdentifierSchema id = collectionSchema.getIdentifier();

        final NamedDataSchema typeSchema = extractSchema(id.getType());
        if (typeSchema != null)
        {
          connectSchemaToResource(visitContext, typeSchema);
        }

        final String params = id.getParams();
        if (params != null)
        {
          final NamedDataSchema paramsSchema = extractSchema(params);
          if (paramsSchema != null)
          {
            connectSchemaToResource(visitContext, paramsSchema);
          }
        }
      }

      @Override
      public void visitParameter(VisitContext visitContext,
                                 RecordTemplate parentResource,
                                 Object parentMethodSchema,
                                 ParameterSchema parameterSchema)
      {
        String parameterTypeString = parameterSchema.getType();
        if (isInlineSchema(parameterTypeString)) // the parameter type field contains a inline schema, so we traverse into it
        {
          visitInlineSchema(visitContext, parameterTypeString);
        }
        else
        {
          final NamedDataSchema schema;

          // else if the parameter is using the legacy format or representing maps and lists with a separate "items" field,
          // grab the schema name from it
          if (parameterSchema.hasItems())
          {
            schema = extractSchema(parameterSchema.getItems());
          }
          else // the only remaining possibility is that the type field contains the name of a data schema
          {
            schema = extractSchema(parameterTypeString);
          }

          if (schema != null)
          {
            connectSchemaToResource(visitContext, schema);
          }
        }
      }

      @Override
      public void visitFinder(VisitContext visitContext,
                              RecordTemplate parentResource,
                              FinderSchema finderSchema)
      {
        final MetadataSchema metadata = finderSchema.getMetadata();
        if (metadata != null)
        {
          final NamedDataSchema metadataTypeSchema = extractSchema(metadata.getType());
          if (metadataTypeSchema != null)
          {
            connectSchemaToResource(visitContext, metadataTypeSchema);
          }
        }
      }

      @Override
      public void visitAction(VisitContext visitContext,
                              RecordTemplate parentResource,
                              ResourceLevel resourceLevel,
                              ActionSchema actionSchema)
      {
        final String returns = actionSchema.getReturns();
        if (returns != null)
        {
          if (isInlineSchema(returns)) // the parameter type field contains a inline schema, so we traverse into it
          {
            visitInlineSchema(visitContext, returns);
          }
          else // otherwise the type field contains the name of a data schema
          {
            final NamedDataSchema returnsSchema = extractSchema(returns);
            if (returnsSchema != null)
            {
              connectSchemaToResource(visitContext, returnsSchema);
            }
          }
        }

        final StringArray throwsArray = actionSchema.getThrows();
        if (throwsArray != null)
        {
          for (String errorName: throwsArray)
          {
            final NamedDataSchema errorSchema = extractSchema(errorName);
            if (errorSchema != null)
            {
              connectSchemaToResource(visitContext, errorSchema);
            }
          }
View Full Code Here

  }

  @Override
  public void renderDataModel(String dataModelName, OutputStream out)
  {
    final NamedDataSchema schema = _relationships.getDataModels().get(dataModelName);
    if (schema == null)
    {
      throw new RoutingException(String.format("Data model named '%s' does not exist", dataModelName), 404) ;
    }
View Full Code Here

        relatedSchemas = new HashMap<String, DataMap>();
        final Node<?> node = _relationships.getRelationships(resourceSchema);
        final Iterator<Node<NamedDataSchema>> schemaItr = node.getAdjacency(NamedDataSchema.class).iterator();
        while (schemaItr.hasNext())
        {
          final NamedDataSchema currResource = (NamedDataSchema) schemaItr.next().getObject();
          relatedSchemas.put(currResource.getFullName(), _codec.stringToMap(currResource.toString()));
        }
        _relatedSchemaCache.put(resourceSchema, relatedSchemas);
      }
    }
View Full Code Here

TOP

Related Classes of com.linkedin.data.schema.NamedDataSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.