Search in sources :

Example 11 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class RequestBuilderSpecGenerator method generateRootRequestBuilder.

private RootBuilderSpec generateRootRequestBuilder(RootBuilderSpec parentRootBuilder, ResourceSchema resource, String sourceFile, Map<String, String> pathKeyTypes) throws IOException {
    ValidationResult validationResult = ValidateDataAgainstSchema.validate(resource.data(), resource.schema(), new ValidationOptions());
    if (!validationResult.isValid()) {
        throw new IllegalArgumentException(String.format("Resource validation error.  Resource File '%s', Error Details '%s'", sourceFile, validationResult.toString()));
    }
    String packageName = resource.getNamespace();
    String resourceName = CodeUtil.capitalize(resource.getName());
    String className;
    if (_version == RestliVersion.RESTLI_2_0_0) {
        className = getBuilderClassNameByVersion(RestliVersion.RESTLI_2_0_0, null, resource.getName(), true);
    } else {
        className = getBuilderClassNameByVersion(RestliVersion.RESTLI_1_0_0, null, resource.getName(), true);
    }
    RootBuilderSpec rootBuilderSpec = null;
    if (resource.hasCollection()) {
        rootBuilderSpec = new CollectionRootBuilderSpec(resource);
    } else if (resource.hasSimple()) {
        rootBuilderSpec = new SimpleRootBuilderSpec(resource);
    } else if (resource.hasActionsSet()) {
        rootBuilderSpec = new ActionSetRootBuilderSpec(resource);
    } else {
        log.warn("Ignoring unsupported association resource: " + resourceName);
        return null;
    }
    rootBuilderSpec.setNamespace(packageName);
    rootBuilderSpec.setClassName(className);
    if (_version == RestliVersion.RESTLI_2_0_0) {
        rootBuilderSpec.setBaseClassName("BuilderBase");
    }
    rootBuilderSpec.setSourceIdlName(sourceFile);
    String resourcePath = getResourcePath(resource.getPath());
    rootBuilderSpec.setResourcePath(resourcePath);
    List<String> pathKeys = getPathKeys(resourcePath);
    rootBuilderSpec.setPathKeys(pathKeys);
    rootBuilderSpec.setParentRootBuilder(parentRootBuilder);
    StringArray supportsList = null;
    RestMethodSchemaArray restMethods = null;
    FinderSchemaArray finders = null;
    ResourceSchemaArray subresources = null;
    ActionSchemaArray resourceActions = null;
    ActionSchemaArray entityActions = null;
    String keyClass = null;
    if (resource.getCollection() != null) {
        CollectionSchema collection = resource.getCollection();
        String keyName = collection.getIdentifier().getName();
        // Complex key is not supported
        keyClass = collection.getIdentifier().getType();
        pathKeyTypes.put(keyName, collection.getIdentifier().getType());
        supportsList = collection.getSupports();
        restMethods = collection.getMethods();
        finders = collection.getFinders();
        subresources = collection.getEntity().getSubresources();
        resourceActions = collection.getActions();
        entityActions = collection.getEntity().getActions();
    } else if (resource.getSimple() != null) {
        SimpleSchema simpleSchema = resource.getSimple();
        keyClass = "Void";
        supportsList = simpleSchema.getSupports();
        restMethods = simpleSchema.getMethods();
        subresources = simpleSchema.getEntity().getSubresources();
        resourceActions = simpleSchema.getActions();
    } else if (resource.getActionsSet() != null) {
        ActionsSetSchema actionsSet = resource.getActionsSet();
        resourceActions = actionsSet.getActions();
    }
    Set<ResourceMethod> supportedMethods = getSupportedMethods(supportsList);
    if (!supportedMethods.isEmpty()) {
        for (ResourceMethod resourceMethod : supportedMethods) {
            validateResourceMethod(resource, resourceName, resourceMethod);
        }
    }
    List<RootBuilderMethodSpec> restMethodSpecs = new ArrayList<>();
    List<RootBuilderMethodSpec> finderSpecs = new ArrayList<>();
    List<RootBuilderMethodSpec> resourceActionSpecs = new ArrayList<>();
    List<RootBuilderMethodSpec> entityActionSpecs = new ArrayList<>();
    List<RootBuilderSpec> subresourceSpecs = new ArrayList<>();
    String schemaClass = resource.getSchema();
    if (restMethods != null) {
        restMethodSpecs = generateBasicMethods(rootBuilderSpec, keyClass, schemaClass, supportedMethods, restMethods, resourceName, pathKeys, pathKeyTypes);
    }
    if (finders != null) {
        finderSpecs = generateFinders(rootBuilderSpec, finders, keyClass, schemaClass, resourceName, pathKeys, pathKeyTypes);
    }
    if (resourceActions != null) {
        resourceActionSpecs = generateActions(rootBuilderSpec, resourceActions, keyClass, resourceName, pathKeys, pathKeyTypes);
    }
    if (entityActions != null) {
        entityActionSpecs = generateActions(rootBuilderSpec, entityActions, keyClass, resourceName, pathKeys, pathKeyTypes);
    }
    if (subresources != null) {
        subresourceSpecs = generateSubResources(sourceFile, rootBuilderSpec, subresources, pathKeyTypes);
    }
    // assign to rootBuilderClass
    if (rootBuilderSpec instanceof CollectionRootBuilderSpec) {
        CollectionRootBuilderSpec rootBuilder = (CollectionRootBuilderSpec) rootBuilderSpec;
        rootBuilder.setRestMethods(restMethodSpecs);
        rootBuilder.setFinders(finderSpecs);
        rootBuilder.setResourceActions(resourceActionSpecs);
        rootBuilder.setEntityActions(entityActionSpecs);
        rootBuilder.setSubresources(subresourceSpecs);
    } else if (rootBuilderSpec instanceof SimpleRootBuilderSpec) {
        SimpleRootBuilderSpec rootBuilder = (SimpleRootBuilderSpec) rootBuilderSpec;
        rootBuilder.setRestMethods(restMethodSpecs);
        rootBuilder.setResourceActions(resourceActionSpecs);
        rootBuilder.setSubresources(subresourceSpecs);
    } else if (rootBuilderSpec instanceof ActionSetRootBuilderSpec) {
        ActionSetRootBuilderSpec rootBuilder = (ActionSetRootBuilderSpec) rootBuilderSpec;
        rootBuilder.setResourceActions(resourceActionSpecs);
    }
    registerBuilderSpec(rootBuilderSpec);
    return rootBuilderSpec;
}
Also used : RestMethodSchemaArray(com.linkedin.restli.restspec.RestMethodSchemaArray) CollectionSchema(com.linkedin.restli.restspec.CollectionSchema) SimpleSchema(com.linkedin.restli.restspec.SimpleSchema) ArrayList(java.util.ArrayList) ResourceSchemaArray(com.linkedin.restli.restspec.ResourceSchemaArray) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationOptions(com.linkedin.data.schema.validation.ValidationOptions) ActionsSetSchema(com.linkedin.restli.restspec.ActionsSetSchema) CollectionRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec) StringArray(com.linkedin.data.template.StringArray) RootBuilderMethodSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderMethodSpec) FinderSchemaArray(com.linkedin.restli.restspec.FinderSchemaArray) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) RootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.RootBuilderSpec) SimpleRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec) CollectionRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.CollectionRootBuilderSpec) ActionSetRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.ActionSetRootBuilderSpec) SimpleRootBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.SimpleRootBuilderSpec) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 12 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class TestRestLiValidationFilter method testHandleProjection.

