MenuNavigation.java
5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package fi.insomnia.bortal.model;
import static javax.persistence.CascadeType.ALL;
import static javax.persistence.CascadeType.PERSIST;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
import org.eclipse.persistence.annotations.PrivateOwned;
import fi.insomnia.bortal.enums.BortalApplication;
import fi.insomnia.bortal.enums.apps.IAppPermission;
@Entity
@Table(name = "menu_navigation",
uniqueConstraints = { @UniqueConstraint(columnNames = {
MenuNavigation.ITEM_COLUMN,
MenuNavigation.EVENT_COLUMN })
})
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class MenuNavigation extends GenericEntity implements Comparable<MenuNavigation> {
private static final long serialVersionUID = 1404769998091479699L;
protected static final String ITEM_COLUMN = "item_id";
protected static final String EVENT_COLUMN = "event_id";
@ManyToOne
@JoinColumn(nullable = false, name = EVENT_COLUMN)
private LanEvent event;
@Lob
private String key;
@Lob
private String header;
@Lob
private String footer;
@Column(nullable = false)
private Integer sort = 1000;
@Column(nullable = false)
private boolean visible = false;
@ManyToOne(cascade = PERSIST)
@JoinColumn(name = ITEM_COLUMN)
private Menuitem item;
@ManyToOne()
private SitePage sitepage;
@ManyToOne
@JoinColumn(nullable = true)
private MenuNavigation parent;
@OneToMany(mappedBy = "parent", cascade = ALL)
@PrivateOwned
@OrderBy("sort")
private List<MenuNavigation> children = new ArrayList<MenuNavigation>();
@Transient
transient private IAppPermission privatePerm;
@Transient
transient private BortalApplication privateApp;
private String application;
private String permission;
private MenuNavigation() {
super();
}
public MenuNavigation(LanEvent ev, String keyString, Integer sort) {
super();
this.sort = sort;
this.event = ev;
this.key = keyString;
this.visible = true;
}
public BortalApplication getApplication() {
if (privateApp == null && application != null) {
privateApp = BortalApplication.valueOf(application);
}
return privateApp;
}
public void setPermission(IAppPermission perm) {
if (perm != null)
{
privatePerm = perm;
privateApp = perm.getParent();
this.application = perm.getParent().toString();
this.permission = perm.toString();
}
}
public IAppPermission getPermission() {
if (privatePerm == null && application != null && permission != null) {
for (IAppPermission appPerm : getApplication().getPermissions()) {
if (appPerm.toString().equals(permission)) {
privatePerm = appPerm;
break;
}
}
}
return privatePerm;
}
public List<MenuNavigation> getChildren() {
return children;
}
public void setChildren(List<MenuNavigation> children) {
this.children = children;
}
public MenuNavigation getParent() {
return parent;
}
public void setParent(MenuNavigation parent) {
this.parent = parent;
}
public Menuitem getItem() {
return item;
}
public void setItem(Menuitem item) {
this.item = item;
}
public String getFooter() {
return footer;
}
public void setFooter(String footer) {
this.footer = footer;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
@Override
public int compareTo(MenuNavigation o) {
return sort.compareTo(o.sort);
}
@Transient
private transient Integer pagesort = 0;
// used only for initialization function...
public MenuNavigation addPage(Menuitem item, IAppPermission permission) {
int childSort = 100;
if (children == null || children.size() == 0) {
children = new ArrayList<MenuNavigation>();
} else {
childSort = children.get(children.size() - 1).getSort() + 10;
}
MenuNavigation add = new MenuNavigation();
add.setSort(pagesort += 10);
if (item != null)
{
add.setKey("submenu" + item.getUrl().replace("/", "."));
}
add.setItem(item);
add.setEvent(event);
add.setPermission(permission);
add.setParent(this);
add.setVisible(true);
add.setSort(childSort);
children.add(add);
return add;
}
public SitePage getSitepage() {
return sitepage;
}
public void setSitepage(SitePage sitepage) {
this.sitepage = sitepage;
}
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
}