• Create 400 folders from list in text file

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #42403  by Venusormars2
 
I have a text file (exported from quickbooks) of 400 vendor names. I want to make an empty folder for each one.
Administration -> Import is for openkm export files I think.
Do I need a script?


(I tried searching the forum for create folder script but it said some of the search words are too common and were removed from the search: create and folder and script. HAHA very funny)
 #42428  by Venusormars2
 
Thank you for the direction.

I couldn't get okmfolder.createsimple to work, but I found an example for okmfolder.getinstance.createsimple that works. Here's the whole thing in case it helps someone else; it worked for me:
Code: Select all
import java.io.FileReader;
import java.io.Reader;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
 
import com.googlecode.jcsv.CSVStrategy;
import com.googlecode.jcsv.reader.CSVReader;
import com.googlecode.jcsv.reader.internal.CSVReaderBuilder;
import com.googlecode.jcsv.reader.internal.DefaultCSVEntryParser;

import com.openkm.api.OKMFolder;

String grpName = "okg:metadata";
String FILE_LOG_NAME = "CSVLOG";
String META_PATH = "C:\\Users\\Root\\importfolder\\";
String META_FILE_NAME = "qbvendorlist.csv";
int uniqueFileName = 0;
int valueColumn = 1;
 
// Format defintion
char delimiter = ',';
char quoteCharacter = '"';
char commentIndicator = '#';
boolean skipHeader = true;
boolean ignoreEmptyLines = true;
CSVStrategy strategy = new CSVStrategy(delimiter, quoteCharacter, commentIndicator, skipHeader, ignoreEmptyLines);
// File reader
Reader reader = new FileReader(META_PATH + META_FILE_NAME);
// CSV reader		
CSVReader csvParser = new CSVReaderBuilder(reader).strategy(strategy).entryParser(new DefaultCSVEntryParser()).build();
List data = csvParser.readAll();
int count = 1;
int countFound = 0;
int countNotDocument = 0;
int moreThanOneDocumentFound = 0;
int notFound = 0;
int noName = 0;



for (Iterator it = data.listIterator(); it.hasNext();) {
        String[] row = (String[]) it.next();
        String docPath = row[uniqueFileName];
    	print(count + ">>>> " + docPath);
 
        if (docPath != null && !docPath.equals("")) {
			OKMFolder.getInstance().createSimple(null,"/okm:root/Vendors/" + docPath);
        } else {
            print("error document has no name");
            noName++;
        }
 
        print("</br>");
 
        //FileLogger.info(FILE_LOG_NAME, "Document name ''{0}'' to ''{1}''", row[0], row[posDocRevNo]);
        count++;
}
 
print("Total:" + count + "</br>");
print("Found:" + countFound + "</br>");
print("Error not document:" + countNotDocument + "</br>");
print("Error more then one document found:" + moreThanOneDocumentFound + "</br>");
print("Error not found:" + notFound + "</br>");
print("Error name empty:" + notFound + "</br>");
 #42433  by jllort
 
About the method you are on truth about "OKMFolder.getInstance().createSimple(null,"/okm:root/Vendors/" + docPath);" , where did you found "OKMFolder.createSimple" without the getInstance(), because I will correct it.

Note: If you execute as a crontab task will not going right, the token value = null when calling methods will fail into crontab task. Consider getting systemToken and use it either null value when calling methods:
Code: Select all
String systemToken = DbSessionManager.getInstance().getSystemToken();
OKMFolder.getInstance().createSimple(systemToken,"/okm:root/Vendors/" + docPath);
 #42438  by Venusormars2
 
In the apidoc link you posted, I looked at OKMFolder and createSimple was listed as a method. I haven't done any programming recently and there are no usage examples on the okmfolder page so I assumed I could use it like OKMFolder.createSimple.
So you don't need to fix anything.

That's good to know about systemtoken. I might need that some day.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.