Difference between revisions of "Knowledge:Script Utilities"

From OpenKM Documentation
Jump to: navigation, search
Line 2: Line 2:
 
<source lang="java">
 
<source lang="java">
 
import com.openkm.spring.PrincipalUtils;
 
import com.openkm.spring.PrincipalUtils;
 +
import java.util.*;
  
 +
HashSet roles = PrincipalUtils.getRoles();
 +
for (Iterator it = roles.iterator(); it.hasNext();) {
 +
    String role = (String) it.next();
 +
    print("{"+role+"}<br/>");
 +
}
 +
 
print(PrincipalUtils.getRoles());
 
print(PrincipalUtils.getRoles());
 
</source>
 
</source>

Revision as of 17:18, 14 November 2012

Get principals

import com.openkm.spring.PrincipalUtils;
import java.util.*;

HashSet roles = PrincipalUtils.getRoles();
for (Iterator it = roles.iterator(); it.hasNext();) {
    String role = (String) it.next();
    print("{"+role+"}<br/>");
}
 
print(PrincipalUtils.getRoles());

List missing datastore document

import com.openkm.module.db.stuff.*;
import com.openkm.dao.bean.*;
import com.openkm.dao.*;

for (NodeDocumentVersion ndv : NodeDocumentVersionDAO.getInstance().findAll()) {
    String verUuid = ndv.getUuid();
    File file = FsDataStore.resolveFile(verUuid);
    
    if (!file.exists()) {
        String docUuid = ndv.getParent();
        String docPath = NodeBaseDAO.getInstance().getPathFromUuid(docUuid);
        print("File: " + file + "<br/>");
        print("Path: " + docPath + "<br/>");
    }
}

Force text extraction from a folder

import com.openkm.dao.bean.*;
import com.openkm.dao.*;

void changeNodes(String parentUuid) {
    for (NodeFolder nFld : NodeFolderDAO.getInstance().findByParent(parentUuid)) {
        print("Folder: " + nFld.getUuid() + "<br/>");
        changeNodes(nFld.getUuid());
    }
    
    for (NodeDocument nDoc : NodeDocumentDAO.getInstance().findByParent(parentUuid)) {
        print("Document: " + nDoc.getUuid() + "<br/>");
        NodeDocumentDAO.getInstance().resetPendingExtractionFlag(nDoc.getUuid());
    }
}

changeNodes("folder-uuid");