MapManageView.java
7.95 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package fi.codecrew.moya.web.cdiview.map;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.EventMapBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class MapManageView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = -3276250982780044688L;
private static final Logger logger = LoggerFactory.getLogger(MapManageView.class);
@EJB
private transient UserBeanLocal userBean;
@EJB
private transient EventBeanLocal eventBean;
@EJB
private transient EventMapBeanLocal eventmapBean;
@EJB
private transient PlaceBeanLocal placebean;
@EJB
private transient ProductBeanLocal productbean;
private transient UploadedFile bgFile;
private List<EventMap> eventmaps;
private EventMap map;
private String mapname;
private String buyableLike;
private boolean tablesHorizontal = false;
private boolean oneRowTable = false;
private int placesInRow = 1;
private int width;
private int height;
private int startX;
private int startY;
private int tableCount = 1;
private int tableXdiff;
private int tableYdiff;
private Product mapproduct;
private String namebase;
private Integer mapId;
private List<Product> productlist;
private StreamedContent streamedFile;
private LanEvent copyEvent;
public void initCreate() {
if (super.requirePermissions(MapPermission.MANAGE_MAPS)) {
super.beginConversation();
}
}
public void initView() {
if (super.requirePermissions(MapPermission.MANAGE_MAPS)) {
map = eventmapBean.find(getMapId());
setProductlist(productbean.getProducts());
super.beginConversation();
streamedFile = new DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 18, 15)),"application/pdf", "paikkakoodit");
}
}
public String submitBg()
{
map.setMapData(bgFile.getContents());
map = eventmapBean.saveMap(map);
return null;
}
public List<EventMap> getMaps() {
if (eventmaps == null) {
eventmaps = eventBean.getCurrentEvent().getEventMaps();
}
return eventmaps;
}
public String lockBuyable() {
int count = placebean.setBuyable(map, buyableLike, false);
this.addFaceMessage("mapManage.lockedPlaces", count);
return null;
}
public String releaseBuyable() {
int count = placebean.setBuyable(map, buyableLike, true);
this.addFaceMessage("mapManage.releasedPlaces", count);
return null;
}
public String saveMap() {
eventmapBean.saveMap(getMap());
return null;
}
public String createMap() {
map = eventmapBean.create(getMapname());
return "edit";
}
public void mapClick(ActionEvent e) {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = e.getComponent().getClientId(context);
Map<String, String> requestParams = context.getExternalContext().getRequestParameterMap();
startX = new Integer(requestParams.get(clientId + ".x")).intValue();
startY = new Integer(requestParams.get(clientId + ".y")).intValue();
}
public String removeAllPlaces()
{
map = eventmapBean.clearPlaces(map);
return null;
}
public String generatePlaces() {
String[] tablenames = getNamebase().split(";");
List<Place> mapplaces = map.getPlaces();
if (mapplaces == null || mapplaces.isEmpty()) {
mapplaces = new ArrayList<Place>();
map.setPlaces(mapplaces);
}
for (int tableI = 0; tableI < tableCount; ++tableI) {
int tableXStart = tableI * tableXdiff;
int tableYStart = tableI * tableYdiff;
int rows = isOneRowTable() ? 1 : 2;
for (int rowI = 0; rowI < rows; ++rowI) {
int rowXStart = tableXStart + (tablesHorizontal ? 0 : width * rowI);
int rowYStart = tableYStart + (tablesHorizontal ? height * rowI : 0);
logger.debug("row start {} {}", rowXStart, rowYStart);
for (int placeI = 1; placeI <= placesInRow; ++placeI) {
Place place = new Place(map);
place.setHeight(Math.abs(height));
place.setWidth(Math.abs(width));
int xpos = startX + rowXStart + (tablesHorizontal ? placeI * width : 0);
int ypos = startY + rowYStart + (tablesHorizontal ? 0 : placeI * height);
logger.debug("Creating map in {} {}", xpos, ypos);
place.setMapX(xpos);
place.setMapY(ypos);
place.setProduct(mapproduct);
place.setName(tablenames[tableI] + (placeI + placesInRow * rowI));
mapplaces.add(place);
}
}
}
logger.debug("places in map after {}", mapplaces.size());
map = eventmapBean.saveMap(map);
logger.debug("places in map merge {}", map.getPlaces().size());
return null;
}
public void setMapname(String mapname) {
this.mapname = mapname;
}
public String getMapname() {
return mapname;
}
public void setMap(EventMap map) {
this.map = map;
}
public EventMap getMap() {
return map;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getStartX() {
return startX;
}
public void setStartX(int startX) {
this.startX = startX;
}
public int getStartY() {
return startY;
}
public void setStartY(int startY) {
this.startY = startY;
}
public Product getMapproduct() {
return mapproduct;
}
public void setMapproduct(Product mapproduct) {
this.mapproduct = mapproduct;
}
public String getNamebase() {
return namebase;
}
public int getTableCount() {
return tableCount;
}
public void setTableCount(int tableCount) {
this.tableCount = tableCount;
}
public int getTableXdiff() {
return tableXdiff;
}
public void setTableXdiff(int tableXdiff) {
this.tableXdiff = tableXdiff;
}
public int getTableYdiff() {
return tableYdiff;
}
public void setTableYdiff(int tableYdiff) {
this.tableYdiff = tableYdiff;
}
public void setTablesHorizontal(boolean tablesHorizontal) {
this.tablesHorizontal = tablesHorizontal;
}
public boolean isTablesHorizontal() {
return tablesHorizontal;
}
public void setPlacesInRow(int placesInRow) {
this.placesInRow = placesInRow;
}
public int getPlacesInRow() {
return placesInRow;
}
public void setOneRowTable(boolean oneRowTable) {
this.oneRowTable = oneRowTable;
}
public boolean isOneRowTable() {
return oneRowTable;
}
public void setNamebase(String namebase) {
this.namebase = namebase;
}
public void setBuyableLike(String buyableLike) {
this.buyableLike = buyableLike;
}
public String getBuyableLike() {
return buyableLike;
}
public void setMapId(Integer mapId) {
this.mapId = mapId;
}
public Integer getMapId() {
return mapId;
}
public void setProductlist(List<Product> productlist) {
this.productlist = productlist;
}
public List<Product> getProductlist() {
return productlist;
}
public LanEvent getCopyEvent() {
return copyEvent;
}
public void setCopyEvent(LanEvent copyEvent) {
this.copyEvent = copyEvent;
}
public UploadedFile getBgFile() {
return bgFile;
}
public void setBgFile(UploadedFile bgFile) {
this.bgFile = bgFile;
}
//StreamedContent new DefaultStreamedContent(pdfstream)
public StreamedContent getStreamedFile() {
//DefaultStreamedContent(new ByteArrayInputStream(placebean.generatePlacesPdf(54, 17, 10, 6)));
return streamedFile;
}
}