Package com.linkedin.restli.restspec

Examples of com.linkedin.restli.restspec.ResourceSchema


    };
  }

  private RichResourceSchema loadResourceSchema(String restspecFile) throws Exception
  {
    ResourceSchema resourceSchema = DataMapUtils.read(new FileInputStream(idlDir + FS + restspecFile), ResourceSchema.class);
    return new RichResourceSchema(resourceSchema);
  }
View Full Code Here


  @Test
  public void test() throws IOException
  {
    final String findersFilename = IDLS_DIR + FINDERS_FILE;
    final ResourceSchema findersIdl = _codec.readResourceSchema(new FileInputStream(findersFilename));
    final FinderSchemaArray finders = findersIdl.getCollection().getFinders();

    for (FinderSchema finder : finders)
    {
      if ("searchWithoutMetadata".equals(finder.getName()))
      {
View Full Code Here

    return parsedModels;
  }

  protected ResourceSchema parseSchema(DataMap data)
  {
    return new ResourceSchema(data);
  }
View Full Code Here

    final ResourceModelEncoder encoder = new ResourceModelEncoder(docsProvider);

    final List<ResourceSchema> rootResourceNodes = new ArrayList<ResourceSchema>();
    for (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.getNamespace() != null)
      {
        final String namespace = rootResourceNode.getNamespace();
        fileName = namespace + "." + fileName;
      }
      if (apiName != null && !apiName.isEmpty())
      {
        fileName = apiName + "-" + fileName;
View Full Code Here

        for (File sourceFile : sources)
        {
          sourceFiles.add(sourceFile);
          try
          {
            ResourceSchema resource = _codec.readResourceSchema(new FileInputStream(sourceFile));
            pushCurrentLocation(new FileDataSchemaLocation(sourceFile));
            generateResourceFacade(resource,
                                   sourceFile.getAbsolutePath(),
                                   new HashMap<String, JClass>(),
                                   new HashMap<String, JClass>(),
View Full Code Here

      for (File idlFile : idlFiles)
      {
        try
        {
          final FileInputStream is = new FileInputStream(idlFile);
          final ResourceSchema resourceSchema = codec.readResourceSchema(is);
          resourceSchemaMap.put(resourceSchema.getName(), resourceSchema);
        }
        catch (IOException e)
        {
          throw new RestLiInternalException(String.format("Error loading restspec IDL file '%s'", idlFile.getName()), e);
        }
View Full Code Here

          ArrayList<ResourceSchema> parents = new ArrayList<ResourceSchema>(hierarchy);
          parents.remove(parents.size()-1);
          _parentResources.put(resourceSchema, parents);

          final ResourceSchema directParent = parents.get(parents.size() - 1);
          List<ResourceSchema> subList = _subResources.get(directParent);
          if (subList == null)
          {
            subList = new ArrayList<ResourceSchema>();
            _subResources.put(directParent, subList);
View Full Code Here

  }

  @Override
  public void renderResource(String resourceName, OutputStream out)
  {
    final ResourceSchema resourceSchema = _resourceSchemas.getResource(resourceName);
    final List<ResourceSchema> parentResources = _resourceSchemas.getParentResources(resourceSchema);
    ExampleRequestResponseGenerator generator = new ExampleRequestResponseGenerator(parentResources, resourceSchema, _schemaResolver);
    if (resourceSchema == null)
    {
      throw new RoutingException(String.format("Resource \"%s\" does not exist", resourceName), HttpStatus.S_404_NOT_FOUND.getCode()) ;
    }

    final Map<String, Object> pageModel = createPageModel();
    pageModel.put("resource", resourceSchema);
    pageModel.put("resourceName", resourceName);
    pageModel.put("resourceFullName", ResourceSchemaUtil.getFullName(resourceSchema));
    pageModel.put("resourceType", getResourceType(resourceSchema));
    pageModel.put("subResources", _resourceSchemas.getSubResources(resourceSchema));

    final List<ResourceMethodDocView> restMethods = new ArrayList<ResourceMethodDocView>();
    final List<ResourceMethodDocView> finders = new ArrayList<ResourceMethodDocView>();
    final List<ResourceMethodDocView> actions = new ArrayList<ResourceMethodDocView>();

    final MethodGatheringResourceSchemaVisitor visitor = new MethodGatheringResourceSchemaVisitor(resourceName);
    ResourceSchemaCollection.visitResources(_resourceSchemas.getResources().values(), visitor);

    for (RecordTemplate methodSchema : visitor.getAllMethods())
    {
      final ExampleRequestResponse capture;
      if (methodSchema instanceof RestMethodSchema)
      {
        RestMethodSchema restMethodSchema = (RestMethodSchema)methodSchema;
        capture = generator.method(ResourceMethod.valueOf(restMethodSchema.getMethod().toUpperCase()));
      }
      else if (methodSchema instanceof FinderSchema)
      {
        FinderSchema finderMethodSchema = (FinderSchema)methodSchema;
        capture = generator.finder(finderMethodSchema.getName());
      }
      else if (methodSchema instanceof ActionSchema)
      {
        ActionSchema actionMethodSchema = (ActionSchema)methodSchema;
        final ResourceLevel resourceLevel = (visitor.getCollectionActions().contains(methodSchema) ?
                                             ResourceLevel.COLLECTION :
                                             ResourceLevel.ENTITY);
        capture = generator.action(actionMethodSchema.getName(), resourceLevel);
      }
      else
      {
        capture = null;
      }

      String requestEntity = null;
      String responseEntity = null;
      if (capture != null)
      {
        try
        {
          DataMap entityMap;

          if (capture.getRequest().getEntity().length() > 0)
          {
            entityMap = DataMapUtils.readMap(capture.getRequest());
            requestEntity = new String(_codec.mapToBytes(entityMap));
          }

          if (capture.getResponse() != null &&
              capture.getResponse().getEntity() != null &&
              capture.getResponse().getEntity().length() > 0)
          {
            entityMap = DataMapUtils.readMap(capture.getResponse());
            responseEntity = new String(_codec.mapToBytes(entityMap));
          }
        }
        catch (IOException e)
        {
          throw new RestLiInternalException(e);
        }
      }

      final ResourceMethodDocView docView = new ResourceMethodDocView(methodSchema,
                                                                      capture,
                                                                      getDoc(methodSchema, resourceSchema.hasSimple()),
                                                                      requestEntity,
                                                                      responseEntity);
      if (methodSchema instanceof RestMethodSchema)
      {
        restMethods.add(docView);
View Full Code Here

      {
        relatedResources = new HashMap<String, ResourceSchema>();
        final Iterator<Node<ResourceSchema>> resourcesItr = node.getAdjacency(ResourceSchema.class).iterator();
        while (resourcesItr.hasNext())
        {
          final ResourceSchema currResource = (ResourceSchema) resourcesItr.next().getObject();
          relatedResources.put(currResource.getName(), currResource);
        }
        _relatedResourceCache.put(parent, relatedResources);
      }

      relatedSchemas = _relatedSchemaCache.get(parent);
      if (relatedSchemas == null)
      {
        relatedSchemas = new HashMap<String, NamedDataSchema>();
        final Iterator<Node<NamedDataSchema>> schemaItr = node.getAdjacency(NamedDataSchema.class).iterator();
        while (schemaItr.hasNext())
        {
          final NamedDataSchema currResource = (NamedDataSchema) schemaItr.next().getObject();
          relatedSchemas.put(currResource.getFullName(), currResource);
        }
        _relatedSchemaCache.put(parent, relatedSchemas);
      }
    }
View Full Code Here

  }

  @Override
  public void renderResource(String resourceName, OutputStream out)
  {
    final ResourceSchema resourceSchema = _relationships.getResourceSchemaCollection().getResource(resourceName);
    if (resourceSchema == null)
    {
      throw new RoutingException(String.format("Resource named '%s' does not exist", resourceName), 404) ;
    }
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.