Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.Key


  @Test
  public void testHeuristicKeySyntaxDetection() throws PathSegment.PathSegmentSyntaxException
  {
    Set<Key> keys = new HashSet<Key>(2);
    keys.add(new Key("foo", Integer.class));
    keys.add(new Key("bar", String.class));

    // heuristic key syntax detection only occurs in Protocol Version 1.0.0
    ProtocolVersion v1 = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();

    Set<String> expectedKeys = new HashSet<String>(Arrays.asList("foo", "bar"));
View Full Code Here


    DataMap dataMap1 = new DataMap();
    dataMap1.put("foo", "1");
    dataMap1.put("bar", "hello");

    Set<Key> keys1 = new HashSet<Key>(2);
    keys1.add(new Key("foo", Integer.class));
    keys1.add(new Key("bar", String.class));

    CompoundKey compoundKey2 = new CompoundKey();
    compoundKey2.append("a", new Long(6));
    compoundKey2.append("b", new Double(3.14));

    DataMap dataMap2 = new DataMap();
    dataMap2.put("a", "6");
    dataMap2.put("b", "3.14");

    Set<Key> keys2 = new HashSet<Key>(2);
    keys2.add(new Key("a", Long.class));
    keys2.add(new Key("b", Double.class));

    return new Object[][]
      {
        { compoundKey1, dataMap1, keys1 },
        { compoundKey2, dataMap2, keys2 }
View Full Code Here

    return new Object[][]
        {
            {
                collectionResourceParams,
                new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()),
                "myComplexKeyCollectionId",
                4545
            },
            {
                simpleResourceParams,
                null,
                null,
                null
            },
            {
                associationResourceParams,
                new Key("myComplexKeyAssociationId", CompoundKey.class, null),
                "myComplexKeyAssociationId",
                new CompoundKey().append("string1", "apples").append("string2", "oranges")
            }
        };
  }
View Full Code Here

    return new Object[][]
        {
            {
                collectionResourceParams,
                new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()),
                "myComplexKeyCollectionId",
                1234
            },
            {
                simpleResourceParams,
                null,
                null,
                null
            },
            {
                associationResourceParams,
                new Key("myComplexKeyAssociationId", CompoundKey.class, null),
                "myComplexKeyAssociationId",
                new CompoundKey().append("string1", "apples").append("string2", "oranges")
            }
        };
  }
View Full Code Here

      List<String> ids = context.getParameterValues(RestConstants.QUERY_BATCH_IDS_PARAM);
      if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0)
      {
        for (String id: ids)
        {
          Key key = resource.getPrimaryKey();
          Object value;
          // in v2, compound keys have already been converted and dealt with, so all we need to do here is convert simple values.
          value = ArgumentUtils.convertSimpleValue(id, key.getDataSchema(), key.getType());
          batchKeys.add(value);
        }
      }
      else
      {
View Full Code Here

    {
      return ArgumentUtils.parseCompoundKey(value, resource.getKeys(), version);
    }
    else
    {
      Key key = resource.getPrimaryKey();
      return ArgumentUtils.convertSimpleValue(value, key.getDataSchema(), key.getType());
    }
  }
View Full Code Here

      {
        //should not happen, since we are using "UTF-8" as the encoding
        throw new RestLiInternalException(e);
      }
      // Key is not found in the set defined for the resource
      Key currentKey = getKeyWithName(keys, name);
      if (currentKey == null)
      {
        errorMessageBuilder.append("Unknown key part named '");
        errorMessageBuilder.append(name);
        errorMessageBuilder.append("'");
        return null;
      }

      String decodedStringValue;
      try
      {
        decodedStringValue =
                URLDecoder.decode(nameValuePair[1], RestConstants.DEFAULT_CHARSET_NAME);
      }
      catch (UnsupportedEncodingException e)
      {
        //should not happen, since we are using "UTF-8" as the encoding
        throw new RestLiInternalException(e);
      }

      compoundKey.append(name, convertSimpleValue(decodedStringValue, currentKey.getDataSchema(), currentKey.getType()));
    }
    return compoundKey;
  }
View Full Code Here

                                          final ResourceModel resource,
                                          final ProtocolVersion version) throws IllegalArgumentException,
                                                                                NumberFormatException

  {
    Key key = resource.getPrimaryKey();
    String decodedValue;
    if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0)
    {
      decodedValue = UriComponent.decode(value, UriComponent.Type.PATH_SEGMENT);
    }
    else
    {
      decodedValue = URLEscaper.unescape(value, URLEscaper.Escaping.URL_ESCAPING);
    }
    return convertSimpleValue(decodedValue, key.getDataSchema(), key.getType());
  }
View Full Code Here

      identifierSchema.setType(buildDataSchemaType(collectionResource.getKeyKeyClass()));
      identifierSchema.setParams(buildDataSchemaType(collectionResource.getKeyParamsClass()));
    }
    else
    {
      Key key = collectionResource.getPrimaryKey();
      identifierSchema.setType(buildDataSchemaType(key.getType(), key.getDataSchema()));
    }

    collectionNode.setIdentifier(identifierSchema);
  }
View Full Code Here

  public void testArgumentBuilder(Parameter<?> param, String keyName, Object keyValue, final DataSchema keySchema) throws RestLiSyntaxException
  {
    ResourceModel model;
    if (keyName != null)
    {
      Key key = new Key(keyName, keyValue.getClass(), keySchema);
      model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, false);
    }
    else
    {
      model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, null, true);
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.Key

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.