From 9a011d35e9c824c9a10e5408bdd4154e9ce3af0e Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Mon, 7 May 2012 16:35:11 +0200 Subject: [PATCH] Create basic UI to bound a user to a worker FEA: ItEr76S27ResourceBinding --- .../business/users/daos/IUserDAO.java | 12 +- .../business/users/daos/UserDAO.java | 24 +++- .../business/test/users/daos/UserDAOTest.java | 39 +++++- .../web/resources/worker/IWorkerModel.java | 48 ++++--- .../worker/WorkerCRUDController.java | 31 +++- .../web/resources/worker/WorkerModel.java | 39 +++++- .../main/webapp/resources/worker/_edition.zul | 132 ++++++++++-------- 7 files changed, 242 insertions(+), 83 deletions(-) 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 b416e3053..5a555f502 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 @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, S.L. * * 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 @@ -25,6 +25,7 @@ import java.util.List; import org.libreplan.business.common.daos.IGenericDAO; import org.libreplan.business.common.exceptions.InstanceNotFoundException; +import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.scenarios.entities.Scenario; import org.libreplan.business.users.entities.OrderAuthorization; import org.libreplan.business.users.entities.User; @@ -33,6 +34,7 @@ import org.libreplan.business.users.entities.User; * DAO interface for the User entity. * * @author Fernando Bellas Permuy + * @author Manuel Rego Casasnovas */ public interface IUserDAO extends IGenericDAO{ @@ -82,4 +84,12 @@ public interface IUserDAO extends IGenericDAO{ public List findByLastConnectedScenario(Scenario scenario); List getOrderAuthorizationsByUser(User user); + + /** + * Returns the list of {@link User}s not bound to any {@link Worker} yet, + * plus the {@link User} bound to the {@link Worker} specified as parameter + * if any. + */ + List getUnboundUsers(Worker worker); + } 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 608faead1..ed11bff4f 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 @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, S.L. * * 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 @@ -21,12 +21,14 @@ package org.libreplan.business.users.daos; +import java.util.ArrayList; import java.util.List; import org.hibernate.Criteria; import org.hibernate.criterion.Restrictions; import org.libreplan.business.common.daos.GenericDAOHibernate; import org.libreplan.business.common.exceptions.InstanceNotFoundException; +import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.scenarios.entities.Scenario; import org.libreplan.business.users.entities.OrderAuthorization; import org.libreplan.business.users.entities.User; @@ -40,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Fernando Bellas Permuy * @author Jacobo Aragunde Perez + * @author Manuel Rego Casasnovas */ @Repository public class UserDAO extends GenericDAOHibernate @@ -127,4 +130,23 @@ public class UserDAO extends GenericDAOHibernate .add(Restrictions.eq("user", user)).list(); return orderAuthorizations; } + + @Override + public List getUnboundUsers(Worker worker) { + List result = new ArrayList(); + for (User user : getUsersOrderByLoginame()) { + if ((user.getWorker() == null) + || (worker != null && !worker.isNewObject() && worker + .getId().equals(user.getWorker().getId()))) { + result.add(user); + } + } + return result; + } + + private List getUsersOrderByLoginame() { + return getSession().createCriteria(User.class).addOrder( + org.hibernate.criterion.Order.asc("loginName")).list(); + } + } diff --git a/libreplan-business/src/test/java/org/libreplan/business/test/users/daos/UserDAOTest.java b/libreplan-business/src/test/java/org/libreplan/business/test/users/daos/UserDAOTest.java index 1f59160a1..77b92058a 100644 --- a/libreplan-business/src/test/java/org/libreplan/business/test/users/daos/UserDAOTest.java +++ b/libreplan-business/src/test/java/org/libreplan/business/test/users/daos/UserDAOTest.java @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, S.L. * * 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 @@ -39,6 +39,8 @@ import org.libreplan.business.common.IAdHocTransactionService; import org.libreplan.business.common.IOnTransaction; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.common.exceptions.ValidationException; +import org.libreplan.business.resources.daos.IWorkerDAO; +import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.users.daos.IProfileDAO; import org.libreplan.business.users.daos.IUserDAO; import org.libreplan.business.users.entities.Profile; @@ -55,6 +57,7 @@ import org.springframework.transaction.annotation.Transactional; * * @author Fernando Bellas Permuy * @author Jacobo Aragunde Perez + * @author Manuel Rego Casasnovas */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE, @@ -71,6 +74,9 @@ public class UserDAOTest { @Autowired IProfileDAO profileDAO; + @Autowired + private IWorkerDAO workerDAO; + @Test public void testBasicSave() throws InstanceNotFoundException { @@ -283,4 +289,35 @@ public class UserDAOTest { Set roles = new HashSet(); return Profile.create(profileName, roles); } + + @Test + public void testUnoundUsers1() { + int previous = userDAO.list(User.class).size(); + userDAO.save(createUser(getUniqueName())); + + List unboundUsers = userDAO.getUnboundUsers(null); + assertEquals(previous + 1, unboundUsers.size()); + } + + private Worker givenStoredWorkerRelatedTo(User user) { + Worker worker = Worker.create(); + worker.setFirstName("Name " + UUID.randomUUID()); + worker.setSurname("Surname " + UUID.randomUUID()); + worker.setNif("ID " + UUID.randomUUID()); + worker.setUser(user); + workerDAO.save(worker); + + return worker; + } + + @Test + public void testUnoundUsers2() { + int previous = userDAO.list(User.class).size(); + User user = createUser(getUniqueName()); + user.setWorker(givenStoredWorkerRelatedTo(user)); + + List unboundUsers = userDAO.getUnboundUsers(null); + assertEquals(previous, unboundUsers.size()); + } + } 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 e3ee56cd1..7d6518dea 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 @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, S.L. * * 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 @@ -33,6 +33,7 @@ import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.resources.entities.CriterionSatisfaction; import org.libreplan.business.resources.entities.ICriterionType; import org.libreplan.business.resources.entities.Worker; +import org.libreplan.business.users.entities.User; import org.libreplan.web.common.IIntegrationEntityModel; import org.libreplan.web.resources.search.ResourcePredicate; @@ -40,44 +41,39 @@ import org.libreplan.web.resources.search.ResourcePredicate; * This interface contains the operations to create/edit a worker. The * creation/edition process of a worker is conversational.
* - * Conversation state: the Worker instance and - * the associated CriterionSatisfaction instances. Some of the + * Conversation state: the Worker instance and the + * associated CriterionSatisfaction instances. Some of the * CriterionSatisfaction instances represent temporal work * relationships (e.g. paternity leave) and others represent locations.
* * Non conversational steps: getWorkers (to return - * all workers) and getLaboralRelatedCriterions (to return - * all Criterion instances representing temporal work - * relationships).
+ * all workers) and getLaboralRelatedCriterions (to return all + * Criterion instances representing temporal work relationships).
* * Conversation protocol: *
    *
  • - * Initial conversation step: prepareForCreate (to create - * a worker) or (exclusive) prepareEditFor (to edit an existing - * worker). - *
  • + * Initial conversation step: prepareForCreate (to create a worker) + * or (exclusive) prepareEditFor (to edit an existing worker). *
  • - * Intermediate conversation steps: getWorker (to return the - * worker being edited/created), getLocalizationsAssigner (to - * assist in the location tab), isCreating (to check if the worker - * is being created or edited), - * getLaboralRelatedCriterionSatisfactions (to return all the - * temporal work relationships), addSatisfaction (to add a - * temporal work relationship), removeSatisfaction (to remove a - * temporal work relationship) (note: to modify an existing temporal work + * Intermediate conversation steps: getWorker (to return the worker + * being edited/created), getLocalizationsAssigner (to assist in + * the location tab), isCreating (to check if the worker is being + * created or edited), getLaboralRelatedCriterionSatisfactions (to + * return all the temporal work relationships), addSatisfaction (to + * add a temporal work relationship), removeSatisfaction (to remove + * a temporal work relationship) (note: to modify an existing temporal work * relationship, it is necessary to remove it and add a new one), * assignCriteria (to add locations), and - * unassignSatisfactions (to remove locations). - *
  • + * unassignSatisfactions (to remove locations). *
  • * Final conversational step: save (to save the worker being - * edited/created). - *
  • + * edited/created). *
