Commit 9e7069a1 by Tuukka Kivilahti

Local basket count is calculated in view, so no need to recalculate it in bean. …

…Other limit's work with the logic that view removes bascet amounts from limits
1 parent d3f8f960
Pipeline #169 passed
in 0 seconds
...@@ -225,7 +225,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -225,7 +225,7 @@ public class ProductBean implements ProductBeanLocal {
ret.put(prod.getId(), BigDecimal.valueOf(freeCount)); ret.put(prod.getId(), BigDecimal.valueOf(freeCount));
} else { } else {
BigDecimal lim = getPrivateProductLimit(prod, user, prodCounts, userroles); BigDecimal lim = getPrivateProductLimit(prod, user, userroles);
ret.put(prod.getId(), lim); ret.put(prod.getId(), lim);
// logger.info("Added product limit {} to {}", lim, prod); // logger.info("Added product limit {} to {}", lim, prod);
...@@ -288,19 +288,19 @@ public class ProductBean implements ProductBeanLocal { ...@@ -288,19 +288,19 @@ public class ProductBean implements ProductBeanLocal {
{ {
product = productFacade.reload(product); product = productFacade.reload(product);
HashSet<Role> userroles = new HashSet<Role>(userbean.findUsersRoles(user)); HashSet<Role> userroles = new HashSet<Role>(userbean.findUsersRoles(user));
return getPrivateProductLimit(product, user, prodCounts, userroles); return getPrivateProductLimit(product, user, userroles);
} }
/** /**
* Returns available products to be bought for the user. * Returns available products to be bought for the user.
*
* *
* @param product * @param product
* @param user * @param user
* @param prodCounts
* @param userroles * @param userroles
* @return Number of buyable products * @return Number of buyable products
*/ */
private BigDecimal getPrivateProductLimit(Product product, EventUser user, Map<Integer, BigDecimal> prodCounts, Set<Role> userroles) private BigDecimal getPrivateProductLimit(Product product, EventUser user, Set<Role> userroles)
{ {
BigDecimal ret = null; BigDecimal ret = null;
if (product != null && product.getProductLimits() != null) if (product != null && product.getProductLimits() != null)
...@@ -308,13 +308,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -308,13 +308,7 @@ public class ProductBean implements ProductBeanLocal {
for (ProductLimitation limit : product.getProductLimits()) for (ProductLimitation limit : product.getProductLimits())
{ {
BigDecimal currentCount = BigDecimal.ZERO;
for (Product p : limit.getProducts())
{
currentCount = currentCount.add(prodCounts.get(p.getId()));
}
// logger.info("Got limit {} for product {}", limit, product);
if (limit.getMatchingRoles() != null && !limit.getMatchingRoles().isEmpty()) if (limit.getMatchingRoles() != null && !limit.getMatchingRoles().isEmpty())
{ {
boolean roleMatched = false; boolean roleMatched = false;
...@@ -330,8 +324,6 @@ public class ProductBean implements ProductBeanLocal { ...@@ -330,8 +324,6 @@ public class ProductBean implements ProductBeanLocal {
} }
} }
BigDecimal count = currentCount;
switch (limit.getType()) switch (limit.getType())
{ {
case GLOBAL_BILLED: { case GLOBAL_BILLED: {
...@@ -340,8 +332,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -340,8 +332,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent()); BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillTot = globBillTot.add(globBilledSummary.getActive()); globBillTot = globBillTot.add(globBilledSummary.getActive());
} }
count = count.add(globBillTot); ret = limit.getUpperLimit().subtract(globBillTot);
ret = limit.getUpperLimit().subtract(count);
break; break;
} }
case GLOBAL_BILL_PAID: case GLOBAL_BILL_PAID:
...@@ -350,22 +341,21 @@ public class ProductBean implements ProductBeanLocal { ...@@ -350,22 +341,21 @@ public class ProductBean implements ProductBeanLocal {
BillSummary billPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent()); BillSummary billPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillPaid = globBillPaid.add(billPaidSummary.getPaid()); globBillPaid = globBillPaid.add(billPaidSummary.getPaid());
} }
count = count.add(globBillPaid); ret = limit.getUpperLimit().subtract(globBillPaid);
ret = limit.getUpperLimit().subtract(count);
break; break;
case GLOBAL_ACCOUNTEVENTS: case GLOBAL_ACCOUNTEVENTS:
BigDecimal globalProductCount = accounteventfacade.getProductCount(limit.getProducts()); BigDecimal globalProductCount = accounteventfacade.getProductCount(limit.getProducts());
if (globalProductCount != null) { if (globalProductCount == null) {
count = count.add(globalProductCount); globalProductCount = BigDecimal.ZERO;
} }
ret = limit.getUpperLimit().subtract(count); ret = limit.getUpperLimit().subtract(globalProductCount);
break; break;
case USER_ACCOUNTEVENTS: case USER_ACCOUNTEVENTS:
BigDecimal userProductCount = accounteventfacade.getProductCount(limit.getProducts(), user); BigDecimal userProductCount = accounteventfacade.getProductCount(limit.getProducts(), user);
if (userProductCount != null) { if (userProductCount == null) {
count = count.add(userProductCount); userProductCount = BigDecimal.ZERO;
} }
ret = limit.getUpperLimit().subtract(count); ret = limit.getUpperLimit().subtract(userProductCount);
break; break;
case USER_BILLED: case USER_BILLED:
BigDecimal userBillTot = BigDecimal.ZERO; BigDecimal userBillTot = BigDecimal.ZERO;
...@@ -373,8 +363,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -373,8 +363,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user); BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillTot = userBillTot.add(userBilledSummary.getActive()); userBillTot = userBillTot.add(userBilledSummary.getActive());
} }
count = count.add(userBillTot); ret = limit.getUpperLimit().subtract(userBillTot);
ret = limit.getUpperLimit().subtract(count);
break; break;
case USER_BILL_PAID: case USER_BILL_PAID:
BigDecimal userBillPaid = BigDecimal.ZERO; BigDecimal userBillPaid = BigDecimal.ZERO;
...@@ -382,8 +371,7 @@ public class ProductBean implements ProductBeanLocal { ...@@ -382,8 +371,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary userPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user); BillSummary userPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillPaid = userBillPaid.add(userPaidSummary.getPaid()); userBillPaid = userBillPaid.add(userPaidSummary.getPaid());
} }
count = count.add(userBillPaid); ret = limit.getUpperLimit().subtract(userBillPaid);
ret = limit.getUpperLimit().subtract(count);
break; break;
default: default:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!