19 package org.turro.publication.entity;
21 import java.io.IOException;
22 import java.io.Writer;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.List;
27 import java.util.TreeSet;
28 import javax.persistence.CascadeType;
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.FetchType;
32 import javax.persistence.GeneratedValue;
33 import javax.persistence.GenerationType;
34 import javax.persistence.Id;
35 import javax.persistence.OneToMany;
36 import javax.persistence.Temporal;
37 import org.turro.string.Strings;
38 import org.turro.action.queue.NotificationCategory;
39 import org.turro.action.queue.Notifications;
40 import org.turro.elephant.entities.db.MailTracker;
41 import org.turro.elephant.util.DateFormats;
42 import org.turro.html.HTMLEntities;
43 import org.turro.jpa.entity.IDaoEntity;
44 import org.turro.newsletter.SendingChoice;
45 import org.turro.plugin.contacts.IContact;
46 import org.turro.reflection.MappingSet;
56 @GeneratedValue(strategy=GenerationType.IDENTITY)
57 @Column(name=
"IDENTIFIER")
60 @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
61 private java.util.Date creation;
63 private boolean accepted, staticContent;
65 private String idCategory;
67 @Temporal(value = javax.persistence.TemporalType.DATE)
68 @Column(name=
"NEWS_DATE")
69 private java.util.Date date;
71 private String title, lang,
template;
75 @OneToMany(mappedBy =
"newsletter", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
76 private Set<NewsSection> newsSections =
new TreeSet<NewsSection>();
83 this.accepted = accepted;
91 this.staticContent = staticContent;
99 this.idCategory = idCategory;
107 this.creation = creation;
155 this.
template =
template;
159 return sendingChoice;
163 this.sendingChoice = sendingChoice;
171 this.newsSections = newsSections;
183 return Strings.isBlank(title) || newsSections.isEmpty();
189 if(newsSections.stream().anyMatch((ns) -> (ns.isUseAsTrigger()))) {
190 return newsSections.stream().anyMatch((ns) -> (ns.isUseAsTrigger() && ns.canShow(contact)));
201 idCategory = category !=
null ? category.
getIdCategory() :
null;
205 return new ArrayList<>();
209 writer.write(
"<#include \"/macros/site/*/buttonMacro.ftl\">\n");
210 writer.write(
"<#include \"/macros/site/*/summaryMacro.ftl\">\n");
211 writer.write(
"<#include \"/envelope/site/*/header" +
212 (Strings.isBlank(
template) ?
"" :
template) +
213 "Template.html\">\n");
215 writer.write(
"<@start_full_table \"2\" \"2\"/>\n");
217 for(
NewsSection ns :
new TreeSet<>(newsSections)) {
218 if(ns.canShow(contact)) {
219 ns.generateSection(writer);
223 writer.write(
"<@end_table/>\n");
225 writer.write(
"<#include \"/envelope/site/*/footer" +
226 (Strings.isBlank(
template) ?
"" :
template) +
227 "Template.html\">\n");
231 NewsSection ns =
new TreeSet<>(newsSections).lower(newsSection);
236 NewsSection ns =
new TreeSet<>(newsSections).higher(newsSection);
241 newsSections.forEach((ns) -> {
252 newsSections.forEach((ns) -> {
253 ns.resetGlobalContext();
260 MappingSet
set =
new MappingSet();
262 new String[] {
"id",
"creation",
"date",
"accepted",
"staticContent" },
263 new String[] {
"title",
"lang",
"template",
"idCategory",
"sendingChoice",
266 new String[] {
"id",
"newsOrder",
"newColumn",
"width",
"useAsTrigger",
267 "hideIfEmpty",
"type" },
268 new String[] {
"body",
"wiki",
"banner" });
static NotificationCategory getCategory(String id)
static String escape(String html)
static String unescape(String html)
void setAccepted(boolean accepted)
String getUnescapedTitle()
NotificationCategory getCategory()
void setLang(String lang)
void setCreation(Date creation)
void setIdCategory(String idCategory)
void setTitle(String title)
void setCategory(NotificationCategory category)
MappingSet getSerializerMappings()
boolean isStaticContent()
void setStaticContent(boolean staticContent)
List< MailTracker > getTrackers()
Set< NewsSection > getNewsSections()
void resetGlobalContext()
boolean trigger(IContact contact)
SendingChoice getSendingChoice()
void setNewsSections(Set< NewsSection > newsSections)
boolean checkEndRow(NewsSection newsSection)
void setSendingChoice(SendingChoice sendingChoice)
boolean checkStartRow(NewsSection newsSection)
void setTemplate(String template)
void generateNewsletter(IContact contact, Writer writer)