Finding People by a Term - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

To find sites by term use the findPeople 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 People by a Term.

For a description of the common parameters, such as fields, see Common Parameters.

import org.alfresco.core.handler.QueriesApi;
import org.alfresco.core.model.PersonEntry;
import org.alfresco.core.model.PersonPagingList;
import org.alfresco.core.model.SiteEntry;
import org.alfresco.core.model.SitePagingList;
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 FindPeopleCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(FindPeopleCmd.class);

    @Autowired
    QueriesApi queriesApi;

    public void execute() throws IOException {
        Integer skipCount = 0;
        Integer maxItems = 100;

        List<String> orderBy = null;
        List<String> fields = null;

        String term = "*mi*";
        LOGGER.info("Searching for people by term: {}", term);
        PersonPagingList result = queriesApi.findPeople(term, skipCount, maxItems, fields, orderBy).getBody().getList();
        for (PersonEntry person: result.getEntries()) {
            LOGGER.info("Found person [id={}][name={}]", person.getEntry().getId(), person.getEntry().getDisplayName());
        }
    }
}

Executing this code gives the following type of result:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar find-people

2021-05-10 14:00:38.019  INFO 55327 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.568 seconds (JVM running for 4.045)
2021-05-10 14:00:38.021  INFO 55327 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: find-people
2021-05-10 14:00:38.022  INFO 55327 --- [           main] o.a.tutorial.restapi.FindPeopleCmd       : Searching for people by term: *mi*
2021-05-10 14:00:38.839  INFO 55327 --- [           main] o.a.tutorial.restapi.FindPeopleCmd       : Found person [id=admin][name=Administrator]
2021-05-10 14:00:38.839  INFO 55327 --- [           main] o.a.tutorial.restapi.FindPeopleCmd       : Found person [id=mjackson][name=Mike Jackson]