From f48f2ead7195b7a2ed8b61f81559b324671caef5 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Thu, 17 Dec 2015 16:02:48 +0200 Subject: [PATCH 1/6] Add limits for users (Mapping, Entity, DAO, Model, DB). Refactoring. Add method for create button of Users to check if users not violating with limits. --- .../business/common/daos/ILimitsDAO.java | 20 +++++++++ .../business/common/daos/LimitsDAO.java | 40 +++++++++++++++++ .../business/common/entities/Limits.java | 34 ++++++++++++++ .../business/email/daos/EmailTemplateDAO.java | 2 +- .../email/daos/IEmailTemplateDAO.java | 2 +- .../email/entities/EmailTemplate.java | 2 +- .../business/users/daos/IUserDAO.java | 2 + .../business/users/daos/UserDAO.java | 5 +++ .../libreplan-business-spring-config.xml | 3 ++ .../business/common/entities/Limits.hbm.xml | 18 ++++++++ .../libreplan/web/common/ILimitsModel.java | 19 ++++++++ .../org/libreplan/web/common/LimitsModel.java | 45 +++++++++++++++++++ .../web/email/IEmailTemplateModel.java | 2 +- .../org/libreplan/web/users/IUserModel.java | 2 + .../web/users/UserCRUDController.java | 15 +++++++ .../org/libreplan/web/users/UserModel.java | 8 ++++ .../src/main/webapp/users/_listUsers.zul | 3 +- 17 files changed, 217 insertions(+), 5 deletions(-) create mode 100644 libreplan-business/src/main/java/org/libreplan/business/common/daos/ILimitsDAO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/common/daos/LimitsDAO.java create mode 100644 libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java create mode 100644 libreplan-business/src/main/resources/org/libreplan/business/common/entities/Limits.hbm.xml create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java create mode 100644 libreplan-webapp/src/main/java/org/libreplan/web/common/LimitsModel.java 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 new file mode 100644 index 000000000..5eda592a6 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/ILimitsDAO.java @@ -0,0 +1,20 @@ +package org.libreplan.business.common.daos; + +import org.libreplan.business.common.entities.Limits; + +import java.util.List; + +/** + * DAO interface for the Limits entity. + * Contract for {@link LimitsDAO} + * + * Created by + * @author Vova Perebykivskiy + * on 17.12.2015. + */ +public interface ILimitsDAO extends IGenericDAO { + List getAll(); + + Limits getUsersType(); + Limits getWorkersType(); +} 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 new file mode 100644 index 000000000..d29492a96 --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/LimitsDAO.java @@ -0,0 +1,40 @@ +package org.libreplan.business.common.daos; + +import org.libreplan.business.common.entities.Limits; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * DAO for {@link Limits} + * + * Created by + * @author Vova Perebykivskiy + * on 24.09.15. + */ + +@Repository +public class LimitsDAO extends GenericDAOHibernate implements ILimitsDAO { + + @Override + public List getAll() { + return list(Limits.class); + } + + @Override + public Limits getUsersType() { + List list = list(Limits.class); + for (Limits item : list) + if (item.getType().equals("users")) return item; + return null; + } + + @Override + public Limits getWorkersType() { + List list = list(Limits.class); + for (Limits item : list) + if (item.getType().equals("workers")) return item; + return null; + } + +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java new file mode 100644 index 000000000..bd746735e --- /dev/null +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java @@ -0,0 +1,34 @@ +package org.libreplan.business.common.entities; + +import org.libreplan.business.common.BaseEntity; + +/** + * Limits entity, represents a limits for any functionality. + * This class is intended to work as a Hibernate component. + * It represents the limit that can be modified only in database. + * + * Created by + * @author Vova Perebykivskiy + * on 17.12.2015. + */ +public class Limits extends BaseEntity{ + + private String type; + + private Long value; + + + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + public Long getValue() { + return value; + } + public void setValue(Long value) { + this.value = value; + } +} diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java index efebb758a..d7ab0a0d6 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/EmailTemplateDAO.java @@ -30,7 +30,7 @@ import java.util.List; * * Created by * @author Vova Perebykivskiy - * on 24.09.15. + * on 24.09.2015. */ @Repository public class EmailTemplateDAO extends GenericDAOHibernate implements IEmailTemplateDAO{ diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java index ab2fe1635..db40ffae4 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/daos/IEmailTemplateDAO.java @@ -30,7 +30,7 @@ import java.util.List; * * Created by * @author Vova Perebykivskiy - * on 29.09.15. + * on 29.09.2015. */ public interface IEmailTemplateDAO extends IGenericDAO{ diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java index a4f6d2c10..6ba95b0dd 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java @@ -29,7 +29,7 @@ import org.libreplan.business.settings.entities.Language; * * Created by * @author Vova Perebykivskiy - * on 29.09.15. + * on 29.09.2015. */ public class EmailTemplate extends BaseEntity { diff --git a/libreplan-business/src/main/java/org/libreplan/business/users/daos/IUserDAO.java b/libreplan-business/src/main/java/org/libreplan/business/users/daos/IUserDAO.java index a6ed0d376..1d868eb1b 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/users/daos/IUserDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/users/daos/IUserDAO.java @@ -35,6 +35,7 @@ import org.libreplan.business.users.entities.User; * * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ public interface IUserDAO extends IGenericDAO{ @@ -102,4 +103,5 @@ public interface IUserDAO extends IGenericDAO{ List findAll(); + Number getRowCount(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java b/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java index b7cb401db..928d788ca 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.Criteria; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.libreplan.business.common.daos.GenericDAOHibernate; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -179,4 +180,8 @@ public class UserDAO extends GenericDAOHibernate return list(User.class); } + @Override + public Number getRowCount() { + return (Number) getSession().createCriteria(User.class).setProjection(Projections.rowCount()).uniqueResult(); + } } diff --git a/libreplan-business/src/main/resources/libreplan-business-spring-config.xml b/libreplan-business/src/main/resources/libreplan-business-spring-config.xml index 4f00767e4..e8f7d79b7 100644 --- a/libreplan-business/src/main/resources/libreplan-business-spring-config.xml +++ b/libreplan-business/src/main/resources/libreplan-business-spring-config.xml @@ -100,6 +100,9 @@ org/libreplan/business/logs/entities/Logs.hbm.xml + + org/libreplan/business/common/entities/Limits.hbm.xml + diff --git a/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Limits.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Limits.hbm.xml new file mode 100644 index 000000000..1d9b3807d --- /dev/null +++ b/libreplan-business/src/main/resources/org/libreplan/business/common/entities/Limits.hbm.xml @@ -0,0 +1,18 @@ + + + + + + + + + 100 + + + + + + + + + \ No newline at end of file diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java new file mode 100644 index 000000000..c9a4ef4da --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java @@ -0,0 +1,19 @@ +package org.libreplan.web.common; + +import org.libreplan.business.common.entities.Limits; + +import java.util.List; + +/** + * Contract for {@link Limits} + * + * Created by + * @author Vova Perebykivskiy + * on 17.12.2015. + */ +public interface ILimitsModel { + List getAll(); + + Limits getUsersType(); + Limits getWorkersType(); +} 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 new file mode 100644 index 000000000..b4f3041a2 --- /dev/null +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/LimitsModel.java @@ -0,0 +1,45 @@ +package org.libreplan.web.common; + +import org.libreplan.business.common.daos.ILimitsDAO; +import org.libreplan.business.common.entities.Limits; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * Model for operations related to {@link Limits}. + * + * Created by + * @author Vova Perebykivskiy + * on 17.12.15. + */ + +@Service +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +public class LimitsModel implements ILimitsModel { + + @Autowired + private ILimitsDAO limitsDAO; + + @Override + @Transactional(readOnly = true) + public List getAll() { + return limitsDAO.getAll(); + } + + @Override + @Transactional(readOnly = true) + public Limits getUsersType() { + return limitsDAO.getUsersType(); + } + + @Override + @Transactional(readOnly = true) + public Limits getWorkersType() { + return limitsDAO.getWorkersType(); + } +} diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java index 74740e622..0393363d5 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/email/IEmailTemplateModel.java @@ -32,7 +32,7 @@ import java.util.List; * * Created by * @author Vova Perebykivskiy - * on 28.09.15. + * on 28.09.2015. */ public interface IEmailTemplateModel { diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/IUserModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/IUserModel.java index 86023176e..8d389db45 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/IUserModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/IUserModel.java @@ -34,6 +34,7 @@ import org.libreplan.business.users.entities.UserRole; * * @author Jacobo Aragunde Perez * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ public interface IUserModel { @@ -134,4 +135,5 @@ public interface IUserModel { List getAllProfiles(); + Number getRowCount(); } 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 da39fc474..1f4851106 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 @@ -32,6 +32,7 @@ import java.util.List; import javax.annotation.Resource; import org.apache.commons.logging.LogFactory; +import org.libreplan.business.common.entities.Limits; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.resources.entities.Worker; @@ -40,12 +41,14 @@ import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.User.UserAuthenticationType; import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.common.BaseCRUDController; +import org.libreplan.web.common.ILimitsModel; import org.libreplan.web.common.Util; import org.libreplan.web.common.entrypoints.EntryPointsHandler; import org.libreplan.web.common.entrypoints.IURLHandlerRegistry; import org.libreplan.web.resources.worker.IWorkerCRUDControllerEntryPoints; import org.libreplan.web.security.SecurityUtils; import org.libreplan.web.users.bootstrap.PredefinedUsers; +import org.springframework.beans.factory.annotation.Autowired; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.event.Event; @@ -67,6 +70,7 @@ import org.zkoss.zul.api.Groupbox; * @author Jacobo Aragunde Perez * @author Manuel Rego Casasnovas * @author Javier Moran Rua + * @author Vova Perebykivskiy */ @SuppressWarnings("serial") public class UserCRUDController extends BaseCRUDController implements @@ -77,6 +81,10 @@ public class UserCRUDController extends BaseCRUDController implements @Resource private IWorkerCRUDControllerEntryPoints workerCRUD; + @Autowired + private ILimitsModel limitsModel; + + @Autowired private IUserModel userModel; private Textbox passwordBox; @@ -491,4 +499,11 @@ public class UserCRUDController extends BaseCRUDController implements } } + public boolean isCreateButtonDisabled(){ + Limits usersTypeLimit = limitsModel.getUsersType(); + Long usersCount = (Long) userModel.getRowCount(); + if (usersTypeLimit != null) + if ( usersCount >= usersTypeLimit.getValue() ) return true; + return false; + } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/users/UserModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/users/UserModel.java index c9e9bbf4f..a78e8c38c 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/users/UserModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/users/UserModel.java @@ -50,6 +50,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Jacobo Aragunde Perez * @author Susana Montes Pedreira * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -275,4 +276,11 @@ public class UserModel implements IUserModel { return profileDAO.listSorted(); } + + @Override + @Transactional(readOnly = true) + public Number getRowCount() { + return userDAO.getRowCount(); + } + } diff --git a/libreplan-webapp/src/main/webapp/users/_listUsers.zul b/libreplan-webapp/src/main/webapp/users/_listUsers.zul index dfc42e57c..c6b887ec0 100644 --- a/libreplan-webapp/src/main/webapp/users/_listUsers.zul +++ b/libreplan-webapp/src/main/webapp/users/_listUsers.zul @@ -35,6 +35,7 @@ From afeea6823b01cb72dbd8a8ea68874441585f8d78 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Fri, 18 Dec 2015 11:05:59 +0200 Subject: [PATCH 2/6] Add limits for workers and machines (Mapping, Entity, DAO, Model, DB). Refactoring. Add method for create button of Workers/Machines to check if users not violating with limits. Add i18n. --- .../business/common/daos/ILimitsDAO.java | 1 + .../business/common/daos/LimitsDAO.java | 8 ++++ .../business/resources/daos/IMachineDAO.java | 6 +++ .../business/resources/daos/IWorkerDAO.java | 4 +- .../business/resources/daos/MachineDAO.java | 7 ++++ .../business/resources/daos/WorkerDAO.java | 8 +++- .../business/users/daos/UserDAO.java | 1 + .../libreplan/web/common/ILimitsModel.java | 1 + .../org/libreplan/web/common/LimitsModel.java | 6 +++ .../web/resources/machine/IMachineModel.java | 5 ++- .../machine/MachineCRUDController.java | 32 ++++++++++++++-- .../web/resources/machine/MachineModel.java | 8 ++++ .../web/resources/worker/IWorkerModel.java | 3 ++ .../worker/WorkerCRUDController.java | 37 +++++++++++++++---- .../web/resources/worker/WorkerModel.java | 12 ++++++ .../web/users/UserCRUDController.java | 17 ++++++++- .../src/main/resources/i18n/keys.pot | 12 ++++++ .../resources/machine/_listMachines.zul | 3 +- .../main/webapp/resources/worker/_list.zul | 3 +- .../src/main/webapp/users/_listUsers.zul | 2 +- 20 files changed, 157 insertions(+), 19 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 5eda592a6..72229644c 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 @@ -17,4 +17,5 @@ public interface ILimitsDAO extends IGenericDAO { Limits getUsersType(); Limits getWorkersType(); + Limits getMachinesType(); } 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 d29492a96..79a657017 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 @@ -37,4 +37,12 @@ public class LimitsDAO extends GenericDAOHibernate implements ILim return null; } + @Override + public Limits getMachinesType() { + List list = list(Limits.class); + for (Limits item : list) + if (item.getType().equals("machines")) return item; + return null; + } + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java index 02a74dd4d..c10f03104 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java @@ -33,6 +33,7 @@ import org.libreplan.business.resources.entities.Machine; * @author Diego Pino Garcia * @author Javier Moran Rua * @author Fernando Bellas Permuy + * @author Vova Perebykivskiy */ public interface IMachineDAO extends IIntegrationEntityDAO { @@ -82,4 +83,9 @@ public interface IMachineDAO extends IIntegrationEntityDAO { * code as the one passed as parameter */ boolean existsMachineWithCodeInAnotherTransaction(String code); + + /** + * Return a number of rows in database table + */ + Number getRowCount(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java index b75034983..299fe28bc 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java @@ -36,7 +36,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas * @author Diego Pino Garcia - * + * @author Vova Perebykivskiy */ public interface IWorkerDAO extends IIntegrationEntityDAO { @@ -127,4 +127,6 @@ public interface IWorkerDAO extends IIntegrationEntityDAO { * Return the list of {@link Worker Workers} bound to any {@link User}. */ List getBound(); + + Number getRowCount(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java index 620fc72d3..a32c7d3c0 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java @@ -23,6 +23,7 @@ package org.libreplan.business.resources.daos; import java.util.List; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.libreplan.business.common.daos.IntegrationEntityDAO; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -40,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Diego Pino Garcia * @author Javier Moran Rua * @author Fernando Bellas Permuy + * @author Vova Perebykivskiy */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) @@ -82,6 +84,11 @@ public class MachineDAO extends IntegrationEntityDAO } } + @Override + public Number getRowCount() { + return (Number) getSession().createCriteria(Machine.class).setProjection(Projections.rowCount()).uniqueResult(); + } + @Override @Transactional(readOnly= true, propagation = Propagation.REQUIRES_NEW) public Machine findUniqueByCodeInAnotherTransaction(String code) diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java index 9c52c4645..ba3f15074 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java @@ -26,6 +26,7 @@ import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.libreplan.business.common.daos.IntegrationEntityDAO; import org.libreplan.business.common.exceptions.InstanceNotFoundException; @@ -43,7 +44,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas * @author Diego Pino Garcia - * + * @author Vova Perebykivskiy */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) @@ -199,4 +200,9 @@ public class WorkerDAO extends IntegrationEntityDAO return criteria.list(); } + @Override + public Number getRowCount() { + return (Number) getSession().createCriteria(Worker.class).setProjection(Projections.rowCount()).uniqueResult(); + } + } \ No newline at end of file diff --git a/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java b/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java index 928d788ca..2f3bab8cf 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/users/daos/UserDAO.java @@ -45,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Fernando Bellas Permuy * @author Jacobo Aragunde Perez * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ @Repository public class UserDAO extends GenericDAOHibernate diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java index c9a4ef4da..b0146b46e 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java @@ -16,4 +16,5 @@ public interface ILimitsModel { Limits getUsersType(); Limits getWorkersType(); + Limits getMachinesType(); } 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 b4f3041a2..3338a3936 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 @@ -42,4 +42,10 @@ public class LimitsModel implements ILimitsModel { public Limits getWorkersType() { return limitsDAO.getWorkersType(); } + + @Override + @Transactional(readOnly = true) + public Limits getMachinesType() { + return limitsDAO.getMachinesType(); + } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java index 3458b5227..7be640035 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java @@ -34,7 +34,7 @@ import org.libreplan.business.resources.entities.Worker; import org.libreplan.web.common.IIntegrationEntityModel; import org.libreplan.web.resources.search.ResourcePredicate; -/* +/** * This interface contains the operations to create/edit a machine. * * Conversation state: the Machine instance and associated entities. @@ -63,6 +63,7 @@ import org.libreplan.web.resources.search.ResourcePredicate; * * @author Diego Pino Garcia * @author Javier Moran Rua + * @author Vova Perebykivskiy */ public interface IMachineModel extends IIntegrationEntityModel { // Initial conversational steps @@ -108,4 +109,6 @@ public interface IMachineModel extends IIntegrationEntityModel { void removeCalendar(); + Number getRowCount(); + } 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 c55db303c..88d255c76 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 @@ -31,15 +31,13 @@ import java.util.Set; import org.joda.time.LocalDate; import org.libreplan.business.calendars.entities.BaseCalendar; import org.libreplan.business.calendars.entities.ResourceCalendar; +import org.libreplan.business.common.entities.Limits; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.resources.entities.Machine; import org.libreplan.web.calendars.BaseCalendarEditionController; import org.libreplan.web.calendars.IBaseCalendarModel; -import org.libreplan.web.common.BaseCRUDController; -import org.libreplan.web.common.ConstraintChecker; -import org.libreplan.web.common.Level; -import org.libreplan.web.common.Util; +import org.libreplan.web.common.*; import org.libreplan.web.common.components.bandboxsearch.BandboxMultipleSearch; import org.libreplan.web.common.components.finders.FilterPair; import org.libreplan.web.costcategories.ResourcesCostCategoryAssignmentController; @@ -47,6 +45,7 @@ import org.libreplan.web.resources.search.ResourcePredicate; import org.libreplan.web.resources.worker.CriterionsController; import org.libreplan.web.resources.worker.CriterionsMachineController; import org.libreplan.web.resources.worker.WorkerCRUDController.LimitingResourceEnum; +import org.springframework.beans.factory.annotation.Autowired; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.event.CheckEvent; @@ -75,9 +74,14 @@ import org.zkoss.zul.api.Window; * Controller for {@link Machine} resource
* @author Diego Pino Garcia * @author Lorenzo Tilve Álvaro + * @author Vova Perebykivskiy */ public class MachineCRUDController extends BaseCRUDController { + @Autowired + private ILimitsModel limitsModel; + + @Autowired private IMachineModel machineModel; private Component configurationUnits; @@ -611,4 +615,24 @@ public class MachineCRUDController extends BaseCRUDController { return machineModel.getMachine(); } + public boolean isCreateButtonDisabled(){ + Limits machinesTypeLimit = limitsModel.getMachinesType(); + Long machinesCount = (Long) machineModel.getRowCount(); + if ( machinesTypeLimit != null ) + if ( machinesCount >= machinesTypeLimit.getValue() ) + return true; + + return false; + } + + public String getShowCreateFormLabel(){ + Limits machinesTypeLimit = limitsModel.getMachinesType(); + Long machinesCount = (Long) machineModel.getRowCount(); + if ( machinesTypeLimit != null ) + if ( machinesCount >= machinesTypeLimit.getValue() ) + return _("Machines limit reached"); + + return _("Create"); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java index 3f83b5855..71e2caf6e 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java @@ -70,6 +70,7 @@ import org.springframework.transaction.annotation.Transactional; /** * @author Diego Pino Garcia * @author Javier Moran Rua + * @author Vova Perebykivskiy */ @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -403,4 +404,11 @@ public class MachineModel extends IntegrationEntityModel implements machine.setCalendar(null); } + @Override + @Transactional(readOnly = true) + public Number getRowCount() { + return machineDAO.getRowCount(); + } + + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java index fbcceee94..8f657ba27 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java @@ -74,6 +74,7 @@ import org.libreplan.web.resources.search.ResourcePredicate; * @author Óscar González Fernández * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ public interface IWorkerModel extends IIntegrationEntityModel { @@ -147,4 +148,6 @@ public interface IWorkerModel extends IIntegrationEntityModel { User getBoundUserFromDB(Worker worker); + Number getRowCount(); + } 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 0df7794c0..aee8b78b0 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 @@ -35,6 +35,7 @@ import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; import org.libreplan.business.calendars.entities.BaseCalendar; import org.libreplan.business.calendars.entities.ResourceCalendar; +import org.libreplan.business.common.entities.Limits; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.resources.entities.ResourceType; @@ -44,13 +45,8 @@ import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.calendars.BaseCalendarEditionController; import org.libreplan.web.calendars.IBaseCalendarModel; +import org.libreplan.web.common.*; import org.libreplan.web.common.BaseCRUDController.CRUDControllerState; -import org.libreplan.web.common.ConstraintChecker; -import org.libreplan.web.common.IMessagesForUser; -import org.libreplan.web.common.Level; -import org.libreplan.web.common.MessagesForUser; -import org.libreplan.web.common.OnlyOneVisible; -import org.libreplan.web.common.Util; import org.libreplan.web.common.components.bandboxsearch.BandboxMultipleSearch; import org.libreplan.web.common.components.bandboxsearch.BandboxSearch; import org.libreplan.web.common.components.finders.FilterPair; @@ -98,6 +94,7 @@ import org.zkoss.zul.api.Window; * @author Óscar González Fernández * @author Lorenzo Tilve Álvaro * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ public class WorkerCRUDController extends GenericForwardComposer implements IWorkerCRUDControllerEntryPoints { @@ -105,6 +102,12 @@ public class WorkerCRUDController extends GenericForwardComposer implements @Autowired private IDBPasswordEncoderService dbPasswordEncoderService; + @Autowired + private ILimitsModel limitsModel; + + @Autowired + private IWorkerModel workerModel; + @Resource private IUserCRUDController userCRUD; @@ -112,8 +115,6 @@ public class WorkerCRUDController extends GenericForwardComposer implements private Window editWindow; - private IWorkerModel workerModel; - private IURLHandlerRegistry URLHandlerRegistry; private OnlyOneVisible visibility; @@ -1159,4 +1160,24 @@ public class WorkerCRUDController extends GenericForwardComposer implements return ""; } + public boolean isCreateButtonDisabled(){ + Limits workersTypeLimit = limitsModel.getWorkersType(); + Long workersCount = (Long) workerModel.getRowCount(); + if ( workersTypeLimit != null ) + if ( workersCount >= workersTypeLimit.getValue() ) + return true; + + return false; + } + + public String getShowCreateFormLabel(){ + Limits workersTypeLimit = limitsModel.getWorkersType(); + Long workersCount = (Long) workerModel.getRowCount(); + if ( workersTypeLimit != null ) + if ( workersCount >= workersTypeLimit.getValue() ) + return _("Workers limit reached"); + + return _("Create"); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java index 3ad9a9265..90ca8a30d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java @@ -49,6 +49,8 @@ import org.libreplan.business.planner.daos.IDayAssignmentDAO; import org.libreplan.business.planner.daos.IResourceAllocationDAO; import org.libreplan.business.resources.daos.ICriterionDAO; import org.libreplan.business.resources.daos.IResourceDAO; +import org.libreplan.business.resources.daos.IWorkerDAO; +import org.libreplan.business.resources.daos.WorkerDAO; import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.resources.entities.CriterionSatisfaction; import org.libreplan.business.resources.entities.CriterionWithItsType; @@ -81,6 +83,7 @@ import org.springframework.transaction.annotation.Transactional; * @author Fernando Bellas Permuy * @author Diego Pino García * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -96,6 +99,9 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel @Autowired private IBaseCalendarDAO baseCalendarDAO; + @Autowired + private IWorkerDAO workerDAO; + private final ICriterionType[] laboralRelatedTypes = { PredefinedCriterionTypes.LOCATION, PredefinedCriterionTypes.CATEGORY, PredefinedCriterionTypes.SKILL }; @@ -697,4 +703,10 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel return null; } + @Override + @Transactional(readOnly = true) + public Number getRowCount() { + return workerDAO.getRowCount(); + } + } 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 1f4851106..5e34cd5ea 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 @@ -64,6 +64,8 @@ import org.zkoss.zul.RowRenderer; import org.zkoss.zul.Textbox; import org.zkoss.zul.api.Groupbox; +import static org.libreplan.web.I18nHelper._; + /** * Controller for CRUD actions over a {@link User} * @@ -97,6 +99,8 @@ public class UserCRUDController extends BaseCRUDController implements private Combobox profilesCombo; + private Button showCreateForm; + private IURLHandlerRegistry URLHandlerRegistry; private RowRenderer usersRenderer = new RowRenderer() { @@ -503,7 +507,18 @@ public class UserCRUDController extends BaseCRUDController implements Limits usersTypeLimit = limitsModel.getUsersType(); Long usersCount = (Long) userModel.getRowCount(); if (usersTypeLimit != null) - if ( usersCount >= usersTypeLimit.getValue() ) return true; + if ( usersCount >= usersTypeLimit.getValue() ) + return true; return false; } + + public String getShowCreateFormLabel(){ + Limits usersTypeLimit = limitsModel.getUsersType(); + Long usersCount = (Long) userModel.getRowCount(); + if (usersTypeLimit != null) + if ( usersCount >= usersTypeLimit.getValue() ) + return _("User limit reached"); + + return _("Create"); + } } diff --git a/libreplan-webapp/src/main/resources/i18n/keys.pot b/libreplan-webapp/src/main/resources/i18n/keys.pot index abbce181b..ca28d77ee 100644 --- a/libreplan-webapp/src/main/resources/i18n/keys.pot +++ b/libreplan-webapp/src/main/resources/i18n/keys.pot @@ -9287,3 +9287,15 @@ msgstr "" #: libreplan-webapp/src/main/webapp/dashboard/_pipeline.zul:2 msgid "Show archived column data" msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java:520 +msgid "User limit reached" +msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/UserCRUDController.java:1178 +msgid "Workers limit reached" +msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java:631 +msgid "Machines limit reached" +msgstr "" \ No newline at end of file diff --git a/libreplan-webapp/src/main/webapp/resources/machine/_listMachines.zul b/libreplan-webapp/src/main/webapp/resources/machine/_listMachines.zul index 81b876387..13697807c 100644 --- a/libreplan-webapp/src/main/webapp/resources/machine/_listMachines.zul +++ b/libreplan-webapp/src/main/webapp/resources/machine/_listMachines.zul @@ -40,6 +40,7 @@ diff --git a/libreplan-webapp/src/main/webapp/resources/worker/_list.zul b/libreplan-webapp/src/main/webapp/resources/worker/_list.zul index 66c72cba3..bd1f71b71 100644 --- a/libreplan-webapp/src/main/webapp/resources/worker/_list.zul +++ b/libreplan-webapp/src/main/webapp/resources/worker/_list.zul @@ -42,6 +42,7 @@ diff --git a/libreplan-webapp/src/main/webapp/users/_listUsers.zul b/libreplan-webapp/src/main/webapp/users/_listUsers.zul index c6b887ec0..3de9d2643 100644 --- a/libreplan-webapp/src/main/webapp/users/_listUsers.zul +++ b/libreplan-webapp/src/main/webapp/users/_listUsers.zul @@ -35,7 +35,7 @@ From 36668ffeedb227cf5b55818ff0662d97a703c0a2 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Fri, 18 Dec 2015 15:24:31 +0200 Subject: [PATCH 3/6] Fix MySQL test failure bug. --- .../workreports/entities/WorkReports.hbm.xml | 2 +- .../ws/workreports/WorkReportServiceTest.java | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libreplan-business/src/main/resources/org/libreplan/business/workreports/entities/WorkReports.hbm.xml b/libreplan-business/src/main/resources/org/libreplan/business/workreports/entities/WorkReports.hbm.xml index 72cdd1b13..78b9f849d 100644 --- a/libreplan-business/src/main/resources/org/libreplan/business/workreports/entities/WorkReports.hbm.xml +++ b/libreplan-business/src/main/resources/org/libreplan/business/workreports/entities/WorkReports.hbm.xml @@ -93,7 +93,7 @@ - + diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java index 88e2b2876..3eaac7fc3 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java @@ -32,6 +32,7 @@ import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CO import java.lang.reflect.Method; import java.math.BigDecimal; +import java.sql.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -44,7 +45,13 @@ import java.util.UUID; import javax.annotation.Resource; import javax.xml.datatype.XMLGregorianCalendar; +import org.hibernate.CacheMode; +import org.hibernate.Hibernate; import org.hibernate.SessionFactory; +import org.hibernate.StatelessSession; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.Projections; +import org.hibernate.criterion.Restrictions; import org.joda.time.LocalDate; import org.joda.time.LocalTime; import org.junit.Test; @@ -576,11 +583,25 @@ public class WorkReportServiceTest { instanceConstraintViolationsListDTO.instanceConstraintViolationsList .size(), equalTo(0)); - List workReports = workReportDAO.getAll(); + /** + * Default code that was before was not working with MySQL + * and works perfect with PostgreSQL + * For example: List workReports = workReportDAO.getAll(); + * was returning 0 but COUNT in DB was 1 + * Also set workReportLines in WorkReports.hbm.xml has been changed to fetch='join' + * Possible reason: Hibernate 4.3.11.Final bug / caching + */ + + StatelessSession statelessSession = sessionFactory.openStatelessSession(); + + List workReports = statelessSession.createCriteria(WorkReport.class) + .addOrder(Order.asc("code")).list(); + assertThat(workReports.size(), equalTo(previous + 1)); - WorkReport imported = workReportDAO - .findExistingEntityByCode(workReportDTO.code); + WorkReport imported = (WorkReport) statelessSession.createCriteria(WorkReport.class) + .add(Restrictions.eq("code", workReportDTO.code.trim()).ignoreCase()).uniqueResult(); + assertThat(imported.getDate(), equalTo(date)); List importedLines = new ArrayList( @@ -600,6 +621,7 @@ public class WorkReportServiceTest { WorkReportLine line = importedLines.remove(0); assertThat(line.getDate().getTime(), equalTo(asTime(each.getDate()))); } + statelessSession.close(); } private long asTime(XMLGregorianCalendar date2) { From 76d05768244ea9a1801aa3a4c0caffb16358f3b6 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Fri, 18 Dec 2015 15:34:13 +0200 Subject: [PATCH 4/6] Optimizing imports. Refactoring. --- .../business/common/daos/ILimitsDAO.java | 19 +++++++++++++++++++ .../business/common/daos/LimitsDAO.java | 19 +++++++++++++++++++ .../business/common/entities/Limits.java | 19 +++++++++++++++++++ .../libreplan/web/common/ILimitsModel.java | 19 +++++++++++++++++++ .../org/libreplan/web/common/LimitsModel.java | 19 +++++++++++++++++++ .../machine/MachineCRUDController.java | 6 +++++- .../worker/WorkerCRUDController.java | 8 +++++++- .../ws/workreports/WorkReportServiceTest.java | 5 +---- 8 files changed, 108 insertions(+), 6 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 72229644c..f6689d3a4 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 @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.common.daos; import org.libreplan.business.common.entities.Limits; 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 79a657017..e51dd983a 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 @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.common.daos; import org.libreplan.business.common.entities.Limits; diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java index bd746735e..b2d810d18 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.business.common.entities; import org.libreplan.business.common.BaseEntity; diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java index b0146b46e..8b525cff0 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.web.common; import org.libreplan.business.common.entities.Limits; 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 3338a3936..4eb8666b7 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 @@ -1,3 +1,22 @@ +/* + * This file is part of LibrePlan + * + * Copyright (C) 2015 LibrePlan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package org.libreplan.web.common; import org.libreplan.business.common.daos.ILimitsDAO; 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 88d255c76..2c29bde9b 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 @@ -37,7 +37,11 @@ import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.resources.entities.Machine; import org.libreplan.web.calendars.BaseCalendarEditionController; import org.libreplan.web.calendars.IBaseCalendarModel; -import org.libreplan.web.common.*; +import org.libreplan.web.common.BaseCRUDController; +import org.libreplan.web.common.ConstraintChecker; +import org.libreplan.web.common.Level; +import org.libreplan.web.common.Util; +import org.libreplan.web.common.ILimitsModel; import org.libreplan.web.common.components.bandboxsearch.BandboxMultipleSearch; import org.libreplan.web.common.components.finders.FilterPair; import org.libreplan.web.costcategories.ResourcesCostCategoryAssignmentController; 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 aee8b78b0..722db4f45 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 @@ -45,7 +45,13 @@ import org.libreplan.business.users.entities.User; import org.libreplan.business.users.entities.UserRole; import org.libreplan.web.calendars.BaseCalendarEditionController; import org.libreplan.web.calendars.IBaseCalendarModel; -import org.libreplan.web.common.*; +import org.libreplan.web.common.ConstraintChecker; +import org.libreplan.web.common.IMessagesForUser; +import org.libreplan.web.common.Level; +import org.libreplan.web.common.MessagesForUser; +import org.libreplan.web.common.OnlyOneVisible; +import org.libreplan.web.common.Util; +import org.libreplan.web.common.ILimitsModel; import org.libreplan.web.common.BaseCRUDController.CRUDControllerState; import org.libreplan.web.common.components.bandboxsearch.BandboxMultipleSearch; import org.libreplan.web.common.components.bandboxsearch.BandboxSearch; diff --git a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java index 3eaac7fc3..d54ef6e30 100644 --- a/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java +++ b/libreplan-webapp/src/test/java/org/libreplan/web/test/ws/workreports/WorkReportServiceTest.java @@ -32,7 +32,6 @@ import static org.libreplan.web.test.WebappGlobalNames.WEBAPP_SPRING_SECURITY_CO import java.lang.reflect.Method; import java.math.BigDecimal; -import java.sql.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -45,12 +44,9 @@ import java.util.UUID; import javax.annotation.Resource; import javax.xml.datatype.XMLGregorianCalendar; -import org.hibernate.CacheMode; -import org.hibernate.Hibernate; import org.hibernate.SessionFactory; import org.hibernate.StatelessSession; import org.hibernate.criterion.Order; -import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.joda.time.LocalDate; import org.joda.time.LocalTime; @@ -99,6 +95,7 @@ import org.springframework.transaction.annotation.Transactional; * Tests for {@link IWorkReportService}. * * @author Manuel Rego Casasnovas + * @author Vova Perebykivskiy */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, From 58b8a3e1c50d840dda8c32fee7b8238ae5460150 Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Mon, 21 Dec 2015 13:38:23 +0200 Subject: [PATCH 5/6] i18n. Email functionality bug fixes. --- .../web/common/ConfigurationController.java | 25 +++++++++++-------- .../src/main/resources/i18n/keys.pot | 4 +++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java index 5e62a9ed4..45f5b8da1 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java @@ -244,7 +244,8 @@ public class ConfigurationController extends GenericForwardComposer { if ( getSelectedConnector() != null && getSelectedConnector().getName().equals("E-mail") && isEmailFieldsValid() == false ) { - messages.showMessage(Level.ERROR, _("Check username/password/sender fields")); + messages.showMessage(Level.ERROR, _("Check all fields")); + } else { ConstraintChecker.isValid(configurationWindow); if (checkValidEntitySequenceRows()) { @@ -1297,7 +1298,8 @@ public class ConfigurationController extends GenericForwardComposer { key.equals(PredefinedConnectorProperties.JIRA_HOURS_TYPE) || key.equals(PredefinedConnectorProperties.HOST) || key.equals(PredefinedConnectorProperties.PORT) || - key.equals(PredefinedConnectorProperties.EMAIL_SENDER) ) { + key.equals(PredefinedConnectorProperties.EMAIL_SENDER) || + key.equals(PredefinedConnectorProperties.PROTOCOL) ) { ((InputElement) comp).setConstraint("no empty:" + _("cannot be empty")); } else if ( key @@ -1326,14 +1328,15 @@ public class ConfigurationController extends GenericForwardComposer { } private boolean isEmailFieldsValid(){ - if ( protocolsCombobox.getSelectedItem().getLabel().equals("STARTTLS") && - emailUsernameTextbox.getValue() != null && - emailPasswordTextbox.getValue() != null && - emailUsernameTextbox.getValue().length() != 0 && - emailPasswordTextbox.getValue().length() != 0 && - emailSenderTextbox.getValue().matches("^\\S+@\\S+\\.\\S+$") ) - return true; - - else return false; + if ( protocolsCombobox != null && protocolsCombobox.getSelectedItem() != null ){ + if ( protocolsCombobox.getSelectedItem().getLabel().equals("STARTTLS") && + emailUsernameTextbox.getValue() != null && + emailPasswordTextbox.getValue() != null && + emailUsernameTextbox.getValue().length() != 0 && + emailPasswordTextbox.getValue().length() != 0 && + emailSenderTextbox.getValue().matches("^\\S+@\\S+\\.\\S+$") ) + return true; + } + return false; } } diff --git a/libreplan-webapp/src/main/resources/i18n/keys.pot b/libreplan-webapp/src/main/resources/i18n/keys.pot index ca28d77ee..68b1068d7 100644 --- a/libreplan-webapp/src/main/resources/i18n/keys.pot +++ b/libreplan-webapp/src/main/resources/i18n/keys.pot @@ -9298,4 +9298,8 @@ msgstr "" #: libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java:631 msgid "Machines limit reached" +msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/common/ConfigurationController.java:247 +msgid "Check fields" msgstr "" \ No newline at end of file From c0b9dcdec542f7956244a6e1a5538d106690a81c Mon Sep 17 00:00:00 2001 From: Vova Perebykivskiy Date: Tue, 22 Dec 2015 17:51:39 +0200 Subject: [PATCH 6/6] i18n. Add Limits functionality. Changes to INSTALL and HACKING documents. (cherry picked from commit 0a0af1e9cded313ac4d5293d16cf834346287ccb) --- HACKING.rst | 19 ++--- INSTALL.rst | 4 +- .../business/common/daos/ILimitsDAO.java | 3 +- .../business/common/daos/LimitsDAO.java | 13 +--- .../business/common/entities/Limits.java | 6 +- .../business/resources/daos/IMachineDAO.java | 6 -- .../business/resources/daos/IResourceDAO.java | 2 + .../business/resources/daos/IWorkerDAO.java | 3 - .../business/resources/daos/MachineDAO.java | 6 -- .../business/resources/daos/ResourceDAO.java | 6 ++ .../business/resources/daos/WorkerDAO.java | 7 -- .../src/main/resources/db.changelog-1.4.xml | 46 +++++++++--- .../libreplan/web/common/ILimitsModel.java | 3 +- .../org/libreplan/web/common/LimitsModel.java | 10 +-- .../web/resources/machine/IMachineModel.java | 4 - .../machine/MachineCRUDController.java | 38 ++++++---- .../web/resources/machine/MachineModel.java | 9 --- .../web/resources/worker/IWorkerModel.java | 4 - .../worker/WorkerCRUDController.java | 73 ++++++++++--------- .../web/resources/worker/WorkerModel.java | 7 -- .../web/users/UserCRUDController.java | 39 +++++----- .../src/main/resources/i18n/keys.pot | 11 ++- 22 files changed, 153 insertions(+), 166 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 082212cb7..f66b75f69 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -228,8 +228,6 @@ Microsoft Windows # Copy downloaded *.jar file to JAVA_HOME location: (e.g. C:\Program Files\Java\jdk1.7.0_80\jre\lib\ext) # Put downloaded *.jar file to Tomcat lib location: (e.g. C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib) -* Download latest ``.war`` file from SourceForge.net (for PostgreSQL) and rename it to libreplan.war:: - # http://sourceforge.net/projects/libreplan/files/LibrePlan/ * Create database:: @@ -266,15 +264,12 @@ Microsoft Windows GRANT ALL PRIVILEGES ON DATABASE libreplan TO libreplan; -* Restore PostgreSQL dump - scripts/database/postgresql_1.4.1.backup:: - * Create an Environment Variable JAVA_HOME # You need to set it to your JDK installed directory * Configure Apache Tomcat Server - # Put your libreplan.war file to Apache Tomcat webapps folder (e.g. C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\) # Go to (e.g. C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost\) and create there libreplan.xml file with this lines of code: @@ -288,13 +283,7 @@ Microsoft Windows url="jdbc:postgresql://localhost/libreplan" /> -* Start Apache Tomcat server - - # Possible location: C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\Tomcat6.exe - -* Go to http://localhost:8080/libreplan ======= -* Restore PostgreSQL dump - scripts/database/postgresql_1.4.1.backup * Download source code:: @@ -316,8 +305,12 @@ Microsoft Windows * Launch application:: - # cd libreplan-webapp - # mvn jetty:run + * Get *.war file from project folder (e.g ../libreplan/libreplan-webapp/target/libreplan-webapp.war) + * Rename it to libreplan.war + * Put your libreplan.war file to Apache Tomcat webapps folder (e.g. C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\) + * Start Apache Tomcat server + + # Possible location: C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\Tomcat6.exe * Go to http://localhost:8080/libreplan-webapp/ diff --git a/INSTALL.rst b/INSTALL.rst index ab8a3d74b..8e14342fb 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -326,7 +326,7 @@ Microsoft Windows Instructions: -* Download and install latest Java Runtime Environment 7u79 (JRE7u79):: +* Download and install latest Java Runtime Environment 7u80 (JRE7u79):: # http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html @@ -367,7 +367,7 @@ Instructions: ON ALL TABLES IN SCHEMA public TO libreplan; -* Restore PostgreSQL dump - scripts/database/postgresql_1.4.1.backup:: +* Restore PostgreSQL / MySQL dump:: * Create an Environment Variable JRE_HOME 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 f6689d3a4..e95b248ea 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 @@ -35,6 +35,5 @@ public interface ILimitsDAO extends IGenericDAO { List getAll(); Limits getUsersType(); - Limits getWorkersType(); - Limits getMachinesType(); + 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 e51dd983a..87a7c7565 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 @@ -49,19 +49,10 @@ public class LimitsDAO extends GenericDAOHibernate implements ILim } @Override - public Limits getWorkersType() { + public Limits getResourcesType() { List list = list(Limits.class); for (Limits item : list) - if (item.getType().equals("workers")) return item; + if (item.getType().equals("workers+machines")) return item; return null; } - - @Override - public Limits getMachinesType() { - List list = list(Limits.class); - for (Limits item : list) - if (item.getType().equals("machines")) return item; - return null; - } - } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java index b2d810d18..1b2a041d1 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/entities/Limits.java @@ -34,7 +34,7 @@ public class Limits extends BaseEntity{ private String type; - private Long value; + private Integer value; public String getType() { @@ -44,10 +44,10 @@ public class Limits extends BaseEntity{ this.type = type; } - public Long getValue() { + public Integer getValue() { return value; } - public void setValue(Long value) { + public void setValue(Integer value) { this.value = value; } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java index c10f03104..02a74dd4d 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IMachineDAO.java @@ -33,7 +33,6 @@ import org.libreplan.business.resources.entities.Machine; * @author Diego Pino Garcia * @author Javier Moran Rua * @author Fernando Bellas Permuy - * @author Vova Perebykivskiy */ public interface IMachineDAO extends IIntegrationEntityDAO { @@ -83,9 +82,4 @@ public interface IMachineDAO extends IIntegrationEntityDAO { * code as the one passed as parameter */ boolean existsMachineWithCodeInAnotherTransaction(String code); - - /** - * Return a number of rows in database table - */ - Number getRowCount(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IResourceDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IResourceDAO.java index 3b3bf3bfe..9855b15ac 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IResourceDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IResourceDAO.java @@ -120,4 +120,6 @@ public interface IResourceDAO extends IIntegrationEntityDAO { */ List getWorkingHoursPerWorker(Integer year, Integer month); + Number getRowCount(); + } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java index 299fe28bc..913ed8702 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/IWorkerDAO.java @@ -36,7 +36,6 @@ import org.springframework.transaction.annotation.Transactional; * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas * @author Diego Pino Garcia - * @author Vova Perebykivskiy */ public interface IWorkerDAO extends IIntegrationEntityDAO { @@ -127,6 +126,4 @@ public interface IWorkerDAO extends IIntegrationEntityDAO { * Return the list of {@link Worker Workers} bound to any {@link User}. */ List getBound(); - - Number getRowCount(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java index a32c7d3c0..062c859a8 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/MachineDAO.java @@ -41,7 +41,6 @@ import org.springframework.transaction.annotation.Transactional; * @author Diego Pino Garcia * @author Javier Moran Rua * @author Fernando Bellas Permuy - * @author Vova Perebykivskiy */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) @@ -84,11 +83,6 @@ public class MachineDAO extends IntegrationEntityDAO } } - @Override - public Number getRowCount() { - return (Number) getSession().createCriteria(Machine.class).setProjection(Projections.rowCount()).uniqueResult(); - } - @Override @Transactional(readOnly= true, propagation = Propagation.REQUIRES_NEW) public Machine findUniqueByCodeInAnotherTransaction(String code) diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/ResourceDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/ResourceDAO.java index c4e155095..018040c33 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/ResourceDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/ResourceDAO.java @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.List; import org.hibernate.Query; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.libreplan.business.common.daos.IntegrationEntityDAO; import org.libreplan.business.labels.entities.Label; @@ -248,6 +249,11 @@ public class ResourceDAO extends IntegrationEntityDAO implements return result; } + @Override + public Number getRowCount() { + return (Number) getSession().createCriteria(Resource.class).setProjection(Projections.rowCount()).uniqueResult(); + } + private List toDTO(List rows) { List result = new ArrayList(); diff --git a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java index ba3f15074..341fb01e6 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/resources/daos/WorkerDAO.java @@ -44,7 +44,6 @@ import org.springframework.transaction.annotation.Transactional; * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas * @author Diego Pino Garcia - * @author Vova Perebykivskiy */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) @@ -199,10 +198,4 @@ public class WorkerDAO extends IntegrationEntityDAO criteria.add(Restrictions.isNotNull("user")); return criteria.list(); } - - @Override - public Number getRowCount() { - return (Number) getSession().createCriteria(Worker.class).setProjection(Projections.rowCount()).uniqueResult(); - } - } \ No newline at end of file diff --git a/libreplan-business/src/main/resources/db.changelog-1.4.xml b/libreplan-business/src/main/resources/db.changelog-1.4.xml index 6535a3098..a92cccb40 100644 --- a/libreplan-business/src/main/resources/db.changelog-1.4.xml +++ b/libreplan-business/src/main/resources/db.changelog-1.4.xml @@ -1,7 +1,7 @@ @@ -14,9 +14,9 @@ Add foreign key constraint to new id_cost_category column on cost_category id + baseTableName="criterion" baseColumnNames="id_cost_category" + referencedTableName="cost_category" referencedColumnNames="id" + onDelete="SET NULL" /> @@ -25,11 +25,11 @@ + defaultValueBoolean="FALSE" /> + columnName="automatic_budget_enabled" + defaultNullValue="FALSE" + columnDataType="BOOLEAN" /> @@ -41,8 +41,32 @@ + baseTableName="configuration" baseColumnNames="automatic_budget_type_of_work_hours" + referencedTableName="type_of_work_hours" referencedColumnNames="id" /> + + + + + + + + + + + + + + + + INSERT INTO limits VALUES(0, 'users', 5); + INSERT INTO limits VALUES(1, 'workers+machines', 10); + diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java index 8b525cff0..36b35f8cb 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/ILimitsModel.java @@ -34,6 +34,5 @@ public interface ILimitsModel { List getAll(); Limits getUsersType(); - Limits getWorkersType(); - Limits getMachinesType(); + Limits getResourcesType(); } 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 4eb8666b7..5ee7c81a4 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 @@ -58,13 +58,7 @@ public class LimitsModel implements ILimitsModel { @Override @Transactional(readOnly = true) - public Limits getWorkersType() { - return limitsDAO.getWorkersType(); - } - - @Override - @Transactional(readOnly = true) - public Limits getMachinesType() { - return limitsDAO.getMachinesType(); + public Limits getResourcesType() { + return limitsDAO.getResourcesType(); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java index 7be640035..9ad7e649d 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/IMachineModel.java @@ -63,7 +63,6 @@ import org.libreplan.web.resources.search.ResourcePredicate; * * @author Diego Pino Garcia * @author Javier Moran Rua - * @author Vova Perebykivskiy */ public interface IMachineModel extends IIntegrationEntityModel { // Initial conversational steps @@ -108,7 +107,4 @@ public interface IMachineModel extends IIntegrationEntityModel { void confirmRemove(Machine machine) throws InstanceNotFoundException; void removeCalendar(); - - Number getRowCount(); - } 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 2c29bde9b..6860100b3 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 @@ -34,6 +34,7 @@ import org.libreplan.business.calendars.entities.ResourceCalendar; import org.libreplan.business.common.entities.Limits; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; +import org.libreplan.business.resources.daos.IResourceDAO; import org.libreplan.business.resources.entities.Machine; import org.libreplan.web.calendars.BaseCalendarEditionController; import org.libreplan.web.calendars.IBaseCalendarModel; @@ -48,6 +49,7 @@ import org.libreplan.web.costcategories.ResourcesCostCategoryAssignmentControlle import org.libreplan.web.resources.search.ResourcePredicate; import org.libreplan.web.resources.worker.CriterionsController; import org.libreplan.web.resources.worker.CriterionsMachineController; +import org.libreplan.web.resources.worker.IWorkerModel; import org.libreplan.web.resources.worker.WorkerCRUDController.LimitingResourceEnum; import org.springframework.beans.factory.annotation.Autowired; import org.zkoss.zk.ui.Component; @@ -88,6 +90,9 @@ public class MachineCRUDController extends BaseCRUDController { @Autowired private IMachineModel machineModel; + @Autowired + private IResourceDAO resourceDAO; + private Component configurationUnits; private CriterionsMachineController criterionsController; @@ -157,9 +162,9 @@ public class MachineCRUDController extends BaseCRUDController { private void setupResourcesCostCategoryAssignmentController(Component comp) { Component costCategoryAssignmentContainer = - editWindow.getFellowIfAny("costCategoryAssignmentContainer"); + editWindow.getFellowIfAny("costCategoryAssignmentContainer"); resourcesCostCategoryAssignmentController = (ResourcesCostCategoryAssignmentController) - costCategoryAssignmentContainer.getVariable("assignmentController", true); + costCategoryAssignmentContainer.getVariable("assignmentController", true); } @Override @@ -455,11 +460,11 @@ public class MachineCRUDController extends BaseCRUDController { LocalDate finishDate = null; if (filterStartDate.getValue() != null) { startDate = LocalDate.fromDateFields(filterStartDate - .getValue()); + .getValue()); } if (filterFinishDate.getValue() != null) { finishDate = LocalDate.fromDateFields(filterFinishDate - .getValue()); + .getValue()); } final Listitem item = filterLimitingResource.getSelectedItem(); @@ -496,7 +501,7 @@ public class MachineCRUDController extends BaseCRUDController { private void setupFilterLimitingResourceListbox() { for(LimitingResourceEnum resourceEnum : - LimitingResourceEnum.getLimitingResourceFilterOptionList()) { + LimitingResourceEnum.getLimitingResourceFilterOptionList()) { Listitem item = new Listitem(); item.setParent(filterLimitingResource); item.setValue(resourceEnum); @@ -574,7 +579,7 @@ public class MachineCRUDController extends BaseCRUDController { row.addEventListener(Events.ON_CLICK, new EventListener() { @Override - public void onEvent(Event event) { + public void onEvent(Event event) { goToEditForm(machine); } }); @@ -620,23 +625,26 @@ public class MachineCRUDController extends BaseCRUDController { } public boolean isCreateButtonDisabled(){ - Limits machinesTypeLimit = limitsModel.getMachinesType(); - Long machinesCount = (Long) machineModel.getRowCount(); - if ( machinesTypeLimit != null ) - if ( machinesCount >= machinesTypeLimit.getValue() ) + Limits resourcesTypeLimit = limitsModel.getResourcesType(); + Integer resourcesCount = (Integer) resourceDAO.getRowCount(); + + if ( resourcesTypeLimit != null ) + if ( resourcesCount >= resourcesTypeLimit.getValue() ) return true; return false; } public String getShowCreateFormLabel(){ - Limits machinesTypeLimit = limitsModel.getMachinesType(); - Long machinesCount = (Long) machineModel.getRowCount(); - if ( machinesTypeLimit != null ) - if ( machinesCount >= machinesTypeLimit.getValue() ) + Limits resourcesTypeLimit = limitsModel.getResourcesType(); + Integer resourcesCount = (Integer) resourceDAO.getRowCount(); + + int resourcesLeft = resourcesTypeLimit.getValue() - resourcesCount; + if ( resourcesTypeLimit != null ) + if ( resourcesCount >= resourcesTypeLimit.getValue() ) return _("Machines limit reached"); - return _("Create"); + return _("Create") + " ( " + resourcesLeft + " " + _("left") + " )"; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java index 71e2caf6e..3b11c5bb0 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineModel.java @@ -70,7 +70,6 @@ import org.springframework.transaction.annotation.Transactional; /** * @author Diego Pino Garcia * @author Javier Moran Rua - * @author Vova Perebykivskiy */ @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -403,12 +402,4 @@ public class MachineModel extends IntegrationEntityModel implements calendarToRemove = machine.getCalendar(); machine.setCalendar(null); } - - @Override - @Transactional(readOnly = true) - public Number getRowCount() { - return machineDAO.getRowCount(); - } - - } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java index 8f657ba27..ab11c7be7 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/IWorkerModel.java @@ -74,7 +74,6 @@ import org.libreplan.web.resources.search.ResourcePredicate; * @author Óscar González Fernández * @author Fernando Bellas Permuy * @author Manuel Rego Casasnovas - * @author Vova Perebykivskiy */ public interface IWorkerModel extends IIntegrationEntityModel { @@ -147,7 +146,4 @@ public interface IWorkerModel extends IIntegrationEntityModel { void setBoundUser(User user); User getBoundUserFromDB(Worker worker); - - Number getRowCount(); - } 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 722db4f45..5a5169343 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 @@ -38,6 +38,7 @@ import org.libreplan.business.calendars.entities.ResourceCalendar; import org.libreplan.business.common.entities.Limits; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; +import org.libreplan.business.resources.daos.IResourceDAO; import org.libreplan.business.resources.entities.ResourceType; import org.libreplan.business.resources.entities.VirtualWorker; import org.libreplan.business.resources.entities.Worker; @@ -114,6 +115,9 @@ public class WorkerCRUDController extends GenericForwardComposer implements @Autowired private IWorkerModel workerModel; + @Autowired + private IResourceDAO resourceDAO; + @Resource private IUserCRUDController userCRUD; @@ -207,10 +211,10 @@ public class WorkerCRUDController extends GenericForwardComposer implements } public WorkerCRUDController(Window listWindow, Window editWindow, - Window editCalendarWindow, - IWorkerModel workerModel, - IMessagesForUser messages, - IWorkerCRUDControllerEntryPoints workerCRUD) { + Window editCalendarWindow, + IWorkerModel workerModel, + IMessagesForUser messages, + IWorkerCRUDControllerEntryPoints workerCRUD) { this.listWindow = listWindow; this.editWindow = editWindow; this.workerModel = workerModel; @@ -511,7 +515,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements Radio radio = new Radio(_(option.label)); if (option.equals(UserBindingOption.CREATE_NEW_USER) && !SecurityUtils - .isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS)) { + .isSuperuserOrUserInRoles(UserRole.ROLE_USER_ACCOUNTS)) { radio.setDisabled(true); radio.setTooltiptext(_("You do not have permissions to create new users")); } @@ -531,7 +535,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements this.filterStartDate = (Datebox) listWindow .getFellowIfAny("filterStartDate"); this.filterLimitingResource = (Listbox) listWindow - .getFellowIfAny("filterLimitingResource"); + .getFellowIfAny("filterLimitingResource"); this.bdFilters = (BandboxMultipleSearch) listWindow .getFellowIfAny("bdFilters"); this.txtfilter = (Textbox) listWindow.getFellowIfAny("txtfilter"); @@ -541,9 +545,9 @@ public class WorkerCRUDController extends GenericForwardComposer implements private void setupResourcesCostCategoryAssignmentController(Component comp) { Component costCategoryAssignmentContainer = - editWindow.getFellowIfAny("costCategoryAssignmentContainer"); + editWindow.getFellowIfAny("costCategoryAssignmentContainer"); resourcesCostCategoryAssignmentController = (ResourcesCostCategoryAssignmentController) - costCategoryAssignmentContainer.getVariable("assignmentController", true); + costCategoryAssignmentContainer.getVariable("assignmentController", true); } private void editAsignedCriterions() { @@ -653,7 +657,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements } private Window getCurrentWindow() { - return editWindow; + return editWindow; } private void updateCalendarController() { @@ -919,7 +923,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements private void setupFilterLimitingResourceListbox() { for(LimitingResourceEnum resourceEnum : - LimitingResourceEnum.getLimitingResourceFilterOptionList()) { + LimitingResourceEnum.getLimitingResourceFilterOptionList()) { Listitem item = new Listitem(); item.setParent(filterLimitingResource); item.setValue(resourceEnum); @@ -1017,7 +1021,7 @@ public class WorkerCRUDController extends GenericForwardComposer implements row.addEventListener(Events.ON_CLICK, new EventListener() { @Override - public void onEvent(Event event) { + public void onEvent(Event event) { goToEditForm(worker); } }); @@ -1061,19 +1065,19 @@ public class WorkerCRUDController extends GenericForwardComposer implements String title; switch (state) { - case CREATE: - if (StringUtils.isEmpty(humanId)) { - title = _("Create {0}", entityType); - } else { - title = _("Create {0}: {1}", entityType, humanId); - } - break; - case EDIT: - title = _("Edit {0}: {1}", entityType, humanId); - break; - default: - throw new IllegalStateException( - "You should be in creation or edition mode to use this method"); + case CREATE: + if (StringUtils.isEmpty(humanId)) { + title = _("Create {0}", entityType); + } else { + title = _("Create {0}: {1}", entityType, humanId); + } + break; + case EDIT: + title = _("Edit {0}: {1}", entityType, humanId); + break; + default: + throw new IllegalStateException( + "You should be in creation or edition mode to use this method"); } ((Caption) editWindow.getFellow("caption")).setLabel(title); } @@ -1167,23 +1171,26 @@ public class WorkerCRUDController extends GenericForwardComposer implements } public boolean isCreateButtonDisabled(){ - Limits workersTypeLimit = limitsModel.getWorkersType(); - Long workersCount = (Long) workerModel.getRowCount(); - if ( workersTypeLimit != null ) - if ( workersCount >= workersTypeLimit.getValue() ) + Limits resourcesTypeLimit = limitsModel.getResourcesType(); + Integer resourcesCount = (Integer) resourceDAO.getRowCount(); + + if ( resourcesTypeLimit != null ) + if ( resourcesCount >= resourcesTypeLimit.getValue() ) return true; return false; } public String getShowCreateFormLabel(){ - Limits workersTypeLimit = limitsModel.getWorkersType(); - Long workersCount = (Long) workerModel.getRowCount(); - if ( workersTypeLimit != null ) - if ( workersCount >= workersTypeLimit.getValue() ) + Limits resourcesTypeLimit = limitsModel.getResourcesType(); + Integer resourcesCount = (Integer) resourceDAO.getRowCount(); + + int resourcesLeft = resourcesTypeLimit.getValue() - resourcesCount; + if ( resourcesTypeLimit != null ) + if ( resourcesCount >= resourcesTypeLimit.getValue() ) return _("Workers limit reached"); - return _("Create"); + return _("Create") + " ( " + resourcesLeft + " " + _("left") + " )"; } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java index 90ca8a30d..aa82fdd70 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerModel.java @@ -702,11 +702,4 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel } return null; } - - @Override - @Transactional(readOnly = true) - public Number getRowCount() { - return workerDAO.getRowCount(); - } - } 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 5e34cd5ea..775f3ee32 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 @@ -119,16 +119,16 @@ public class UserCRUDController extends BaseCRUDController implements Button[] buttons = Util.appendOperationsAndOnClickEvent(row, new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - goToEditForm(user); - } - }, new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - confirmDelete(user); - } - }); + @Override + public void onEvent(Event event) throws Exception { + goToEditForm(user); + } + }, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + confirmDelete(user); + } + }); // Disable remove button for default admin as it's mandatory if (isDefaultAdmin(user)) { @@ -260,7 +260,7 @@ public class UserCRUDController extends BaseCRUDController implements userModel.setPassword(password); //update the constraint on the confirmation password box ((Textbox)editWindow.getFellowIfAny("passwordConfirmation")). - clearErrorMessage(true); + clearErrorMessage(true); } public Constraint validatePasswordConfirmation() { @@ -382,11 +382,11 @@ public class UserCRUDController extends BaseCRUDController implements Button removeButton = Util .createRemoveButton(new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - removeRole(role); - } - }); + @Override + public void onEvent(Event event) throws Exception { + removeRole(role); + } + }); removeButton.setDisabled(areRolesAndProfilesDisabled() || role.equals(UserRole.ROLE_BOUND_USER) || isUserDefaultAdmin()); @@ -505,7 +505,7 @@ public class UserCRUDController extends BaseCRUDController implements public boolean isCreateButtonDisabled(){ Limits usersTypeLimit = limitsModel.getUsersType(); - Long usersCount = (Long) userModel.getRowCount(); + Integer usersCount = (Integer) userModel.getRowCount(); if (usersTypeLimit != null) if ( usersCount >= usersTypeLimit.getValue() ) return true; @@ -514,11 +514,12 @@ public class UserCRUDController extends BaseCRUDController implements public String getShowCreateFormLabel(){ Limits usersTypeLimit = limitsModel.getUsersType(); - Long usersCount = (Long) userModel.getRowCount(); + Integer usersCount = (Integer) userModel.getRowCount(); + int usersLeft = usersTypeLimit.getValue() - usersCount; if (usersTypeLimit != null) if ( usersCount >= usersTypeLimit.getValue() ) return _("User limit reached"); - return _("Create"); + return _("Create") + " ( " + usersLeft + " " + _("left") + " )"; } } diff --git a/libreplan-webapp/src/main/resources/i18n/keys.pot b/libreplan-webapp/src/main/resources/i18n/keys.pot index 68b1068d7..2255f22e5 100644 --- a/libreplan-webapp/src/main/resources/i18n/keys.pot +++ b/libreplan-webapp/src/main/resources/i18n/keys.pot @@ -8631,6 +8631,9 @@ msgstr "" #: libreplan-webapp/src/main/webapp/advance/_listAdvanceTypes.zul:33 #: libreplan-webapp/src/main/webapp/unittypes/_listUnitTypes.zul:32 #: libreplan-webapp/src/main/webapp/qualityforms/_listQualityForm.zul:58 +#: libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java:523 +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java:640 +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java:1187 msgid "Create" msgstr "" @@ -9292,7 +9295,13 @@ msgstr "" msgid "User limit reached" msgstr "" -#: libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/UserCRUDController.java:1178 +#: libreplan-webapp/src/main/java/org/libreplan/web/users/UserCRUDController.java:523 +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/machine/MachineCRUDController.java:640 +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java:1187 +msgid "left" +msgstr "" + +#: libreplan-webapp/src/main/java/org/libreplan/web/resources/worker/WorkerCRUDController.java:1178 msgid "Workers limit reached" msgstr ""