Script - Basic samples

Update repository statistics

Refresh the Statistics.

import com.openkm.core.*;
 
new RepositoryInfo().run();

Show jBPM mail configuration  

import org.jbpm.*;
 
print("Templates: " + JbpmConfiguration.Configs.getString("resource.mail.templates") + "<br/>");
print("From: " + JbpmConfiguration.Configs.getString("jbpm.mail.from.address") + "<br/>");
print("Host: " + JbpmConfiguration.Configs.getString("jbpm.mail.smtp.host") + "<br/>");

Reset user document size 

The application assigns a specific size from the repository to some user ( it's used by user quota exceed checking ).

import com.openkm.dao.bean.cache.*;
import com.openkm.cache.*;
 
UserItems ui = UserItemsManager.get("okmAdmin");
ui.setSize(0);

Refresh user items  

The application internally assign documents to users ( also used by user quota exceed checking )

import com.openkm.cache.*;
 
UserItemsManager.refreshDbUserItems();

Create some folders and set property group

import com.openkm.api.*;
 
for (int i=0; i < 10; i++) {
    String path = "/okm:root/fld_" + i;
    OKMFolder.getInstance().createSimple(null, path);
    OKMPropertyGroup.getInstance().addGroup(null, path, "okg:technology");
}

Show number of documents, folders and size from a given path

import com.openkm.bean.*;
import com.openkm.util.*;
import com.openkm.api.*;
 
ContentInfo ci = OKMFolder.getInstance().getContentInfo(null, "/okm:root/path/to/folder");
print("Folders: " + ci.getFolders() + "<br/>");
print("Documents: " + ci.getDocuments() + "<br/>");
print("Size: " + FormatUtil.formatSize(ci.getSize()) + "<br/>");

Get path by UUID  

import com.openkm.api.OKMRepository;
String path = OKMRepository.getInstance().getNodePath(null, "b99f7973-4b90-457a-a2d0-cf2090ba995d");
print(path);

Show all documents used in every running workflow  

import com.openkm.module.common.CommonWorkflowModule;
import com.openkm.bean.workflow.ProcessDefinition;
import com.openkm.bean.workflow.ProcessInstance;
import com.openkm.core.Config;
 
for (ProcessDefinition procDef : CommonWorkflowModule.findAllProcessDefinitions()) {
    for (ProcessInstance procIns : CommonWorkflowModule.findProcessInstances(procDef.getId())) {
        if (procIns.getEnd() == null) {
            String uuid = (String) procIns.getVariables().get(Config.WORKFLOW_PROCESS_INSTANCE_VARIABLE_UUID);
            print("Doc UUID: " + uuid + ", Process Definition: " + procDef.getId() + ", Process Instance: " + procIns.getId());
        }
    }
}