Search code examples
javadatabaselotus-domino

Take databalse1's embeddedObjects to another database2 notes in JavaAgent


I try to put piece of document of database1 to another document of another database2.

DatabaseOld => documentOld DatabaseNew => documentNew

documentOld => documentNew

When I try to extract the document the program crash and the message is : "the object store database is disabled (c:/temp/1514548644864864/Original.jpg)"

I call my method with this :

List<PieceJointeDTO> pieceJointeToRenvoyers = gererPieceJointe(champ, nomChamp, nomRepertoire);

and this is my method :

private List<PieceJointeDTO> gererPieceJointe(RichTextItem rti, String nomChamp, String nomRepertoire)  {

        List<PieceJointeDTO> pieceJointeToRenvoyers = new ArrayList<PieceJointeDTO>();      
        String namePieceJointe = "";        
        Vector<?> vector1 = null;
        Enumeration<?> enumera1;
        EmbeddedObject embeddedObject1 = null;      
        boolean debut = true;       
        EmbeddedObject embeddedTemp = null;

        try 
        {
            // récupère les pièces jointes          
            try 
            {               
                vector1 = rti.getEmbeddedObjects();

                enumera1 = vector1.elements();

                while (enumera1.hasMoreElements()) 
                {       
                    //recycle l'objet si ce n'est pas le premier passage du while
                    if (debut == true)
                    {
                        embeddedObject1 = (EmbeddedObject) enumera1.nextElement();                      
                        debut = false;
                    }   else
                    {
                        embeddedTemp = (EmbeddedObject) enumera1.nextElement(); 
                        embeddedObject1.recycle();
                        embeddedObject1 = embeddedTemp; 
                    }

                    //si l'objet est une pièce jointe
                    if (embeddedObject1.getType() == EmbeddedObject.EMBED_ATTACHMENT) 
                    {                       
                        namePieceJointe = embeddedObject1.getName();                                                        

                        //recupere la taille du fichier joint
                        monDocNew.replaceItemValue(nomChamp, embeddedObject1.getFileSize()); 

                        //extrait la pièce jointe et la copie dans un objet File 
                        String chemin = nomRepertoire + namePieceJointe;
                        if (!new File(nomRepertoire).exists()) 
                        {                                       
                            // Créer le dossier avec tous ses parents
                            new File(nomRepertoire).mkdirs();
                        }
                        System.out.println("extratfile");
                        embeddedObject1.extractFile(chemin);  <= it's here
                        System.out.println("fin extratcfile");
                        File tempPieceJointe = new File(chemin);            

                        PieceJointeDTO pieceJointeToInsert = buildPieceJointe(tempPieceJointe, namePieceJointe, chemin);                            
                        pieceJointeToRenvoyers.add(pieceJointeToInsert);

                        pieceJointeToInsert = null;                                                 
                    }                                       
                }
            } finally
            {
                vector1 = null;
                enumera1 = null;

                UtilMemoire.purgeMemoire();
            }
        } catch (NotesException e) {
            System.out.println("ERREUR notes " + namePieceJointe + " sur méthode gererPieceJointe() sur javaagent phototheque");
             e.printStackTrace();
        }
        return pieceJointeToRenvoyers;
    }

Normally, my method works when I put the piece of document in enreg DB2. I can put some elements in another database if I don't use textrich (only string for exemple).

I open the two database correctly, I don't understand what's happen? Could you help me ?


Solution

  • If you're using DAOS on a Domino version 8.5.1 then look at: http://www-10.lotus.com/ldd/nd85forum.nsf/7756aedc25e6d81285256324005ac76c/54eb57a653ebc3bdca2579c1001d79a7?OpenDocument then you need to upgrade!

    I suggest you to copy the whole document to the new DB and update the "new document" in the copied document (remove unecessary items for example) it will avoid the pain of attachments. You can use:

    Document doc = dc.getFirstDocument();
    Document docCopy = db.createDocument();
    doc.copyAllItems(docCopy, false);
    

    my prevered solution if I need to change the doc NB dont forget to if (docCopy.save()), see the example in help

    OR

    doc.copyToDatabase(newdb);
    

    NB I feel that your special treatment for the first iteration of the loop is not optimized (remark "le premier passage du while" in your code, NB rigolo les commentaires en francais ;-) using directly enumera1.nextElement() would be better see an example in Can I get access to Lotus Notes embedded files without actually extracting them?