Script - Count all children subfolder

Count all children folders - and subfolders into, recursion - into first level folder ( okm:root children folders ).

import com.openkm.api.*;
import com.openkm.bean.*;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.openkm.dao.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
 
class Util {
    public int childCount(String uuid)  {
        String qsUUIDList = "select uuid from NodeFolder nf where nf.parent=:parent";
        Session session = null;
        Transaction tx = null;
        int value = 0;
        List uuidList = new ArrayList();
try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qsUUIDList).setCacheable(true); q.setString("parent", uuid); uuidList = q.list(); HibernateUtil.commit(tx); value = uuidList.size(); print(value); } catch (HibernateException e) { HibernateUtil.rollback(tx); } finally { HibernateUtil.close(session); } for (String childUuid : uuidList) { value = value + childCount(childUuid); } return value; } } Util util = new Util(); for (Folder fld : OKMFolder.getInstance().getChildren(null, "/okm:root")) { print(fld.getPath()+"->"+util.childCount(fld.getUuid())+"<br/>"); }