OKMImport

Basics

In almost all methods you'll see a parameter named "parentUuid". The value of this parameter can be a valid document UUID node.

Example of docId:

  • Using UUID -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f"

Also, in all methods you'll see a parameter named "token". Because cron tasks are executed in the background without authentication, the methods used in this scenario might use the token parameter. From the default application execution context you must use the "null" value, which indicates that the application should use the "user session".

In special cases you might be "promoted to Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

createDocument

Description:

MethodReturn valuesDescription

createDocument(String token, String parentUuid, String docName, File file)

NodeDocument

Create a new document.

The parameter parentUuid must be a valid folder or record UUID.

The parameter file is the file of the document.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMImport;
import com.openkm.db.bean.NodeDocument;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class);
            File doc = new File("/home/openkm/sample.pdf");
            NodeDocument nodeDoc = okmImport.createDocument(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "document.pdf", file);
            System.out.println(nodeDoc);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

createFolder

Description:

MethodReturn valuesDescription

createDocument(String token, String parentUuid, String fldName)

NodeFolder

Create a new folder.

The parameter parentUuid must be a valid folder or record UUID.

The parameter fldName is the name of the folder.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMImport;
import com.openkm.db.bean.NodeFolder;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class);
            NodeFolder nodeFld = okmImport.createFolder(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newFolderName");
            System.out.println(nodeFld);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

createRecord

Description:

MethodReturn valuesDescription

createRecord(String token, String parentUuid, String recName)

NodeRecord

Create a new record.

The parameter parentUuid must be a valid folder or record UUID.

The parameter recName is the name of the record.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMImport;
import com.openkm.db.bean.NodeRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class);
            NodeRecord nodeRec = okmImport.createRecord(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newRecordName");
            System.out.println(nodeRec);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

createMail

Description:

MethodReturn valuesDescription

createMail(String token, String parentUuid, File file)

NodeMail

Create a new mail.

The parameter parentUuid must be a valid folder or record UUID.

The parameter file is the file of the mail.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMImport;
import com.openkm.db.bean.NodeMail;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class);
            NodeMail nodeMail = okmImport.createMail(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newMailName");
            System.out.println(nodeMail);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

importFolder

Description:

MethodReturn valuesDescription

importFolder(String token, String parentUuid, File folder, int threads)

void

Import a local folder hierarchy.

The parameter parentUuid must be a valid folder or record UUID.

The value threads sets the number of concurrent threads used by the import feature. This value should never be higher than the number of server cores. If you have 20 cores, a good starting point might be to use 10 threads; take into consideration that other software, such as the database and the OS, are also using the hardware.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMImport;
import com.openkm.db.bean.NodeFolder;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class);
            File fld = new File("/home/openkm/import/");
            okmImport.importFolder(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", fld, 4);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}