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 {
ret.put(prod.getId(), BigDecimal.valueOf(freeCount));
} else {
BigDecimal lim = getPrivateProductLimit(prod, user, prodCounts, userroles);
BigDecimal lim = getPrivateProductLimit(prod, user, userroles);
ret.put(prod.getId(), lim);
// logger.info("Added product limit {} to {}", lim, prod);
......@@ -288,19 +288,19 @@ public class ProductBean implements ProductBeanLocal {
{
product = productFacade.reload(product);
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.
*
*
* @param product
* @param user
* @param prodCounts
* @param userroles
* @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;
if (product != null && product.getProductLimits() != null)
......@@ -308,13 +308,7 @@ public class ProductBean implements ProductBeanLocal {
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())
{
boolean roleMatched = false;
......@@ -330,8 +324,6 @@ public class ProductBean implements ProductBeanLocal {
}
}
BigDecimal count = currentCount;
switch (limit.getType())
{
case GLOBAL_BILLED: {
......@@ -340,8 +332,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary globBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillTot = globBillTot.add(globBilledSummary.getActive());
}
count = count.add(globBillTot);
ret = limit.getUpperLimit().subtract(count);
ret = limit.getUpperLimit().subtract(globBillTot);
break;
}
case GLOBAL_BILL_PAID:
......@@ -350,22 +341,21 @@ public class ProductBean implements ProductBeanLocal {
BillSummary billPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent());
globBillPaid = globBillPaid.add(billPaidSummary.getPaid());
}
count = count.add(globBillPaid);
ret = limit.getUpperLimit().subtract(count);
ret = limit.getUpperLimit().subtract(globBillPaid);
break;
case GLOBAL_ACCOUNTEVENTS:
BigDecimal globalProductCount = accounteventfacade.getProductCount(limit.getProducts());
if (globalProductCount != null) {
count = count.add(globalProductCount);
if (globalProductCount == null) {
globalProductCount = BigDecimal.ZERO;
}
ret = limit.getUpperLimit().subtract(count);
ret = limit.getUpperLimit().subtract(globalProductCount);
break;
case USER_ACCOUNTEVENTS:
BigDecimal userProductCount = accounteventfacade.getProductCount(limit.getProducts(), user);
if (userProductCount != null) {
count = count.add(userProductCount);
if (userProductCount == null) {
userProductCount = BigDecimal.ZERO;
}
ret = limit.getUpperLimit().subtract(count);
ret = limit.getUpperLimit().subtract(userProductCount);
break;
case USER_BILLED:
BigDecimal userBillTot = BigDecimal.ZERO;
......@@ -373,8 +363,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary userBilledSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillTot = userBillTot.add(userBilledSummary.getActive());
}
count = count.add(userBillTot);
ret = limit.getUpperLimit().subtract(count);
ret = limit.getUpperLimit().subtract(userBillTot);
break;
case USER_BILL_PAID:
BigDecimal userBillPaid = BigDecimal.ZERO;
......@@ -382,8 +371,7 @@ public class ProductBean implements ProductBeanLocal {
BillSummary userPaidSummary = billLineFacade.getLineSummary(p, eventbean.getCurrentEvent(), user);
userBillPaid = userBillPaid.add(userPaidSummary.getPaid());
}
count = count.add(userBillPaid);
ret = limit.getUpperLimit().subtract(count);
ret = limit.getUpperLimit().subtract(userBillPaid);
break;
default:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!