Sorting a list of DocumentModel in a pageProvider

Hello,

I have created a new pageProvider in java which extends the CoreQueryDocumentPageProvider. My purpose is to find all the documents in the current document and the documents inside them on and on.

This makes me using a recursive request. So I think I must to do it in java rather than with NXQL.

I am using this pageprovider in a contentview in Studio. But the problem is that the sorting of the table is not working.

Here's my page provider :

public class ListeDetailDossierPageProvider extends
    CoreQueryDocumentPageProvider {

@Override
public List<DocumentModel> getCurrentPage() {

    if (currentPageDocuments == null) {
        currentPageDocuments = new ArrayList<DocumentModel>();
        if (hasError()) {
            return currentPageDocuments;
        }
        setResultsCount(0);

        try {
            executeQuery();
        } catch (ClientException e) {
            errorMessage = e.getMessage();
        }
    }
    return currentPageDocuments;
}

private void executeQuery() throws ClientException {

    Object[] params = getParameters();
    currentPageDocuments = new ArrayList<DocumentModel>();

    if (params != null && params.length == 1 && params[0] != null) {
        currentPageDocuments = getAllChildren(null,
                getCoreSession().getDocument(new IdRef((String) params[0])));
        resultsCount = currentPageDocuments.size();
    }
}

public List<DocumentModel> getAllChildren(List<DocumentModel> list,
        DocumentModel parent) {
    if (list == null) {
        list = new ArrayList<>();
    }

    if (!parent.isFolder()) {
        return list;
    }

    try {
        for (DocumentModel children : getCoreSession().getChildren(parent.getRef())) {
            list.add(children);
            getAllChildren(list, children);
        }
    } catch (ClientException e) {
        return new ArrayList<>();
    }
    return list;
}
0 votes

1 answers

2240 views

ANSWER



Nevermind, I solved my problem. I replace the getCoreSession().getChildren(parent.getRef()) with:

`String nxql = “SELECT * FROM Document WHERE ecm:parentId = "

                + "'" + parent.getId() +"'"
                + " AND ecm:isCheckedInVersion = 0 "
                + "AND ecm:mixinType != 'HiddenInNavigation' "
                + "AND ecm:currentLifeCycleState != 'deleted' "
                + getSortClause(sortInfos);
        List<DocumentModel> childrenList = getCoreSession()
                .query(nxql);`
0 votes