Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

'depth' query parameter added in below URLsNotesDecision
URL: http://<IP:PORT>/v1v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/node?xpath=/&include-descendants=true&depth=1
  • depth is an optional query parameter or mandatory 
  • how to handle include-descendants query parameter? can we remove this parameter and use only depth parameter.  depth = -1 is same as include-descendants= true 
  • depth values treated as below
  • -1 : all descendants 
  • 0 : no descendants
  • 1, 2, 3, ... : number or descendants  {all | none | number}

    descendants is optional query parameter with default value of "all". possible values of descendants is as below :

    1.  all : to get all descendants 
    2.  none: don't include descendants
    3.  number : positive number 1 to n, to query nodes till nth descendant 
    1. we need to support different version for this query API for backward compatibility 
    URL: http://<IP:PORT>/v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query?cps-path=/&include-descendents=true&depth=1descendants={all | none | number}

    descendants is optional query parameter with default value of "all". possible values of descendants is as below :

    1.  all : to get all descendants 
    2.  none: don't include descendants
    3.  number : positive number 1 to n, to query nodes till nth descendant 
    1. we need to support different version for this query API for backward compatibility 




    Implementations: 


    changes files changes/notesDecision
    cpsData.yml
    nodeByDataspaceAndAnchor:
    get:
    ...
          - $ref: 'components.yml#/components/parameters/depthInQuerydescendantsInQuery'
    ...

    cpsQuery.yml
    nodesByDataspaceAndAnchorAndCpsPath:
    get:
    ...
    - $ref: 'components.yml#/components/parameters/depthInQuerydescendantsInQuery'
    ...

    components.yml
    depthInQuerydescendantsInQuery:
    name: depthdescendants
    in: query
    description: depthdescendants parameter for large query outputs to limit descendants. use "all", "none" or number
    required: false
    schema:
    type: string
    default: all
    example: 13
    pattern: <use pattern to validate accepted values for descendants>

    DataRestController.java
    @Override
    public ResponseEntity<Object> getNodeByDataspaceAndAnchor(final String dataspaceName, final String anchorName,
    FetchDescendantsOption.java

    We Need to change this class to accept for any other depth values except -1, 0 and 1.  

    Do we need to change FetchDescendantsOption to support multiple depths or add depth as separate argument along

    with FetchDescendantsOption

    FragmentRepository.java
    @Query(value = "SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId,"
    + " CAST(attributes AS TEXT) AS attributes"
    +final "String FROMxpath, FRAGMENTfinal WHERE anchor_id = :anchorId"String descendants) {
    +final "FetchDescendantsOption ANDfetchDescendantsOption ( xpath = :parentXpath OR xpath LIKE CONCAT(:parentXpath,'/%') )"= Boolean.TRUE.equals(includeDescendants),
    nativeQuery = true)
    List<FragmentExtract> findByAnchorIdAndParentXpath(@Param("anchorId") int anchorId,? new FetchDescendantsOption(depth) : FetchDescendantsOption.OMIT_DESCENDANTS;
    final DataNode dataNode = cpsDataService.getDataNode(dataspaceName, anchorName, xpath,
    fetchDescendantsOption, depth);
    final String prefix @Param("parentXpath") String parentXpath, = prefixResolver.getPrefix(dataspaceName, anchorName, xpath);
    return new @Param("depth") Integer depth);
    we need to change query to support depth or we can query all fragments and then select fragment data till given depth value(in below code). 
    FragmentEntityArranger.java
    private static FragmentEntity reuniteChildrenWithTheirParents(final Map<Long, 
    FragmentEntity> fragmentEntityPerId, Integer depthResponseEntity<>(DataMapUtils.toDataMapWithIdentifier(dataNode, prefix), HttpStatus.OK);
    }

    private FetchDescendantsOption getFetchDescendantsOption(String descendants) {
    final Collection<FragmentEntity> fragmentEntitiesWithoutParentInResultSet = new HashSet<>();
    for (final FragmentEntity fragmentEntity : fragmentEntityPerId.values()) if("all".equals(descendants)){
    final FragmentEntity parentFragmentEntity = fragmentEntityPerId.get(fragmentEntity.getParentId());return FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
    }
    else if (parentFragmentEntity == null) ("none".equals(descendants)){
    return
    fragmentEntitiesWithoutParentInResultSet.add(fragmentEntity);
    FetchDescendantsOption.OMIT_DESCENDANTS;
    } else {
    return
    parentFragmentEntity.getChildFragments().add(fragmentEntitynew FetchDescendantsOption(Integer.valueOf(descendants));
    }
    }
    return fragmentEntitiesWithoutParentInResultSet.stream().findFirst().orElse(null);
    }
    we can reunite children as per given depth value.