Script - Count all children subfolder
Count all children folders - and subfolders into, recursion - into first level folder ( okm:root children folders ).
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import com.openkm.api.OKMFolder;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
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 {
SessionFactory sessionFactory = ContextWrapper.getContext().getBean(SessionFactory.class);
session = sessionFactory.openSession();
tx = session.beginTransaction();
Query q = session.createQuery(qsUUIDList).setCacheable(true);
q.setString("parent", uuid);
uuidList = q.list();
tx.commit();
value = uuidList.size();
print(value);
} catch (HibernateException e) {
tx.rollback();
} finally {
session.close();
}
for (Object childUuid : uuidList) {
value = value + childCount((String) childUuid);
}
return value;
}
}
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
Util util = new Util();
// /okm:root = 151f3a54-f370-47d6-801a-d20faecec180
for (Folder fld : okmFolder.getChildren(null, "151f3a54-f370-47d6-801a-d20faecec180")) {
print(fld.getPath() + "->" + util.childCount(fld.getUuid()) + "<br/>");
}