/**
 * Ensures that the validation filter safely and correctly reacts to projections given a variety of resource types,
 * resource methods, and projection masks. This was motivated by a bug that caused an NPE in the validation filter
 * when the resource being queried was a {@link RestLiActions} resource and thus had no value class.
 */
@Test(dataProvider = "validateWithProjectionData")
@SuppressWarnings({ "unchecked" })
public void testHandleProjection(ResourceModel resourceModel, RestLiResponseData<RestLiResponseEnvelope> responseData, MaskTree projectionMask, boolean expectError) {
    ResourceMethod resourceMethod = responseData.getResourceMethod();
    when(filterRequestContext.getRequestData()).thenReturn(new RestLiRequestDataImpl.Builder().entity(makeTestRecord()).build());
    when(filterRequestContext.getMethodType()).thenReturn(resourceMethod);
    when(filterRequestContext.getFilterResourceModel()).thenReturn(new FilterResourceModelImpl(resourceModel));
    when(filterRequestContext.getProjectionMask()).thenReturn(projectionMask);
    when(filterResponseContext.getResponseData()).thenReturn((RestLiResponseData) responseData);
    RestLiValidationFilter validationFilter = new RestLiValidationFilter();
    try {
        validationFilter.onRequest(filterRequestContext);
        if (expectError) {
            Assert.fail("Expected an error to be thrown on request in the validation filter, but none was thrown.");
        }
    } catch (RestLiServiceException e) {
        if (expectError) {
            Assert.assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST);
            return;
        } else {
            Assert.fail("An unexpected exception was thrown on request in the validation filter.", e);
        }
    }
    validationFilter.onResponse(filterRequestContext, filterResponseContext);
}
Also used : FilterResourceModelImpl(com.linkedin.restli.internal.server.filter.FilterResourceModelImpl) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RestLiRequestDataImpl(com.linkedin.restli.server.RestLiRequestDataImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 13 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class BaseResourceSpec method getImportsForMethods.

public List<String> getImportsForMethods() {
    if (_imports == null) {
        Set<String> imports = new TreeSet<>();
        if (getActions().size() > 0) {
            imports.add(ActionRequest.class.getName());
            imports.add(ActionResponse.class.getName());
            imports.add(ActionResponseDecoder.class.getName());
            imports.add(DynamicRecordTemplate.class.getName());
            imports.add(FieldDef.class.getName());
            // Add action value class to imports
            getActions().stream().forEach(actionMethodSpec -> {
                if (!SpecUtils.checkIfShortNameConflictAndUpdateMapping(_importCheckConflict, ClassUtils.getShortClassName(actionMethodSpec.getValueClassName()), actionMethodSpec.getValueClassName())) {
                    imports.add(actionMethodSpec.getValueClassName());
                    actionMethodSpec.setUsingShortClassName(true);
                }
                if (actionMethodSpec.hasReturnTypeRef() && !SpecUtils.checkIfShortNameConflictAndUpdateMapping(_importCheckConflict, ClassUtils.getShortClassName(actionMethodSpec.getValueTypeRefClassName()), actionMethodSpec.getValueTypeRefClassName())) {
                    imports.add(actionMethodSpec.getValueTypeRefClassName());
                    actionMethodSpec.setUsingShortTypeRefClassName(true);
                }
            });
        }
        for (RestMethodSpec methodSpec : getRestMethods()) {
            ResourceMethod method = ResourceMethod.fromString(methodSpec.getMethod());
            switch(method) {
                case GET:
                    imports.add(GetRequest.class.getName());
                    break;
                case BATCH_GET:
                    imports.add(BatchGetEntityRequest.class.getName());
                    imports.add(BatchKVResponse.class.getName());
                    imports.add(EntityResponse.class.getName());
                    imports.add(BatchEntityResponseDecoder.class.getName());
                    break;
                case CREATE:
                    imports.add(CreateIdRequest.class.getName());
                    imports.add(IdResponse.class.getName());
                    imports.add(IdResponseDecoder.class.getName());
                    if (methodSpec.returnsEntity()) {
                        imports.add(CreateIdEntityRequest.class.getName());
                        imports.add(IdEntityResponse.class.getName());
                        imports.add(IdEntityResponseDecoder.class.getName());
                    }
                    break;
                case BATCH_CREATE:
                    imports.add(CollectionRequest.class.getName());
                    imports.add(BatchCreateIdRequest.class.getName());
                    imports.add(CreateIdStatus.class.getName());
                    imports.add(BatchCreateIdResponse.class.getName());
                    imports.add(BatchCreateIdDecoder.class.getName());
                    if (methodSpec.returnsEntity()) {
                        imports.add(BatchCreateIdEntityRequest.class.getName());
                        imports.add(CreateIdEntityStatus.class.getName());
                        imports.add(BatchCreateIdEntityResponse.class.getName());
                        imports.add(BatchCreateIdEntityDecoder.class.getName());
                    }
                    break;
                case PARTIAL_UPDATE:
                    imports.add(PatchRequest.class.getName());
                    imports.add(PartialUpdateRequest.class.getName());
                    if (methodSpec.returnsEntity()) {
                        imports.add(PartialUpdateEntityRequest.class.getName());
                        imports.add(EntityResponseDecoder.class.getName());
                    }
                    break;
                case BATCH_PARTIAL_UPDATE:
                    imports.add(PatchRequest.class.getName());
                    imports.add(BatchPartialUpdateRequest.class.getName());
                    imports.add(CollectionRequest.class.getName());
                    imports.add(UpdateStatus.class.getName());
                    imports.add(BatchKVResponse.class.getName());
                    imports.add(KeyValueRecordFactory.class.getName());
                    imports.add(KeyValueRecord.class.getName());
                    if (methodSpec.returnsEntity()) {
                        imports.add(BatchPartialUpdateEntityRequest.class.getName());
                        imports.add(UpdateEntityStatus.class.getName());
                    }
                    break;
                case UPDATE:
                    imports.add(UpdateRequest.class.getName());
                    break;
                case BATCH_UPDATE:
                    imports.add(BatchUpdateRequest.class.getName());
                    imports.add(BatchKVResponse.class.getName());
                    imports.add(KeyValueRecordFactory.class.getName());
                    imports.add(KeyValueRecord.class.getName());
                    imports.add(CollectionRequest.class.getName());
                    imports.add(UpdateStatus.class.getName());
                    break;
                case DELETE:
                    imports.add(DeleteRequest.class.getName());
                    break;
                case BATCH_DELETE:
                    imports.add(BatchDeleteRequest.class.getName());
                    imports.add(UpdateStatus.class.getName());
                    break;
                case GET_ALL:
                    imports.add(GetAllRequest.class.getName());
                    imports.add(CollectionResponse.class.getName());
                    break;
                default:
                    break;
            }
        }
        if (!getFinders().isEmpty()) {
            imports.add(FindRequest.class.getName());
            imports.add(CollectionResponse.class.getName());
        }
        if (!getBatchFinders().isEmpty()) {
            imports.add(BatchFindRequest.class.getName());
            imports.add(BatchCollectionResponse.class.getName());
            imports.add(BatchFinderCriteriaResult.class.getName());
        }
        // than complex key, etc.
        if (_entityClassName == null) {
            if (getEntityClass() == null) {
                _entityClassName = Void.class.getSimpleName();
            } else if (SpecUtils.checkIfShortNameConflictAndUpdateMapping(_importCheckConflict, getEntityClass().getClassName(), getEntityClass().getBindingName())) {
                _entityClassName = getEntityClass().getFullName();
            } else {
                imports.add(getEntityClass().getFullName());
                _entityClassName = getEntityClass().getClassName();
            }
        }
        // Add param classes to imports
        Stream.of(getRestMethods().stream().map(RestMethodSpec::getAllParameters).flatMap(List::stream), getActions().stream().map(ActionMethodSpec::getAllParameters).flatMap(List::stream), getFinders().stream().map(MethodSpec::getAllParameters).flatMap(List::stream), getBatchFinders().stream().map(MethodSpec::getAllParameters).flatMap(List::stream)).reduce(Stream::concat).orElseGet(Stream::empty).forEach(paramSpec -> {
            if (!SpecUtils.checkIfShortNameConflictAndUpdateMapping(_importCheckConflict, ClassUtils.getShortClassName(paramSpec.getParamClassName()), paramSpec.getParamClassName())) {
                imports.add(paramSpec.getParamClassName());
                paramSpec.setUsingShortClassName(true);
            }
            if (paramSpec.hasParamTypeRef() && !SpecUtils.checkIfShortNameConflictAndUpdateMapping(_importCheckConflict, ClassUtils.getShortClassName(paramSpec.getParamTypeRefClassName()), paramSpec.getParamTypeRefClassName())) {
                imports.add(paramSpec.getParamTypeRefClassName());
                paramSpec.setUsingShortTypeRefClassName(true);
            }
            if (paramSpec.isArray() && !SpecUtils.checkIfShortNameConflictAndUpdateMapping(_importCheckConflict, ClassUtils.getShortClassName(paramSpec.getItemClassName()), paramSpec.getItemClassName())) {
                imports.add(paramSpec.getItemClassName());
                paramSpec.setUsingShortItemClassName(true);
            }
        });
        // Sub resources are handled recursively
        _imports = getResourceSpecificImports(imports);
    }
    return _imports.stream().filter(importClass -> !(importClass.startsWith(SpecUtils.JAVA_LANG_PREFIX) || SpecUtils.PRIMITIVE_CLASS_NAMES.contains(importClass))).collect(Collectors.toList());
}
Also used : BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) BatchCreateIdEntityRequest(com.linkedin.restli.client.BatchCreateIdEntityRequest) ResourceMethod(com.linkedin.restli.common.ResourceMethod) BatchEntityResponseDecoder(com.linkedin.restli.internal.client.BatchEntityResponseDecoder) CollectionResponse(com.linkedin.restli.common.CollectionResponse) ClassUtils(org.apache.commons.lang.ClassUtils) ActionRequest(com.linkedin.restli.client.ActionRequest) UpdateStatus(com.linkedin.restli.common.UpdateStatus) RestSpecCodec(com.linkedin.restli.restspec.RestSpecCodec) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) BatchCreateIdEntityRequest(com.linkedin.restli.client.BatchCreateIdEntityRequest) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) Pair(org.apache.commons.lang3.tuple.Pair) PartialUpdateRequest(com.linkedin.restli.client.PartialUpdateRequest) ActionResponseDecoder(com.linkedin.restli.internal.client.ActionResponseDecoder) CreateIdRequest(com.linkedin.restli.client.CreateIdRequest) ByteString(com.linkedin.data.ByteString) EntityResponse(com.linkedin.restli.common.EntityResponse) Map(java.util.Map) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) FieldDef(com.linkedin.data.template.FieldDef) BatchPartialUpdateRequest(com.linkedin.restli.client.BatchPartialUpdateRequest) BatchCreateIdRequest(com.linkedin.restli.client.BatchCreateIdRequest) BatchCreateIdDecoder(com.linkedin.restli.internal.client.BatchCreateIdDecoder) Set(java.util.Set) BatchGetEntityRequest(com.linkedin.restli.client.BatchGetEntityRequest) IdResponseDecoder(com.linkedin.restli.internal.client.IdResponseDecoder) Collectors(java.util.stream.Collectors) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) UpdateRequest(com.linkedin.restli.client.UpdateRequest) List(java.util.List) Stream(java.util.stream.Stream) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) DataSchemaLocation(com.linkedin.data.schema.DataSchemaLocation) RestLiToolsUtils(com.linkedin.restli.internal.tools.RestLiToolsUtils) ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) FindRequest(com.linkedin.restli.client.FindRequest) GetRequest(com.linkedin.restli.client.GetRequest) GetAllRequest(com.linkedin.restli.client.GetAllRequest) ActionResponse(com.linkedin.restli.common.ActionResponse) BatchUpdateRequest(com.linkedin.restli.client.BatchUpdateRequest) DataSchema(com.linkedin.data.schema.DataSchema) BatchCreateIdEntityDecoder(com.linkedin.restli.internal.client.BatchCreateIdEntityDecoder) HashMap(java.util.HashMap) DataSchemaResolver(com.linkedin.data.schema.DataSchemaResolver) BatchFindRequest(com.linkedin.restli.client.BatchFindRequest) CustomTypeUtil(com.linkedin.util.CustomTypeUtil) TreeSet(java.util.TreeSet) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) TemplateSpecGenerator(com.linkedin.pegasus.generator.TemplateSpecGenerator) LinkedList(java.util.LinkedList) DeleteRequest(com.linkedin.restli.client.DeleteRequest) FileDataSchemaLocation(com.linkedin.data.schema.resolver.FileDataSchemaLocation) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) PartialUpdateEntityRequest(com.linkedin.restli.client.PartialUpdateEntityRequest) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) CompoundKey(com.linkedin.restli.common.CompoundKey) File(java.io.File) IdResponse(com.linkedin.restli.common.IdResponse) IdEntityResponseDecoder(com.linkedin.restli.internal.client.IdEntityResponseDecoder) BatchPartialUpdateEntityRequest(com.linkedin.restli.client.BatchPartialUpdateEntityRequest) CreateIdEntityRequest(com.linkedin.restli.client.CreateIdEntityRequest) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) EntityResponseDecoder(com.linkedin.restli.internal.client.EntityResponseDecoder) ResourceSchemaArray(com.linkedin.restli.restspec.ResourceSchemaArray) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) CollectionRequest(com.linkedin.restli.common.CollectionRequest) ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) Collections(java.util.Collections) BatchDeleteRequest(com.linkedin.restli.client.BatchDeleteRequest) CollectionRequest(com.linkedin.restli.common.CollectionRequest) BatchPartialUpdateRequest(com.linkedin.restli.client.BatchPartialUpdateRequest) UpdateStatus(com.linkedin.restli.common.UpdateStatus) PartialUpdateEntityRequest(com.linkedin.restli.client.PartialUpdateEntityRequest) BatchPartialUpdateEntityRequest(com.linkedin.restli.client.BatchPartialUpdateEntityRequest) IdEntityResponseDecoder(com.linkedin.restli.internal.client.IdEntityResponseDecoder) ByteString(com.linkedin.data.ByteString) ActionResponseDecoder(com.linkedin.restli.internal.client.ActionResponseDecoder) TreeSet(java.util.TreeSet) GetRequest(com.linkedin.restli.client.GetRequest) List(java.util.List) LinkedList(java.util.LinkedList) Stream(java.util.stream.Stream) GetAllRequest(com.linkedin.restli.client.GetAllRequest) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) BatchCreateIdEntityRequest(com.linkedin.restli.client.BatchCreateIdEntityRequest) CreateIdEntityRequest(com.linkedin.restli.client.CreateIdEntityRequest) PartialUpdateRequest(com.linkedin.restli.client.PartialUpdateRequest) BatchPartialUpdateRequest(com.linkedin.restli.client.BatchPartialUpdateRequest) UpdateRequest(com.linkedin.restli.client.UpdateRequest) BatchUpdateRequest(com.linkedin.restli.client.BatchUpdateRequest) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchCreateIdEntityDecoder(com.linkedin.restli.internal.client.BatchCreateIdEntityDecoder) PatchRequest(com.linkedin.restli.common.PatchRequest) ActionResponse(com.linkedin.restli.common.ActionResponse) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) FieldDef(com.linkedin.data.template.FieldDef) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) IdResponseDecoder(com.linkedin.restli.internal.client.IdResponseDecoder) BatchFindRequest(com.linkedin.restli.client.BatchFindRequest) BatchUpdateRequest(com.linkedin.restli.client.BatchUpdateRequest) BatchEntityResponseDecoder(com.linkedin.restli.internal.client.BatchEntityResponseDecoder) IdEntityResponseDecoder(com.linkedin.restli.internal.client.IdEntityResponseDecoder) EntityResponseDecoder(com.linkedin.restli.internal.client.EntityResponseDecoder) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) BatchCreateIdDecoder(com.linkedin.restli.internal.client.BatchCreateIdDecoder) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) BatchDeleteRequest(com.linkedin.restli.client.BatchDeleteRequest) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) BatchPartialUpdateEntityRequest(com.linkedin.restli.client.BatchPartialUpdateEntityRequest) BatchEntityResponseDecoder(com.linkedin.restli.internal.client.BatchEntityResponseDecoder) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) ActionRequest(com.linkedin.restli.client.ActionRequest) BatchGetEntityRequest(com.linkedin.restli.client.BatchGetEntityRequest) BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) CreateIdRequest(com.linkedin.restli.client.CreateIdRequest) BatchCreateIdRequest(com.linkedin.restli.client.BatchCreateIdRequest) PartialUpdateRequest(com.linkedin.restli.client.PartialUpdateRequest) BatchPartialUpdateRequest(com.linkedin.restli.client.BatchPartialUpdateRequest) FindRequest(com.linkedin.restli.client.FindRequest) BatchFindRequest(com.linkedin.restli.client.BatchFindRequest) BatchCreateIdRequest(com.linkedin.restli.client.BatchCreateIdRequest) DeleteRequest(com.linkedin.restli.client.DeleteRequest) BatchDeleteRequest(com.linkedin.restli.client.BatchDeleteRequest) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 14 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testBatchingWithNullProjectionFirst.

