Page 1 of 1

Create 400 folders from list in text file

PostPosted:Thu Oct 13, 2016 2:52 pm
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)

Re: Create 400 folders from list in text file

PostPosted:Sat Oct 15, 2016 8:49 am
by jllort
Take a look here https://wiki.openkm.com/index.php/CSV_importer ( you can get some ideas about how doing it ).

Also you might be interested in https://docs.openkm.com/apidoc/com/okm/6.3.1/ ( look for OKMFolder class )

Re: Create 400 folders from list in text file

PostPosted:Tue Oct 18, 2016 8:48 pm
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>");

Re: Create 400 folders from list in text file

PostPosted:Wed Oct 19, 2016 7:16 am
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);

Re: Create 400 folders from list in text file

PostPosted:Wed Oct 19, 2016 3:45 pm
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.