[MGNLCAMPU-117] Calling PublishCampaignCommand via rest results in null pointer Created: 04/Oct/23 Updated: 04/Oct/23 |
|
| Status: | Open |
| Project: | Campaign Publisher |
| Component/s: | None |
| Affects Version/s: | 2.0.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Trivial |
| Reporter: | Richard Gange | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | API-first | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Template: |
|
||||
| Acceptance criteria: |
Empty
|
||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||
| Bug DoR: |
[ ]*
Steps to reproduce, expected, and actual results filled
[ ]*
Affected version filled
|
||||
| Description |
|
When trying to call the PublishCampaignCommand with the commands endpoint I ended up with a null pointer. 2023-10-04 15:30:25 2023-10-04 12:30:25,618 ERROR o.magnolia.rest.service.command.v2.CommandEndpoint: Error executing command [activate] from catalog [campaign-publisher] with commandMap [{comment=Published via REST, repository=campaigns, path=/Xmas-sample, recursive=false}]
2023-10-04 15:30:25 java.lang.NullPointerException: null
2023-10-04 15:30:25 at info.magnolia.campaignpublisher.command.PublishCampaignCommand.getCommandForNode(PublishCampaignCommand.java:160) ~[magnolia-campaign-publisher-2.0.4.jar:?]
2023-10-04 15:30:25 at info.magnolia.campaignpublisher.command.PublishCampaignCommand.execute(PublishCampaignCommand.java:105) ~[magnolia-campaign-publisher-2.0.4.jar:?]
2023-10-04 15:30:25 at info.magnolia.commands.CommandsManager.executeCommand(CommandsManager.java:256) ~[magnolia-core-6.2.32.jar:?]
Initially my attempt to make the call was modelled after the publish page example in our docs. curl http://localhost:8080/dx-core-webapp/.rest/commands/v2/campaign-publisher/activate \ -H "Content-Type: application/json" \ -X POST --user superuser:superuser \ --data \ '{ "comment": "Published via REST", "repository": "campaigns", "path": "/Xmas-sample", "recursive": false }' After some time debugging I discovered the issue was related to the mappings being null here. When trying to publish the path /Xmas-sample through the UI I found that mappings was set to an empty list anyway. Why not make sure mappings isn't null...
private Command getCommandForNode(Node node) throws RepositoryException {
String nodeType = node.getPrimaryNodeType().getName();
if (mappings != null) for (PublishCampaignAction.CommandMappingDefinition definition : mappings) {
if (nodeType.equals(definition.getNodeType())) {
String catalog = definition.getCatalog();
String command = definition.getCommand();
return commandsManager.getCommand(catalog, command);
}
}
return commandsManager.getCommand(getCommandName());
}
In any case I was able to workaround the issue by setting it in the post data: curl http://localhost:8080/dx-core-webapp/.rest/commands/v2/campaign-publisher/activate \ -H "Content-Type: application/json" \ -X POST --user superuser:superuser \ --data \ '{ "comment": "Published via REST", "repository": "campaigns", "path": "/Xmas-sample", "recursive": false, "commandMappings": [] }' |