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

Do not remove attachments from Document when ignore Blob property in PUT requests

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 9.10
    • Fix Version/s: 9.10-HF19, 10.3
    • Component/s: Automation, Core IO
    • Release Notes Summary:
      Removing attached files is correctly handled in PUT requests.
    • Tags:
    • Backlog priority:
      900
    • Upgrade notes:
      Hide

      Since 10.3, it is now possible to update blob(s) through the REST API when PUTing a document. Nuxeo reads the JSON object for a blob property and tries to resolve a blob from the download url set in the data field.
      The format of the JSON object is:

      {
        "data": "http://SERVER/nuxeo/nxfile/repository/docid/xpath"
      }
      

      All other fields are ignored.

      Nuxeo does the following when trying to resolve a blob:

      • fetch the document
      • fetch the referenced blob property
      • check the download permissions
        If one of the above fails (null, not found, no permission, ...), you get back a Bad Request response (400) when saving the document.

      On 9.10-HF19, it is not enabled by default to avoid any behavior changes. To enable it, you need to contribute the following configuration property:

      <require>org.nuxeo.ecm.core.automation.core.properties</require>
        <extension point="configuration" target="org.nuxeo.runtime.ConfigurationService">
        <property name="nuxeo.automation.object.blob.decoder.enabled">true</property>
      </extension>
      
      Show
      Since 10.3, it is now possible to update blob(s) through the REST API when PUTing a document. Nuxeo reads the JSON object for a blob property and tries to resolve a blob from the download url set in the data field. The format of the JSON object is: { "data": "http://SERVER/nuxeo/nxfile/repository/docid/xpath" } All other fields are ignored. Nuxeo does the following when trying to resolve a blob: fetch the document fetch the referenced blob property check the download permissions If one of the above fails (null, not found, no permission, ...), you get back a Bad Request response (400) when saving the document. On 9.10-HF19, it is not enabled by default to avoid any behavior changes. To enable it, you need to contribute the following configuration property: <require>org.nuxeo.ecm.core.automation.core.properties</require> <extension point="configuration" target="org.nuxeo.runtime.ConfigurationService"> <property name="nuxeo.automation.object.blob.decoder.enabled">true</property> </extension>
    • Sprint:
      nxfit 10.3.5, nxfit 10.3.6
    • Story Points:
      5

      Description

      Sending a PUT request with a payload which tries to update a BlobList property will remove some of the blobs if the payload contains less values than the property.

      Steps to reproduce

      1. Create a File document
      2. Attach 3 files to the attachments (files:files metadata). The resulting JSON is
        {
            "entity-type": "document",
            "repository": "default",
            "uid": "a5aba8bc-d3d2-4500-884d-1cd388cc799b",
            "path": "/default-domain/UserWorkspaces/Administrator/File",
            "type": "File",
            "state": "project",
            "parentRef": "a4071fa3-5335-4daa-8833-a895c53c1ce1",
            "isCheckedOut": true,
            "isVersion": false,
            "isProxy": false,
            "changeToken": "34-0",
            "title": "File",
            "lastModified": "2018-08-22T08:57:52.736Z",
            "properties": {
                "uid:uid": null,
                "uid:major_version": 0,
                "uid:minor_version": 0,
                "thumb:thumbnail": {
                    "name": "attestation.png",
                    "mime-type": "image/png",
                    "encoding": null,
                    "digestAlgorithm": "MD5",
                    "digest": "601a2680ae02481ea717b40f10f9d68f",
                    "length": "5519",
                    "data": "http://nereid2:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/thumb:thumbnail/attestation.png"
                },
                "file:content": {
                    "name": "attestation.doc",
                    "mime-type": "application/msword",
                    "encoding": null,
                    "digestAlgorithm": "MD5",
                    "digest": "a38439b314e9b7a6d32af9391144f65e",
                    "length": "10752",
                    "data": "http://nereid2:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/file:content/attestation.doc"
                },
                "common:icon-expanded": null,
                "common:icon": "/icons/word.png",
                "files:files": [
                    {
                        "file": {
                            "name": "toto0.doc",
                            "mime-type": "application/msword",
                            "encoding": null,
                            "digestAlgorithm": "MD5",
                            "digest": "f34f26891fd8d94c756a366fc0aeb876",
                            "length": "58880",
                            "data": "http://localhost:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/files:files/0/file/toto0.doc"
                        }
                    },
                    {
                        "file": {
                            "name": "toto1.odt",
                            "mime-type": "application/vnd.oasis.opendocument.text",
                            "encoding": null,
                            "digestAlgorithm": "MD5",
                            "digest": "f2518c4c6b994ce95bb3a150f7ecb1ef",
                            "length": "13716",
                            "data": "http://localhost:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/files:files/2/file/toto1.odt"
                        }
                    },
                    {
                        "file": {
                            "name": "toto2.doc",
                            "mime-type": "application/msword",
                            "encoding": null,
                            "digestAlgorithm": "MD5",
                            "digest": "a38439b314e9b7a6d32af9391144f65e",
                            "length": "10752",
                            "data": "http://nereid2:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/files:files/3/file/toto2.doc"
                        }
                    }
                ],
                "dc:description": null,
                "dc:language": null,
                "dc:coverage": null,
                "dc:valid": null,
                "dc:creator": "Administrator",
                "dc:modified": "2018-08-22T08:57:52.736Z",
                "dc:lastContributor": "Administrator",
                "dc:rights": null,
                "dc:expired": null,
                "dc:format": null,
                "dc:created": "2018-08-17T12:10:37.717Z",
                "dc:title": "File",
                "dc:issued": null,
                "dc:nature": null,
                "dc:subjects": [],
                "dc:contributors": [
                    "Administrator"
                ],
                "dc:source": null,
                "dc:publisher": null,
                "relatedtext:relatedtextresources": []
            },
            "facets": [
                "Versionable",
                "Publishable",
                "Commentable",
                "HasRelatedText",
                "Thumbnail"
            ]
        }
        
      3. Run the following cURL command after adapting the UUID and the host
        curl -X PUT \
          http://localhost:8080/nuxeo/api/v1/id/a5aba8bc-d3d2-4500-884d-1cd388cc799b \
          -H 'Accept: text/plain,application/json, application/json' \
          -H 'Authorization: Basic QWRtaW5pc3RyYXRvcjpBZG1pbmlzdHJhdG9y' \
          -H 'Cache-Control: no-cache' \
          -H 'Content-Type: application/json' \
          -H 'Postman-Token: 67197919-de73-4a15-8635-87c17e23d630' \
          -H 'X-NXproperties: *' \
          -d '{
          "entity-type": "document",
          "uid": "a5aba8bc-d3d2-4500-884d-1cd388cc799b",
          "properties": {
            "files:files": [
              {
                    "name": "toto2.doc",
                    "mime-type": "application/msword",
                    "encoding": null,
                    "digestAlgorithm": "MD5",
                    "digest": "a38439b314e9b7a6d32af9391144f65e",
                    "length": "10752",
                    "data": "http://localhost:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/files:files/3/file/toto2.doc"
              }
            ]
          }
        }'
        
      4. Observe that the 2 last attachments have been removed. If the cURL command have had two values for files:files, only the last attachment would have been removed.
        The resulting JSON of the previous command is
        {
          "entity-type": "document",
          "repository": "default",
          "uid": "a5aba8bc-d3d2-4500-884d-1cd388cc799b",
          "path": "/default-domain/UserWorkspaces/Administrator/File",
          "type": "File",
          "state": "project",
          "parentRef": "a4071fa3-5335-4daa-8833-a895c53c1ce1",
          "isCheckedOut": true,
          "isVersion": false,
          "isProxy": false,
          "changeToken": "35-0",
          "title": "File",
          "lastModified": "2018-08-22T09:02:06.441Z",
          "properties": {
            "uid:uid": null,
            "uid:major_version": 0,
            "uid:minor_version": 0,
            "thumb:thumbnail": {
              "name": "attestation.png",
              "mime-type": "image/png",
              "encoding": null,
              "digestAlgorithm": "MD5",
              "digest": "601a2680ae02481ea717b40f10f9d68f",
              "length": "5519",
              "data": "http://localhost:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/thumb:thumbnail/attestation.png"
            },
            "file:content": {
              "name": "attestation.doc",
              "mime-type": "application/msword",
              "encoding": null,
              "digestAlgorithm": "MD5",
              "digest": "a38439b314e9b7a6d32af9391144f65e",
              "length": "10752",
              "data": "http://localhost:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/file:content/attestation.doc"
            },
            "common:icon-expanded": null,
            "common:icon": "/icons/word.png",
            "files:files": [
              {
                "file": {
                  "name": "toto0.doc",
                  "mime-type": "application/msword",
                  "encoding": null,
                  "digestAlgorithm": "MD5",
                  "digest": "f34f26891fd8d94c756a366fc0aeb876",
                  "length": "58880",
                  "data": "http://localhost:8080/nuxeo/nxfile/default/a5aba8bc-d3d2-4500-884d-1cd388cc799b/files:files/0/file/toto0.doc"
                }
              }
            ],
            "dc:description": null,
            "dc:language": null,
            "dc:coverage": null,
            "dc:valid": null,
            "dc:creator": "Administrator",
            "dc:modified": "2018-08-22T09:02:06.441Z",
            "dc:lastContributor": "Administrator",
            "dc:rights": null,
            "dc:expired": null,
            "dc:format": null,
            "dc:created": "2018-08-17T12:10:37.717Z",
            "dc:title": "File",
            "dc:issued": null,
            "dc:nature": null,
            "dc:subjects": [],
            "dc:contributors": [
              "Administrator"
            ],
            "dc:source": null,
            "dc:publisher": null,
            "relatedtext:relatedtextresources": []
          },
          "facets": [
            "Versionable",
            "Publishable",
            "Commentable",
            "HasRelatedText",
            "Thumbnail"
          ]
        }
        

      This behavior may be the consequence of NXP-18488 which sets the property to null when decoding JSON to a BlobProperty where the data starts with http.

      Expect result:
      It is ok to block the update but not to loose some data

      Ideally there should be a way (a third JSONBlobDecoder implementation?) to be able to update a bloblist property.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 days, 2 hours
                  2d 2h

                    PagerDuty

                    Error rendering 'com.pagerduty.jira-server-plugin:PagerDuty'. Please contact your Jira administrators.