formatter and other stuff

1 parent 84e77079
......@@ -38,14 +38,7 @@ import fi.insomnia.bortal.utilities.I18n;
*/
@Stateless
@LocalBean
@DeclareRoles({
BillPermission.S_CREATE_BILL,
BillPermission.S_READ_ALL,
BillPermission.S_VIEW_OWN,
BillPermission.S_WRITE_ALL,
SpecialPermission.S_USER,
SpecialPermission.S_VERKKOMAKSU_CHECK,
})
@DeclareRoles({ BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER, SpecialPermission.S_VERKKOMAKSU_CHECK, })
public class BillBean implements BillBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(BillBean.class);
......@@ -92,7 +85,8 @@ public class BillBean implements BillBeanLocal {
EventUser currentuser = permbean.getCurrentUser();
logger.debug("bill {} user {}", bill, currentuser);
if (bill != null && !currentuser.equals(bill.getUser()) && !permbean.hasPermission(BillPermission.READ_ALL)) {
if (bill != null && !currentuser.equals(bill.getUser())
&& !permbean.hasPermission(BillPermission.READ_ALL)) {
bill = null;
}
return bill;
......@@ -197,26 +191,29 @@ public class BillBean implements BillBeanLocal {
@Override
@RolesAllowed(BillPermission.S_READ_ALL)
public Collection<BillSummary> getBillLineSummary() {
Collection<BillSummary> ret = billLineFacade.getLineSummary(eventbean.getCurrentEvent());
Collection<BillSummary> ret = billLineFacade.getLineSummary(eventbean
.getCurrentEvent());
return ret;
}
@Override
@RolesAllowed({ BillPermission.S_WRITE_ALL, SpecialPermission.S_VERKKOMAKSU_CHECK })
@RolesAllowed({ BillPermission.S_WRITE_ALL,
SpecialPermission.S_VERKKOMAKSU_CHECK })
public void markPaid(Bill bill, Calendar when) {
if (bill.getAccountEvent() != null || bill.getPaidDate() != null)
{
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
throw new EJBException("Bill already marked paid!");
}
bill = billFacade.reload(bill);
Product creditproduct = productBean.findCreditProduct();
EventUser user = bill.getUser();
AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), user);
AccountEvent ac = productBean.createAccountEvent(creditproduct,
bill.totalPrice(), user);
logger.info("Created creditentry. {}, userproducts {}", ac, user.getAccountEvents().size());
logger.info("Created creditentry. {}, userproducts {}", ac, user
.getAccountEvents().size());
ac.setDelivered(when);
ac.setEventTime(when);
......@@ -231,17 +228,24 @@ public class BillBean implements BillBeanLocal {
for (BillLine bl : bill.getBillLines()) {
Product prod = bl.getLineProduct();
if (prod != null
&& prod.getProductFlags().contains(ProductFlag.PREPAID_INSTANT_CREATE)) {
logger.debug("Creating Bill prepaidInstant product {}, {}", prod.getName(), bl.getQuantity());
if (prod.getProductFlags().contains(ProductFlag.RESERVE_PLACE_WHEN_BOUGHT)
|| prod.getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT))
{
placebean.lockPlaceProduct(bill.getUser(), prod, bl.getQuantity());
&& prod.getProductFlags().contains(
ProductFlag.PREPAID_INSTANT_CREATE)) {
logger.debug("Creating Bill prepaidInstant product {}, {}",
prod.getName(), bl.getQuantity());
if (prod.getProductFlags().contains(
ProductFlag.RESERVE_PLACE_WHEN_BOUGHT)
|| prod.getProductFlags().contains(
ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) {
placebean.lockPlaceProduct(bill.getUser(), prod,
bl.getQuantity());
}
AccountEvent ac2 = productPBean.createAccountEvent(prod, bl.getQuantity(), user, bill.getSentDate());
logger.info("Created ac from product. {}, userproducts {}", ac2, user.getAccountEvents().size());
AccountEvent ac2 = productPBean.createAccountEvent(prod,
bl.getQuantity(), user, bill.getSentDate(), bl.getFoodwave());
logger.info("Created ac from product. {}, userproducts {}",
ac2, user.getAccountEvents().size());
ac2.setSeller(permbean.getCurrentUser());
}
......@@ -249,7 +253,9 @@ public class BillBean implements BillBeanLocal {
}
MailMessage msg = new MailMessage();
msg.setSubject(I18n.get("bill.billMarkedPaidMail.subject"));
msg.setMessage(I18n.get("bill.billMarkedPaidMail.message", (bill.getBillNumber() == null) ? "----" : bill.getBillNumber().toString()));
msg.setMessage(I18n.get("bill.billMarkedPaidMail.message", (bill
.getBillNumber() == null) ? "----" : bill.getBillNumber()
.toString()));
msg.setTo(bill.getUser().getUser());
utilbean.sendMail(msg);
eventUserFacade.flush();
......@@ -259,9 +265,13 @@ public class BillBean implements BillBeanLocal {
@Override
@RolesAllowed({ BillPermission.S_CREATE_BILL, BillPermission.S_WRITE_ALL })
public void createBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to create bill for user ");
throw new EJBAccessException("Could not create bill for another user");
if (!permbean.isCurrentUser(bill.getUser())
&& !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied,
permbean.getCurrentUser(),
"Not enought rights to create bill for user ");
throw new EJBAccessException(
"Could not create bill for another user");
}
billFacade.create(bill);
generateBillNumber(bill);
......@@ -275,9 +285,13 @@ public class BillBean implements BillBeanLocal {
@Override
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_READ_ALL })
public List<Bill> find(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(BillPermission.READ_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to get bill list for user ");
throw new EJBAccessException("Could not list bills for another user");
if (!permbean.isCurrentUser(user)
&& !permbean.hasPermission(BillPermission.READ_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied,
permbean.getCurrentUser(),
"Not enought rights to get bill list for user ");
throw new EJBAccessException(
"Could not list bills for another user");
}
return billFacade.find(user);
}
......
......@@ -18,6 +18,7 @@ import fi.insomnia.bortal.model.AccountEvent;
import fi.insomnia.bortal.model.Discount;
import fi.insomnia.bortal.model.DiscountInstance;
import fi.insomnia.bortal.model.EventUser;
import fi.insomnia.bortal.model.FoodWave;
import fi.insomnia.bortal.model.Product;
/**
......@@ -31,7 +32,8 @@ public class ProductPBean {
private PermissionBean permbean;
@EJB
private AccountEventFacade accounteventfacade;
private static final Logger logger = LoggerFactory.getLogger(ProductPBean.class);
private static final Logger logger = LoggerFactory
.getLogger(ProductPBean.class);
/**
* Default constructor.
......@@ -40,6 +42,11 @@ public class ProductPBean {
// TODO Auto-generated constructor stub
}
public AccountEvent createAccountEvent(Product product,
BigDecimal quantity, EventUser user, Calendar date) {
return this.createAccountEvent(product, quantity, user, date, null);
}
/**
* Creates new AccountEvent from provided product to provided user <br>
* <strong>Notice</strong>, that this function expects the user parameter to
......@@ -56,11 +63,13 @@ public class ProductPBean {
* AccountEvent creation time
* @return The created AccountEvent entity
*/
public AccountEvent createAccountEvent(Product product, BigDecimal quantity, EventUser user, Calendar date) {
public AccountEvent createAccountEvent(Product product,
BigDecimal quantity, EventUser user, Calendar date,
FoodWave foodwave) {
if (!product.getEvent().equals(user.getEvent()))
{
throw new EJBException("Trying to create accountevent for different event in user and product");
if (!product.getEvent().equals(user.getEvent())) {
throw new EJBException(
"Trying to create accountevent for different event in user and product");
}
BigDecimal unitPrice = product.getPrice().negate();
......@@ -69,11 +78,16 @@ public class ProductPBean {
unitPrice = unitPrice.multiply(d.getPercentage());
}
AccountEvent ret = new AccountEvent(user, product, unitPrice, quantity, Calendar.getInstance());
AccountEvent ret = new AccountEvent(user, product, unitPrice, quantity,
Calendar.getInstance());
ret.setDelivered(Calendar.getInstance());
ret.setSeller(permbean.getCurrentUser());
if (foodwave != null) {
ret.setFoodWave(foodwave);
}
List<DiscountInstance> accEventdiscounts = ret.getDiscountInstances();
for (Discount d : discounts) {
// discountsArray.add(discInst);
......
......@@ -14,6 +14,7 @@ import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
......@@ -45,6 +46,7 @@ public class FoodWaveTemplate extends GenericEntity {
private List<Product> products;
@OneToMany(mappedBy = "template")
@OrderBy(value = "time")
private List<FoodWave> foodwaves;
public FoodWaveTemplate() {
......
......@@ -19,7 +19,6 @@
<ui:define name="title">
<h1>#{i18n['user.shop.title']}</h1>
<users:usertabs tabId="foodwave" />
</ui:define>
<ui:define name="content">
Kiitoksia tilauksesta, muista käydä maksamassa tilaukset tiskillä.
......
......@@ -18,8 +18,7 @@
</f:metadata>
<ui:define name="title">
<h1>#{i18n['user.shop.title']}</h1>
<users:usertabs tabId="foodwave" />
<h1>#{i18n['user.shop.title']}</h1>
</ui:define>
<ui:define name="content">
......
......@@ -20,7 +20,6 @@
<ui:define name="title">
<h1>#{i18n['user.foodwave.products.title']}</h1>
<users:usertabs tabId="foodwave" />
</ui:define>
<ui:define name="content">
......
......@@ -12,7 +12,6 @@
<ui:define name="title">
<h1>#{i18n['user.shop.title']}</h1>
<users:usertabs tabId="foodwave" />
</ui:define>
<ui:define name="content">
......
......@@ -26,6 +26,7 @@ public class FoodShopView extends GenericCDIView {
private static final long serialVersionUID = 1288114954999406683L;
@Inject
@SelectedUser
private EventUser user;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!