1 | |
package org.paneris.rimauresq.model; |
2 | |
|
3 | |
import org.paneris.rimauresq.model.generated.UserTableBase; |
4 | |
import org.melati.poem.AccessPoemException; |
5 | |
import org.melati.poem.DefinitionSource; |
6 | |
import org.melati.poem.Database; |
7 | |
import org.melati.poem.InitialisationPoemException; |
8 | |
import org.melati.poem.JdbcPersistent; |
9 | |
import org.melati.poem.Persistent; |
10 | |
import org.melati.poem.PoemException; |
11 | |
import org.melati.poem.PoemTask; |
12 | |
import org.melati.poem.PoemThread; |
13 | |
import org.melati.poem.ValidationPoemException; |
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 4 | public class UserTable extends UserTableBase { |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public UserTable( |
57 | |
Database database, String name, |
58 | |
DefinitionSource definitionSource) throws PoemException { |
59 | 4 | super(database, name, definitionSource); |
60 | 4 | } |
61 | |
|
62 | |
|
63 | |
|
64 | |
public void init() throws PoemException { |
65 | 4 | super.init(); |
66 | |
|
67 | |
|
68 | |
|
69 | 4 | getEmailColumn().setRaw_unsafe(guestUser, ""); |
70 | 4 | getEmailColumn().setRaw_unsafe(administratorUser, ""); |
71 | 4 | } |
72 | |
|
73 | |
public void postInitialise() { |
74 | 4 | super.postInitialise(); |
75 | 4 | PoemThread.withAccessToken( |
76 | |
getDatabase().getUserTable().administratorUser(), |
77 | |
new PoemTask() { |
78 | |
public void run() { |
79 | 4 | if (((User)administratorUser()).getEmail().equals("")) |
80 | 4 | getEmailColumn().setRaw_unsafe(administratorUser, |
81 | |
"rimauresq@paneris.co.uk"); |
82 | 4 | } |
83 | |
|
84 | 4 | public String toString() { |
85 | 0 | return "Creating User defaults"; |
86 | |
} |
87 | |
} |
88 | |
); |
89 | 4 | } |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public User ensure(String name, String title, String tel, |
95 | |
String email) { |
96 | 0 | User p = (User)getNameColumn().firstWhereEq(name); |
97 | 0 | if (p == null) { |
98 | 0 | p = (User)newPersistent(); |
99 | 0 | p.setLogin(name); |
100 | 0 | p.setName(name); |
101 | 0 | p.setPassword(name); |
102 | 0 | p.setTitle(title); |
103 | 0 | p.setTel(tel); |
104 | 0 | p.setEmail(email); |
105 | 0 | p.makePersistent(); |
106 | |
} |
107 | 0 | return p; |
108 | |
} |
109 | |
|
110 | |
protected JdbcPersistent _newPersistent() { |
111 | 12 | User u = (User)super._newPersistent(); |
112 | 12 | u.setNews_unsafe(Boolean.TRUE); |
113 | 12 | return u; |
114 | |
} |
115 | |
|
116 | |
public void create(Persistent persistent) |
117 | |
throws AccessPoemException, ValidationPoemException, |
118 | |
InitialisationPoemException { |
119 | 10 | User u = (User)persistent; |
120 | 10 | if (u.getLogin() == null) |
121 | 2 | u.setLogin("tmp"); |
122 | 10 | if (u.getPassword() == null) |
123 | 2 | u.setPassword("tmp"); |
124 | 10 | super.create(persistent); |
125 | 10 | if (u.getLogin() == "tmp") |
126 | 2 | u.setLogin(u.troid().toString()); |
127 | 10 | if (u.getPassword() == "tmp") |
128 | 2 | u.setPassword(u.troid().toString()); |
129 | 10 | } |
130 | |
} |
131 | |
|