Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-4946

Getting error when uploading a file after creating a data resource.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Release Branch 11.04, Trunk
    • Fix Version/s: 14.12.01, 12.04.06, 13.07.02
    • Component/s: content
    • Labels:
      None

      Description

      Steps to generate error -

      • Content -> DataResource -> Create New

      Case 1 -

      • Create a data resource of type '*_FILE' and remain objectInfo field empty.
      • Then go to upload tab, here getting an error in the file preview section - "java.lang.NullPointerException".
      • Browse and upload a file.
      • It throws an error -
        "Error in Service [persistContentAndAssoc]: org.ofbiz.service.GenericServiceException: Service [updateFile] target threw an unexpected exception (null)".

      Case 2 -

      • While creating a data resource with non-empty objectInfo field.
      • Then go to upload tab, here getting an error in the file preview section - "org.ofbiz.webapp.view.ViewHandlerException: No file found".
      • Browse and upload a file.
      • It throws an error -
        "Error in Service [updateFile]: Unable to open file for writing: /home/.../xyz.pdf".

      on upload, 'persistContentAndAssoc' service called which calls 'persistDataResourceAndDataMethod'. This method then call 'createFile' or 'updateFile' services after checking that data resource is already existed or newly created. While the screen flow in OFBiz CMS is such that, you will get an upload tab(to upload files) only after the creation of data resource. And in this case 'updateFile' service called and gives error.

      • Found that 'createFile' service also gives error -
        "Error in Service [createFile]: Unable to obtain a reference to file".

      The reason, I have found is that both services 'createFile' and 'updateFile' gets the path as per the objectInfo specified, and then create/update a file at that location. While creating a new data resource, how can anybody specify the location at which file will place after uploading?

      1. OFBIZ-4946.patch
        31 kB
        Jacques Le Roux
      2. OFBIZ-4946.patch
        29 kB
        Jacques Le Roux
      3. OFBIZ-4946.patch
        13 kB
        Ashish Ambulkar
      4. OFBIZ-4946-complete.patch
        53 kB
        Arun Patidar
      5. OFBIZ-4946-complete.patch
        54 kB
        Jacques Le Roux
      6. OFBIZ-4946 labels.patch
        24 kB
        Jacques Le Roux

        Activity

        Hide
        ashish18 Ashish Ambulkar added a comment - - edited

        Found a service 'attachUploadToDataResource' which serve both the purpose create/update a file. But it handles only 'OFBIZ_FILE' and 'LOCAL_FILE' dataResourceTypeId (in file types). While the dataResourceTypeId 'CONTEXT_FILE', 'OFBIZ_FILE_BIN', 'LOCAL_FILE_BIN' and 'CONTEXT_FILE_BIN' are not handled in this service. I have called this service from 'persistContentAndAssoc' and it works.

        Also provided handling for the above mentioned dataResourceTypeIds that were not handled earlier by the service 'attachUploadToDataResource'.

        Show
        ashish18 Ashish Ambulkar added a comment - - edited Found a service 'attachUploadToDataResource' which serve both the purpose create/update a file. But it handles only 'OFBIZ_FILE' and 'LOCAL_FILE' dataResourceTypeId (in file types). While the dataResourceTypeId 'CONTEXT_FILE', 'OFBIZ_FILE_BIN', 'LOCAL_FILE_BIN' and 'CONTEXT_FILE_BIN' are not handled in this service. I have called this service from 'persistContentAndAssoc' and it works. Also provided handling for the above mentioned dataResourceTypeIds that were not handled earlier by the service 'attachUploadToDataResource'.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Hi Ashish,

        I have reviewed, tested and amended your patch not committed it.

        Changes I did:

        1. I fixed the NPE you reported in DataResourceWorker class (only functional change, others are trivial)
        2. I removed some now useless commentted out lines
        3. I removed old slipped in Debug.logInfo in ContentManagementServices class
        4. I have commented out the rendering of the uoloaded file content in UploadImage screen. I unsuccessfully tried to improve. I let this part commented out, in case someone want to give it a go later...
        5. I have added objectInfo and imageData labels in ImageUpload form
        6. I have added dataResourceId labels in DataResourceForms file

        Note that to work properly the last change needs the OFBIZ-4946 labels.patch to be applied before. With it, I have not only added ContentDataResourceId and ContentContentShow labels but used ContentDataResourceId in some fomrs. I's really appreciate if you could check that those labels additions in forms have not unwanted side effects.

        Also I lately found a an error in you work. That's why I did not commit. CONTEXT_FILE and CONTEXT_FILE_BIN shown as "(rel to webapp root)" are not working. You get this error:
        <<Error calling event: org.ofbiz.webapp.event.EventHandlerException: Service invocation error (Could not commit transaction for service [persistContentAndAssoc] call: Roll back error, could not commit transaction, was rolled back instead because of: Error in Service [createAnonFile]: Cannot find CONTEXT_FILE with an empty context root!)>>

        Show
        jacques.le.roux Jacques Le Roux added a comment - Hi Ashish, I have reviewed, tested and amended your patch not committed it. Changes I did: I fixed the NPE you reported in DataResourceWorker class (only functional change, others are trivial) I removed some now useless commentted out lines I removed old slipped in Debug.logInfo in ContentManagementServices class I have commented out the rendering of the uoloaded file content in UploadImage screen. I unsuccessfully tried to improve. I let this part commented out, in case someone want to give it a go later... I have added objectInfo and imageData labels in ImageUpload form I have added dataResourceId labels in DataResourceForms file Note that to work properly the last change needs the OFBIZ-4946 labels.patch to be applied before. With it, I have not only added ContentDataResourceId and ContentContentShow labels but used ContentDataResourceId in some fomrs. I's really appreciate if you could check that those labels additions in forms have not unwanted side effects. Also I lately found a an error in you work. That's why I did not commit. CONTEXT_FILE and CONTEXT_FILE_BIN shown as "(rel to webapp root)" are not working. You get this error: <<Error calling event: org.ofbiz.webapp.event.EventHandlerException: Service invocation error (Could not commit transaction for service [persistContentAndAssoc] call: Roll back error, could not commit transaction, was rolled back instead because of: Error in Service [createAnonFile] : Cannot find CONTEXT_FILE with an empty context root!)>>
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        BTW I forgot to attach a newer patch I did while working on it, changes:

        • msg if uploadPath is empty in saveContextFileDataResource => add a label
        • I guess
          uploadImage.put("rootDir", context.get("rootDir"));
          should be
          uploadImage.put("rootDir", context.get("objectInfo"));
          in persistDataResourceAndDataMethod
        Show
        jacques.le.roux Jacques Le Roux added a comment - BTW I forgot to attach a newer patch I did while working on it, changes: msg if uploadPath is empty in saveContextFileDataResource => add a label I guess uploadImage.put("rootDir", context.get("rootDir")); should be uploadImage.put("rootDir", context.get("objectInfo")); in persistDataResourceAndDataMethod
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Who cares?

        Show
        jacques.le.roux Jacques Le Roux added a comment - Who cares?
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        I attached an updated, replacement OFBIZ-4946-complete.patch

        Show
        jacques.le.roux Jacques Le Roux added a comment - I attached an updated, replacement OFBIZ-4946 -complete.patch
        Hide
        arunpati Arun Patidar added a comment -

        Attached is the modified patch 'OFBIZ-4946-complete.patch' which is compatible with latest code base.
        I did not make any functional change in the patch, only updated it to make compatible with recent code base.
        I have verified the fix and its working fine after applying the patch.

        Show
        arunpati Arun Patidar added a comment - Attached is the modified patch ' OFBIZ-4946 -complete.patch' which is compatible with latest code base. I did not make any functional change in the patch, only updated it to make compatible with recent code base. I have verified the fix and its working fine after applying the patch.
        Hide
        toashishvijay Ashish Vijaywargiya added a comment -

        Thanks Ashish Ambulkar for creating the issue. Thanks Arun and Jacques for the contribution. Recent patch has been committed in trunk at r1646984

        Show
        toashishvijay Ashish Vijaywargiya added a comment - Thanks Ashish Ambulkar for creating the issue. Thanks Arun and Jacques for the contribution. Recent patch has been committed in trunk at r1646984
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Backported in
        R13.07 r1647094
        R12.04 r1647095

        Show
        jacques.le.roux Jacques Le Roux added a comment - Backported in R13.07 r1647094 R12.04 r1647095
        Hide
        toashishvijay Ashish Vijaywargiya added a comment -

        Thanks Jacques!

        Show
        toashishvijay Ashish Vijaywargiya added a comment - Thanks Jacques!

          People

          • Assignee:
            toashishvijay Ashish Vijaywargiya
            Reporter:
            ashish18 Ashish Ambulkar
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development