Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-25472

Fix 'DocumentModel#copyContent' when source document has dynamically-added facets and schemas

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 8.10, 9.10, 10.2
    • Fix Version/s: 8.10-HF35, 9.10-HF14, 10.3
    • Component/s: Core

      Description

      The rendition service, during the rendition process (class RenditionCreator), creates a copy of the source document (create document with same doc type + copy facets/schemas) using DocumentModel#copyContent. The problem is that copyContent expects both source and destination document to have the same schemas, which is not always the case i.e. the source document is member of a collection, meaning it was dynamically assigned an additonal schema collectionMember (by adding facet CollectionMember). In this case, the destination document won't have this schema at creation time, subsequent call to saveDocument would then throw an exception because of the missing fields in the destination document.

      Also make sure that the dynamically-added facets are not copied because it could produce a data inconsistency, the facet is copied but the associated schema is not, a service could rely on the fact that the facet is present to presume the associated schema is present too.

      Here is a unit test to demonstrate the exception:

      	@Test
      	public void testCanCopyContentOfDocumentInACollectionAndSaveTarget() {
      		DocumentModel testWorkspace = session.createDocumentModel("/default-domain/workspaces", "testWorkspace",
      				"Workspace");
      		testWorkspace = session.createDocument(testWorkspace);
      		DocumentModel testFile1 = session.createDocumentModel(testWorkspace.getPathAsString(), "File 1", "File");
      		testFile1 = session.createDocument(testFile1);
      
      		DocumentModel testFile2 = session.createDocumentModel(testWorkspace.getPathAsString(), "File 2", "File");
      		testFile2 = session.createDocument(testFile2);
      
      		collectionManager.addToNewCollection(COLLECTION_NAME, COLLECTION_DESCRIPTION, testFile1, session);
      		assertTrue(collectionManager.isCollected(testFile1));
      		assertFalse(collectionManager.isCollected(testFile2));
      
      		testFile2.copyContent(testFile1);
      		testFile2 = session.saveDocument(testFile2);
      		assertFalse(collectionManager.isCollected(testFile2));
      	}
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours
                2h