Search in sources :

Example 26 with Key

use of com.linkedin.restli.server.Key in project rest.li by linkedin.

the class TestBatchUpdateArgumentBuilder method failureData.

@DataProvider(name = "failureData")
private Object[][] failureData() {
    Object[] compoundKeys = new Object[] { new CompoundKey().append("string1", "XXX").append("string2", "oranges"), new CompoundKey().append("string1", "coffee").append("string2", "tea") };
    Object[] complexResourceKeys = new Object[] { new ComplexResourceKey<>(new MyComplexKey().setA("A1").setB(111L), new EmptyRecord()), new ComplexResourceKey<>(new MyComplexKey().setA("A2").setB(222L), new EmptyRecord()) };
    return new Object[][] { { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"b\":123,\"a\":\"abc\"}," + "\"10002\":{\"b\":456,\"a\":\"XY\"}}}", new Object[] { 10001, 99999 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"b\":123,\"a\":\"abc\"}," + "\"99999\":{\"b\":456,\"a\":\"XY\"}}}", new Object[] { 10001, 10002 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("integerKey", Integer.class, new IntegerDataSchema()), null, "{\"entities\":{\"10001\":{\"b\":123,\"a\":\"abc\"}," + "\"10002\":{\"b\":456,\"a\":\"XY\"}}}", new Object[] { 10001, 10002, 10003 }, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"string1=apples&string2=oranges\":{\"b\":123,\"a\":\"abc\"}," + "\"string1=coffee&string2=tea\":{\"b\":456,\"a\":\"XY\"}}}", compoundKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"string1=coffee&string2=tea\":{\"b\":123,\"a\":\"abc\"}," + "\"string2=tea&string1=coffee\":{\"b\":456,\"a\":\"XY\"}}}", compoundKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"(string1:coffee,string2:tea)\":{\"b\":456,\"a\":\"XY\"}," + "\"(string1:apples,string2:oranges)\":{\"b\":123,\"a\":\"abc\"}}}", compoundKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), new Key("compoundKey", CompoundKey.class, null), new Key[] { new Key("string1", String.class), new Key("string2", String.class) }, "{\"entities\":{\"(string1:coffee,string2:tea)\":{\"b\":456,\"a\":\"XY\"}," + "\"(string2:tea,string1:coffee)\":{\"b\":123,\"a\":\"abc\"}}}", compoundKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"a=A1&b=999\":{\"b\":123,\"a\":\"abc\"}," + "\"a=A2&b=222\":{\"b\":456,\"a\":\"XY\"}}}", complexResourceKeys, ERROR_MESSAGE_BATCH_KEYS_MISMATCH }, { // Duplicate key in the entities body
    AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), new Key("complexKey", ComplexResourceKey.class, null), null, "{\"entities\":{\"a=A1&b=111\":{\"b\":123,\"a\":\"abc\"}," + "\"b=111&a=A1\":{\"b\":456,\"a\":\"XY\"}}}", complexResourceKeys, ERROR_MESSAGE_DUPLICATE_BATCH_KEYS } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Example 27 with Key

use of com.linkedin.restli.server.Key in project rest.li by linkedin.

the class TestPatchArgumentBuilder method argumentData.

@DataProvider(name = "argumentData")
private Object[][] argumentData() {
    @SuppressWarnings("rawtypes") Parameter<?> patchParam = new Parameter<>("", PatchRequest.class, null, false, null, Parameter.ParamType.POST, false, new AnnotationSet(new Annotation[] {}));
    List<Parameter<?>> collectionResourceParams = new ArrayList<>();
    collectionResourceParams.add(new Parameter<>("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
    collectionResourceParams.add(patchParam);
    List<Parameter<?>> simpleResourceParams = new ArrayList<>();
    simpleResourceParams.add(patchParam);
    List<Parameter<?>> associationResourceParams = new ArrayList<>();
    associationResourceParams.add(new Parameter<>("myComplexKeyAssociationId", CompoundKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
    associationResourceParams.add(patchParam);
    List<Parameter<?>> complexResourceKeyParams = new ArrayList<>();
    @SuppressWarnings("rawtypes") Parameter<ComplexResourceKey> complexResourceKeyParam = new Parameter<>("complexKeyTestId", ComplexResourceKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {}));
    complexResourceKeyParams.add(complexResourceKeyParam);
    complexResourceKeyParams.add(patchParam);
    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") }, { complexResourceKeyParams, new Key("complexKeyTestId", ComplexResourceKey.class, null), "complexKeyTestId", new ComplexResourceKey<>(new MyComplexKey().setA("keyString").setB(1234L), new EmptyRecord()) } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Parameter(com.linkedin.restli.internal.server.model.Parameter) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Example 28 with Key

use of com.linkedin.restli.server.Key in project rest.li by linkedin.

the class RestLiAnnotationReader method checkIfKeyIsValid.

/**
 * For a given path key name and resource model, returns true if the path key exists in the resource,
 * its parent, or any of its super-parents (if applicable).
 */
private static void checkIfKeyIsValid(String keyName, ResourceModel model) {
    ResourceModel nextModel = model;
    while (nextModel != null) {
        Set<Key> keys = nextModel.getKeys();
        for (Key key : keys) {
            if (key.getName().equals(keyName)) {
                return;
            }
        }
        nextModel = nextModel.getParentResourceModel();
    }
    throw new ResourceConfigException("Parameter " + keyName + " not found in path keys of class " + model.getResourceClass());
}
Also used : ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) AlternativeKey(com.linkedin.restli.server.annotations.AlternativeKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key)

Aggregations

ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)28 Key (com.linkedin.restli.server.Key)28 CompoundKey (com.linkedin.restli.common.CompoundKey)22 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)10 AlternativeKey (com.linkedin.restli.server.AlternativeKey)8 IntegerDataSchema (com.linkedin.data.schema.IntegerDataSchema)7 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)7 DataProvider (org.testng.annotations.DataProvider)7 EmptyRecord (com.linkedin.restli.common.EmptyRecord)6 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)6 HashSet (java.util.HashSet)6 Test (org.testng.annotations.Test)5 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 RestRequest (com.linkedin.r2.message.rest.RestRequest)4 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)4 Parameter (com.linkedin.restli.internal.server.model.Parameter)4 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)4 ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)4 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)4 RoutingException (com.linkedin.restli.server.RoutingException)4