Hello Justin,
Here is my example code:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import java.util.Vector;
import com.ibm.edms.od.ODConfig;
import com.ibm.edms.od.ODCriteria;
import com.ibm.edms.od.ODFolder;
import com.ibm.edms.od.ODHit;
import com.ibm.edms.od.ODNote;
import com.ibm.edms.od.ODServer;
/**
* @author fc065089
*
*/
public class Main {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out
.println("Usage: Program <Property File> <Doc Id File> <Annotation file>");
System.exit(1);
}
// Handle Property file
String propertyFile = args[0];
Properties prop = new Properties();
prop.load(new FileInputStream(propertyFile));
String cmodServer = prop.getProperty("cmod.server");
int cmodPort = Integer.parseInt(prop.getProperty("cmod.port"));
String cmodUser = prop.getProperty("cmod.user");
String cmodPWD = prop.getProperty("cmod.pwd");
String odwekInstallDir = prop.getProperty("odwek.installdir");
boolean isNotePublic = Boolean.parseBoolean(prop
.getProperty("cmod.annot.public"));
boolean canCopyNote = Boolean.parseBoolean(prop
.getProperty("cmod.annot.copy"));
// Handle Doc IDs
String listDocID = args[1];
// Handle Annotation file
String annotationFile = args[2];
BufferedReader bufferedReader = new BufferedReader(new FileReader(
annotationFile));
StringBuffer annotationText = new StringBuffer();
String line = null;
while ((line = bufferedReader.readLine()) != null)
annotationText.append(line).append("\n");
bufferedReader.close();
ODNote odNote = new ODNote();
odNote.setPublic(isNotePublic);
odNote.setOkToCopy(canCopyNote);
odNote.setText(annotationText.toString());
if (odwekInstallDir != null)
Utils.addLibraryPathUsr(odwekInstallDir);
ODConfig odc = new ODConfig();
ODServer ods = new ODServer(odc);
ods.setPort(cmodPort);
ods.setServerName(cmodServer);
ods.setUserId(cmodUser);
ods.setPassword(cmodPWD);
ods.initialize("Testing annotation");
ods.logon();
bufferedReader = new BufferedReader(new FileReader(listDocID));
HashMap<String, HashMap<String, HashSet<String>>> myList = new HashMap<String, HashMap<String, HashSet<String>>>();
int count = 1;
while ((line = bufferedReader.readLine()) != null) {
if (line.startsWith("#") || "".equals(line.trim()))
continue;
String[] lineSplitted = line.split(";");
if (lineSplitted[0] == null || lineSplitted[1] == null
|| lineSplitted[2] == null
|| "".equals(lineSplitted[0].trim())
|| "".equals(lineSplitted[1].trim())
|| "".equals(lineSplitted[2].trim())) {
System.err.println("WARNING: Problem with line " + count
+ " of file " + listDocID
+ ", the format is 'Folder;FolderField;DocId");
System.err.println("Skipping");
continue;
}
String folder = lineSplitted[0];
String folderField = lineSplitted[1];
String docId = lineSplitted[2];
if (!myList.containsKey(folder))
myList.put(folder, new HashMap<String, HashSet<String>>());
HashMap<String, HashSet<String>> myFields = myList.get(folder);
if (!myFields.containsKey(folderField))
myFields.put(folderField, new HashSet<String>());
HashSet<String> myDocIds = myFields.get(folderField);
myDocIds.add(docId);
count++;
}
bufferedReader.close();
for (String folder : myList.keySet()) {
@SuppressWarnings("unchecked")
Enumeration<String> odfstr = ods.getFolderNames();
boolean found = false;
for (; odfstr.hasMoreElements();) {
String odftmp = odfstr.nextElement();
if (odftmp.equals(folder)) {
found = true;
}
}
if (!found) {
System.err.println("WARNING: Problem for the the folder '"
+ folder + "' because the folder doesn't exist.");
System.err.println("Skipping");
continue;
}
ODFolder odf = ods.openFolder(folder);
for (String folderField : myList.get(folder).keySet()) {
@SuppressWarnings("unchecked")
Enumeration<ODCriteria> odcs = odf.getCriteria();
found = false;
for (; odcs.hasMoreElements();) {
ODCriteria odctmp = odcs.nextElement();
if (odctmp.getName().equals(folderField)) {
found = true;
}
}
if (!found) {
System.err
.println("WARNING: Problem for the Folder Field '"
+ folderField
+ "' in the folder '"
+ folder
+ "' because the folder field doesn't exist in Folder.");
System.err.println("Skipping");
continue;
}
ODCriteria odCrit = odf.getCriteria(folderField);
for (String docId : myList.get(folder).get(folderField)) {
odCrit.setSearchValue(docId);
@SuppressWarnings("unchecked")
Vector<ODHit> odHits = odf.search();
odHits.size();
if (odHits.size() > 1) {
System.err.println("WARNING: Problem the docID '"
+ docId + "' for the Folder Field '"
+ folderField + "' in the folder '" + folder
+ "' because it is not uniq, found "
+ odHits.size() + " entries.");
System.err.println("Skipping");
continue;
} else {
if (odHits.size() == 0) {
System.err.println("WARNING: Problem the docID '"
+ docId + "' for the Folder Field '"
+ folderField + "' in the folder '"
+ folder + "' because it is not found.");
System.err.println("Skipping");
continue;
}
}
if (odHits.get(0).hasPermToAddNotes()) {
odHits.get(0).addNote(odNote);
System.out.println("Note added in folder '" + folder
+ "' " + folderField + "='" + docId + "'");
} else {
System.err
.println("WARNING: Problem the docID '"
+ docId
+ "' for the Folder Field '"
+ folderField
+ "' in the folder '"
+ folder
+ "' because user '"
+ cmodUser
+ "' don't have permission to add annotations.");
System.err.println("Skipping");
}
odHits.clear();
}
}
odf.close();
}
ods.logoff();
ods.terminate();
}
}
I give this code as is, without any support.
It works for me, but it might not work for you!!!
It does only a mass add of one single annotation to many documents.
It requires several information
- Property file
- List of DocIds
- Annotation to add
The property file must have the following entries:
cmod.server=locahost
cmod.port=1445
cmod.user=admin
cmod.pwd=password
odwek.installdir=/usr/lpp/ars/www
cmod.annot.public=true
cmod.annot.copy=false
The format of the file for the DocID is the following:
Folder;Folder Field;DocId
Then the annotation file is really only... the text file, and the whole content will be added to each DocId entries found.
This is a very specific use case, and the code was done in 30 minutes... so don't expect it to be enterprise ready :-D
--
Alessandro