Package com.linkedin.restli.restspec

Examples of com.linkedin.restli.restspec.ResourceSchema


  {
    Request<OptionsResponse> optionsRequest = builders.options().build();
    OptionsResponse optionsResponse = REST_CLIENT.sendRequest(optionsRequest).getResponse().getEntity();
    Map<String, ResourceSchema> resources = optionsResponse.getResourceSchemas();
    Assert.assertEquals(resources.size(), 1);
    ResourceSchema resourceSchema = resources.get("com.linkedin.restli.examples.greetings.client." + resourceName);
    // sanity check the resource schema
    Assert.assertEquals(resourceSchema.getName(), resourceName);
    Assert.assertTrue(resourceSchema.hasCollection());
  }
View Full Code Here


   * @param resourceModel {@link ResourceModel} to build the schema for
   * @return {@link ResourceSchema} for the provided resource model
   */
  public ResourceSchema buildResourceSchema(final ResourceModel resourceModel)
  {
    ResourceSchema rootNode = new ResourceSchema();

    switch (resourceModel.getResourceType())
    {
      case ACTIONS:
        appendActionsModel(rootNode, resourceModel);
        break;
      case SIMPLE:
        appendSimple(rootNode, resourceModel);
        break;
      default:
        appendCollection(rootNode, resourceModel);
        break;
    }

    final DataMap customAnnotation = resourceModel.getCustomAnnotationData();
    if (!customAnnotation.isEmpty())
    {
      rootNode.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
    }

    return rootNode;
  }
