Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2284

After import node tree all imported nodes lose backreferences

    XMLWordPrintable

Details

    • Hide
      JcrSessionTest.java
          @Test
          public void shouldRestoreBackreferencePropertiesAterImport() throws Exception {
              Node referenceableNode = session.getRootNode().addNode("referenceable");
              referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
              Value strongRefValue = session.getValueFactory().createValue(referenceableNode, false);
      
              Node node1 = session.getRootNode().addNode("node1");
              node1.setProperty("prop1", strongRefValue);
      
              session.save();
      
              ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
              session.exportSystemView("/referenceable", outputStream, false, false);
      
              // Import node tree. This lose backreferences for all nodes in the imported tree
              ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
              session.importXML("/referenceable", inputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
      
              // Now save the changes
              session.save();
      
              PropertyIterator propertyIterator = referenceableNode.getReferences();
              assertEquals(1, propertyIterator.getSize());
          }
      
      Show
      JcrSessionTest.java @Test public void shouldRestoreBackreferencePropertiesAterImport() throws Exception { Node referenceableNode = session.getRootNode().addNode( "referenceable" ); referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString()); Value strongRefValue = session.getValueFactory().createValue(referenceableNode, false ); Node node1 = session.getRootNode().addNode( "node1" ); node1.setProperty( "prop1" , strongRefValue); session.save(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); session.exportSystemView( "/referenceable" , outputStream, false , false ); // Import node tree. This lose backreferences for all nodes in the imported tree ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); session.importXML( "/referenceable" , inputStream, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); // Now save the changes session.save(); PropertyIterator propertyIterator = referenceableNode.getReferences(); assertEquals(1, propertyIterator.getSize()); }

    Description

      After import existing node tree from xml all imported nodes lose backreferences.

      We write workaround helper which store existing backreferences before import and restore them after import:

      // Find in imported xml all nodes that exists in the store and memorize backreferences for them
      BackreferencesRestorerContentHandlerWrapper referrersHandler = new BackreferencesRestorerContentHandlerWrapper(nodeIdentifier, session);
      parser.setContentHandler(referrersHandler);
      parser.parse(new InputSource(new ByteArrayInputStream(buffer)));
      
      // Do import after that we lose backreferences
      session.importXML(path, new ByteArrayInputStream(buffer), ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
      
      // Now we restore backreferences...
      referrersHandler.restoreReferences();
      

      But is bad workaround and not stable for production

      Attachments

        Activity

          People

            rhauch Randall Hauch (Inactive)
            gbelov_jira German Belov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: