class ComplaintWorkflowAPIController {

    @RequestMapping(method = RequestMethod.POST, value = "/workflow", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Complaint startApprovalWorkflow(
            @RequestBody Complaint in,
            Authentication auth,
            HttpServletResponse response,
            HttpSession session) throws AcmUserActionFailedException
    {
        if (log.isDebugEnabled())
        {
            log.debug("Got a complaint: " + in + "; complaint ID: '" + in.getComplaintId() + "'");
            log.debug("complaint type: " + in.getComplaintType());
        }

        Long complaintId = in.getComplaintId();
        boolean isNew = (null == complaintId) || (0 == complaintId);

        String ipAddress = (String) session.getAttribute("acm_ip_address");

        if (isNew)
        {
            getEventPublisher().publishComplaintWorkflowEvent(in, auth, ipAddress, false);
            throw new AcmUserActionFailedException(
                    "start approval process",
                    "task",
                    complaintId,
                    "You must save the complaint first",
                    null);
        }

        getEventPublisher().publishComplaintWorkflowEvent(in, auth, ipAddress, true);

        return in;

    }

}