mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Remove unnecessary escape method (#6692)
This commit is contained in:
		
							parent
							
								
									ce84336ef6
								
							
						
					
					
						commit
						17fe98432d
					
				| @ -34,7 +34,8 @@ import org.apache.cloudstack.quota.dao.QuotaAccountDao; | ||||
| import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; | ||||
| import org.apache.cloudstack.quota.vo.QuotaAccountVO; | ||||
| import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; | ||||
| import org.apache.commons.lang3.text.StrSubstitutor; | ||||
| import org.apache.commons.lang.StringEscapeUtils; | ||||
| import org.apache.commons.lang.text.StrSubstitutor; | ||||
| import org.apache.log4j.Logger; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| @ -81,6 +82,10 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana | ||||
| 
 | ||||
|     boolean _smtpDebug = false; | ||||
| 
 | ||||
|     static final String ACCOUNT_NAME = "accountName"; | ||||
|     static final String ACCOUNT_USERS = "accountUsers"; | ||||
|     static final String DOMAIN_NAME = "domainName"; | ||||
| 
 | ||||
|     public QuotaAlertManagerImpl() { | ||||
|         super(); | ||||
|     } | ||||
| @ -203,25 +208,20 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana | ||||
|                 userNames = userNames.substring(0, userNames.length() - 1); | ||||
|             } | ||||
| 
 | ||||
|             final Map<String, String> optionMap = new HashMap<String, String>(); | ||||
|             optionMap.put("accountName", account.getAccountName()); | ||||
|             optionMap.put("accountID", account.getUuid()); | ||||
|             optionMap.put("accountUsers", userNames); | ||||
|             optionMap.put("domainName", accountDomain.getName()); | ||||
|             optionMap.put("domainID", accountDomain.getUuid()); | ||||
|             optionMap.put("quotaBalance", QuotaConfig.QuotaCurrencySymbol.value() + " " + balance.toString()); | ||||
|             if (emailType == QuotaEmailTemplateTypes.QUOTA_STATEMENT) { | ||||
|                 optionMap.put("quotaUsage", QuotaConfig.QuotaCurrencySymbol.value() + " " + usage.toString()); | ||||
|             } | ||||
|             final Map<String, String> subjectOptionMap = generateOptionMap(account, userNames, accountDomain, balance, usage, emailType, false); | ||||
|             final Map<String, String> bodyOptionMap = generateOptionMap(account, userNames, accountDomain, balance, usage, emailType, true); | ||||
| 
 | ||||
|             if (s_logger.isDebugEnabled()) { | ||||
|                 s_logger.debug("accountName" + account.getAccountName() + "accountID" + account.getUuid() + "accountUsers" + userNames + "domainName" + accountDomain.getName() + "domainID" | ||||
|                         + accountDomain.getUuid()); | ||||
|                 s_logger.debug(String.format("Sending quota alert with values: accountName [%s], accountID [%s], accountUsers [%s], domainName [%s], domainID [%s].", | ||||
|                         account.getAccountName(), account.getUuid(), userNames, accountDomain.getName(), accountDomain.getUuid())); | ||||
|             } | ||||
| 
 | ||||
|             final StrSubstitutor templateEngine = new StrSubstitutor(optionMap); | ||||
|             final String subject = templateEngine.replace(emailTemplate.getTemplateSubject()); | ||||
|             final String body = templateEngine.replace(emailTemplate.getTemplateBody()); | ||||
|             final StrSubstitutor subjectSubstitutor = new StrSubstitutor(subjectOptionMap); | ||||
|             final String subject = subjectSubstitutor.replace(emailTemplate.getTemplateSubject()); | ||||
| 
 | ||||
|             final StrSubstitutor bodySubstitutor = new StrSubstitutor(bodyOptionMap); | ||||
|             final String body = bodySubstitutor.replace(emailTemplate.getTemplateBody()); | ||||
| 
 | ||||
|             try { | ||||
|                 sendQuotaAlert(account.getUuid(), emailRecipients, subject, body); | ||||
|                 emailToBeSent.sentSuccessfully(_quotaAcc); | ||||
| @ -237,6 +237,34 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /* | ||||
|     * | ||||
|     * | ||||
|      */ | ||||
|     public Map<String, String> generateOptionMap(AccountVO accountVO, String userNames, DomainVO domainVO, final BigDecimal balance, final BigDecimal usage, | ||||
|                                                  final QuotaConfig.QuotaEmailTemplateTypes emailType, boolean escapeHtml) { | ||||
|         final Map<String, String> optionMap = new HashMap<>(); | ||||
|         optionMap.put("accountID", accountVO.getUuid()); | ||||
|         optionMap.put("domainID", domainVO.getUuid()); | ||||
|         optionMap.put("quotaBalance", QuotaConfig.QuotaCurrencySymbol.value() + " " + balance.toString()); | ||||
| 
 | ||||
|         if (emailType == QuotaEmailTemplateTypes.QUOTA_STATEMENT) { | ||||
|             optionMap.put("quotaUsage", QuotaConfig.QuotaCurrencySymbol.value() + " " + usage.toString()); | ||||
|         } | ||||
| 
 | ||||
|         if (escapeHtml) { | ||||
|             optionMap.put(ACCOUNT_NAME, StringEscapeUtils.escapeHtml(accountVO.getAccountName())); | ||||
|             optionMap.put(ACCOUNT_USERS, StringEscapeUtils.escapeHtml(userNames)); | ||||
|             optionMap.put(DOMAIN_NAME, StringEscapeUtils.escapeHtml(domainVO.getName())); | ||||
|             return optionMap; | ||||
|         } | ||||
| 
 | ||||
|         optionMap.put(ACCOUNT_NAME, accountVO.getAccountName()); | ||||
|         optionMap.put(ACCOUNT_USERS, userNames); | ||||
|         optionMap.put(DOMAIN_NAME, domainVO.getName()); | ||||
|         return optionMap; | ||||
|     } | ||||
| 
 | ||||
|     public static long getDifferenceDays(Date d1, Date d2) { | ||||
|         long diff = d2.getTime() - d1.getTime(); | ||||
|         return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); | ||||
|  | ||||
| @ -61,7 +61,6 @@ import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; | ||||
| import org.apache.cloudstack.quota.vo.QuotaTariffVO; | ||||
| import org.apache.cloudstack.quota.vo.QuotaUsageVO; | ||||
| import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; | ||||
| import org.apache.commons.lang.StringEscapeUtils; | ||||
| import org.apache.log4j.Logger; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| @ -552,8 +551,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { | ||||
|     @Override | ||||
|     public boolean updateQuotaEmailTemplate(QuotaEmailTemplateUpdateCmd cmd) { | ||||
|         final String templateName = cmd.getTemplateName(); | ||||
|         final String templateSubject = StringEscapeUtils.escapeJavaScript(cmd.getTemplateSubject()); | ||||
|         final String templateBody = StringEscapeUtils.escapeJavaScript(cmd.getTemplateBody()); | ||||
|         final String templateSubject = cmd.getTemplateSubject(); | ||||
|         final String templateBody = cmd.getTemplateBody(); | ||||
|         final String locale = cmd.getLocale(); | ||||
| 
 | ||||
|         final List<QuotaEmailTemplatesVO> templates = _quotaEmailTemplateDao.listAllQuotaEmailTemplates(templateName); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user