To find a node, such as a folder or file, by a term use the findNodes method of the QueriesApi, which is a search API you can use when doing simple search on a term. For more complex search, such as Alfresco Full Text Search (AFTS), use the Search API (see Finding Content by a Search Query).
For more information about this ReST API endpoint, see Finding Folders and Files by a Term.
For a description of the common parameters, such as include, see Common Parameters.
import org.alfresco.core.handler.QueriesApi; import org.alfresco.core.model.NodeEntry; import org.alfresco.core.model.NodePagingList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.List; @Component public class FindNodesCmd { static final Logger LOGGER = LoggerFactory.getLogger(FindNodesCmd.class); @Autowired QueriesApi queriesApi; public void execute() throws IOException { String rootNodeId = "-root-"; // The id of the node to start the search from. Supports the aliases -my-, -root- and -shared-. Integer skipCount = 0; Integer maxItems = 100; // Restrict the returned results to only those of the given node type and its sub-types String nodeType = null; List<String> include = null; List<String> orderBy = null; List<String> fields = null; String term = "Dict*"; LOGGER.info("Searching for nodes by term: {}", term); NodePagingList result = queriesApi.findNodes( term, rootNodeId, skipCount, maxItems, nodeType, include, orderBy, fields).getBody().getList(); for (NodeEntry node: result.getEntries()) { LOGGER.info("Found node [name={}][id={}]", node.getEntry().getName(), node.getEntry().getId()); } } }
Executing this code gives the following type of result:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar find-nodes 2021-05-10 13:40:47.999 INFO 54955 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.429 seconds (JVM running for 3.909) 2021-05-10 13:40:48.001 INFO 54955 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: find-nodes 2021-05-10 13:40:48.003 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Searching for nodes by term: Dict* 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Dictionary][id=b1264564-9b33-4003-bff9-58f2591cea54] 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Dictionary-stuff.txt][id=6f7689af-b31e-493a-ad3a-298abcf03664] 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=InviteHelper.txt][id=4875faf1-6366-477a-a97b-b30d15f33808] 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Data Dictionary][id=392f377c-4a0b-4ab1-8327-3034269030a5] 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=readme.html][id=d38b8cb0-0973-4bfd-84c5-9db4959d4715] 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Project Contract.pdf][id=1a0b110f-1e09-4ca2-b367-fe25e4964a4e] 2021-05-10 13:40:49.143 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Meeting Notes 2011-02-10.doc][id=a8290263-4178-48f5-a0b0-be155a424828] 2021-05-10 13:40:49.144 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Meeting Notes 2011-02-03.doc][id=150398b3-7f82-4cf6-af63-c450ef6c5eb8] 2021-05-10 13:40:49.144 INFO 54955 --- [ main] o.a.tutorial.restapi.FindNodesCmd : Found node [name=Meeting Notes 2011-01-27.doc][id=f3bb5d08-9fd1-46da-a94a-97f20f1ef208]