dotCMS / core

Headless/Hybrid Content Management System for Enterprises
http://dotcms.com
Other
864 stars 466 forks source link

Removing Categories through REST API #22756

Closed waqasakramdot closed 2 years ago

waqasakramdot commented 2 years ago

Describe the bug Whenever REST API call made to clear/remove categories it returns 500

To Reproduce Example.

News has category type so Today news has two categories sport, entertainment so when trying to remove all categories with type:{} It returns 500 /api/v1/workflow/actions/fire { "actionName": "Save", "comments": "saving content", "contentlet": { "contentType":"News", "identifier": "f3fd1b2042418d84592334b3b9a27627", "inode": "22540f01-7322-4c79-bb1a-e57810a85f0b", "type":{}, "title":"blkjjhj Second Content", "languageId": "1" } }.

Logs:

ERROR workflow.WorkflowResource: Exception on firing, workflow action: ceca71a0-deee-4999-bd47-b01baa1bcfc8, inode: null java.lang.NullPointerException: null at com.dotmarketing.portlets.categories.business.CategoryAPIImpl.findByVariable_aroundBody72(CategoryAPIImpl.java:787) ~[dotcms_22.03.2_999999.jar:?] at com.dotmarketing.portlets.categories.business.CategoryAPIImpl$AjcClosure73.run(CategoryAPIImpl.java:1) ~[dotcms_22.03.2_999999.jar:?] at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) ~[aspectjrt-1.9.2.jar:?]

ian-b-cooper commented 2 years ago

This is a blocker for one of our customers, more information here: https://dotcms.zendesk.com/agent/tickets/108185

wezell commented 2 years ago

Just to be clear - the pattern for categories and relationships is this:

nollymar commented 2 years ago

PR: #22820

fabrizzio-dotCMS commented 2 years ago

Testing on this is blocked by https://github.com/dotCMS/core/issues/22787

nollymar commented 2 years ago

Internal QA: Needs work. Docker image used: dotcms/dotcms:22.09_60ad81cf_SNAPSHOT

I tested the following escenarios:

Content Type definition:

Screen Shot 2022-08-31 at 11 26 14 AM
  1. Save a new piece of content without categories using Workflow API. Test Result: OK.

    PUT localhost:8080/api/v1/workflow/actions/fire
    {
    "actionName": "save",
    "comments": "saving content",
    "contentlet": {
      "contentType":"MyType",
      "title": "Content 2",
      "mycats": []
    }
    } 
  2. Update the piece of content adding new categories using Workflow API. Test Result: OK.

    PUT localhost:8080/api/v1/workflow/actions/fire
    {
    "actionName": "save",
    "comments": "saving content",
    "contentlet": {
      "contentType":"MyType",
      "title": "Content 2",
      "mycats": ["baby", "toddler", "backcountry"], 
      "identifier": "8f2eecb0211e75325b6da6644427700d",
      "inode": "379bc15a-1564-4c2d-ba35-0fdba53db9e2"
    }
    }  
  3. Update the piece of content sending null categories using Workflow API. Test Result: Categories are wiped out when they should have been ignored.

    PUT localhost:8080/api/v1/workflow/actions/fire
    {
    "actionName": "save",
    "comments": "saving content",
    "contentlet": {
      "contentType":"MyType",
      "title": "Content 2",
      "mycats": null, 
      "identifier": "8f2eecb0211e75325b6da6644427700d",
      "inode": "379bc15a-1564-4c2d-ba35-0fdba53db9e2"
    }
    }   
  4. Update the piece of content ignoring the category field using Workflow API. Test Result: Categories are wiped out when they should have been ignored.

    PUT localhost:8080/api/v1/workflow/actions/fire
    {
    "actionName": "save",
    "comments": "saving content",
    "contentlet": {
      "contentType":"MyType",
      "title": "Content 2"
      "identifier": "8f2eecb0211e75325b6da6644427700d",
      "inode": "379bc15a-1564-4c2d-ba35-0fdba53db9e2"
    }
    }   
  5. Save a new piece of content with categories using Content API. Test Result: OK.

    PUT http://localhost:8080/api/content/publish/1
    {
    "contentType":"MyType",
    "contentHost":"demo.dotcms.com",
    "title":"Content 3",
    "mycats": ["baby", "toddler", "backcountry"]
    }
  6. Update a piece of content without categories using Content API. Test Result: OK (categories are maintained).

    PUT http://localhost:8080/api/content/publish/1
    {
    "contentType":"MyType",
    "contentHost":"demo.dotcms.com",
    "identifier":"939d0beb97a51036aa5355fe8fc9c73b",
    "title":"Content 3"
    }
  7. Update a piece of content sending empty categories using Content API. Test Result: Error (categories should be wiped out).

    PUT http://localhost:8080/api/content/publish/1
    {
    "contentType":"MyType",
    "contentHost":"demo.dotcms.com",
    "identifier":"939d0beb97a51036aa5355fe8fc9c73b",
    "title":"Content 3",
    "mycats": []
    }
  8. Update a piece of content sending null categories using Content API. Test Result: Error (see message below).

    PUT http://localhost:8080/api/content/publish/1
    {
    "contentType":"MyType",
    "contentHost":"demo.dotcms.com",
    "identifier":"939d0beb97a51036aa5355fe8fc9c73b",
    "title":"Content 3",
    "mycats": null
    }

    Error details:

    {
    "message": "Attempt to set unrecognized object [null] as category. This field only accepts arrays like ['cat-key','cat-var','cat-inode'] or a string like 'cat-key','cat-var','cat-inode' "
    }
fabrizzio-dotCMS commented 2 years ago

new PR https://github.com/dotCMS/core/pull/22930/

nollymar commented 2 years ago

Internal QA: Passed

All the test cases are working correctly, even with multiple category fields.

Docker image used: dotcms/dotcms:22.09_6c9f2315_SNAPSHOT

josemejias07 commented 2 years ago

QA Comment

I went ahead and tested the 8 points mentioned above by Nollymar using postman. I gave my report to Bryan and he will be finishing the work on this.

bryanboza commented 2 years ago

According to the merged changes, we add a postman test just for the workflow resource, but we made changes in the content resource too, then we need to add a postman test to those changes.

nollymar commented 2 years ago

Postman test implemented here: #22966

bryanboza commented 2 years ago

Fixed, tested on release-22.09 // Docker // Postman

erickgonzalez commented 1 year ago

The api/content doesn't work in 22.03.5 and 21.06.13 LTS due to changes in the JsonObject and libraries.

But the workflow works as it should.