aaltoja, aaltoja

1 parent 76da913a
......@@ -75,5 +75,10 @@ public class FoodWaveBean implements FoodWaveBeanLocal {
public FoodWaveTemplate findTemplate(Integer templateId) {
return fwtFacade.find(templateId);
}
@Override
public List<FoodWave> getEventFoodWaves() {
return foodWaveFacade.getEventFoodWaves();
}
}
......@@ -21,24 +21,28 @@ import fi.insomnia.bortal.model.OrgRole_;
public class FoodWaveFacade extends IntegerPkGenericFacade<FoodWave> {
@EJB
EventBeanLocal eventBean;
public FoodWaveFacade() {
super(FoodWave.class);
}
public List<FoodWave> getEventFoodWaves() {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<FoodWave> cq = cb.createQuery(FoodWave.class);
Root<FoodWave> root = cq.from(FoodWave.class);
cq.where( cb.equal(root.get(FoodWave_.template).get(FoodWaveTemplate_.event), eventBean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList();
}
public List<FoodWave> getOpenFoodWaves() {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<FoodWave> cq = cb.createQuery(FoodWave.class);
Root<FoodWave> root = cq.from(FoodWave.class);
cq.where(cb.greaterThan(root.get(FoodWave_.time), Calendar.getInstance()),
cb.isFalse(root.get(FoodWave_.closed)),
cb.equal(root.get(FoodWave_.template).get(FoodWaveTemplate_.event), eventBean.getCurrentEvent())
);
cq.where(cb.greaterThan(root.get(FoodWave_.time), Calendar.getInstance()), cb.isFalse(root.get(FoodWave_.closed)), cb.equal(root.get(FoodWave_.template).get(FoodWaveTemplate_.event), eventBean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList();
}
......
......@@ -25,4 +25,6 @@ public interface FoodWaveBeanLocal {
public FoodWave findFoodwave(Integer foodwaveId);
public FoodWave merge(FoodWave foodWave);
public List<FoodWave> getEventFoodWaves();
}
......@@ -47,6 +47,9 @@ public class FoodWave extends GenericEntity {
@OneToMany(mappedBy = "foodWave")
private List<AccountEvent> accountEvents;
@OneToMany(mappedBy = "foodwave")
private List<BillLine> billLines;
@ManyToOne
@JoinColumn(name = "template_id", referencedColumnName = "id", nullable = false)
private FoodWaveTemplate template;
......@@ -92,7 +95,7 @@ public class FoodWave extends GenericEntity {
public boolean isClosed() {
return closed;
}
public void setClosed(boolean waveClosed) {
this.closed = waveClosed;
}
......@@ -112,7 +115,7 @@ public class FoodWave extends GenericEntity {
public FoodWaveTemplate getTemplate() {
return template;
}
public boolean isFull() {
return false;
}
......@@ -121,30 +124,46 @@ public class FoodWave extends GenericEntity {
* Check if foodwave is orderable
*
* That means that it's not closed, full and it's in future
*
* @return
*/
public boolean isOrderable() {
if(isClosed()) {
if (isClosed()) {
return false;
}
if(getTime().before(Calendar.getInstance())) {
if (getTime().before(Calendar.getInstance())) {
return false;
}
if(isFull()) {
if (isFull()) {
return false;
}
return true;
}
}
public List<BillLine> getBillLines() {
return billLines;
}
public void setBillLines(List<BillLine> billLines) {
this.billLines = billLines;
}
public int getReservedCount() {
int retval = 0;
if (getAccountEvents() != null) {
retval += getAccountEvents().size();
}
if (getBillLines() != null) {
retval += getBillLines().size();
}
return retval;
}
}
......@@ -9,8 +9,8 @@
</session-config>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
<!--<param-value>Development</param-value>-->
<!-- <param-value>Production</param-value> -->
<param-value>Development</param-value>
</context-param>
<context-param>
......
......@@ -37,8 +37,7 @@ public class FoodWaveView extends GenericCDIView {
public void initTemplateList() {
if (super.requirePermissions(ShopPermission.LIST_USERPRODUCTS)) {
setTemplates(new ListDataModel<FoodWaveTemplate>(
foodWaveBean.getTemplates()));
setTemplates(new ListDataModel<FoodWaveTemplate>(foodWaveBean.getTemplates()));
super.beginConversation();
}
......@@ -65,8 +64,11 @@ public class FoodWaveView extends GenericCDIView {
}
public void initUserFoodWaveList() {
this.foodWaves = new ListDataModel<FoodWave>(
foodWaveBean.getOpenFoodWaves());
this.foodWaves = new ListDataModel<FoodWave>(foodWaveBean.getOpenFoodWaves());
}
public void initFoodwaveManagerList() {
this.foodWaves = new ListDataModel<FoodWave>(foodWaveBean.getEventFoodWaves());
}
public String editTemplate() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!