Uploaded image for project: 'Service Packs and Hot Fixes'
  1. Service Packs and Hot Fixes
  2. MNT-21787

Allow list children API (GET /nodes/{nodeId}/children) to filter on all files and folders with matching name pattern using wildcard characters * and ?

    Details

    • Type: Improvement
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 6.2.2
    • Fix Version/s: 6.2.N
    • Component/s: ACS REST API
    • Labels:
      None
    • Bug Priority:
      Category 4
    • ACT Numbers:

      01013507

    • Premier Customer:
      Yes

      Description

      This is a quick win and quick fix for Alfresco.

      In the list children (GET /nodes/{nodeId}/children) of V1 REST API, customer wants Alfresco to add a new filter to the existing list of filters (see image below) for searching for all files and folders with matching name pattern using wildcard characters * and ?. For example, user can enter a filter "where=(name=test*.txt)" to list all files and folders that have names like test*.txt.

      This feature is already available in the FileFolderService.java which the list children API is basically getting its result from. We just need to introduce a new method signature to allow "pattern" to be passed in.

      This is the method in FileFolderServiceImpl.java that the current list children of V1 REST API is using. As you can see, the second parameter in listImpl has been hard coded with a null. This is the exact "pattern" parameter that the customer wants.

          public PagingResults<FileInfo> list(NodeRef rootNodeRef,
                                              Set<QName> assocTypeQNames,
                                              Set<QName> searchTypeQNames,
                                              Set<QName> ignoreAspectQNames,
                                              List<Pair<QName, Boolean>> sortProps,
                                              List<FilterProp> filterProps,
                                              PagingRequest pagingRequest)
          {
              CannedQueryResults<NodeRef> results = listImpl(rootNodeRef, null,  assocTypeQNames, searchTypeQNames, ignoreAspectQNames, sortProps, filterProps, pagingRequest);
              return getPagingResults(pagingRequest, results);
          }
      

      If you look at some other methods in FileFolderService.java, you can see that some methods already allows "pattern" to be passed in, for example, this method:

          /**
           * Lists page of immediate child files and/or folders of the given context node
           * with pattern matching and optional filtering (exclusion of certain child file/folder subtypes) and sorting
           * 
           * Pattern uses '*' as a wildcard
           * 
           * @since 4.0
           */
          @Auditable(parameters = {"contextNodeRef", "files", "folders", "ignoreTypeQNames", "sortProps", "pagingRequest"})
          public PagingResults<FileInfo> list(NodeRef contextNodeRef,
                                            boolean files,
                                            boolean folders,
                                            String pattern,
                                            Set<QName> ignoreTypeQNames,
                                            List<Pair<QName, Boolean>> sortProps,
                                            PagingRequest pagingRequest);
      

      The customer is wondering whether Alfresco can add one more method signature to FileFoderService that accepts "pattern" as a parameter for the list children API to use, something like this:

          /**
           * Lists page of immediate child objects of the given context node
           * with specification of which types to list and optional filtering (exclusion of certain child file/folder subtypes) and sorting
           * @param pattern String
           * @param rootNodeRef NodeRef
           * @param assocTypeQNames QNames of assoc types to list
           * @param searchTypeQNames QNames of node types to list
           * @param pagingRequest PagingRequest
           * @return list of node refs, never null
           */
          @Auditable(parameters = {"rootNodeRef"})
          public PagingResults<FileInfo> list(String pattern, NodeRef rootNodeRef, Set<QName> assocTypeQNames, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, List<FilterProp> filterProps, PagingRequest pagingRequest);
      
      

      And in V1 REST API's NodesImpl.java's listChildren(..) method, call this new method instead, like so:

      String pattern = null;
      
      pattern = propertyWalker.getProperty(PARAM_NAME, WhereClauseParser.EQUALS, String.class);
      
      pagingResults = fileFolderService.list(pattern, parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
      

      Of course, you will also need to add PARAM_NAME to the LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES in NodesImpl.java like so:

          // list children filtering (via where clause)
          private final static Set<String> LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES =
                  new HashSet<>(Arrays.asList(new String[] {PARAM_NAME, PARAM_ISFOLDER, PARAM_ISFILE, PARAM_NODETYPE, PARAM_ISPRIMARY, PARAM_ASSOC_TYPE}));
      

      That's it! All of a sudden, the API will be able to filter on file and folder names.

      Under the hood, this is the SQL query that's executed: "select_GetChildrenCannedQueryWithProps", the "pattern" parameter is basically passed in to a LIKE search so customer can enter something like "name=Test*.txt".

        Attachments

          Structure

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ctan Craig Tan [X] (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Structure Helper Panel