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.
This commit is contained in:
parent
f48f2ead71
commit
afeea6823b
20 changed files with 157 additions and 19 deletions
|
|
@ -17,4 +17,5 @@ public interface ILimitsDAO extends IGenericDAO<Limits, Long> {
|
|||
|
||||
Limits getUsersType();
|
||||
Limits getWorkersType();
|
||||
Limits getMachinesType();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,4 +37,12 @@ public class LimitsDAO extends GenericDAOHibernate<Limits, Long> implements ILim
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Limits getMachinesType() {
|
||||
List<Limits> list = list(Limits.class);
|
||||
for (Limits item : list)
|
||||
if (item.getType().equals("machines")) return item;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import org.libreplan.business.resources.entities.Machine;
|
|||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
* @author Javier Moran Rua <jmoran@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
public interface IMachineDAO extends IIntegrationEntityDAO<Machine> {
|
||||
|
||||
|
|
@ -82,4 +83,9 @@ public interface IMachineDAO extends IIntegrationEntityDAO<Machine> {
|
|||
* code as the one passed as parameter
|
||||
*/
|
||||
boolean existsMachineWithCodeInAnotherTransaction(String code);
|
||||
|
||||
/**
|
||||
* Return a number of rows in database table
|
||||
*/
|
||||
Number getRowCount();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
public interface IWorkerDAO extends IIntegrationEntityDAO<Worker> {
|
||||
|
||||
|
|
@ -127,4 +127,6 @@ public interface IWorkerDAO extends IIntegrationEntityDAO<Worker> {
|
|||
* Return the list of {@link Worker Workers} bound to any {@link User}.
|
||||
*/
|
||||
List<Worker> getBound();
|
||||
|
||||
Number getRowCount();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <dpino@igalia.com>
|
||||
* @author Javier Moran Rua <jmoran@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
|
|
@ -82,6 +84,11 @@ public class MachineDAO extends IntegrationEntityDAO<Machine>
|
|||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
|
|
|
|||
|
|
@ -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 <fbellas@udc.es>
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
*
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
|
|
@ -199,4 +200,9 @@ public class WorkerDAO extends IntegrationEntityDAO<Worker>
|
|||
return criteria.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getRowCount() {
|
||||
return (Number) getSession().createCriteria(Worker.class).setProjection(Projections.rowCount()).uniqueResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Jacobo Aragunde Perez <jaragunde@igalia.com>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@Repository
|
||||
public class UserDAO extends GenericDAOHibernate<User, Long>
|
||||
|
|
|
|||
|
|
@ -16,4 +16,5 @@ public interface ILimitsModel {
|
|||
|
||||
Limits getUsersType();
|
||||
Limits getWorkersType();
|
||||
Limits getMachinesType();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <dpino@igalia.com>
|
||||
* @author Javier Moran Rua <jmoran@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
public interface IMachineModel extends IIntegrationEntityModel {
|
||||
// Initial conversational steps
|
||||
|
|
@ -108,4 +109,6 @@ public interface IMachineModel extends IIntegrationEntityModel {
|
|||
|
||||
void removeCalendar();
|
||||
|
||||
Number getRowCount();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <br />
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
public class MachineCRUDController extends BaseCRUDController<Machine> {
|
||||
|
||||
@Autowired
|
||||
private ILimitsModel limitsModel;
|
||||
|
||||
@Autowired
|
||||
private IMachineModel machineModel;
|
||||
|
||||
private Component configurationUnits;
|
||||
|
|
@ -611,4 +615,24 @@ public class MachineCRUDController extends BaseCRUDController<Machine> {
|
|||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
/**
|
||||
* @author Diego Pino Garcia <dpino@igalia.com>
|
||||
* @author Javier Moran Rua <jmoran@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ import org.libreplan.web.resources.search.ResourcePredicate;
|
|||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
public interface IWorkerModel extends IIntegrationEntityModel {
|
||||
|
||||
|
|
@ -147,4 +148,6 @@ public interface IWorkerModel extends IIntegrationEntityModel {
|
|||
|
||||
User getBoundUserFromDB(Worker worker);
|
||||
|
||||
Number getRowCount();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <ogonzalez@igalia.com>
|
||||
* @author Lorenzo Tilve Álvaro <ltilve@igalia.com>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <fbellas@udc.es>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
* @author Vova Perebykivskiy <vova@libreplan-enterprise.com>
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<User> implements
|
|||
|
||||
private Combobox profilesCombo;
|
||||
|
||||
private Button showCreateForm;
|
||||
|
||||
private IURLHandlerRegistry URLHandlerRegistry;
|
||||
|
||||
private RowRenderer usersRenderer = new RowRenderer() {
|
||||
|
|
@ -503,7 +507,18 @@ public class UserCRUDController extends BaseCRUDController<User> 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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ""
|
||||
|
|
@ -40,6 +40,7 @@
|
|||
</columns>
|
||||
</newdatasortablegrid>
|
||||
<button id="show_create_form" onClick="controller.goToCreateForm();"
|
||||
label="${i18n:_('Create')}" sclass="create-button global-action">
|
||||
label="@{controller.getShowCreateFormLabel}" sclass="create-button global-action"
|
||||
disabled="@{controller.isCreateButtonDisabled}">
|
||||
</button>
|
||||
</window>
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
</newdatasortablegrid>
|
||||
|
||||
<button id="show_create_form" onClick="controller.goToCreateForm();"
|
||||
label="${i18n:_('Create')}" sclass="create-button global-action">
|
||||
label="@{controller.getShowCreateFormLabel}" sclass="create-button global-action"
|
||||
disabled="@{controller.isCreateButtonDisabled}">
|
||||
</button>
|
||||
</window>
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
</columns>
|
||||
</newdatasortablegrid>
|
||||
<button id="show_create_form" onClick="controller.goToCreateForm();"
|
||||
label="${i18n:_('Create')}" sclass="create-button global-action"
|
||||
label="@{controller.getShowCreateFormLabel}" sclass="create-button global-action"
|
||||
disabled="@{controller.isCreateButtonDisabled}">
|
||||
</button>
|
||||
</window>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue