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).
- *