Page 1 of 1
Bulk Export Folders
PostPosted:Fri Apr 14, 2017 6:29 pm
by kennymac
I found the following export example below. However, I do not even know where to begin in setting this up. Also I am not familiar with this language "Permisos de circulación". What I am trying to do is export all documents as PDF in a single folder will be fine. Any help you can provide is greatly appreciated. OpenKM Version is 6.4.24(build: 27101).
Code: Select allimport java.io.File;
import java.io.FileOutputStream;
import java.io.StringWriter;
import com.openkm.util.FileUtils;
import com.openkm.util.impexp.RepositoryExporter;
import com.openkm.util.impexp.TextInfoDecorator;
import com.openkm.util.ArchiveUtils;
import org.apache.commons.io.IOUtils;
// Destination
File file = new File("/home/openkm/import/folderExport.zip");
// OpenKM folder contents to be exported
String fldPath = "/okm:root/Permisos de circulación/import";
FileOutputStream os = new FileOutputStream(file);
StringWriter out = new StringWriter();
File tmp = FileUtils.createTempDir();
RepositoryExporter.exportDocuments(null, fldPath, tmp, false, false, out, new TextInfoDecorator(fldPath));
ArchiveUtils.createZip(tmp, "import", os);
org.apache.commons.io.FileUtils.deleteDirectory(tmp);
IOUtils.closeQuietly(out);
os.flush();
os.close();
Re: Bulk Export Folders
PostPosted:Sat Apr 15, 2017 7:49 am
by jllort
The previous script, use internal repository exporter tool. That will export folders and sub folders with documents into. Seems this is not what you wish, please explain with more detail your problem ( you want doing daily export, based on what ? new documents, documents updated last day, only from some specific folders, export to file system, overwrite existing exported ones, etc... ? explain the problem you are trying to solve and probably we can give you some clues about how doing it ).
If you are a user of professional version 6.4.24 you should use the OpenKM customer website for support. If you ignore how use it, please as for them at the contact website form
https://www.openkm.com/en/contact.html
Re: Bulk Export Folders
PostPosted:Thu Apr 27, 2017 3:13 pm
by kennymac
I apologize for my delayed response, I am trying to export all documents into there folders as a pdf. So I can move away from openkm. It does not work for our needs anymore. I do have the commercial setup but the lic lapsed. If you can help it is greatly appreciated, however I might just pay for them to help on this last case.
Re: Bulk Export Folders
PostPosted:Fri Apr 28, 2017 6:49 pm
by jllort
You do not want to merge all PDF is a single PDF no ? only collect all documents into the repository and export into a single server folder no ?
For it must iterate across the repository ( try understanding what it does this scripts
https://docs.openkm.com/kcenter/view/ok ... rsal-.html ) and then with OKMDocument API you can export documents
https://docs.openkm.com/apidoc/com/okm/ ... ument.html ( must consider two methods getChildren and getContent ). Not much else.
Re: Bulk Export Folders
PostPosted:Fri Apr 28, 2017 7:06 pm
by kennymac
I need to keep the folders/subfolders hierarchy. The different types of documents I have cannot be merged or it will be useless for me.
Re: Bulk Export Folders
PostPosted:Sat Apr 29, 2017 11:27 am
by jllort
Basically with what I provided before you can doing it. It's a simply folders recursive traversal and documents. For each object you must create a folder or write a document in your file system. Except the two openkm methods you will need for getting folders and documents the JAVA code will be exactly as you copy from file system origin to file system destination folders.
Re: Bulk Export Folders
PostPosted:Tue May 02, 2017 9:18 pm
by kennymac
Forgive me for sounding completely ignorant, I am

. Is this a server ran script with a .sh extension or am I a running this through the reports area in web gui? I have created a .sh script located here
https://docs.openkm.com/kcenter/view/ok ... rsal-.html and receive multiple errors.
Code: Select allimport org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.api.*;
import com.openkm.bean.*;
Logger log = LoggerFactory.getLogger("com.openkm.scripting");
int MAX_DEPTH = Integer.MAX_VALUE;
void nodeTask(String path, int depth) throws Exception {
for (Document doc : OKMDocument.getInstance().getChildren(null, path)) {
log.info("Document: {}", doc.getPath());
}
for (Folder fld : OKMFolder.getInstance().getChildren(null, path)) {
log.info("Folder: {}", fld.getPath());
if (depth < MAX_DEPTH) {
nodeTask(fld.getPath(), depth + 1);
}
}
}
log.info("**** Process BEGIN ****");
nodeTask("/okm:root", 0);
log.info("**** Process END ****");
import.im6: unable to open X server `' @ error/import.c/ImportImageCommand/368.
import.im6: unable to open X server `' @ error/import.c/ImportImageCommand/368.
import.im6: unable to open X server `' @ error/import.c/ImportImageCommand/368.
import.im6: unable to open X server `' @ error/import.c/ImportImageCommand/368.
./export.sh: line 6: syntax error near unexpected token `('
./export.sh: line 6: `Logger log = LoggerFactory.getLogger("com.openkm.scripting");'
Re: Bulk Export Folders
PostPosted:Wed May 03, 2017 8:35 pm
by jllort
Script execution : Go to Administration > Scripting and paste there the code.
However for more complete solution I suggest create a jar file (
https://docs.openkm.com/kcenter/view/ok ... lipse.html ) you will get best control of the code rather script, where you can have some mistake and you'll only detect while executing. For example in your case might be interesting a crontab job
https://docs.openkm.com/kcenter/view/ok ... b-job.html