• Not able to update property group by csv importer

  • 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.
 #41725  by umeshj1982
 
Hi,
I am not able to upload the metadata with csv importer.

below is my CSV importer program. It is having 7 metadata fileds.

The program is updating property group but it is not uploading the data in property group. So can someone help in this case.
Code: Select all
import java.io.Reader;
import java.io.FileReader;
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.dao.bean.QueryParams;
import com.openkm.bean.QueryResult;
import com.openkm.api.OKMSearch;
import com.openkm.util.FileLogger;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.PathUtils;

String grpName = "okg:kp";
String FILE_LOG_NAME = "CSVLOG";
String META_PATH = "D:/csv/";
String META_FILE_NAME = "Test.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("")) {
        QueryParams queryParams = new QueryParams();
        queryParams.setDomain(QueryParams.DOCUMENT);
        queryParams.setName(PathUtils.getName(docPath));
        Collection results = OKMSearch.getInstance().find(null, queryParams);

        if (results.size() == 1) {
            QueryResult queryResult = (QueryResult) results.iterator().next();
            if (queryResult.getDocument() != null) {
                print("found");
                countFound++;
                
                // Add Group
                OKMPropertyGroup.getInstance().addGroup(null, docPath, grpName);

                // Add metadata
                Map map = new HashMap();
                map.put("okp:kp.value", row[valueColumn]);
                OKMPropertyGroup.getInstance().setPropertiesSimple(null, docPath, grpName, map);
            } else {
                print("error is not document");
                countNotDocument++;
            }
        } else if (results.size() > 1) {
            print("error more than one document found can not decide");
            moreThanOneDocumentFound++;
        } else {
            print("not found");
            notFound++;
        }
    } 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>");
 #41751  by jllort
 
This scripts goes applies a logic what considers:
- Into de repository the document exists
- Into the repository only exists a documents with the name into the csv

How is your csv ( post few lines here ).

I suppose your code never goes into the if (results.size() == 1) {
 #41755  by umeshj1982
 
Hi Jilliort,

Sample csv format is pasted below. The property group is getting updated by this but the data is not getting imported so please help in this case.
Code: Select all
/okm:root/KP/2008/AE10320.pdf,AE10320,GLOBAL DIAMOND TENDERS DMCC,SHREE RAMKRISHNA EXPORT,174.23,62351.65,05-08-2008,07-06-2008
/okm:root/KP/2008/AE10323.pdf,AE10323,Simex,Kanubhai B. Shah & CO.,1147.7,1541648.03,05-11-2008,07-09-2008
/okm:root/KP/2008/AE10346.pdf,AE10346,Sparkling Gems L.L.C.,S. Vinod Kumar Diamonds Pvt. Ltd.,1762.39,398653.23,13-05-2008,07-11-2008
 #41756  by jllort
 
When you talk about, the property group is updated but not the data ? what are you talking about the data ?

If document name is unique across all the repository "AE10320.PDF" is not necessary you set all the path, with name will be enought ( but you should make minimal changes in script ).

Which is your metadata xml definition ?
 #41758  by umeshj1982
 
Hi,

Below is the xml for property group
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//openkm//DTD Property Groups 2.0//EN" "H:\openkm\tomcat/property-groups-2.1.dtd">
<property-groups>
  <property-group label="Certificate Number" name="okg:certifcatenumber" readonly="false" visible="true">
    <input label="Certificate Number" name="okp:certificatenumber" readonly="false" type="text"/>
  </property-group>
  <property-group label="metadata" name="okg:metadata" readonly="false" visible="true">
    <input label="document id" name="okp:metadata.docid" readonly="false" type="text"/>
  </property-group>
  <property-group label="KP" name="okg:kp" readonly="false" visible="true">
    <input label="Certificate Number" name="okp:kp.certificatenumber" readonly="false" type="text"/>
    <input label="Name of Exporter" name="okp:kp.nameofexporter" readonly="false" type="text"/>
    <input label="Name of Importer" name="okp:kp.nameofimporter" readonly="false" type="text"/>
    <input label="Carat weight" name="okp:kp.caratweight" readonly="false" type="text"/>
    <input label="Carat value" name="okp:kp.caratvalue" readonly="false" type="text"/>
    <input label="Date of Issue" name="okp:kp.dateofissue" readonly="false" type="text"/>
    <input label="Date of Expiry" name="okp:kp.dateofexpiry" readonly="false" type="text"/>
  </property-group>
</property-groups>
 #41763  by umeshj1982
 
Hi,

I got some success in the property group updation by csv. Now I am getting below error. Can you please help me in resolving the issue. In this case all files are in unique name also no other file is updated in any other folder with same name.
Code: Select all
1>>>> /okm:root/KP/2013/HK1320477.pdf error more than one document found can not decide 
2>>>> /okm:root/KP/2013/HK1320478.pdf error more than one document found can not decide 
3>>>> /okm:root/KP/2013/HK1320479.pdf error more than one document found can not decide 
4>>>> /okm:root/KP/2013/HK1320480.pdf error more than one document found can not decide 
5>>>> /okm:root/KP/2013/HK1320482.pdf error more than one document found can not decide
 #41771  by jllort
 
The error is clear. The logic suppose only exist one document named "XXXXX" in the whole repository, but search returns more than one document with the same name, could in trash or other subfolders.
Code: Select all
QueryParams queryParams = new QueryParams();
queryParams.setDomain(QueryParams.DOCUMENT);
queryParams.setName(PathUtils.getName(docPath));
Because you have the final path, can use it, without making a search for setting the metadata ( basically not executing the query and using docPath ).

Remove this section and will going right for you ( hope you have understood why you are getting this error ? )
Code: Select all
QueryParams queryParams = new QueryParams();
queryParams.setDomain(QueryParams.DOCUMENT);
queryParams.setName(PathUtils.getName(docPath));
Collection results = OKMSearch.getInstance().find(null, queryParams);

if (results.size() == 1) {
 #41785  by jllort
 
I suggest you take control about what you have in your hands. Take the code in the documentation as an starting point. We suggest build your own step by step, understanding each piece of code and what is doing.

As I explained before, the sample code makes a query ( search engine ) looking a document named XXXX. In your case, probably you do not need it and can execute directly it "OKMPropertyGroup.getInstance().addGroup(null, docPath, grpName);" without doing the query.

Put the code for you is not the solution if you do not understanding what are you doing, is always better ( and we know tedious ) investigate and test, for getting real control on what are you doing. The expended time on it is always a good investment.

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.