@Test public void testParticipantIsAdded() { AcmMarshaller acmMarshaller = ObjectConverter.createJSONMarshallerForTests(); Complaint jsonComplaint = getComplaint(); String currentJsonObject = acmMarshaller.marshal(jsonComplaint); AcmObjectHistory previousHistory = new AcmObjectHistory(); previousHistory.setObjectType(ComplaintConstants.OBJECT_TYPE); previousHistory.setObjectString(currentJsonObject); AcmObjectHistory currentHistory = new AcmObjectHistory(); currentHistory.setObjectType(ComplaintConstants.OBJECT_TYPE); AcmParticipant participant = new AcmParticipant(); participant.setObjectType(ParticipantConstants.OBJECT_TYPE); participant.setParticipantType("reader"); participant.setId(12345L); participant.setParticipantLdapId("nana-acm"); jsonComplaint.getParticipants().add(participant); currentJsonObject = acmMarshaller.marshal(jsonComplaint); currentHistory.setObjectString(currentJsonObject); AcmObjectHistoryEvent event = new AcmObjectHistoryEvent(currentHistory); event.setIpAddress(IP_ADDRESS); event.setUserId(USER_ID); expect(mockAcmObjectHistoryService.getAcmObjectHistory(OBJECT_ID, ComplaintConstants.OBJECT_TYPE)).andReturn(previousHistory); Capture<Complaint> complaintCapture = Capture.newInstance(); Capture<String> ipAddressCapture = Capture.newInstance(); Capture<String> eventsStatusCapture = Capture.newInstance(); mockComplaintEventPublisher.publishParticipantsModifiedInComplaint(eq(participant), capture(complaintCapture), capture(ipAddressCapture), capture(eventsStatusCapture)); expectLastCall().anyTimes(); replayAll(); complaintEventListener.onApplicationEvent(event); verifyAll(); assertEquals("added", eventsStatusCapture.getValue()); verifyEvent(ipAddressCapture.getValue(), complaintCapture.getValue(), jsonComplaint); }
@Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isComplaint = checkExecution(acmObjectHistory.getObjectType()); if (isComplaint) { String ipAddress = event.getIpAddress(); AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedComplaint = acmObjectHistory.getObjectString(); Complaint updatedComplaint = converter.unmarshall(jsonUpdatedComplaint, Complaint.class); AcmAssignment acmAssignment = createAcmAssignment(updatedComplaint); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService() .getAcmObjectHistory(updatedComplaint.getComplaintId(), ComplaintConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); Complaint existing = converter.unmarshall(json, Complaint.class); acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "priority.changed"); } if (isDetailsChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "details.changed"); } if (isStatusChanged(existing, updatedComplaint)) { String calId = updatedComplaint.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && complaintStatusClosed.contains(updatedComplaint.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(ComplaintConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedComplaint.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedComplaint.getId(), updatedComplaint.getObjectType()); } } getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "status.changed", "from " + existing.getStatus() + " to " + updatedComplaint.getStatus()); } if (isLocationChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "location.updated"); } checkParticipants(existing, updatedComplaint, event.getIpAddress()); } if (isAssigneeChanged(acmAssignment)) { getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(acmAssignment, event.getUserId(), ipAddress); } } } }
ComplaintEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isComplaint = checkExecution(acmObjectHistory.getObjectType()); if (isComplaint) { String ipAddress = event.getIpAddress(); AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedComplaint = acmObjectHistory.getObjectString(); Complaint updatedComplaint = converter.unmarshall(jsonUpdatedComplaint, Complaint.class); AcmAssignment acmAssignment = createAcmAssignment(updatedComplaint); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService() .getAcmObjectHistory(updatedComplaint.getComplaintId(), ComplaintConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); Complaint existing = converter.unmarshall(json, Complaint.class); acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "priority.changed"); } if (isDetailsChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "details.changed"); } if (isStatusChanged(existing, updatedComplaint)) { String calId = updatedComplaint.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && complaintStatusClosed.contains(updatedComplaint.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(ComplaintConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedComplaint.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedComplaint.getId(), updatedComplaint.getObjectType()); } } getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "status.changed", "from " + existing.getStatus() + " to " + updatedComplaint.getStatus()); } if (isLocationChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "location.updated"); } checkParticipants(existing, updatedComplaint, event.getIpAddress()); } if (isAssigneeChanged(acmAssignment)) { getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(acmAssignment, event.getUserId(), ipAddress); } } } } }
ComplaintEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isComplaint = checkExecution(acmObjectHistory.getObjectType()); if (isComplaint) { String ipAddress = event.getIpAddress(); AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedComplaint = acmObjectHistory.getObjectString(); Complaint updatedComplaint = converter.unmarshall(jsonUpdatedComplaint, Complaint.class); AcmAssignment acmAssignment = createAcmAssignment(updatedComplaint); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService() .getAcmObjectHistory(updatedComplaint.getComplaintId(), ComplaintConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); Complaint existing = converter.unmarshall(json, Complaint.class); acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "priority.changed"); } if (isDetailsChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "details.changed"); } if (isStatusChanged(existing, updatedComplaint)) { String calId = updatedComplaint.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && complaintStatusClosed.contains(updatedComplaint.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(ComplaintConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedComplaint.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedComplaint.getId(), updatedComplaint.getObjectType()); } } getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "status.changed", "from " + existing.getStatus() + " to " + updatedComplaint.getStatus()); } if (isLocationChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "location.updated"); } checkParticipants(existing, updatedComplaint, event.getIpAddress()); } if (isAssigneeChanged(acmAssignment)) { getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(acmAssignment, event.getUserId(), ipAddress); } } } }  }
ComplaintEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isComplaint = checkExecution(acmObjectHistory.getObjectType()); if (isComplaint) { String ipAddress = event.getIpAddress(); AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedComplaint = acmObjectHistory.getObjectString(); Complaint updatedComplaint = converter.unmarshall(jsonUpdatedComplaint, Complaint.class); AcmAssignment acmAssignment = createAcmAssignment(updatedComplaint); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService() .getAcmObjectHistory(updatedComplaint.getComplaintId(), ComplaintConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); Complaint existing = converter.unmarshall(json, Complaint.class); acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "priority.changed"); } if (isDetailsChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "details.changed"); } if (isStatusChanged(existing, updatedComplaint)) { String calId = updatedComplaint.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && complaintStatusClosed.contains(updatedComplaint.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(ComplaintConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedComplaint.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedComplaint.getId(), updatedComplaint.getObjectType()); } } getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "status.changed", "from " + existing.getStatus() + " to " + updatedComplaint.getStatus()); } if (isLocationChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "location.updated"); } checkParticipants(existing, updatedComplaint, event.getIpAddress()); } if (isAssigneeChanged(acmAssignment)) { getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(acmAssignment, event.getUserId(), ipAddress); } } } }  @Override void onApplicationEvent(AcmObjectHistoryEvent event); boolean isAssigneeChanged(AcmAssignment assignment); AcmObjectHistoryService getAcmObjectHistoryService(); void setAcmObjectHistoryService(AcmObjectHistoryService acmObjectHistoryService); ComplaintEventPublisher getComplaintEventPublisher(); void setComplaintEventPublisher(ComplaintEventPublisher complaintEventPublisher); AcmObjectHistoryEventPublisher getAcmObjectHistoryEventPublisher(); void setAcmObjectHistoryEventPublisher(AcmObjectHistoryEventPublisher acmObjectHistoryEventPublisher); AcmAssignmentDao getAcmAssignmentDao(); void setAcmAssignmentDao(AcmAssignmentDao acmAssignmentDao); OutlookContainerCalendarService getCalendarService(); void setCalendarService(OutlookContainerCalendarService calendarService); boolean isShouldDeleteCalendarFolder(); void setShouldDeleteCalendarFolder(boolean shouldDeleteCalendarFolder); void setComplaintStatusClosed(String complaintStatusClosed); void setCalendarAdminService(OutlookCalendarAdminServiceExtension calendarAdminService); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); void setFolderCreatorDao(AcmOutlookFolderCreatorDao folderCreatorDao); }
ComplaintEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isComplaint = checkExecution(acmObjectHistory.getObjectType()); if (isComplaint) { String ipAddress = event.getIpAddress(); AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedComplaint = acmObjectHistory.getObjectString(); Complaint updatedComplaint = converter.unmarshall(jsonUpdatedComplaint, Complaint.class); AcmAssignment acmAssignment = createAcmAssignment(updatedComplaint); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService() .getAcmObjectHistory(updatedComplaint.getComplaintId(), ComplaintConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); Complaint existing = converter.unmarshall(json, Complaint.class); acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "priority.changed"); } if (isDetailsChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "details.changed"); } if (isStatusChanged(existing, updatedComplaint)) { String calId = updatedComplaint.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && complaintStatusClosed.contains(updatedComplaint.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(ComplaintConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedComplaint.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedComplaint.getId(), updatedComplaint.getObjectType()); } } getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "status.changed", "from " + existing.getStatus() + " to " + updatedComplaint.getStatus()); } if (isLocationChanged(existing, updatedComplaint)) { getComplaintEventPublisher().publishComplaintModified(updatedComplaint, ipAddress, "location.updated"); } checkParticipants(existing, updatedComplaint, event.getIpAddress()); } if (isAssigneeChanged(acmAssignment)) { getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(acmAssignment, event.getUserId(), ipAddress); } } } }  @Override void onApplicationEvent(AcmObjectHistoryEvent event); boolean isAssigneeChanged(AcmAssignment assignment); AcmObjectHistoryService getAcmObjectHistoryService(); void setAcmObjectHistoryService(AcmObjectHistoryService acmObjectHistoryService); ComplaintEventPublisher getComplaintEventPublisher(); void setComplaintEventPublisher(ComplaintEventPublisher complaintEventPublisher); AcmObjectHistoryEventPublisher getAcmObjectHistoryEventPublisher(); void setAcmObjectHistoryEventPublisher(AcmObjectHistoryEventPublisher acmObjectHistoryEventPublisher); AcmAssignmentDao getAcmAssignmentDao(); void setAcmAssignmentDao(AcmAssignmentDao acmAssignmentDao); OutlookContainerCalendarService getCalendarService(); void setCalendarService(OutlookContainerCalendarService calendarService); boolean isShouldDeleteCalendarFolder(); void setShouldDeleteCalendarFolder(boolean shouldDeleteCalendarFolder); void setComplaintStatusClosed(String complaintStatusClosed); void setCalendarAdminService(OutlookCalendarAdminServiceExtension calendarAdminService); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); void setFolderCreatorDao(AcmOutlookFolderCreatorDao folderCreatorDao);  }