View Full Code Here

        return buildResourceSchema(resourceModel);
      }
      else
      {
        DataMap resourceSchemaDataMap = codec.bytesToMap(IOUtils.toByteArray(stream));
        return new ResourceSchema(resourceSchemaDataMap);
      }
    }
    catch (IOException e)
    {
      throw new RuntimeException("Failed to read " + resourceFilePath.toString() + " from classpath.", e);
View Full Code Here

    // subresources
    ResourceSchemaArray subresources = new ResourceSchemaArray();
    for (ResourceModel subResourceModel : resourceModel.getSubResources())
    {
      ResourceSchema subresource = new ResourceSchema();

      switch (subResourceModel.getResourceType())
      {
        case COLLECTION:
        case ASSOCIATION:
          appendCollection(subresource, subResourceModel);
          break;
        case SIMPLE:
          appendSimple(subresource, subResourceModel);
          break;
        default:
          break;
      }

      final DataMap customAnnotation = subResourceModel.getCustomAnnotationData();
      if (!customAnnotation.isEmpty())
      {
        subresource.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
      }

      subresources.add(subresource);
    }
View Full Code Here

    final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);

    final List<ResourceSchema> rootResourceNodes = new ArrayList<ResourceSchema>();
    for (Map.Entry<String, ResourceModel> entry: rootResourceMap.entrySet())
    {
      final ResourceSchema rootResourceNode = encoder.buildResourceSchema(entry.getValue());
      rootResourceNodes.add(rootResourceNode);
    }

    for (ResourceSchema rootResourceNode: rootResourceNodes)
    {
      String fileName = rootResourceNode.getName();
      if (rootResourceNode.hasNamespace())
      {
        final String namespace = rootResourceNode.getNamespace();
        fileName = namespace + "." + fileName;
      }
      if (apiName != null && !apiName.isEmpty())
      {
        fileName = apiName + "-" + fileName;
View Full Code Here

    _currRestspecPath = currRestspecPath;
   
    Stack<Object> path = new Stack<Object>();
    path.push("");

    ResourceSchema prevRec = null;
    ResourceSchema currRec = null;

    try
    {
      prevRec = _codec.readResourceSchema(new FileInputStream(prevRestspecPath));
    }
View Full Code Here

    final DataSchemaResolver schemaResolver = new ClassNameDataSchemaResolver();
    final ValidationOptions valOptions = new ValidationOptions(RequiredMode.MUST_BE_PRESENT);
    ExampleRequestResponse capture;
    ValidationResult valRet;

    final ResourceSchema greetings = resourceSchemas.getResource("greetings");
    ExampleRequestResponseGenerator greetingsGenerator = new ExampleRequestResponseGenerator(greetings, schemaResolver);

    final ResourceSchema groups = resourceSchemas.getResource("groups");
    ExampleRequestResponseGenerator groupsGenerator = new ExampleRequestResponseGenerator(groups, schemaResolver);

    final ResourceSchema groupsContacts = resourceSchemas.getResource("groups.contacts");
    ExampleRequestResponseGenerator groupsContactsGenerator = new ExampleRequestResponseGenerator(Collections.singletonList(groups), groupsContacts, schemaResolver);

    final ResourceSchema greeting = resourceSchemas.getResource("greeting");
    ExampleRequestResponseGenerator greetingGenerator = new ExampleRequestResponseGenerator(greeting, schemaResolver);

    final ResourceSchema actions = resourceSchemas.getResource("actions");
    ExampleRequestResponseGenerator actionsGenerator = new ExampleRequestResponseGenerator(actions, schemaResolver);

    List<ResourceSchema> subResources = resourceSchemas.getSubResources(greeting);
    final ResourceSchema subgreetings = subResources.get(0);
    ExampleRequestResponseGenerator subgreetingsGenerator = new ExampleRequestResponseGenerator(Collections.singletonList(greeting), subgreetings, schemaResolver);

    subResources = resourceSchemas.getSubResources(subgreetings);
    final ResourceSchema subsubgreeting = subResources.get(0);
    ExampleRequestResponseGenerator subsubgreetingGenerator = new ExampleRequestResponseGenerator(Arrays.asList(greeting, subgreetings), subsubgreeting, schemaResolver);

    capture = greetingsGenerator.method(ResourceMethod.GET);
    valRet = validateSingleResponse(capture.getResponse(), Greeting.class, valOptions);
    Assert.assertTrue(valRet.isValid(), valRet.getMessages().toString());
View Full Code Here

    expectedTypes.put("com.linkedin.restli.examples.greetings.client.manualProjections", ResourceType.COLLECTION);
    expectedTypes.put("com.linkedin.restli.examples.scala.client.scalaGreetings", ResourceType.COLLECTION);

    for (Map.Entry<String, ResourceSchema> entry: _schemas.getResources().entrySet())
    {
      final ResourceSchema schema = entry.getValue();
      final ResourceType actualType;
      if (schema.hasCollection())
      {
        actualType = ResourceType.COLLECTION;
      }
      else if (schema.hasAssociation())
      {
        actualType = ResourceType.ASSOCIATION;
      }
      else if (schema.hasSimple())
      {
        actualType = ResourceType.SIMPLE;
      }
      else
      {
        Assert.assertTrue(schema.hasActionsSet());
        actualType = ResourceType.ACTIONS;
      }

      final String schemaFullName = getResourceSchemaFullName(schema, entry.getKey());
      final ResourceType expectedType = expectedTypes.get(schemaFullName);
View Full Code Here

  }

  @Test
  public void testSubresource()
  {
    final ResourceSchema groupsResource = _schemas.getResource("groups");
    final List<ResourceSchema> groupsSubresources = _schemas.getSubResources(groupsResource);
    Assert.assertEquals(groupsSubresources.size(), 1);
    final ResourceSchema groupsContactsResource = groupsSubresources.get(0);
    Assert.assertEquals(groupsContactsResource.getName(), "contacts");
    Assert.assertEquals(groupsContactsResource.getNamespace(), groupsResource.getNamespace());

    final ResourceSchema noNamespaceResource = _schemas.getResource("noNamespace");
    final List<ResourceSchema> actualNoNamespaceSubresources = _schemas.getSubResources(noNamespaceResource);
    Assert.assertEquals(actualNoNamespaceSubresources.size(), 2);

    final Set<String> expectedNoNamespaceSubresources = new HashSet<String>();
    expectedNoNamespaceSubresources.add("noNamespaceSub");
    expectedNoNamespaceSubresources.add("com.linkedin.restli.examples.noNamespace");

    for (ResourceSchema sub: actualNoNamespaceSubresources)
    {
      final String schemaFullName = getResourceSchemaFullName(sub, sub.getName());
      Assert.assertTrue(expectedNoNamespaceSubresources.contains(schemaFullName));
    }

    final ResourceSchema greetingResource = _schemas.getResource("greeting");
    final List<ResourceSchema> greetingSubResources = _schemas.getSubResources(greetingResource);
    Assert.assertEquals(greetingSubResources.size(), 1);
    final ResourceSchema subgreetingsResource = greetingSubResources.get(0);
    Assert.assertEquals(subgreetingsResource.getName(), "subgreetings");
    Assert.assertEquals(subgreetingsResource.getNamespace(), greetingResource.getNamespace());

    final List<ResourceSchema> subgreetingsSubResources = _schemas.getSubResources(subgreetingsResource);
    Assert.assertEquals(subgreetingsSubResources.size(), 1);
    final ResourceSchema subsubgreetingResource = subgreetingsSubResources.get(0);
    Assert.assertEquals(subsubgreetingResource.getName(), "subsubgreeting");
    Assert.assertEquals(subsubgreetingResource.getNamespace(), greetingResource.getNamespace());
  }
View Full Code Here

  private void addPathKeys(AbstractRequestBuilder<?, ?, ?> builder)
  {
    for (Map.Entry<ResourceSchema, ResourceSpec> entry : _parentResources.entrySet())
    {
      ResourceSchema resourceSchema = entry.getKey();
      ResourceSpec resourceSpec = entry.getValue();
      if (resourceSpec.getKeyType() != null)
      {
        switch(toResourceKeyType(resourceSpec.getKeyType().getType()))
        {
          case PRIMITIVE:
          case COMPLEX:
            String keyName = resourceSchema.getCollection().getIdentifier().getName();
            builder.pathKey(keyName, generateKey(resourceSpec, resourceSchema, null));
            break;
          case COMPOUND:
            // old assocKey version
            Map<String, CompoundKey.TypeInfo> keyParts = resourceSpec.getKeyParts();
            for (Map.Entry<String, CompoundKey.TypeInfo> infoEntry : keyParts.entrySet())
            {
              String key = infoEntry.getKey();
              CompoundKey.TypeInfo typeInfo = infoEntry.getValue();
              builder.pathKey(key, _dataGenerator.buildData(key, typeInfo.getBinding().getSchema()));
            }
            // new key version
            String assocKeyName = resourceSchema.getAssociation().getIdentifier();
            builder.pathKey(assocKeyName, generateKey(resourceSpec, resourceSchema, null));
            break;
          case NONE:
            break;
          default:
View Full Code Here

TOP

Related Classes of com.linkedin.restli.restspec.ResourceSchema

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.