CCM NG/ccm-cms: Avoid NPE in ItemWorkflowRequestLocalHelper when no workflow is assigned to a ContentItem.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4790 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 06a336d252
pull/2/head
jensp 2017-06-20 11:25:05 +00:00
parent 21bc4a1ec4
commit 18d1304c5b
1 changed files with 12 additions and 7 deletions

View File

@ -40,7 +40,7 @@ class ItemWorkflowRequestLocalHelper {
@Inject @Inject
private ContentItemRepository itemRepo; private ContentItemRepository itemRepo;
@Inject @Inject
private WorkflowRepository workflowRepo; private WorkflowRepository workflowRepo;
@ -53,12 +53,17 @@ class ItemWorkflowRequestLocalHelper {
.format("No ContentItem with ID %d in the database.", .format("No ContentItem with ID %d in the database.",
item.getObjectId()))); item.getObjectId())));
final Workflow workflow = workflowRepo final Workflow workflow;
.findById(contentItem.getWorkflow().getWorkflowId()) if (contentItem.getWorkflow() == null) {
.orElseThrow(() -> new IllegalArgumentException(String workflow = null;
.format("No Workflow with ID %d in the database.", } else {
contentItem.getWorkflow().getWorkflowId()))); workflow = workflowRepo
.findById(contentItem.getWorkflow().getWorkflowId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Workflow with ID %d in the database.",
contentItem.getWorkflow().getWorkflowId())));
}
return workflow; return workflow;
} }