Package com.linkedin.data.template

Examples of com.linkedin.data.template.DynamicRecordTemplate


      .build();

    Map<FieldDef<?> , Object> parameters = new HashMap<FieldDef<?> , Object>(1);
    parameters.put(new FieldDef<TransferOwnershipRequest>("request", TransferOwnershipRequest.class,
                                                          DataTemplateUtil.getSchema(TransferOwnershipRequest.class)), ownershipRequest);
    DynamicRecordTemplate requestInput = createDynamicRecordTemplate("transferOwnership", parameters);
    checkRequestBuilder(request, ResourceMethod.ACTION, ActionResponseDecoder.class, expectedUri, requestInput, version);
  }
View Full Code Here


  }

  private static DynamicRecordTemplate createDynamicRecordTemplate(String schemaName, Map<FieldDef<?>, Object> fieldDefs)
  {
    RecordDataSchema recordDataSchema = DynamicRecordMetadata.buildSchema(schemaName, fieldDefs.keySet());
    return new DynamicRecordTemplate(recordDataSchema, fieldDefs);
  }
View Full Code Here

  public void testActionOnSubresource(RootBuilderWrapper<Integer, GroupContact> builders, ProtocolVersion version, String expectedUri)
  {
    Request<Void> request = builders.<Void>action("SpamContacts").setPathKey("groupId", 42).build();

    Map<FieldDef<?> , Object> parameters = new HashMap<FieldDef<?> , Object>(1);
    DynamicRecordTemplate requestInput = createDynamicRecordTemplate("spamContacts", parameters);
    checkRequestBuilder(request, ResourceMethod.ACTION, ActionResponseDecoder.class, expectedUri, requestInput, version);
  }
View Full Code Here

  @Override
  public Object[] buildArguments(RestLiRequestData requestData, RoutingResult routingResult)
  {
    ResourceMethodDescriptor resourceMethodDescriptor = routingResult.getResourceMethod();
    List<Parameter<?>> parameters = resourceMethodDescriptor.getParameters();
    DynamicRecordTemplate template = (DynamicRecordTemplate) requestData.getEntity();
    DataMap data = template.data();
    Object[] arguments = new Object[parameters.size()];
    int i = 0;
    for (Parameter<?> param : parameters)
    {
      Object value;
      if (!data.containsKey(param.getName()))
      {
        if (param.isOptional() && param.hasDefaultValue())
        {
          value = param.getDefaultValue();
        }
        else if (param.isOptional())
        {
          value = null;
        }
        else if (param.getParamType() == Parameter.ParamType.CALLBACK)
        {
          value = null;
        }
        else if (param.getParamType() == Parameter.ParamType.PARSEQ_CONTEXT_PARAM || param.getParamType() == Parameter.ParamType.PARSEQ_CONTEXT)
        {
          value = null;
        }
        else
        {
          throw new RoutingException("Parameter '" + param.getName() + "' of method '"
              + resourceMethodDescriptor.getActionName() + "' is required", HttpStatus.S_400_BAD_REQUEST.getCode());
        }
      }
      else
      {
        try
        {
          value = template.getValue(param);
        }
        catch (TemplateOutputCastException e)
        {
          throw new RoutingException("Parameter '" + param.getName() + "' of method '"
                                         + resourceMethodDescriptor.getActionName() + "' must be of type '"
View Full Code Here

    }
    else
    {
      data = DataMapUtils.readMap(request);
    }
    DynamicRecordTemplate template = new DynamicRecordTemplate(data, resourceMethodDescriptor.getRequestDataSchema());
    ValidationResult result =
        ValidateDataAgainstSchema.validate(data, template.schema(), new ValidationOptions(RequiredMode.IGNORE,
                                                                                          CoercionMode.NORMAL));
    if (!result.isValid())
    {
      throw new RoutingException("Parameters of method '" + resourceMethodDescriptor.getActionName()
          + "' failed validation with error '" + result.getMessages() + "'", HttpStatus.S_400_BAD_REQUEST.getCode());
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    ActionResponseDecoder<V> actionResponseDecoder = new ActionResponseDecoder<V>(responseFieldDef, actionResponseDataSchema);

    return new ActionRequest<V>(new DynamicRecordTemplate(requestDataSchema, _actionParams),
                                _headers,
                                actionResponseDecoder,
                                _resourceSpec,
                                _queryParams,
                                _name,
View Full Code Here

   
    FieldDef<String> actionParam = new FieldDef<String>("param", String.class, DataTemplateUtil.getSchema(String.class));
    DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("bar", Collections.singleton(actionParam));
    DataMap dataMap = new DataMap();
    dataMap.put("param", "paramValue");
    DynamicRecordTemplate input = new DynamicRecordTemplate(dataMap, requestMetadata.getRecordDataSchema());

    FieldDef<String> actionResponse =
        new FieldDef<String>("response", String.class, DataTemplateUtil.getSchema(String.class));
    DynamicRecordMetadata responseMetaData = new DynamicRecordMetadata("bar", Collections.singleton(actionResponse));
    ActionResponseDecoder<String> decoder =
View Full Code Here

    ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, "42").id(1L).build();

    DataMap d = new DataMap();
    d.put("p", "42");
    @SuppressWarnings("unchecked")
    DynamicRecordTemplate expectedRecordTemplate =
        new DynamicRecordTemplate(d, DynamicRecordMetadata.buildSchema("action",
                                                                       Arrays.asList(new FieldDef<String>("p",
                                                                                                          String.class,
                                                                                                          DataTemplateUtil.getSchema(String.class)))));

    testUriGeneration(request, expectedUri, version);
View Full Code Here

TOP

Related Classes of com.linkedin.data.template.DynamicRecordTemplate

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.