FoodWaveBean.java
3.97 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
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import fi.codecrew.moya.enums.apps.ShopPermission;
import fi.codecrew.moya.facade.FoodWaveFacade;
import fi.codecrew.moya.facade.FoodWaveTemplateFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.FoodWaveTemplate;
import fi.codecrew.moya.model.Product;
/**
* Session Bean implementation class FoodWaveBean
*/
@Stateless
@DeclareRoles({ ShopPermission.S_MANAGE_PRODUCTS, ShopPermission.S_SHOP_FOODWAVE, ShopPermission.S_MANAGE_FOODWAVES })
public class FoodWaveBean implements FoodWaveBeanLocal {
@EJB
private FoodWaveTemplateFacade fwtFacade;
@EJB
private FoodWaveFacade foodWaveFacade;
@EJB
private ProductFacade productfacade;
@Override
@RolesAllowed(ShopPermission.S_MANAGE_PRODUCTS)
public List<FoodWaveTemplate> getTemplates() {
return fwtFacade.findAllTemplates();
}
@Override
@RolesAllowed(ShopPermission.S_MANAGE_PRODUCTS)
public void createFoodWave(FoodWave fw) {
foodWaveFacade.create(fw);
}
@Override
@RolesAllowed(ShopPermission.S_MANAGE_PRODUCTS)
public FoodWaveTemplate saveOrCreateTemplate(FoodWaveTemplate template) {
if (template.getId() == null)
{
fwtFacade.create(template);
} else {
template = fwtFacade.merge(template);
}
return template;
}
@Override
public List<FoodWave> findShoppableFoodwaves() {
throw new java.lang.UnsupportedOperationException();
}
@Override
@RolesAllowed(ShopPermission.S_SHOP_FOODWAVE)
public List<FoodWave> getOpenFoodWaves() {
return foodWaveFacade.getOpenFoodWaves();
}
@RolesAllowed({ ShopPermission.S_SHOP_FOODWAVE, ShopPermission.S_MANAGE_FOODWAVES })
public FoodWave findFoodwave(Integer foodwaveId) {
return foodWaveFacade.find(foodwaveId);
}
@Override
public FoodWaveTemplate saveTemplate(FoodWaveTemplate waveTemplate) {
return fwtFacade.merge(waveTemplate);
}
@Override
public FoodWave merge(FoodWave foodWave) {
foodWave = foodWaveFacade.merge(foodWave);
return foodWave;
}
@Override
public FoodWaveTemplate findTemplate(Integer templateId) {
return fwtFacade.find(templateId);
}
@Override
public List<FoodWave> getEventFoodWaves() {
return foodWaveFacade.getEventFoodWaves();
}
@Override
@RolesAllowed(ShopPermission.S_MANAGE_FOODWAVES)
public FoodWaveTemplate addProductToTemplate(FoodWaveTemplate template, Product product) {
template = fwtFacade.reload(template);
if (product.getId() == null)
{
productfacade.create(product);
} else {
product = productfacade.reload(product);
}
if (product.getFoodWaveTemplates() == null) {
product.setFoodWaveTemplates(new ArrayList<FoodWaveTemplate>());
}
if (template.getProducts() == null)
{
template.setProducts(new ArrayList<Product>());
}
template.getProducts().add(product);
product.getFoodWaveTemplates().add(template);
return template;
}
@Override
public FoodWaveTemplate removeProductFromTemplate(Product product, FoodWaveTemplate template) {
template = fwtFacade.merge(template);
product = productfacade.merge(product);
template.getProducts().remove(product);
product.getFoodWaveTemplates().remove(template);
return template;
}
}