aaltoja, aaltoja

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