BPM, Workflow, and Case

 View Only
  • 1.  Retrieve annotations / IBM Filenet P8

    Posted 19 days ago
    Edited by Mansour SOW 16 days ago

    Hi community,

    I want to retrieve annotations from a lower document version  and add them to a higher version in ibm fileNET P8 using java code.

    In my process, I call up methods for writing on a PDF document, generating a new version of the document each time,I lose the annotations from one version to another.
    Before generating the new version, I wanted to retrieve the annotations from the current version and put them on the newly created one.

    Need yours supports and tips.



    ------------------------------
    Mansour SOW
    BPM Technical Lead
    ------------------------------



  • 2.  RE: Retrieve annotations / IBM Filenet P8

    Posted 12 days ago

    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);
    }
    I need your support.


    ------------------------------
    Mansour SOW
    BPM Technical Lead
    ------------------------------



  • 3.  RE: Retrieve annotations / IBM Filenet P8

    IBM Champion
    Posted 11 days ago

    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
    ------------------------------



  • 4.  RE: Retrieve annotations / IBM Filenet P8
    Best Answer

    Posted 10 days ago
    Edited by Mansour SOW 10 days ago

    Hi Christoph,

    Thank for you response.

    It works finally, I just had to add this bit of code.

    PropertyFilter docpf = new PropertyFilter();

     docpf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_ELEMENTS,null));
     docpf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.ANNOTATED_CONTENT_ELEMENT,null));
     docpf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.ANNOTATED_OBJECT,null));
     docpf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.ANNOTATIONS,null));



    ------------------------------
    Mansour SOW
    BPM Technical Lead
    ------------------------------