From 9dce4e47cedb329e3cfb555d57712b1b9bafb10e Mon Sep 17 00:00:00 2001 From: Paul Luchyn Date: Mon, 21 Nov 2016 16:55:32 +0200 Subject: [PATCH 1/2] Added nonlimiting limits --- .../business/common/daos/ILimitsDAO.java | 3 +- .../business/common/daos/LimitsDAO.java | 26 ++++------- .../org/libreplan/web/common/LimitsModel.java | 10 ++++- .../machine/MachineCRUDController.java | 43 +++++++++++++------ .../worker/WorkerCRUDController.java | 37 ++++++++++++---- .../web/users/UserCRUDController.java | 30 ++++++++++--- 6 files changed, 101 insertions(+), 48 deletions(-) diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/ILimitsDAO.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/ILimitsDAO.java index e3e27eb62..e9499f172 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/ILimitsDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/ILimitsDAO.java @@ -33,7 +33,6 @@ public interface ILimitsDAO extends IGenericDAO { List getAll(); - Limits getUsersType(); + Limits getLimitsByType(String type); - Limits getResourcesType(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/LimitsDAO.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/LimitsDAO.java index 80fd3bb45..8f5ace6a9 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/LimitsDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/LimitsDAO.java @@ -19,6 +19,7 @@ package org.libreplan.business.common.daos; +import org.hibernate.criterion.Restrictions; import org.libreplan.business.common.entities.Limits; import org.springframework.stereotype.Repository; @@ -38,25 +39,14 @@ public class LimitsDAO extends GenericDAOHibernate implements ILim return list(Limits.class); } - @Override - public Limits getUsersType() { - List list = list(Limits.class); - for (Limits item : list) { - if ("users".equals(item.getType())) { - return item; - } - } - return null; - } @Override - public Limits getResourcesType() { - List list = list(Limits.class); - for (Limits item : list) { - if ("workers+machines".equals(item.getType())) { - return item; - } - } - return null; + public Limits getLimitsByType(String type) { + + return (Limits) getSession() + .createCriteria(Limits.class) + .add(Restrictions.eq("type", type)) + .uniqueResult(); } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/LimitsModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/LimitsModel.java index b82ff0ec6..72edd8c63 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/LimitsModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/LimitsModel.java @@ -20,6 +20,7 @@ package org.libreplan.web.common; import org.libreplan.business.common.daos.ILimitsDAO; +import org.libreplan.business.common.daos.LimitsDAO; import org.libreplan.business.common.entities.Limits; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; @@ -39,6 +40,10 @@ import java.util.List; @Scope(BeanDefinition.SCOPE_PROTOTYPE) public class LimitsModel implements ILimitsModel { + public static final String USER_LIMITS_TYPE = "users"; + + public static final String RESOURCES_LIMITS_TYPE = "workers+machines"; + @Autowired private ILimitsDAO limitsDAO; @@ -51,12 +56,13 @@ public class LimitsModel implements ILimitsModel { @Override @Transactional(readOnly = true) public Limits getUsersType() { - return limitsDAO.getUsersType(); + return limitsDAO.getLimitsByType(USER_LIMITS_TYPE); } @Override @Transactional(readOnly = true) public Limits getResourcesType() { - return limitsDAO.getResourcesType(); + return limitsDAO.getLimitsByType(RESOURCES_LIMITS_TYPE); } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java index a4286abcf..416461780 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java @@ -584,26 +584,43 @@ public class MachineCRUDController extends BaseCRUDController { return machineModel.getMachine(); } - public boolean isCreateButtonDisabled(){ + /** + * Should be public! + * Used in _listMachines.zul + */ + public boolean isCreateButtonDisabled() { Limits resourcesTypeLimit = limitsModel.getResourcesType(); - Integer resourcesCount = resourceDAO.getRowCount().intValue(); - - if ( resourcesTypeLimit != null ) - if ( resourcesCount >= resourcesTypeLimit.getValue() ) - return true; - - return false; + if (isNullOrZeroValue(resourcesTypeLimit)) { + return false; + } else { + Integer resources = resourceDAO.getRowCount().intValue(); + return resources >= resourcesTypeLimit.getValue(); + } } + /** + * Should be public! + * Used in _listMachines.zul + */ public String getShowCreateFormLabel(){ Limits resourcesTypeLimit = limitsModel.getResourcesType(); - Integer resourcesCount = resourceDAO.getRowCount().intValue(); - int resourcesLeft = resourcesTypeLimit.getValue() - resourcesCount; - if ( resourcesCount >= resourcesTypeLimit.getValue() ) - return _("Machines limit reached"); + if (isNullOrZeroValue(resourcesTypeLimit)) { + return _("Create"); + } - return _("Create") + " ( " + resourcesLeft + " " + _("left") + " )"; + Integer resources = resourceDAO.getRowCount().intValue(); + int resourcesLeft = resourcesTypeLimit.getValue() - resources; + + return resources >= resourcesTypeLimit.getValue() + ? _("Machines limit reached") + : _("Create") + " ( " + resourcesLeft + " " + _("left") + " )"; + } + + private boolean isNullOrZeroValue (Limits resourcesTypeLimit) { + return resourcesTypeLimit == null || + resourcesTypeLimit.getValue() == null || + resourcesTypeLimit.getValue().equals(0); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java index 0dcf86166..6c192c2ef 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java @@ -1114,22 +1114,43 @@ public class WorkerCRUDController extends GenericForwardComposer implements IWor : ""; } + /** + * Should be public! + * Used in resources/worker/_list.zul + */ public boolean isCreateButtonDisabled() { Limits resourcesTypeLimit = limitsModel.getResourcesType(); - Integer resourcesCount = resourceDAO.getRowCount().intValue(); - - return resourcesTypeLimit != null && resourcesCount >= resourcesTypeLimit.getValue(); + if (isNullOrZeroValue(resourcesTypeLimit)) { + return false; + } else { + Integer resources = resourceDAO.getRowCount().intValue(); + return resources >= resourcesTypeLimit.getValue(); + } } + /** + * Should be public! + * Used in resources/worker/_list.zul + */ public String getShowCreateFormLabel() { Limits resourcesTypeLimit = limitsModel.getResourcesType(); - Integer resourcesCount = resourceDAO.getRowCount().intValue(); - int resourcesLeft = resourcesTypeLimit.getValue() - resourcesCount; - if (resourcesCount >= resourcesTypeLimit.getValue()) - return _("Workers limit reached"); + if (isNullOrZeroValue(resourcesTypeLimit)) { + return _("Create"); + } - return _("Create") + " ( " + resourcesLeft + " " + _("left") + " )"; + Integer resources = resourceDAO.getRowCount().intValue(); + int resourcesLeft = resourcesTypeLimit.getValue() - resources; + + return resources >= resourcesTypeLimit.getValue() + ? _("Workers limit reached") + : _("Create") + " ( " + resourcesLeft + " " + _("left") + " )"; + } + + private boolean isNullOrZeroValue (Limits resourcesTypeLimit) { + return resourcesTypeLimit == null || + resourcesTypeLimit.getValue() == null || + resourcesTypeLimit.getValue().equals(0); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java index 7cb41cd52..388be3d24 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java @@ -440,10 +440,18 @@ public class UserCRUDController extends BaseCRUDController implements IUse } } + /** + * Should be public! + * Used in _listUsers.zul + */ public boolean isCreateButtonDisabled() { Limits usersTypeLimit = limitsModel.getUsersType(); - Integer usersCount = userModel.getRowCount().intValue(); - return usersTypeLimit != null && usersCount >= usersTypeLimit.getValue(); + if (isNullOrZeroValue(usersTypeLimit)) { + return false; + } else { + Integer users = userModel.getRowCount().intValue(); + return users >= usersTypeLimit.getValue(); + } } /** @@ -452,11 +460,23 @@ public class UserCRUDController extends BaseCRUDController implements IUse */ public String getShowCreateFormLabel() { Limits usersTypeLimit = limitsModel.getUsersType(); - Integer usersCount = userModel.getRowCount().intValue(); - int usersLeft = usersTypeLimit.getValue() - usersCount; - return usersCount >= usersTypeLimit.getValue() + if (isNullOrZeroValue(usersTypeLimit)) { + return _("Create"); + } + + Integer users = userModel.getRowCount().intValue(); + int usersLeft = usersTypeLimit.getValue() - users; + + return users >= usersTypeLimit.getValue() ? _("User limit reached") : _("Create") + " ( " + usersLeft + " " + _("left") + " )"; } + + private boolean isNullOrZeroValue (Limits usersTypeLimit) { + return usersTypeLimit == null || + usersTypeLimit.getValue() == null || + usersTypeLimit.getValue().equals(0); + } + } From a8ee928a9cb4552767b8d539b5fbbf7d5fc40af2 Mon Sep 17 00:00:00 2001 From: Paul Luchyn Date: Wed, 23 Nov 2016 17:10:38 +0200 Subject: [PATCH 2/2] Added javadoc --- .../libreplan/business/orders/entities/Order.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java index dc6d6c3c9..2928af686 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java +++ b/libreplan-business/src/main/java/org/libreplan/business/orders/entities/Order.java @@ -224,6 +224,10 @@ public class Order extends OrderLineGroup implements Comparable { return getCurrentVersionInfo().isUsingTheOwnerScenario(); } + /** + * Should be public! + * Used in orders/_edition.zul + */ public BigDecimal getWorkBudget() { if (workBudget == null) { return BigDecimal.ZERO; @@ -238,6 +242,10 @@ public class Order extends OrderLineGroup implements Comparable { this.workBudget = workBudget; } + /** + * Should be public! + * Used in orders/_edition.zul + */ public BigDecimal getMaterialsBudget() { if (materialsBudget == null) { return BigDecimal.ZERO; @@ -252,6 +260,10 @@ public class Order extends OrderLineGroup implements Comparable { this.materialsBudget = materialsBudget; } + /** + * Should be public! + * Used in orders/_edition.zul + */ public BigDecimal getTotalManualBudget() { return getWorkBudget().add(getMaterialsBudget()); }