* * @author Óscar González Fernández * @author Fernando Bellas Permuy + * @author Manuel Rego Casasnovas */ public interface IWorkerModel extends IIntegrationEntityModel { @@ -142,4 +138,10 @@ public interface IWorkerModel extends IIntegrationEntityModel { void removeCalendar(); -} \ No newline at end of file + List getPossibleUsersToBound(); + + User getBoundUser(); + + void setBoundUser(User user); + +} 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 13eea9a06..8462f3aeb 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 @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, S.L. * * 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 @@ -38,6 +38,7 @@ import org.libreplan.business.common.exceptions.ValidationException; import org.libreplan.business.resources.entities.ResourceType; import org.libreplan.business.resources.entities.VirtualWorker; import org.libreplan.business.resources.entities.Worker; +import org.libreplan.business.users.entities.User; import org.libreplan.web.calendars.BaseCalendarEditionController; import org.libreplan.web.calendars.IBaseCalendarModel; import org.libreplan.web.common.BaseCRUDController.CRUDControllerState; @@ -71,6 +72,7 @@ import org.zkoss.zul.Label; import org.zkoss.zul.Listbox; import org.zkoss.zul.Listcell; import org.zkoss.zul.Listitem; +import org.zkoss.zul.ListitemRenderer; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Row; import org.zkoss.zul.RowRenderer; @@ -82,8 +84,10 @@ import org.zkoss.zul.api.Window; /** * Controller for {@link Worker} resource
+ * * @author Óscar González Fernández * @author Lorenzo Tilve Álvaro + * @author Manuel Rego Casasnovas */ public class WorkerCRUDController extends GenericForwardComposer implements IWorkerCRUDControllerEntryPoints { @@ -896,4 +900,29 @@ public class WorkerCRUDController extends GenericForwardComposer implements } } + public List getPossibleUsersToBound() { + return workerModel.getPossibleUsersToBound(); + } + + public User getBoundUser() { + return workerModel.getBoundUser(); + } + + public void setBoundUser(User user) { + workerModel.setBoundUser(user); + } + + public ListitemRenderer getUsersRenderer() { + return new ListitemRenderer() { + + @Override + public void render(Listitem item, Object data) throws Exception { + User user = (User) data; + + item.setLabel(user.getLoginName()); + item.setValue(user); + } + }; + } + } 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 46d8033d0..3c3c282a7 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 @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2011 Igalia, S.L. + * Copyright (C) 2010-2012 Igalia, S.L. * * 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 @@ -59,6 +59,8 @@ import org.libreplan.business.resources.entities.Resource; import org.libreplan.business.resources.entities.VirtualWorker; import org.libreplan.business.resources.entities.Worker; import org.libreplan.business.scenarios.IScenarioManager; +import org.libreplan.business.users.daos.IUserDAO; +import org.libreplan.business.users.entities.User; import org.libreplan.business.workreports.daos.IWorkReportLineDAO; import org.libreplan.web.calendars.IBaseCalendarModel; import org.libreplan.web.common.IntegrationEntityModel; @@ -73,9 +75,11 @@ import org.springframework.transaction.annotation.Transactional; /** * Model for worker
+ * * @author Óscar González Fernández * @author Fernando Bellas Permuy * @author Diego Pino García + * @author Manuel Rego Casasnovas */ @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -127,6 +131,9 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel @Autowired private IScenarioManager scenarioManager; + @Autowired + private IUserDAO userDAO; + @Autowired public WorkerModel(IResourceDAO resourceDAO, ICriterionDAO criterionDAO) { Validate.notNull(resourceDAO); @@ -224,6 +231,7 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel this.worker = (Worker) resourceDAO.find(worker.getId()); forceLoadSatisfactions(this.worker); forceLoadCalendar(this.worker); + forceLoadUser(this.worker); localizationsAssigner = new MultipleCriterionActiveAssigner( criterionDAO, this.worker, PredefinedCriterionTypes.LOCATION); @@ -257,6 +265,12 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel baseCalendar.getExceptions().size(); } + private void forceLoadUser(Worker worker) { + if (worker.getUser() != null) { + worker.getUser().getLoginName(); + } + } + @Override @Transactional(readOnly = true) public void assignCriteria(Collection criteria) { @@ -614,4 +628,27 @@ public class WorkerModel extends IntegrationEntityModel implements IWorkerModel worker.setCalendar(null); } + @Override + @Transactional(readOnly = true) + public List getPossibleUsersToBound() { + List users = new ArrayList(); + users.addAll(userDAO.getUnboundUsers(worker)); + return users; + } + + @Override + public User getBoundUser() { + if (worker != null) { + return worker.getUser(); + } + return null; + } + + @Override + public void setBoundUser(User user) { + if (worker != null) { + worker.setUser(user); + } + } + } diff --git a/libreplan-webapp/src/main/webapp/resources/worker/_edition.zul b/libreplan-webapp/src/main/webapp/resources/worker/_edition.zul index cf6d17fce..4d0874868 100644 --- a/libreplan-webapp/src/main/webapp/resources/worker/_edition.zul +++ b/libreplan-webapp/src/main/webapp/resources/worker/_edition.zul @@ -3,7 +3,7 @@ Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e Desenvolvemento Tecnolóxico de Galicia - Copyright (C) 2010-2011 Igalia, S.L. + Copyright (C) 2010-2012 Igalia, S.L. 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 @@ -37,60 +37,82 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +