Difference between revisions of "Folders deep"
From OpenKM Documentation
(Created page with 'Find folders with some deep. <source lang="java"> // com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath(); import org.hibernate.HibernateException; import org.hibernate.Query…') |
|||
Line 13: | Line 13: | ||
import com.openkm.dao.HibernateUtil; | import com.openkm.dao.HibernateUtil; | ||
import com.openkm.core.Config; | import com.openkm.core.Config; | ||
+ | import com.openkm.api.OKMRepository; | ||
+ | import com.openkm.api.OKMFolder; | ||
Logger log = LoggerFactory.getLogger("com.openkm.folder.deep"); | Logger log = LoggerFactory.getLogger("com.openkm.folder.deep"); | ||
Line 24: | Line 26: | ||
for (NodeBase nb : q.list()) { | for (NodeBase nb : q.list()) { | ||
− | if (depth == MAX_DEPTH) { | + | if (depth == MAX_DEPTH && OKMFolder.getInstance().isValid(null, OKMRepository.getInstance().getNodePath(null, nb.getUuid()))) { |
− | print("uuid:"+nb.getUuid()+ " path:"+OKMRepository.getInstance().getNodePath(null, nb.getUuid())+"<br/>"); | + | print("uuid:"+ nb.getUuid() + " path:"+OKMRepository.getInstance().getNodePath(null, nb.getUuid())+"<br/>"); |
} else if (depth < MAX_DEPTH) { | } else if (depth < MAX_DEPTH) { | ||
findNodePathHelper(session, nb, depth + 1); | findNodePathHelper(session, nb, depth + 1); | ||
Line 46: | Line 48: | ||
for (NodeBase nb : q.list()) { | for (NodeBase nb : q.list()) { | ||
// Process in depth | // Process in depth | ||
− | findNodePathHelper(session, nb, | + | findNodePathHelper(session, nb, 0); |
} | } | ||
Revision as of 09:49, 6 February 2013
Find folders with some deep.
// com.openkm.dao.NodeBaseDAO.getInstance().fixNodePath();
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.core.DatabaseException;
import com.openkm.dao.bean.NodeBase;
import com.openkm.dao.HibernateUtil;
import com.openkm.core.Config;
import com.openkm.api.OKMRepository;
import com.openkm.api.OKMFolder;
Logger log = LoggerFactory.getLogger("com.openkm.folder.deep");
int MAX_DEPTH = 5;
int count = 0;
void findNodePathHelper(Session session, NodeBase parentNode, int depth) throws HibernateException {
String qs = "from NodeBase nb where nb.parent=:parent";
Query q = session.createQuery(qs).setCacheable(true);
q.setString("parent", parentNode.getUuid());
for (NodeBase nb : q.list()) {
if (depth == MAX_DEPTH && OKMFolder.getInstance().isValid(null, OKMRepository.getInstance().getNodePath(null, nb.getUuid()))) {
print("uuid:"+ nb.getUuid() + " path:"+OKMRepository.getInstance().getNodePath(null, nb.getUuid())+"<br/>");
} else if (depth < MAX_DEPTH) {
findNodePathHelper(session, nb, depth + 1);
}
}
}
log.info("***** Process BEGIN *****");
String qs = "from NodeBase nb where nb.parent=:parent";
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
// First level nodes
Query q = session.createQuery(qs);
q.setString("parent", Config.ROOT_NODE_UUID);
for (NodeBase nb : q.list()) {
// Process in depth
findNodePathHelper(session, nb, 0);
}
HibernateUtil.commit(session.getTransaction());
} catch (HibernateException e) {
HibernateUtil.rollback(session.getTransaction());
throw new DatabaseException(e.getMessage(), e);
} finally {
HibernateUtil.close(session);
}
log.info("***** Process END *****");