1
2
3
4 package de.tivsource.page.install;
5
6 import java.util.Date;
7 import java.util.logging.Logger;
8
9 import javax.ejb.EJB;
10 import javax.servlet.ServletContextEvent;
11 import javax.servlet.ServletContextListener;
12
13 import de.tivsource.page.dao.administration.RoleDaoLocal;
14 import de.tivsource.page.dao.administration.UserDaoLocal;
15 import de.tivsource.page.dao.property.PropertyDaoLocal;
16 import de.tivsource.page.entity.property.Property;
17
18
19
20
21
22 public class AppStartup implements ServletContextListener {
23
24 private static final Logger LOGGER = Logger.getLogger("INFO");
25
26 @EJB
27 private RoleDaoLocal roleDaoLocal;
28
29 @EJB
30 private UserDaoLocal userDaoLocal;
31
32 @EJB
33 private PropertyDaoLocal propertyDaoLocal;
34
35 @Override
36 public void contextDestroyed(ServletContextEvent arg0) {
37
38 }
39
40 @Override
41 public void contextInitialized(ServletContextEvent arg0) {
42
43
44 Property dbProperty = propertyDaoLocal.findByKey("isInstalled");
45 boolean isInstalled = false;
46
47 if(dbProperty != null) {
48 isInstalled = dbProperty.getValue().equals("true") ? true : false;
49 }
50
51
52 if(!isInstalled) {
53 CreateRole createRole = new CreateRole();
54 createRole.setRoleDaoLocal(roleDaoLocal);
55 createRole.generate();
56
57 CreateUser createUser = new CreateUser();
58 createUser.setUserDaoLocal(userDaoLocal);
59 createUser.setRoleDaoLocal(roleDaoLocal);
60 createUser.generate();
61
62
63 Property property = new Property();
64 property.setKey("isInstalled");
65 property.setModified(new Date());
66 property.setModifiedAddress("localhost");
67 property.setModifiedBy("Installer");
68 property.setValue("true");
69 propertyDaoLocal.merge(property);
70 }
71
72 checkAllAttributesExisting();
73
74 }
75
76
77
78
79 private void checkAllAttributesExisting() {
80 String[][] properties = {
81 {"appointment.archive.list.description", "true"},
82 {"appointment.archive.list.pointInTime.date", "true"},
83 {"appointment.archive.list.pointInTime.date.preposition", "true"},
84 {"appointment.archive.list.pointInTime.nice", "true"},
85 {"appointment.archive.list.pointInTime.time", "true"},
86 {"appointment.archive.pointInTime.date", "true"},
87 {"appointment.archive.pointInTime.nice", "true"},
88 {"appointment.archive.pointInTime.time", "true"},
89 {"appointment.booking.text.de", "Ticket kaufen"},
90 {"appointment.booking.text.en", "Buy a ticket"},
91 {"appointment.list.description", "true"},
92 {"appointment.list.pointInTime.date", "true"},
93 {"appointment.list.pointInTime.date.preposition", "true"},
94 {"appointment.list.pointInTime.nice", "true"},
95 {"appointment.list.pointInTime.time", "true"},
96 {"appointment.pointInTime.date", "true"},
97 {"appointment.pointInTime.nice", "true"},
98 {"appointment.pointInTime.time", "true"},
99 {"captcha.image.lastModified", "Sun, 24 Nov 2019 14:26:08 GMT"},
100 {"companion.page.enabled", "false"},
101 {"contact.page.enabled", "true"},
102 {"cookieconsent.button.background", "#f1d600"},
103 {"cookieconsent.content.dismiss", "Akzeptieren"},
104 {"cookieconsent.content.href", "/public/privacy/index.html"},
105 {"cookieconsent.content.link", "Mehr erfahren"},
106 {"cookieconsent.content.message", "Wir verwenden Cookies, um Ihr Erlebnis auf unserer Website so angenehm wie möglich zu gestalten. Durch die Nutzung unserer Website erklären Sie sich mit unserer Verwendung von Cookies einverstanden."},
107 {"cookieconsent.content.target", ""},
108 {"cookieconsent.popup.background", "#000"},
109 {"cookieconsent.position", "top"},
110 {"css-path", "/var/www/html/css/"},
111 {"cssFile.lastModified", "Sun, 24 Nov 2019 14:26:08 GMT"},
112 {"event.show.description", "true"},
113 {"module.request", "false"},
114 {"request.template.path", "file:/srv/tiv-page/templates/template_request.xml"},
115 };
116 for (int i = 0; i < properties.length; i++) {
117 if(!checkAttribute(properties[i][0], properties[i][1])) {
118 LOGGER.info("Eigenschaft: " + properties[i][0] + " hinzugefügt.");
119 }
120 }
121 }
122
123 private Boolean checkAttribute(String inputKey, String inputValue) {
124 Property dbProperty = propertyDaoLocal.findByKey(inputKey);
125
126 if(dbProperty != null) {
127 return true;
128 }
129 Property property = new Property();
130 property.setKey(inputKey);
131 property.setModified(new Date());
132 property.setModifiedAddress("localhost");
133 property.setModifiedBy("Installer");
134 property.setValue(inputValue);
135 propertyDaoLocal.merge(property);
136 return false;
137 }
138
139 }