Skip to content
Other versions

Loading…

OKMImport

In most methods you’ll see a parameter named “parentUuid”. The value of this parameter can be a valid document UUID node.

Also, in all methods you’ll see a parameter named “token”. Because the Cron task is 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 must use the “user session”.

Description:

Method Return values Description
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();
}
}
}

Description:

Method Return values Description
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();
}
}
}

Description:

Method Return values Description
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();
}
}
}

Description:

Method Return values Description
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();
}
}
}

Description:

Method Return values Description
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 exceed 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, like 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();
}
}
}