Script - Change the author of the documents into folder
Esta página aún no está disponible en tu idioma.
The script changes the author of all the documents into some folder and subfolder childs.
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;import com.openkm.api.*;
class Util { public void changeAuthor(String uuid) { String qsUUIDList = "select uuid from NodeDocument nf where nf.parent=:parent"; Session session = null; Transaction tx = null; int value = 0; List uuidList = new ArrayList();
try { // Get document by folder ( parent node is the folder uuid ) session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Query q = session.createQuery(qsUUIDList).setCacheable(true); q.setString("parent", uuid); uuidList = q.list();
// Change document versions author for (String docUUID : uuidList) { // Document version ( parent node is the document uuid ) q = session.createQuery("update NodeDocumentVersion set author=:author where parent=:parent"); q.setString("parent", docUUID); q.setString("author", "newAuthor"); q.executeUpdate(); // Document first creation author ( uuid is the main node UUID in the node base ) q = session.createQuery("update NodeBase set author=:author where uuid=:uuid"); q.setString("uuid", docUUID); q.setString("author", "newAuthor"); q.executeUpdate(); } HibernateUtil.commit(tx);
} catch (HibernateException e) { HibernateUtil.rollback(tx); } finally { HibernateUtil.close(session); } }
public void renameDocumentsAuthorInFolder(String fldUuid) { changeAuthor(fldUuid); for (Folder fld : OKMFolder.getInstance().getChildren(null, fldUuid)) { renameDocumentsAuthorInFolder(fld.getUuid()); } }}
String fldUUID = OKMRepository.getInstance().getNodeUuid(null, "/okm:root/importOne");Util util = new Util();util.renameDocumentsAuthorInFolder(fldUUID);