Thank for you response.
It works finally, I just had to add this bit of code.
Original Message:
Sent: Thu July 11, 2024 05:44 AM
From: Christoph Sünderkamp
Subject: Retrieve annotations / IBM Filenet P8
Hi Mansour
look at the difference between getInstance and fetchInstance: Working with Documents - IBM Documentation
Your code snippet may start a little too late: I don't quite understand what the doc.refresh is supposed to achieve...
The same goes for calling Factory.Document.getInstance... you already have access to the newDoc. Why are you getting it again?
For versioning take a look here: Working with Versioning-related Objects - IBM Documentation
For property caching take a look here: Properties - IBM Documentation I think you have to fetch the Annotations property.
------------------------------
Christoph Sünderkamp
------------------------------
Original Message:
Sent: Tue July 09, 2024 12:14 PM
From: Mansour SOW
Subject: Retrieve annotations / IBM Filenet P8
Hi community,
I finally found a java code in the IBM documentation that lets me copy annotations from one PDF document to another.
I've tested this method, and it works.
However, when I call this method just after creating a new document version (checking), I get an exception (see screenshot) :The Annotations property has been found in the property collection
// copie annotation old doc to new
public void copyAnnotations(Document oldDoc, Document newDoc) {
AnnotationSet oldAnnos = oldDoc.get_Annotations();
Iterator<Annotation> annoIter = oldAnnos.iterator();
while (annoIter.hasNext()) {
Annotation oldAnno = annoIter.next();
ContentElementList oldCEs = oldAnno.get_ContentElements();
ContentElementList newCEs = Factory.ContentElement.createList();
Iterator<ContentElement> ceIter = oldCEs.iterator();
while (ceIter.hasNext()) {
ContentElement ce = ceIter.next();
if (ce instanceof ContentTransfer) {
InputStream is = ((ContentTransfer)ce).accessContentStream();
ContentTransfer ctNew = Factory.ContentTransfer.createInstance();
ctNew.setCaptureSource(is);
// TODO update F_ANNOTATEDID and F_ID in ctNew
newCEs.add(ctNew);
}
}
// Create new Annotation with copied content and associate it to new document
ObjectStore os =oldDoc.getObjectStore();
Annotation newAnno = Factory.Annotation.createInstance(os, oldAnno.get_ClassDescription().get_Id().toString());
newAnno.set_Permissions(oldAnno.get_Permissions());
newAnno.set_ContentElements(newCEs);
newAnno.set_AnnotatedObject(newDoc);
newAnno.save(RefreshMode.REFRESH, null);
}
}
Find below the sample java code where I call the method copyAnnotations :
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
//
doc.refresh();
VersionSeries vs = doc.get_VersionSeries();
Document newDoc =(Document) vs.get_CurrentVersion();
String idNewDoc = newDoc.get_Id().toString();
doc.save(RefreshMode.REFRESH);
if (idNewDoc!=null && idOld!=null) {
Document Oldoc =Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id(idOld) );
Document Newdoc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id(idNewDoc));
copyAnnotations(Oldoc,Newdoc);
}
------------------------------
Mansour SOW
BPM Technical Lead