@Test public void startApprovalWorkflow() throws Exception { Complaint complaint = new Complaint(); complaint.setComplaintId(500L); complaint.setComplaintType("complaintType"); Person person = new Person(); person.setFamilyName("Jones"); person.setGivenName("David"); PostalAddress address = new PostalAddress(); address.setCity("Falls Church"); address.setState("VA"); address.setStreetAddress("8221 Old Courthouse Road"); person.getAddresses().add(address); PersonAssociation personAssoc = new PersonAssociation(); personAssoc.setPerson(person); personAssoc.setPersonDescription("sample Description"); personAssoc.setPersonType("Originator"); complaint.setOriginator(personAssoc); complaint.setApprovers(Arrays.asList("user1", "user2")); ObjectMapper objectMapper = new ObjectMapper(); String in = objectMapper.writeValueAsString(complaint); log.debug("Input JSON: " + in); Capture<Complaint> capturedComplaint = new Capture<>(); mockEventPublisher.publishComplaintWorkflowEvent( capture(capturedComplaint), eq(mockAuthentication), eq("acm_ip_address"), eq(true)); expect(mockAuthentication.getName()).andReturn("user"); replayAll(); MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute("acm_ip_address", "acm_ip_address"); mockMvc.perform( post("/api/latest/plugin/complaint/workflow") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .session(mockSession) .principal(mockAuthentication) .content(in)) .andReturn(); verifyAll(); Complaint handled = capturedComplaint.getValue(); assertEquals(complaint.getComplaintNumber(), handled.getComplaintNumber()); }
@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; }
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; } }
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; }  }
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; }  @RequestMapping(method = RequestMethod.POST, value = "/workflow", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Complaint startApprovalWorkflow(
            @RequestBody Complaint in,
            Authentication auth,
            HttpServletResponse response,
            HttpSession session); ComplaintEventPublisher getEventPublisher(); void setEventPublisher(ComplaintEventPublisher eventPublisher); }
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; }  @RequestMapping(method = RequestMethod.POST, value = "/workflow", produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Complaint startApprovalWorkflow(
            @RequestBody Complaint in,
            Authentication auth,
            HttpServletResponse response,
            HttpSession session); ComplaintEventPublisher getEventPublisher(); void setEventPublisher(ComplaintEventPublisher eventPublisher);  }