Package com.linkedin.data.schema

Examples of com.linkedin.data.schema.ArrayDataSchema


  {
    DataSchema dereferencedDataSchema = schema.getDereferencedDataSchema();
    switch (dereferencedDataSchema.getType())
    {
      case ARRAY:
        ArrayDataSchema arraySchema = (ArrayDataSchema) dereferencedDataSchema;
        CustomInfo customInfo = firstCustomInfo(arraySchema.getItems());
        if (customInfo != null)
        {
          return new ClassInfo(customInfo.customSchema.getNamespace(), customInfo.customSchema.getName() + ARRAY_SUFFIX);
        }
        else
        {
          ClassInfo classInfo = classNameForUnnamedTraverse(parentClass, memberName, arraySchema.getItems());
          classInfo.name += ARRAY_SUFFIX;
          return classInfo;
        }
      case MAP:
        MapDataSchema mapSchema = (MapDataSchema) dereferencedDataSchema;
View Full Code Here


        typeOrder.add(namedDataSchema);
      }
    }
    else if (schema instanceof ArrayDataSchema)
    {
      ArrayDataSchema arraySchema = (ArrayDataSchema)schema;
      recordType(arraySchema.getItems(), foundTypes, typeOrder);
    }
    else if (schema instanceof MapDataSchema)
    {
      MapDataSchema mapSchema = (MapDataSchema)schema;
      recordType(mapSchema.getValues(), foundTypes, typeOrder);
View Full Code Here

  public void testArraySchema()
  {
    for (Map.Entry<DataSchema.Type, Class<? extends DirectArrayTemplate<?>>> entry: _dataSchemaTypeToprimitiveArrayMap.entrySet())
    {
      final PrimitiveDataSchema itemsSchema = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchema(entry.getKey());
      final ArrayDataSchema arraySchema = new ArrayDataSchema(itemsSchema);
      final DataList value = (DataList) SchemaSampleDataGenerator.buildData(arraySchema, _spec);
      final ParameterizedType arrayType = (ParameterizedType) entry.getValue().getGenericSuperclass();
      assert(arrayType.getRawType() == DirectArrayTemplate.class);
      Assert.assertSame(value.get(0).getClass(), arrayType.getActualTypeArguments()[0]);
    }
View Full Code Here

      }
    }
    else
    {
      final List<String> itemStringValues = context.getParameterValues(param.getName());
      ArrayDataSchema parameterSchema = null;
      if (param.getDataSchema() instanceof ArrayDataSchema)
      {
        parameterSchema = (ArrayDataSchema)param.getDataSchema();
      }
      else
      {
        throw new RoutingException("An array schema is expected.",
                                   HttpStatus.S_400_BAD_REQUEST.getCode());
      }

      convertedValue = Array.newInstance(param.getItemType(), itemStringValues.size());
      int j = 0;
      for (String itemStringValue : itemStringValues)
      {
        if (itemStringValue == null)
        {
          throw new RoutingException("Parameter '" + param.getName()
                                         + "' cannot contain null values", HttpStatus.S_400_BAD_REQUEST.getCode());
        }
        try
        {
          Array.set(convertedValue,
                    j++,
                    ArgumentUtils.convertSimpleValue(itemStringValue, parameterSchema.getItems(), param.getItemType()));
        }
        catch (NumberFormatException e)
        {
          Class<?> targetClass = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass(parameterSchema.getItems().getDereferencedType());
          // thrown from Integer.valueOf or Long.valueOf
          throw new RoutingException(String.format("Array parameter '%s' value '%s' must be of type '%s'",
                                                   param.getName(),
                                                   itemStringValue,
                                                   targetClass.getName()),
View Full Code Here

  @Test(dataProvider="dataElementFactories")
  public void testDataElement(DataElementFactory factory) throws IOException
  {
    RecordDataSchema fooSchema = (RecordDataSchema) TestUtil.dataSchemaFromString(fooSchemaText);
    ArrayDataSchema arraySchema = (ArrayDataSchema) fooSchema.getField("array").getType();

    String fooText =
      "{\n" +
      "  \"int\" : 34,\n" +
      "  \"string\" : \"abc\",\n" +
      "  \"array\" : [\n" +
      "    { \"int\" : 56 },\n" +
      "    { \"string\" : \"xyz\" },\n" +
      "    { \"array\" : [\n" +
      "      { \"int\" : 78 }\n" +
      "    ] }\n" +
      "  ]\n" +
      "}\n";

    DataMap foo = TestUtil.dataMapFromString(fooText);

    DataElement root = factory.create(foo, DataElement.ROOT_NAME, fooSchema, null);
    DataElement int1 = factory.create(foo.get("int"), "int", fooSchema.getField("int").getType(), root);
    DataElement string1 = factory.create(foo.get("string"), "string", fooSchema.getField("string").getType(), root);
    DataElement array1 = factory.create(foo.get("array"), "array", fooSchema.getField("array").getType(), root);

    DataElement foo20 = factory.create(array1.getChild(0), 0, arraySchema.getItems(), array1);
    DataElement foo21 = factory.create(array1.getChild(1), 1, arraySchema.getItems(), array1);
    DataElement foo22 = factory.create(array1.getChild(2), 2, arraySchema.getItems(), array1);

    DataElement int20 = factory.create(foo20.getChild("int"), "int", fooSchema.getField("int").getType(), foo20);
    DataElement string21 = factory.create(foo21.getChild("string"), "string", fooSchema.getField("string").getType(), foo21);
    DataElement array22 = factory.create(foo22.getChild("array"), "array", fooSchema.getField("array").getType(), foo22);

    DataElement foo30 = factory.create(array22.getChild(0), 0, arraySchema.getItems(), array22);
    DataElement int30 = factory.create(foo30.getChild("int"), "int", fooSchema.getField("int").getType(), foo30);

    // test path

    Object[][] testPathInput =
View Full Code Here

    }
    if (typerefDataSchema != null)
    {
      if (type.isArray())
      {
        return new ArrayDataSchema(typerefDataSchema);
      }
      else
      {
        return typerefDataSchema;
      }
    }
    else if (RestModelConstants.CLASSES_WITHOUT_SCHEMAS.contains(type))
    {
      return null;
    }
    else if (type.isArray())
    {
      DataSchema itemSchema = DataTemplateUtil.getSchema(type.getComponentType());
      return new ArrayDataSchema(itemSchema);
    }
    return DataTemplateUtil.getSchema(type);
  }
View Full Code Here

  {
    super(data, null);
    _elementClass = elementClass;
    StringBuilder errorMessageBuilder = new StringBuilder(10);
    Name elementSchemaName = new Name(elementClass.getSimpleName());
    _arraySchema = new ArrayDataSchema(new RecordDataSchema(elementSchemaName, RecordDataSchema.RecordType.RECORD));
    _arrayField = new RecordDataSchema.Field(_arraySchema);
    _arrayField.setName(ELEMENTS, errorMessageBuilder);

    if (data().get(ELEMENTS) == null)
    {
View Full Code Here

    public void index(int index)
    {
      DataSchema newSchema = null;
      if (_currentSchema != null && _currentSchema.getType() == DataSchema.Type.ARRAY)
      {
        ArrayDataSchema arraySchema = (ArrayDataSchema) _currentSchema;
        newSchema = arraySchema.getItems();
      }
      _pendingSchema = newSchema;
      super.index(index);
    }
View Full Code Here

  @SuppressWarnings({"unchecked"})
  private <T> void putArray(RecordDataSchema.Field field, FieldDef<T> fieldDef, T value)
  {
    DataList data = new DataList();
    Class<?> itemType = null;
    ArrayDataSchema arrayDataSchema = null;
    if (fieldDef.getDataSchema() instanceof ArrayDataSchema)
    {
      arrayDataSchema = (ArrayDataSchema)fieldDef.getDataSchema();
      DataSchema itemSchema = arrayDataSchema.getItems();

      if (itemSchema instanceof TyperefDataSchema)
      {
        itemType = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass(
            itemSchema.getDereferencedType());
View Full Code Here

  }

  private static RecordDataSchema generateSchema()
  {
    StringBuilder errorMessageBuilder = new StringBuilder(10);
    ArrayDataSchema arraySchema = new ArrayDataSchema(new RecordDataSchema(new Name(CreateStatus.class.getSimpleName()), RecordDataSchema.RecordType.RECORD));
    RecordDataSchema.Field arrayField = new RecordDataSchema.Field(arraySchema);
    arrayField.setName(CollectionResponse.ELEMENTS, errorMessageBuilder);
    RecordDataSchema schema = new RecordDataSchema(new Name(BatchCreateIdResponse.class.getSimpleName()), RecordDataSchema.RecordType.RECORD);
    schema.setFields(Arrays.asList(arrayField), errorMessageBuilder);
    return schema;
View Full Code Here

TOP

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

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.