code_junkie

Groovy/Grails SimpleTemplateEngine Freezes

Nov 13th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. def ccIdToEmailMap = [:]
  2. def emailTemplateFile = Utilities.retrieveFile("email${File.separator}emailTemplate.gtpl")
  3. def engine = new SimpleTemplateEngine()
  4. def clientContacts = ClientContact.list()
  5. for(ClientContact cc in clientContactList)
  6. {
  7. def binding = [clientContact : cc]
  8.  
  9. //STOPS (FREEZES) EITHER HERE OR....
  10. def template = template = engine.createTemplate(emailTemplateFile).make(binding)
  11.  
  12. //OR STOPS (FREEZES) HERE
  13. def body = template.toString()
  14.  
  15. def email = [text: body, to: cc.emailAddress]
  16. ccIdToEmailMap.put(cc.id, email)
  17. println "added to map"
  18. }
  19. return ccIdToEmailMap
  20.  
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  22. "http://www.w3.org/TR/html4/loose.dtd">
  23.  
  24.  
  25. <html>
  26. <head>
  27. <title>Happy Holidays from google Partners</title>
  28. </head>
  29.  
  30. <body>
  31. <table width="492" cellpadding="0" cellspacing="0" style="border:2px solid #acacac;margin:8px auto;" align="center">
  32. <tr>
  33. <td colspan="5" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/cardbg.gif" width="492" height="10" border="0"></td>
  34. </tr>
  35.  
  36. <tr>
  37. <td width="6" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/sidebgl.gif" width="6" height="453" border="0"></td>
  38. <td style="background:#fff;border:1px solid #acacac;padding:2px;" width="228">
  39. <div style="width:208px;margin:4px 8px 0px 8px; color:#515151;">
  40. <font face="Times New Roman" size="2">
  41. <span style="font:14px 'Times New Roman',times,serif;">Static text that is the same for each email
  42. <br>&nbsp;<br>
  43. More text
  44. <br>&nbsp;<br>
  45. We wish you health and happiness during the holidays and a year of growth in 2009.
  46. </span>
  47. </font>
  48. </div>
  49. </td>
  50. <td style="background:#c9f4fe;border-top:1px solid #acacac;border-bottom:1px solid #acacac;" width="5"><img src="http://www.google.com/holiday2008/vertbg.gif" border="0" height="453" width="5"></td>
  51. <td width="247" style="background:#fff;border:1px solid #acacac;"><img src="http://www.google.com/holiday2008/snowing.gif" width="247" height="453" border="0"></td>
  52. <td width="6" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/sidebgr.gif" width="6" height="453" border="0"></td>
  53. </tr>
  54. <tr>
  55. <td width="6" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/sidebgr.gif" width="6" height="38" border="0"></td>
  56. <td colspan="3" style="border:1px solid #acacac;" align="center"><img src="http://www.google.com/holiday2008/happyholidays.gif" width="480" height="38" alt="Happy Holidays" border="0"></td>
  57. <td width="6" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/sidebgr.gif" width="6" height="38" border="0"></td>
  58. </tr>
  59. <tr>
  60. <td width="6" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/sidebgr.gif" width="6" height="120" border="0"></td>
  61. <td colspan="3" style="background-color#fff;border:1px solid #acacac;padding:2px;" valign="top">
  62. <img src="http://www.google.com/holiday2008/gogl_logo_card.gif" width="140" height="40" alt="google partners" border="0" align="right" hspace="4" vspace="4" />
  63. <font face="Times New Roman" size="2">
  64. <div style="padding:4px;font:12pt 'Times New Roman',serif;color:#515151;">
  65. <span style="font-size:10pt"><i>from:</i></span>
  66.  
  67. <div style="padding:2px 4px;">
  68. <% clientContact.owners.eachWithIndex { it, i -> %>
  69. <% if(i < (clientContact.owners.size() - 1)) { %>
  70. ${it.toString()},
  71. <% }else { %>
  72. ${it.toString()}
  73. <% } %>
  74. <% } %>
  75. </div>
  76. </div>
  77. </font>
  78. </td>
  79. <td width="6" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/sidebgr.gif" width="6" height="120" border="0"></td>
  80. </tr>
  81. <tr>
  82. <td colspan="5" bgcolor="#c1e0f3"><img src="http://www.google.com/holiday2008/cardbg.gif" width="492" height="10" border="0"></td>
  83.  
  84. </tr>
  85. </table>
  86. </body>
  87. </html>
  88.  
  89. def ccIdToEmailMap = [:]
  90. def emailTemplateFile = Utilities.retrieveFile("email${File.separator}emailTemplate.gtpl")
  91. def engine = new SimpleTemplateEngine()
  92. def template = engine.createTemplate(emailTemplateFile)
  93. def clientContacts = ClientContact.list()
  94. for(ClientContact cc in clientContactList)
  95. {
  96. def binding = [clientContact : cc]
  97. def body = template.make(binding).toString()
  98. def email = [text: body, to: cc.emailAddress]
  99. ccIdToEmailMap.put(cc.id, email)
  100. println "added to map"
  101. }
  102. return ccIdToEmailMap
  103.  
  104. def emailTemplateFile = null
  105. def ccIdToEmailMap = [:]
  106.  
  107. emailTemplateFile = Utilities.retrieveFile("email${File.separator}emailTemplate.gtpl")
  108. def engine = new SimpleTemplateEngine()
  109. def template = engine.createTemplate(emailTemplateFile)
  110. for(ClientContact cc in clientContactList)
  111. {
  112. //there was a locking problem when we tried to create the template for too many client contacts
  113. //i believe it was caused by lazy-fetching of the person/owners. So, I fetch them before we bind
  114. //and make the email body.
  115. def criteria = ClientContact.createCriteria()
  116. cc = criteria.get {
  117. eq("id", cc.id)
  118. fetchMode('relationship', FM.EAGER)
  119. fetchMode('relationship.person', FM.EAGER)
  120. }
  121. def binding = [clientContact : cc]
  122. def body = template.make(binding).toString()
  123. def email = [text: body, to: cc.emailAddress]
  124. ccIdToEmailMap.put(cc.id, email)
  125. }
  126.  
  127. return ccIdToEmailMap
Add Comment
Please, Sign In to add comment