@Test
public void testBatchingWithNullProjectionFirst() {
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
    batchRequestBuilder1.ids(1);
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
    batchRequestBuilder2.ids(2, 3);
    batchRequestBuilder2.fields(FIELDS.message());
    BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
    @SuppressWarnings("unchecked") BatchGetRequest<TestRecord> batchingRequest = BatchGetRequestBuilder.batch(Arrays.asList(batchRequest1, batchRequestBuilder2.build()));
    Assert.assertEquals(batchingRequest.getBaseUriTemplate(), batchRequest1.getBaseUriTemplate());
    Assert.assertEquals(batchingRequest.getPathKeys(), batchRequest1.getPathKeys());
    Assert.assertEquals(batchingRequest.getFields(), Collections.emptySet());
    Assert.assertEquals(batchingRequest.getObjectIds(), new HashSet<>(Arrays.asList(1, 2, 3)));
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 15 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testSimpleBatchingFailureWithDiffParams.

@Test
public void testSimpleBatchingFailureWithDiffParams() {
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
    batchRequestBuilder1.ids(1, 2).fields(FIELDS.id()).setParam("param1", "value1");
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
    batchRequestBuilder2.ids(2, 3).fields(FIELDS.id(), FIELDS.message()).setParam("param1", "value1").setParam("param2", "value2");
    BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
    BatchGetRequest<TestRecord> batchRequest2 = batchRequestBuilder2.build();
    try {
        @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> batchRequestsList = Arrays.asList(batchRequest1, batchRequest2);
        BatchGetRequestBuilder.batch(batchRequestsList);
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ignored) {
    // Expected
    }
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Aggregations

ResourceMethod (com.linkedin.restli.common.ResourceMethod)54 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)18 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)13 DataMap (com.linkedin.data.DataMap)12 TestRecord (com.linkedin.restli.client.test.TestRecord)12 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)10 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)6 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)6 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)5 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 Foo (com.linkedin.pegasus.generator.examples.Foo)4 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)4 ResourceSchemaArray (com.linkedin.restli.restspec.ResourceSchemaArray)4 JClass (com.sun.codemodel.JClass)4 JDefinedClass (com.sun.codemodel.JDefinedClass)4 ByteString (com.linkedin.data.ByteString)3