Page 1 of 1

Not able to update property group by csv importer

PostPosted:Mon May 02, 2016 7:11 pm
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>");

Re: Not able to update property group by csv importer

PostPosted:Thu May 05, 2016 5:17 pm
by umeshj1982
Hi,

Can some one please reply on this. As I have stuck at this point.

Re: Not able to update property group by csv importer

PostPosted:Sat May 07, 2016 6:50 am
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) {

Re: Not able to update property group by csv importer

PostPosted:Sat May 07, 2016 8:04 am
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

Re: Not able to update property group by csv importer

PostPosted:Sat May 07, 2016 7:43 pm
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 ?

Re: Not able to update property group by csv importer

PostPosted:Sun May 08, 2016 7:39 am
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>

Re: Not able to update property group by csv importer

PostPosted:Tue May 10, 2016 4:57 am
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

Re: Not able to update property group by csv importer

PostPosted:Wed May 11, 2016 6:11 pm
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) {

Re: Not able to update property group by csv importer

PostPosted:Thu May 12, 2016 8:29 am
by umeshj1982
Hi,

Can you please elaborate which code to remove or you can post the code as mentioned in first thread along with the removal of mentioned code.

Re: Not able to update property group by csv importer

PostPosted:Sat May 14, 2016 7:58 am
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.