@Test public void testAssigneeIsChanged() { AcmMarshaller acmMarshaller = ObjectConverter.createJSONMarshallerForTests(); CaseFile jsonCaseFile = getCase(); String currentJsonObject = acmMarshaller.marshal(jsonCaseFile); AcmObjectHistory previousHistory = new AcmObjectHistory(); previousHistory.setObjectType(CaseFileConstants.OBJECT_TYPE); previousHistory.setObjectString(currentJsonObject); AcmObjectHistory currentHistory = new AcmObjectHistory(); currentHistory.setObjectType(CaseFileConstants.OBJECT_TYPE); jsonCaseFile.getParticipants().get(0).setParticipantLdapId(NEW_ASSIGNEE); currentJsonObject = acmMarshaller.marshal(jsonCaseFile); currentHistory.setObjectString(currentJsonObject); AcmObjectHistoryEvent event = new AcmObjectHistoryEvent(currentHistory); event.setIpAddress(IP_ADDRESS); event.setUserId(USER_ID); AcmAssignment assignment = new AcmAssignment(); Capture<AcmAssignment> captureAssignment = Capture.newInstance(); Capture<String> captureUserId = Capture.newInstance(); Capture<String> captureIpAddress = Capture.newInstance(); expect(mockAcmObjectHistoryService.getAcmObjectHistory(OBJECT_ID, CaseFileConstants.OBJECT_TYPE)).andReturn(previousHistory); expect(mockAcmAssignmentDao.save(capture(captureAssignment))).andReturn(assignment); mockAcmObjectHistoryEventPublisher.publishAssigneeChangeEvent(eq(assignment), capture(captureUserId), capture(captureIpAddress)); expectLastCall().anyTimes(); replayAll(); caseFileEventListener.onApplicationEvent(event); verifyAll(); assertEquals(OBJECT_ID, captureAssignment.getValue().getObjectId()); assertEquals(OBJECT_NAME, captureAssignment.getValue().getObjectName()); assertEquals(OBJECT_TITLE, captureAssignment.getValue().getObjectTitle()); assertEquals(CaseFileConstants.OBJECT_TYPE, captureAssignment.getValue().getObjectType()); assertEquals(NEW_ASSIGNEE, captureAssignment.getValue().getNewAssignee()); assertEquals(OLD_ASSIGNEE, captureAssignment.getValue().getOldAssignee()); assertEquals(IP_ADDRESS, captureIpAddress.getValue()); assertEquals(USER_ID, captureUserId.getValue()); }
@Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isCaseFile = checkExecution(acmObjectHistory.getObjectType()); if (isCaseFile) { AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedCaseFile = acmObjectHistory.getObjectString(); CaseFile updatedCaseFile = converter.unmarshall(jsonUpdatedCaseFile, CaseFile.class); AcmAssignment acmAssignment = createAcmAssignment(updatedCaseFile); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService().getAcmObjectHistory(updatedCaseFile.getId(), CaseFileConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); CaseFile existing = converter.unmarshall(json, CaseFile.class); if (existing != null) { acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "priority.changed"); } if (isDetailsChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "details.changed"); } String title = existing.getTitle(); String updatedTitle = updatedCaseFile.getTitle(); if (!Objects.equals(title, updatedTitle)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "title.changed", "Case File Title changed from " + title + " to " + updatedTitle); } String owningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(existing.getParticipants()); String updatedOwningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(updatedCaseFile.getParticipants()); if (!Objects.equals(owningGroup, updatedOwningGroup)) { AcmParticipant updatedParticipant = updatedCaseFile.getParticipants().stream() .filter(p -> "owning group".equals(p.getParticipantType())).findFirst().orElse(null); getCaseFileEventUtility().raiseParticipantsModifiedInCaseFile(updatedParticipant, updatedCaseFile, event.getIpAddress(), "changed", "Owning Group Changed from " + owningGroup + " to " + updatedOwningGroup); } checkParticipants(existing, updatedCaseFile, event.getIpAddress()); if (isStatusChanged(existing, updatedCaseFile)) { String calId = updatedCaseFile.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && caseFileStatusClosed.contains(updatedCaseFile.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(CaseFileConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedCaseFile.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedCaseFile.getId(), updatedCaseFile.getObjectType()); } } getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "status.changed", "from " + existing.getStatus() + " to " + updatedCaseFile.getStatus()); } } } if (isAssigneeChanged(acmAssignment)) { AcmAssignment assignmentSaved = getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(assignmentSaved, event.getUserId(), event.getIpAddress()); } } } }
CaseFileEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isCaseFile = checkExecution(acmObjectHistory.getObjectType()); if (isCaseFile) { AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedCaseFile = acmObjectHistory.getObjectString(); CaseFile updatedCaseFile = converter.unmarshall(jsonUpdatedCaseFile, CaseFile.class); AcmAssignment acmAssignment = createAcmAssignment(updatedCaseFile); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService().getAcmObjectHistory(updatedCaseFile.getId(), CaseFileConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); CaseFile existing = converter.unmarshall(json, CaseFile.class); if (existing != null) { acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "priority.changed"); } if (isDetailsChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "details.changed"); } String title = existing.getTitle(); String updatedTitle = updatedCaseFile.getTitle(); if (!Objects.equals(title, updatedTitle)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "title.changed", "Case File Title changed from " + title + " to " + updatedTitle); } String owningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(existing.getParticipants()); String updatedOwningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(updatedCaseFile.getParticipants()); if (!Objects.equals(owningGroup, updatedOwningGroup)) { AcmParticipant updatedParticipant = updatedCaseFile.getParticipants().stream() .filter(p -> "owning group".equals(p.getParticipantType())).findFirst().orElse(null); getCaseFileEventUtility().raiseParticipantsModifiedInCaseFile(updatedParticipant, updatedCaseFile, event.getIpAddress(), "changed", "Owning Group Changed from " + owningGroup + " to " + updatedOwningGroup); } checkParticipants(existing, updatedCaseFile, event.getIpAddress()); if (isStatusChanged(existing, updatedCaseFile)) { String calId = updatedCaseFile.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && caseFileStatusClosed.contains(updatedCaseFile.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(CaseFileConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedCaseFile.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedCaseFile.getId(), updatedCaseFile.getObjectType()); } } getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "status.changed", "from " + existing.getStatus() + " to " + updatedCaseFile.getStatus()); } } } if (isAssigneeChanged(acmAssignment)) { AcmAssignment assignmentSaved = getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(assignmentSaved, event.getUserId(), event.getIpAddress()); } } } } }
CaseFileEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isCaseFile = checkExecution(acmObjectHistory.getObjectType()); if (isCaseFile) { AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedCaseFile = acmObjectHistory.getObjectString(); CaseFile updatedCaseFile = converter.unmarshall(jsonUpdatedCaseFile, CaseFile.class); AcmAssignment acmAssignment = createAcmAssignment(updatedCaseFile); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService().getAcmObjectHistory(updatedCaseFile.getId(), CaseFileConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); CaseFile existing = converter.unmarshall(json, CaseFile.class); if (existing != null) { acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "priority.changed"); } if (isDetailsChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "details.changed"); } String title = existing.getTitle(); String updatedTitle = updatedCaseFile.getTitle(); if (!Objects.equals(title, updatedTitle)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "title.changed", "Case File Title changed from " + title + " to " + updatedTitle); } String owningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(existing.getParticipants()); String updatedOwningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(updatedCaseFile.getParticipants()); if (!Objects.equals(owningGroup, updatedOwningGroup)) { AcmParticipant updatedParticipant = updatedCaseFile.getParticipants().stream() .filter(p -> "owning group".equals(p.getParticipantType())).findFirst().orElse(null); getCaseFileEventUtility().raiseParticipantsModifiedInCaseFile(updatedParticipant, updatedCaseFile, event.getIpAddress(), "changed", "Owning Group Changed from " + owningGroup + " to " + updatedOwningGroup); } checkParticipants(existing, updatedCaseFile, event.getIpAddress()); if (isStatusChanged(existing, updatedCaseFile)) { String calId = updatedCaseFile.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && caseFileStatusClosed.contains(updatedCaseFile.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(CaseFileConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedCaseFile.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedCaseFile.getId(), updatedCaseFile.getObjectType()); } } getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "status.changed", "from " + existing.getStatus() + " to " + updatedCaseFile.getStatus()); } } } if (isAssigneeChanged(acmAssignment)) { AcmAssignment assignmentSaved = getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(assignmentSaved, event.getUserId(), event.getIpAddress()); } } } }  }
CaseFileEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isCaseFile = checkExecution(acmObjectHistory.getObjectType()); if (isCaseFile) { AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedCaseFile = acmObjectHistory.getObjectString(); CaseFile updatedCaseFile = converter.unmarshall(jsonUpdatedCaseFile, CaseFile.class); AcmAssignment acmAssignment = createAcmAssignment(updatedCaseFile); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService().getAcmObjectHistory(updatedCaseFile.getId(), CaseFileConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); CaseFile existing = converter.unmarshall(json, CaseFile.class); if (existing != null) { acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "priority.changed"); } if (isDetailsChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "details.changed"); } String title = existing.getTitle(); String updatedTitle = updatedCaseFile.getTitle(); if (!Objects.equals(title, updatedTitle)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "title.changed", "Case File Title changed from " + title + " to " + updatedTitle); } String owningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(existing.getParticipants()); String updatedOwningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(updatedCaseFile.getParticipants()); if (!Objects.equals(owningGroup, updatedOwningGroup)) { AcmParticipant updatedParticipant = updatedCaseFile.getParticipants().stream() .filter(p -> "owning group".equals(p.getParticipantType())).findFirst().orElse(null); getCaseFileEventUtility().raiseParticipantsModifiedInCaseFile(updatedParticipant, updatedCaseFile, event.getIpAddress(), "changed", "Owning Group Changed from " + owningGroup + " to " + updatedOwningGroup); } checkParticipants(existing, updatedCaseFile, event.getIpAddress()); if (isStatusChanged(existing, updatedCaseFile)) { String calId = updatedCaseFile.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && caseFileStatusClosed.contains(updatedCaseFile.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(CaseFileConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedCaseFile.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedCaseFile.getId(), updatedCaseFile.getObjectType()); } } getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "status.changed", "from " + existing.getStatus() + " to " + updatedCaseFile.getStatus()); } } } if (isAssigneeChanged(acmAssignment)) { AcmAssignment assignmentSaved = getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(assignmentSaved, event.getUserId(), event.getIpAddress()); } } } }  @Override void onApplicationEvent(AcmObjectHistoryEvent event); boolean isAssigneeChanged(AcmAssignment assignment); void checkParticipants(CaseFile caseFile, CaseFile updatedCaseFile, String ipAddress); AcmObjectHistoryService getAcmObjectHistoryService(); void setAcmObjectHistoryService(AcmObjectHistoryService acmObjectHistoryService); CaseFileEventUtility getCaseFileEventUtility(); void setCaseFileEventUtility(CaseFileEventUtility caseFileEventUtility); 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 setCaseFileStatusClosed(String caseFileStatusClosed); void setCalendarAdminService(OutlookCalendarAdminServiceExtension calendarAdminService); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); void setFolderCreatorDao(AcmOutlookFolderCreatorDao folderCreatorDao); }
CaseFileEventListener implements ApplicationListener<AcmObjectHistoryEvent> { @Override public void onApplicationEvent(AcmObjectHistoryEvent event) { if (event != null) { AcmObjectHistory acmObjectHistory = (AcmObjectHistory) event.getSource(); boolean isCaseFile = checkExecution(acmObjectHistory.getObjectType()); if (isCaseFile) { AcmUnmarshaller converter = getObjectConverter().getJsonUnmarshaller(); String jsonUpdatedCaseFile = acmObjectHistory.getObjectString(); CaseFile updatedCaseFile = converter.unmarshall(jsonUpdatedCaseFile, CaseFile.class); AcmAssignment acmAssignment = createAcmAssignment(updatedCaseFile); AcmObjectHistory acmObjectHistoryExisting = getAcmObjectHistoryService().getAcmObjectHistory(updatedCaseFile.getId(), CaseFileConstants.OBJECT_TYPE); if (acmObjectHistoryExisting != null) { String json = acmObjectHistoryExisting.getObjectString(); CaseFile existing = converter.unmarshall(json, CaseFile.class); if (existing != null) { acmAssignment.setOldAssignee(ParticipantUtils.getAssigneeIdFromParticipants(existing.getParticipants())); if (isPriorityChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "priority.changed"); } if (isDetailsChanged(existing, updatedCaseFile)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "details.changed"); } String title = existing.getTitle(); String updatedTitle = updatedCaseFile.getTitle(); if (!Objects.equals(title, updatedTitle)) { getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "title.changed", "Case File Title changed from " + title + " to " + updatedTitle); } String owningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(existing.getParticipants()); String updatedOwningGroup = ParticipantUtils.getOwningGroupIdFromParticipants(updatedCaseFile.getParticipants()); if (!Objects.equals(owningGroup, updatedOwningGroup)) { AcmParticipant updatedParticipant = updatedCaseFile.getParticipants().stream() .filter(p -> "owning group".equals(p.getParticipantType())).findFirst().orElse(null); getCaseFileEventUtility().raiseParticipantsModifiedInCaseFile(updatedParticipant, updatedCaseFile, event.getIpAddress(), "changed", "Owning Group Changed from " + owningGroup + " to " + updatedOwningGroup); } checkParticipants(existing, updatedCaseFile, event.getIpAddress()); if (isStatusChanged(existing, updatedCaseFile)) { String calId = updatedCaseFile.getContainer().getCalendarFolderId(); if (shouldDeleteOnClose() && calId != null && caseFileStatusClosed.contains(updatedCaseFile.getStatus())) { Optional<AcmOutlookUser> user = calendarAdminService .getEventListenerOutlookUser(CaseFileConstants.OBJECT_TYPE); if (user.isPresent()) { getCalendarService().deleteFolder(user.get(), updatedCaseFile.getContainer(), DeleteMode.MoveToDeletedItems); folderCreatorDao.deleteObjectReference(updatedCaseFile.getId(), updatedCaseFile.getObjectType()); } } getCaseFileEventUtility().raiseCaseFileModifiedEvent(updatedCaseFile, event.getIpAddress(), "status.changed", "from " + existing.getStatus() + " to " + updatedCaseFile.getStatus()); } } } if (isAssigneeChanged(acmAssignment)) { AcmAssignment assignmentSaved = getAcmAssignmentDao().save(acmAssignment); getAcmObjectHistoryEventPublisher().publishAssigneeChangeEvent(assignmentSaved, event.getUserId(), event.getIpAddress()); } } } }  @Override void onApplicationEvent(AcmObjectHistoryEvent event); boolean isAssigneeChanged(AcmAssignment assignment); void checkParticipants(CaseFile caseFile, CaseFile updatedCaseFile, String ipAddress); AcmObjectHistoryService getAcmObjectHistoryService(); void setAcmObjectHistoryService(AcmObjectHistoryService acmObjectHistoryService); CaseFileEventUtility getCaseFileEventUtility(); void setCaseFileEventUtility(CaseFileEventUtility caseFileEventUtility); 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 setCaseFileStatusClosed(String caseFileStatusClosed); void setCalendarAdminService(OutlookCalendarAdminServiceExtension calendarAdminService); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); void setFolderCreatorDao(AcmOutlookFolderCreatorDao folderCreatorDao);  }