List of usage examples for java.text DateFormat FULL
int FULL
To view the source code for java.text DateFormat FULL.
Click Source Link
From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderSentConfirmationEmailBean orderSentConfirmationEmailBean) *///from w ww .ja va 2 s . co m public void buildAndSaveOrderShippedConfirmationMail(final RequestData requestData, final Customer customer, final String velocityPath, final OrderSentConfirmationEmailBean orderSentConfirmationEmailBean) throws Exception { try { final Localization localization = requestData.getLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(orderSentConfirmationEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put("currentDate", dateFormatter.format(currentDate)); model.put("customer", customer); model.put("orderSentConfirmationEmailBean", orderSentConfirmationEmailBean); model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromEmail = orderSentConfirmationEmailBean.getFromEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ORDER_SHIPPED, model); mimeMessagePreparator.setTo(customer.getEmail()); mimeMessagePreparator.setFrom(fromEmail); mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale)); mimeMessagePreparator.setReplyTo(fromEmail); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.order_shipped.shipped_email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "order-shipped-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "order-shipped-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_ORDER_SHIPPED); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { LOG.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { LOG.error("Error, can't build the message :", e); throw e; } catch (IOException e) { LOG.error("Error, can't serializable the message :", e); throw e; } }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception //w w w .j a v a2 s. co m */ public Email buildAndSaveCustomerResetPasswordConfirmationMail(final RequestData requestData, final Customer customer, final String velocityPath, final CustomerResetPasswordConfirmationEmailBean customerResetPasswordConfirmationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(customerResetPasswordConfirmationEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put(CUSTOMER, customer); model.put("customerResetPasswordConfirmationEmailBean", customerResetPasswordConfirmationEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String loginUrl = urlService.generateUrl(FoUrls.LOGIN, requestData); model.put("loginUrl", urlService.buildAbsoluteUrl(requestData, loginUrl)); String fromAddress = handleFromAddress(customerResetPasswordConfirmationEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(customerResetPasswordConfirmationEmailBean.getFromName(), locale); String toEmail = customer.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject(coreMessageSource .getMessage("email.reset_password_confirmation.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "reset-password-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "reset-password-confirmation-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } return email; }
From source file:org.rhq.enterprise.server.system.SystemManagerBean.java
@RequiredPermission(Permission.MANAGE_SETTINGS) public ServerDetails getServerDetails(Subject subject) { CoreServerMBean coreServerMBean = LookupUtil.getCoreServer(); ServerDetails serverDetails = new ServerDetails(); serverDetails.setProductInfo(getProductInfo(subject)); HashMap<Detail, String> details = serverDetails.getDetails(); DateFormat localTimeFormatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL); details.put(ServerDetails.Detail.SERVER_LOCAL_TIME, localTimeFormatter.format(new Date())); details.put(ServerDetails.Detail.SERVER_TIMEZONE, TimeZone.getDefault().getDisplayName()); details.put(ServerDetails.Detail.SERVER_HOME_DIR, coreServerMBean.getJBossServerHomeDir().getAbsolutePath()); details.put(ServerDetails.Detail.SERVER_INSTALL_DIR, coreServerMBean.getInstallDir().getAbsolutePath()); SystemDatabaseInformation dbInfo = SystemDatabaseInformation.getInstance(); details.put(ServerDetails.Detail.DATABASE_CONNECTION_URL, dbInfo.getDatabaseConnectionURL()); details.put(ServerDetails.Detail.DATABASE_DRIVER_NAME, dbInfo.getDatabaseDriverName()); details.put(ServerDetails.Detail.DATABASE_DRIVER_VERSION, dbInfo.getDatabaseDriverVersion()); details.put(ServerDetails.Detail.DATABASE_PRODUCT_NAME, dbInfo.getDatabaseProductName()); details.put(ServerDetails.Detail.DATABASE_PRODUCT_VERSION, dbInfo.getDatabaseProductVersion()); details.put(ServerDetails.Detail.CURRENT_MEASUREMENT_TABLE, dbInfo.getCurrentMeasurementTable()); details.put(ServerDetails.Detail.NEXT_MEASUREMENT_TABLE_ROTATION, dbInfo.getNextMeasurementTableRotation()); return serverDetails; }
From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, OrderSentConfirmationEmailBean orderSentConfirmationEmailBean) *//* w w w . j av a 2 s. co m*/ public void buildAndSaveOrderShippedConfirmationMail(final RequestData requestData, final Customer customer, final String velocityPath, final OrderSentConfirmationEmailBean orderSentConfirmationEmailBean) throws Exception { try { final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(orderSentConfirmationEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put(CUSTOMER, customer); model.put("orderSentConfirmationEmailBean", orderSentConfirmationEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromAddress = handleFromAddress(orderSentConfirmationEmailBean.getFromAddress(), locale); String fromName = handleFromName(orderSentConfirmationEmailBean.getFromName(), locale); String toEmail = customer.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ORDER_SHIPPED, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.order_shipped.shipped_email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "order-shipped-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "order-shipped-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_ORDER_SHIPPED); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } }
From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean) *//*from ww w . ja v a 2s . com*/ public void buildAndSaveAbandonedShoppingCartMail(final RequestData requestData, final Customer customer, final String velocityPath, final AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean) throws Exception { try { final Localization localization = requestData.getLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(abandonedShoppingCartEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put("currentDate", dateFormatter.format(currentDate)); model.put("customer", customer); model.put("abandonedShoppingCartEmailBean", abandonedShoppingCartEmailBean); model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromEmail = abandonedShoppingCartEmailBean.getFromEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART, model); mimeMessagePreparator.setTo(customer.getEmail()); mimeMessagePreparator.setFrom(fromEmail); mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale)); mimeMessagePreparator.setReplyTo(fromEmail); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject(coreMessageSource .getMessage("email.abandoned_shopping_cart.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "abandoned-shopping-cart-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "abandoned-shopping-cart-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { LOG.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { LOG.error("Error, can't build the message :", e); throw e; } catch (IOException e) { LOG.error("Error, can't serializable the message :", e); throw e; } }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception // w ww .j a v a 2 s.c o m */ public Email buildAndSaveUserNewAccountMail(final RequestData requestData, final String velocityPath, final UserNewAccountConfirmationEmailBean userNewAccountConfirmationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(userNewAccountConfirmationEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put("userNewAccountConfirmationEmailBean", userNewAccountConfirmationEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); Map<String, String> urlParams = new HashMap<String, String>(); urlParams.put(RequestConstants.REQUEST_PARAMETER_NEW_CUSTOMER_VALIDATION_EMAIL, URLEncoder.encode(userNewAccountConfirmationEmailBean.getEmail(), Constants.ANSI)); urlParams.put(RequestConstants.REQUEST_PARAMETER_NEW_ACCOUNT_VALIDATION_TOKEN, UUID.randomUUID().toString()); String resetPasswordUrl = urlService.generateUrl(FoUrls.CUSTOMER_NEW_ACCOUNT_VALIDATION, requestData, urlParams); model.put("newUserValidationUrl", urlService.buildAbsoluteUrl(requestData, resetPasswordUrl)); String fromAddress = handleFromAddress(userNewAccountConfirmationEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(userNewAccountConfirmationEmailBean.getFromName(), locale); String toEmail = userNewAccountConfirmationEmailBean.getToEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_NEW_ACCOUNT_CONFIRMATION, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { userNewAccountConfirmationEmailBean.getLastname(), userNewAccountConfirmationEmailBean.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.new_account.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "new-account-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "new-account-confirmation-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_NEW_ACCOUNT_CONFIRMATION); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } return email; }
From source file:org.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see org.hoteia.qalingo.core.service.EmailService#buildAndSaveOrderShippedConfirmationMail(Localization localization, Customer customer, String velocityPath, AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean) *//*from w w w.j a va 2 s. c o m*/ public void buildAndSaveAbandonedShoppingCartMail(final RequestData requestData, final Customer customer, final String velocityPath, final AbandonedShoppingCartEmailBean abandonedShoppingCartEmailBean) throws Exception { try { final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(abandonedShoppingCartEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put(CUSTOMER, customer); model.put("abandonedShoppingCartEmailBean", abandonedShoppingCartEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromAddress = handleFromAddress(abandonedShoppingCartEmailBean.getFromAddress(), locale); String fromName = handleFromName(abandonedShoppingCartEmailBean.getFromName(), locale); String toEmail = customer.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { customer.getLastname(), customer.getFirstname() }; mimeMessagePreparator.setSubject(coreMessageSource .getMessage("email.abandoned_shopping_cart.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "abandoned-shopping-cart-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "abandoned-shopping-cart-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_ABANDONED_SHOPPING_CART); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception // w w w . j a va 2 s . c o m */ public Email buildAndSaveUserForgottenPasswordMail(final RequestData requestData, final User user, final String velocityPath, final UserForgottenPasswordEmailBean userForgottenPasswordEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(userForgottenPasswordEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put(CUSTOMER, user); model.put("userForgottenPasswordEmailBean", userForgottenPasswordEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); Map<String, String> urlParams = new HashMap<String, String>(); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_EMAIL, URLEncoder.encode(user.getEmail(), Constants.ANSI)); urlParams.put(RequestConstants.REQUEST_PARAMETER_PASSWORD_RESET_TOKEN, userForgottenPasswordEmailBean.getToken()); String resetPasswordUrl = backofficeUrlService.generateUrl(BoUrls.RESET_PASSWORD, requestData, urlParams); model.put("activeChangePasswordUrl", backofficeUrlService.buildAbsoluteUrl(requestData, resetPasswordUrl)); String canceResetPasswordUrl = backofficeUrlService.generateUrl(BoUrls.CANCEL_RESET_PASSWORD, requestData, urlParams); model.put("cancelChangePasswordUrl", backofficeUrlService.buildAbsoluteUrl(requestData, canceResetPasswordUrl)); model.put("userForgottenPasswordEmailBean", userForgottenPasswordEmailBean); String fromAddress = handleFromAddress(userForgottenPasswordEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(userForgottenPasswordEmailBean.getFromName(), locale); String toEmail = user.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_FORGOTTEN_PASSWORD, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { user.getLastname(), user.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.forgotten_password.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "forgotten-password-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "forgotten-password-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_FORGOTTEN_PASSWORD); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } return email; }
From source file:org.sakaiproject.assignment2.logic.impl.AssignmentLogicImpl.java
/** * Given the originalAssignment and the updated (or newly created) version, will determine if an * announcement needs to be added, updated, or deleted. Announcements are updated * if there is a change in title, open date, or group restrictions. They are * deleted if the assignment is changed to draft status. Does not re-check permissions, so * make sure you are authorized to update assignments if you call this method. * @param originalAssignmentWithGroups - original assignment with the group info populated * @param updatedAssignment - updated (or newly created) assignment with the group info populated *//*from www.ja v a 2 s . com*/ private void saveAssignmentAnnouncement(Assignment2 originalAssignment, Assignment2 updatedAssignment) { if (updatedAssignment == null) { throw new IllegalArgumentException("Null updatedAssignment passed to saveAssignmentAnnouncement"); } if (updatedAssignment.getId() == null) { throw new IllegalArgumentException( "The updatedAssignment passed to saveAssignmentAnnouncement must have an id"); } // make the open date locale-aware // use a date which is related to the current users locale DateFormat df = externalLogic.getDateFormat(null, DateFormat.FULL, bundleLogic.getLocale(), true); // create url to point back to this assignment to be included in the description // ASNN-477 //String assignUrl = externalLogic.getAssignmentViewUrl(REDIRECT_ASSIGNMENT_VIEW_ID) + "/" + updatedAssignment.getId(); String toolTitle = externalLogic.getToolTitle(); String newAnncSubject = bundleLogic.getFormattedMessage("assignment2.assignment_annc_subject", new Object[] { toolTitle, updatedAssignment.getTitle() }); String newAnncBody = bundleLogic.getFormattedMessage("assignment2.assignment_annc_body", new Object[] { updatedAssignment.getTitle(), df.format(updatedAssignment.getOpenDate()), toolTitle }); String updAnncSubject = bundleLogic.getFormattedMessage("assignment2.assignment_annc_subject_edited", new Object[] { toolTitle, updatedAssignment.getTitle() }); String updAnncBody = bundleLogic.getFormattedMessage("assignment2.assignment_annc_body_edited", new Object[] { updatedAssignment.getTitle(), df.format(updatedAssignment.getOpenDate()), toolTitle }); if (originalAssignment == null) { // this was a new assignment // check to see if there will be an announcement for the open date if (updatedAssignment.getHasAnnouncement() && !updatedAssignment.isDraft()) { // add an announcement for the open date for this assignment String announcementId = announcementLogic.addOpenDateAnnouncement( updatedAssignment.getListOfAssociatedGroupReferences(), updatedAssignment.getContextId(), newAnncSubject, newAnncBody, updatedAssignment.getOpenDate()); updatedAssignment.setAnnouncementId(announcementId); dao.update(updatedAssignment); } } else if (updatedAssignment.isDraft()) { if (updatedAssignment.getAnnouncementId() != null) { announcementLogic.deleteOpenDateAnnouncement(updatedAssignment.getAnnouncementId(), updatedAssignment.getContextId()); updatedAssignment.setAnnouncementId(null); dao.update(updatedAssignment); } } else if (originalAssignment.getAnnouncementId() == null && updatedAssignment.getHasAnnouncement()) { // this is a new announcement String announcementId = announcementLogic.addOpenDateAnnouncement( updatedAssignment.getListOfAssociatedGroupReferences(), updatedAssignment.getContextId(), newAnncSubject, newAnncBody, updatedAssignment.getOpenDate()); updatedAssignment.setAnnouncementId(announcementId); dao.update(updatedAssignment); } else if (originalAssignment.getAnnouncementId() != null && !updatedAssignment.getHasAnnouncement()) { // we must remove the original announcement announcementLogic.deleteOpenDateAnnouncement(updatedAssignment.getAnnouncementId(), updatedAssignment.getContextId()); updatedAssignment.setAnnouncementId(null); dao.update(updatedAssignment); } else if (updatedAssignment.getHasAnnouncement()) { // if title, open date, or group restrictions were updated, we need to update the announcement Date oldTime = (Date) originalAssignment.getOpenDate(); Date newTime = updatedAssignment.getOpenDate(); if (!originalAssignment.getTitle().equals(updatedAssignment.getTitle()) || (oldTime.after(newTime) || oldTime.before(newTime)) || !originalAssignment.getListOfAssociatedGroupReferences() .equals(updatedAssignment.getListOfAssociatedGroupReferences())) { announcementLogic.updateOpenDateAnnouncement(updatedAssignment.getAnnouncementId(), updatedAssignment.getListOfAssociatedGroupReferences(), updatedAssignment.getContextId(), updAnncSubject, updAnncBody, updatedAssignment.getOpenDate()); // don't need to re-save assignment b/c id already exists } } }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception //w ww. j a v a2 s . com */ public Email buildAndSaveUserResetPasswordConfirmationMail(final RequestData requestData, final User user, final String velocityPath, final UserResetPasswordConfirmationEmailBean userResetPasswordConfirmationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(userResetPasswordConfirmationEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put(CUSTOMER, user); model.put("userResetPasswordConfirmationEmailBean", userResetPasswordConfirmationEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String loginUrl = backofficeUrlService.generateUrl(BoUrls.LOGIN, requestData); model.put("loginUrl", backofficeUrlService.buildAbsoluteUrl(requestData, loginUrl)); String fromAddress = handleFromAddress(userResetPasswordConfirmationEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(userResetPasswordConfirmationEmailBean.getFromName(), locale); String toEmail = user.getEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); Object[] parameters = { user.getLastname(), user.getFirstname() }; mimeMessagePreparator.setSubject(coreMessageSource .getMessage("email.reset_password_confirmation.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "reset-password-confirmation-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "reset-password-confirmation-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_RESET_PASSWORD_CONFIRMATION); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } return email; }