@Test public void testAcknowledgementEmailInternal() throws Exception { testEmailExpect(); expect(mockedRequest.getCreator()).andReturn(userId); expect(mockedRequest.isExternal()).andReturn(false); AcmUser internalUser = new AcmUser(); internalUser.setUserId(userId); expect(mockedUserDao.findByUserId(userId)).andReturn(internalUser); expect(mockedTemplatingEngine.process(anyString(), anyString(), anyObject())).andReturn("body text"); Capture<EmailWithAttachmentsDTO> capturedEmailWithAttachmentsDTO = Capture.newInstance(); Capture<Authentication> capturedAuthentication = Capture.newInstance(); Capture<AcmUser> capturedAcmUser = Capture.newInstance(); mockedNotificationSender.sendEmailWithAttachments(capture(capturedEmailWithAttachmentsDTO), capture(capturedAuthentication), capture(capturedAcmUser)); replayAll(); acknowledgementService.emailAcknowledgement(requestId); verifyAll(); assertEquals(String.format("%s %s", "New Request", caseNumber), capturedEmailWithAttachmentsDTO.getValue().getSubject()); assertEquals(emailAddress, capturedEmailWithAttachmentsDTO.getValue().getEmailAddresses().get(0)); assertEquals(fileId, capturedEmailWithAttachmentsDTO.getValue().getAttachmentIds().get(0)); assertEquals(userId, capturedAcmUser.getValue().getUserId()); }
public void emailAcknowledgement(Long requestId) { if (!foiaConfigurationService.readConfiguration().getReceivedDateEnabled()) { FOIARequest request = getRequestDao().find(requestId); String emailAddress = extractRequestorEmailAddress(request.getOriginator().getPerson()); if (emailAddress != null) { EmailWithAttachmentsDTO emailData = new EmailWithAttachmentsDTO(); emailData.setEmailAddresses(Arrays.asList(emailAddress)); emailData.setSubject(String.format("%s %s", request.getRequestType(), request.getCaseNumber())); emailData.setHeader(EMAIL_HEADER_ATTACHMENT); try { String body = getTemplatingEngine().process(emailBodyTemplate, "request", request); emailData.setBody(body); emailData.setTemplate(body); } catch (TemplateException | IOException e) { log.error("Unable to generate email for {} about {} with ID [{}]", emailAddress, request.getObjectType(), requestId, e); emailData.setBody(EMAIL_BODY_ATTACHMENT); } emailData.setFooter(EMAIL_FOOTER_ATTACHMENT); FOIADocumentDescriptor documentDescriptor = documentGeneratorService.getDocumentDescriptor(request, FOIAConstants.ACK); EcmFile ackFile = getEcmFileDao().findForContainerAttachmentFolderAndFileType(request.getContainer().getId(), request.getContainer().getAttachmentFolder().getId(), documentDescriptor.getDoctype()); emailData.setAttachmentIds(Arrays.asList(ackFile.getFileId())); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String userIdOrName = request.getCreator(); try { if (request.isExternal()) { getNotificationSender().sendEmailWithAttachments(emailData, auth, userIdOrName); } else { getNotificationSender().sendEmailWithAttachments(emailData, auth, getUserDao().findByUserId(userIdOrName)); } } catch (Exception e) { log.error("Unable to email {} for {} [{}]", request.getRequestType(), documentDescriptor.getDoctype(), requestId, e); } } } }
AcknowledgementDocumentService { public void emailAcknowledgement(Long requestId) { if (!foiaConfigurationService.readConfiguration().getReceivedDateEnabled()) { FOIARequest request = getRequestDao().find(requestId); String emailAddress = extractRequestorEmailAddress(request.getOriginator().getPerson()); if (emailAddress != null) { EmailWithAttachmentsDTO emailData = new EmailWithAttachmentsDTO(); emailData.setEmailAddresses(Arrays.asList(emailAddress)); emailData.setSubject(String.format("%s %s", request.getRequestType(), request.getCaseNumber())); emailData.setHeader(EMAIL_HEADER_ATTACHMENT); try { String body = getTemplatingEngine().process(emailBodyTemplate, "request", request); emailData.setBody(body); emailData.setTemplate(body); } catch (TemplateException | IOException e) { log.error("Unable to generate email for {} about {} with ID [{}]", emailAddress, request.getObjectType(), requestId, e); emailData.setBody(EMAIL_BODY_ATTACHMENT); } emailData.setFooter(EMAIL_FOOTER_ATTACHMENT); FOIADocumentDescriptor documentDescriptor = documentGeneratorService.getDocumentDescriptor(request, FOIAConstants.ACK); EcmFile ackFile = getEcmFileDao().findForContainerAttachmentFolderAndFileType(request.getContainer().getId(), request.getContainer().getAttachmentFolder().getId(), documentDescriptor.getDoctype()); emailData.setAttachmentIds(Arrays.asList(ackFile.getFileId())); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String userIdOrName = request.getCreator(); try { if (request.isExternal()) { getNotificationSender().sendEmailWithAttachments(emailData, auth, userIdOrName); } else { getNotificationSender().sendEmailWithAttachments(emailData, auth, getUserDao().findByUserId(userIdOrName)); } } catch (Exception e) { log.error("Unable to email {} for {} [{}]", request.getRequestType(), documentDescriptor.getDoctype(), requestId, e); } } } } }
AcknowledgementDocumentService { public void emailAcknowledgement(Long requestId) { if (!foiaConfigurationService.readConfiguration().getReceivedDateEnabled()) { FOIARequest request = getRequestDao().find(requestId); String emailAddress = extractRequestorEmailAddress(request.getOriginator().getPerson()); if (emailAddress != null) { EmailWithAttachmentsDTO emailData = new EmailWithAttachmentsDTO(); emailData.setEmailAddresses(Arrays.asList(emailAddress)); emailData.setSubject(String.format("%s %s", request.getRequestType(), request.getCaseNumber())); emailData.setHeader(EMAIL_HEADER_ATTACHMENT); try { String body = getTemplatingEngine().process(emailBodyTemplate, "request", request); emailData.setBody(body); emailData.setTemplate(body); } catch (TemplateException | IOException e) { log.error("Unable to generate email for {} about {} with ID [{}]", emailAddress, request.getObjectType(), requestId, e); emailData.setBody(EMAIL_BODY_ATTACHMENT); } emailData.setFooter(EMAIL_FOOTER_ATTACHMENT); FOIADocumentDescriptor documentDescriptor = documentGeneratorService.getDocumentDescriptor(request, FOIAConstants.ACK); EcmFile ackFile = getEcmFileDao().findForContainerAttachmentFolderAndFileType(request.getContainer().getId(), request.getContainer().getAttachmentFolder().getId(), documentDescriptor.getDoctype()); emailData.setAttachmentIds(Arrays.asList(ackFile.getFileId())); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String userIdOrName = request.getCreator(); try { if (request.isExternal()) { getNotificationSender().sendEmailWithAttachments(emailData, auth, userIdOrName); } else { getNotificationSender().sendEmailWithAttachments(emailData, auth, getUserDao().findByUserId(userIdOrName)); } } catch (Exception e) { log.error("Unable to email {} for {} [{}]", request.getRequestType(), documentDescriptor.getDoctype(), requestId, e); } } } }  }
AcknowledgementDocumentService { public void emailAcknowledgement(Long requestId) { if (!foiaConfigurationService.readConfiguration().getReceivedDateEnabled()) { FOIARequest request = getRequestDao().find(requestId); String emailAddress = extractRequestorEmailAddress(request.getOriginator().getPerson()); if (emailAddress != null) { EmailWithAttachmentsDTO emailData = new EmailWithAttachmentsDTO(); emailData.setEmailAddresses(Arrays.asList(emailAddress)); emailData.setSubject(String.format("%s %s", request.getRequestType(), request.getCaseNumber())); emailData.setHeader(EMAIL_HEADER_ATTACHMENT); try { String body = getTemplatingEngine().process(emailBodyTemplate, "request", request); emailData.setBody(body); emailData.setTemplate(body); } catch (TemplateException | IOException e) { log.error("Unable to generate email for {} about {} with ID [{}]", emailAddress, request.getObjectType(), requestId, e); emailData.setBody(EMAIL_BODY_ATTACHMENT); } emailData.setFooter(EMAIL_FOOTER_ATTACHMENT); FOIADocumentDescriptor documentDescriptor = documentGeneratorService.getDocumentDescriptor(request, FOIAConstants.ACK); EcmFile ackFile = getEcmFileDao().findForContainerAttachmentFolderAndFileType(request.getContainer().getId(), request.getContainer().getAttachmentFolder().getId(), documentDescriptor.getDoctype()); emailData.setAttachmentIds(Arrays.asList(ackFile.getFileId())); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String userIdOrName = request.getCreator(); try { if (request.isExternal()) { getNotificationSender().sendEmailWithAttachments(emailData, auth, userIdOrName); } else { getNotificationSender().sendEmailWithAttachments(emailData, auth, getUserDao().findByUserId(userIdOrName)); } } catch (Exception e) { log.error("Unable to email {} for {} [{}]", request.getRequestType(), documentDescriptor.getDoctype(), requestId, e); } } } }  void emailAcknowledgement(Long requestId); void generateAndUpload(String objectType, Long requestId); NotificationSender getNotificationSender(); void setNotificationSender(NotificationSender notificationSender); UserDao getUserDao(); void setUserDao(UserDao userDao); EcmFileDao getEcmFileDao(); void setEcmFileDao(EcmFileDao ecmFileDao); FOIARequestDao getRequestDao(); void setRequestDao(FOIARequestDao requestDao); FOIADocumentGeneratorService getDocumentGeneratorService(); void setDocumentGeneratorService(FOIADocumentGeneratorService documentDescriptorService); DocumentGenerator getDocumentGenerator(); void setDocumentGenerator(DocumentGenerator documentGenerator); FoiaConfigurationService getFoiaConfigurationService(); void setFoiaConfigurationService(FoiaConfigurationService foiaConfigurationService); FOIAQueueCorrespondenceService getFoiaQueueCorrespondenceService(); void setFoiaQueueCorrespondenceService(FOIAQueueCorrespondenceService foiaQueueCorrespondenceService); String getEmailBodyTemplate(); void setEmailBodyTemplate(Resource emailBodyTemplate); TemplatingEngine getTemplatingEngine(); void setTemplatingEngine(TemplatingEngine templatingEngine); }
AcknowledgementDocumentService { public void emailAcknowledgement(Long requestId) { if (!foiaConfigurationService.readConfiguration().getReceivedDateEnabled()) { FOIARequest request = getRequestDao().find(requestId); String emailAddress = extractRequestorEmailAddress(request.getOriginator().getPerson()); if (emailAddress != null) { EmailWithAttachmentsDTO emailData = new EmailWithAttachmentsDTO(); emailData.setEmailAddresses(Arrays.asList(emailAddress)); emailData.setSubject(String.format("%s %s", request.getRequestType(), request.getCaseNumber())); emailData.setHeader(EMAIL_HEADER_ATTACHMENT); try { String body = getTemplatingEngine().process(emailBodyTemplate, "request", request); emailData.setBody(body); emailData.setTemplate(body); } catch (TemplateException | IOException e) { log.error("Unable to generate email for {} about {} with ID [{}]", emailAddress, request.getObjectType(), requestId, e); emailData.setBody(EMAIL_BODY_ATTACHMENT); } emailData.setFooter(EMAIL_FOOTER_ATTACHMENT); FOIADocumentDescriptor documentDescriptor = documentGeneratorService.getDocumentDescriptor(request, FOIAConstants.ACK); EcmFile ackFile = getEcmFileDao().findForContainerAttachmentFolderAndFileType(request.getContainer().getId(), request.getContainer().getAttachmentFolder().getId(), documentDescriptor.getDoctype()); emailData.setAttachmentIds(Arrays.asList(ackFile.getFileId())); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String userIdOrName = request.getCreator(); try { if (request.isExternal()) { getNotificationSender().sendEmailWithAttachments(emailData, auth, userIdOrName); } else { getNotificationSender().sendEmailWithAttachments(emailData, auth, getUserDao().findByUserId(userIdOrName)); } } catch (Exception e) { log.error("Unable to email {} for {} [{}]", request.getRequestType(), documentDescriptor.getDoctype(), requestId, e); } } } }  void emailAcknowledgement(Long requestId); void generateAndUpload(String objectType, Long requestId); NotificationSender getNotificationSender(); void setNotificationSender(NotificationSender notificationSender); UserDao getUserDao(); void setUserDao(UserDao userDao); EcmFileDao getEcmFileDao(); void setEcmFileDao(EcmFileDao ecmFileDao); FOIARequestDao getRequestDao(); void setRequestDao(FOIARequestDao requestDao); FOIADocumentGeneratorService getDocumentGeneratorService(); void setDocumentGeneratorService(FOIADocumentGeneratorService documentDescriptorService); DocumentGenerator getDocumentGenerator(); void setDocumentGenerator(DocumentGenerator documentGenerator); FoiaConfigurationService getFoiaConfigurationService(); void setFoiaConfigurationService(FoiaConfigurationService foiaConfigurationService); FOIAQueueCorrespondenceService getFoiaQueueCorrespondenceService(); void setFoiaQueueCorrespondenceService(FOIAQueueCorrespondenceService foiaQueueCorrespondenceService); String getEmailBodyTemplate(); void setEmailBodyTemplate(Resource emailBodyTemplate); TemplatingEngine getTemplatingEngine(); void setTemplatingEngine(TemplatingEngine templatingEngine);  }