diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/IResourceGroupDao.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/IResourceGroupDao.java
deleted file mode 100644
index 790bae027..000000000
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/IResourceGroupDao.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.navalplanner.business.resources.daos;
-
-import org.navalplanner.business.common.daos.IGenericDao;
-import org.navalplanner.business.resources.entities.ResourceGroup;
-
-/**
- * DAO interface for the ResourceGroup entity.
- *
- * @author Fernando Bellas Permuy
- *
- */
-public interface IResourceGroupDao extends IGenericDao {}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/ResourcesDaoRegistry.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/ResourcesDaoRegistry.java
index ce1c7e36f..304fcf053 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/ResourcesDaoRegistry.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/ResourcesDaoRegistry.java
@@ -7,33 +7,29 @@ import org.springframework.beans.factory.annotation.Autowired;
// (I think it is not necessary).
/**
- * A registry of resource DAOs. Classes in which dependency injection (DI) is
- * not directly supported by Spring (e.g. entities) must use this class to
+ * A registry of resource DAOs. Classes in which dependency injection (DI) is
+ * not directly supported by Spring (e.g. entities) must use this class to
* access resource DAOs. For the rest of classes (e.g. services, tests, etc.),
* Spring DI is a more convenient option.
- *
* @author Fernando Bellas Permuy
- *
*/
public final class ResourcesDaoRegistry {
-
+
private static ResourcesDaoRegistry instance = new ResourcesDaoRegistry();
-
+
@Autowired
private IResourceDao resourceDao;
-
+
@Autowired
private IWorkerDao workerDao;
-
- @Autowired
- private IResourceGroupDao resourceGroupDao;
-
- private ResourcesDaoRegistry() {}
+
+ private ResourcesDaoRegistry() {
+ }
public static ResourcesDaoRegistry getInstance() {
return instance;
}
-
+
public static IResourceDao getResourceDao() {
return getInstance().resourceDao;
}
@@ -42,8 +38,4 @@ public final class ResourcesDaoRegistry {
return getInstance().workerDao;
}
- public static IResourceGroupDao getResourceGroupDao() {
- return getInstance().resourceGroupDao;
- }
-
}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/impl/ResourceGroupDaoHibernate.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/impl/ResourceGroupDaoHibernate.java
deleted file mode 100644
index e297c8763..000000000
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/daos/impl/ResourceGroupDaoHibernate.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.navalplanner.business.resources.daos.impl;
-
-import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
-import org.navalplanner.business.resources.daos.IResourceGroupDao;
-import org.navalplanner.business.resources.entities.ResourceGroup;
-
-/**
- * Hibernate DAO for the ResourceGroup entity.
- *
- * @author Fernando Bellas Permuy
- *
- */
-public class ResourceGroupDaoHibernate
- extends GenericDaoHibernate
- implements IResourceGroupDao {}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java
index 711a8de70..e9243f74f 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/Resource.java
@@ -13,54 +13,34 @@ import org.navalplanner.business.resources.daos.ResourcesDaoRegistry;
/**
* This class acts as the base class for all resources.
- *
* @author Fernando Bellas Permuy
- *
*/
public abstract class Resource {
-
+
private Long id;
- private ResourceGroup resourceGroup;
-
+
@SuppressWarnings("unused")
private long version;
public Long getId() {
return id;
}
-
- public ResourceGroup getResourceGroup() {
- return resourceGroup;
- }
- public void setResourceGroup(ResourceGroup resourceGroup) {
- this.resourceGroup = resourceGroup;
- }
-
public abstract int getDailyCapacity();
-
+
/**
- * It removes the resource from the database and updates references.
- * The default implementation removes the resource from the resource group
- * it belongs to (if it belongs to someone) and from the database. This
- * implementation should be valid for simple resources.
+ * It removes the resource from the database and updates references. The
+ * default implementation removes the resource from the resource group it
+ * belongs to (if it belongs to someone) and from the database. This
+ * implementation should be valid for simple resources.
*/
public void remove() {
-
- /* Remove from the resource group it belongs to. */
- ResourceGroup resourceGroup = getResourceGroup();
-
- if (resourceGroup != null) {
- resourceGroup.removeResource(this);
- }
-
/* Remove from the database. */
try {
ResourcesDaoRegistry.getResourceDao().remove(getId());
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
-
}
}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/ResourceGroup.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/ResourceGroup.java
deleted file mode 100644
index 3c874bbab..000000000
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/entities/ResourceGroup.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.navalplanner.business.resources.entities;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
-import org.navalplanner.business.resources.daos.ResourcesDaoRegistry;
-
-/**
- * This class models a resource group. A resource group represents a resource
- * containing other resources.
- *
- * @author Fernando Bellas Permuy
- *
- */
-public class ResourceGroup extends Resource {
-
- private Set resources = new HashSet();
-
- public Set getResources() {
- return resources;
- }
-
- public void setResources(Set resources) {
- this.resources = resources;
- }
-
- public void addResource(Resource resource) {
-
- /*
- * Remove resource from its current resource group (if it belongs to
- * one).
- */
- if (resource.getResourceGroup() != null) {
- resource.getResourceGroup().removeResource(resource);
- }
-
- /* Add resource to this resource group. */
- resource.setResourceGroup(this);
- resources.add(resource);
-
- }
-
- public void addResource(Long resourceId) throws InstanceNotFoundException {
-
- Resource resource =
- ResourcesDaoRegistry.getResourceDao().find(resourceId);
- addResource(resource);
-
- }
-
- public void removeResource(Resource resource) {
-
- if (resources.contains(resource)) {
- resources.remove(resource);
- resource.setResourceGroup(null);
- }
-
- }
-
- @Override
- public int getDailyCapacity() {
-
- int dailyCapacity = 0;
-
- for (Resource r : resources) {
- dailyCapacity += r.getDailyCapacity();
- }
-
- return dailyCapacity;
-
- }
-
- @Override
- public void remove() {
-
- for (Resource r : resources) {
- r.setResourceGroup(null);
- }
- resources.clear();
-
- super.remove();
-
- }
-
-
-}
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/ResourceService.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/ResourceService.java
index cca0af797..1af8811a7 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/ResourceService.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/ResourceService.java
@@ -8,9 +8,7 @@ import org.navalplanner.business.resources.entities.Worker;
/**
* Interface for the resource management service.
- *
* @author Fernando Bellas Permuy
- *
*/
public interface ResourceService {
@@ -24,16 +22,9 @@ public interface ResourceService {
public Resource findResource(Long resourceId)
throws InstanceNotFoundException;
- /**
- * It adds a resource to a resource group. It the resource already belongs
- * to a resource group, the resource is moved to the new group.
- */
- public void addResourceToResourceGroup(Long resourceId,
- Long resourceGroupId) throws InstanceNotFoundException;
-
- public int getResourceDailyCapacity(Long resourceId)
- throws InstanceNotFoundException;
-
+ public int getResourceDailyCapacity(Long resourceId)
+ throws InstanceNotFoundException;
+
/**
* It removes a resource. If the resource is a composite resource, the
* resources contained in it are not removed.
diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/impl/ResourceServiceImpl.java b/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/impl/ResourceServiceImpl.java
index 45429a8cc..6cc399cbd 100644
--- a/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/impl/ResourceServiceImpl.java
+++ b/navalplanner-business/src/main/java/org/navalplanner/business/resources/services/impl/ResourceServiceImpl.java
@@ -4,9 +4,7 @@ import java.util.List;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.resources.daos.IResourceDao;
-import org.navalplanner.business.resources.daos.IResourceGroupDao;
import org.navalplanner.business.resources.entities.Resource;
-import org.navalplanner.business.resources.entities.ResourceGroup;
import org.navalplanner.business.resources.entities.Worker;
import org.navalplanner.business.resources.services.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -23,9 +21,6 @@ public class ResourceServiceImpl implements ResourceService {
@Autowired
private IResourceDao resourceDao;
- @Autowired
- private IResourceGroupDao resourceGroupDao;
-
public void saveResource(Resource resource) {
resourceDao.save(resource);
}
@@ -38,15 +33,6 @@ public class ResourceServiceImpl implements ResourceService {
}
- public void addResourceToResourceGroup(Long resourceId, Long resourceGroupId)
- throws InstanceNotFoundException {
-
- ResourceGroup resourceGroup = resourceGroupDao.find(resourceGroupId);
-
- resourceGroup.addResource(resourceId);
-
- }
-
@Transactional(readOnly = true)
public int getResourceDailyCapacity(Long resourceId)
throws InstanceNotFoundException {
diff --git a/navalplanner-business/src/main/resources/navalplanner-business-spring-config.xml b/navalplanner-business/src/main/resources/navalplanner-business-spring-config.xml
index b882228a7..72dd606ee 100644
--- a/navalplanner-business/src/main/resources/navalplanner-business-spring-config.xml
+++ b/navalplanner-business/src/main/resources/navalplanner-business-spring-config.xml
@@ -1,66 +1,69 @@
-
+
-
-
+
+
-
+
- org/navalplanner/business/resources/entities/Resources.hbm.xml
+
+ org/navalplanner/business/resources/entities/Resources.hbm.xml
+
-
+
-
+
-
-
-
-
-
-
-
-
+ p:sessionFactory-ref="sessionFactory" />
+
+
+
+
+
+
+
+
-
-
-
-
-
+
-
+
+
+
+
-
-
+
+
diff --git a/navalplanner-business/src/main/resources/org/navalplanner/business/resources/entities/Resources.hbm.xml b/navalplanner-business/src/main/resources/org/navalplanner/business/resources/entities/Resources.hbm.xml
index 05fc6c425..aa34c6ff9 100644
--- a/navalplanner-business/src/main/resources/org/navalplanner/business/resources/entities/Resources.hbm.xml
+++ b/navalplanner-business/src/main/resources/org/navalplanner/business/resources/entities/Resources.hbm.xml
@@ -4,46 +4,31 @@
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
-
+
-
+
-
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
\ No newline at end of file
diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java
index 38c0c3e8b..4a069103e 100644
--- a/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java
+++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/resources/services/ResourceServiceTest.java
@@ -8,7 +8,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.resources.daos.IResourceDao;
-import org.navalplanner.business.resources.entities.ResourceGroup;
+import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
import org.navalplanner.business.resources.services.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.navalplanner.business.BusinessGlobalNames.BUSINESS_SPRING_CONFIG_FILE;
@@ -45,159 +44,39 @@ public class ResourceServiceTest {
@Autowired
private SessionFactory sessionFactory;
- @Test
- public void testAddResourceToResourceGroup()
- throws InstanceNotFoundException {
-
- /* Two workers. One of them belongs to a resource group. */
- Worker worker1 = new Worker("worker-1", "worker-1-surname",
- "11111111A", 8);
- Worker worker2 = new Worker("worker-2", "worker-2-surname",
- "22222222B", 7);
- ResourceGroup resourceGroup1 = new ResourceGroup();
- resourceGroup1.addResource(worker1);
- resourceService.saveResource(resourceGroup1); // worker1 is also saved.
- resourceService.saveResource(worker2);
-
- /* A resource group. */
- ResourceGroup resourceGroup2 = new ResourceGroup();
- resourceService.saveResource(resourceGroup2);
-
- /* Add workers to resource group. */
- resourceService.addResourceToResourceGroup(worker1.getId(),
- resourceGroup2.getId());
- resourceService.addResourceToResourceGroup(worker2.getId(),
- resourceGroup2.getId());
-
- /* Check resource group. */
- ResourceGroup resourceGroup = (ResourceGroup) resourceService
- .findResource(resourceGroup2.getId());
-
- assertEquals(2, resourceGroup.getResources().size());
- assertTrue(resourceGroup.getResources().contains(worker1));
- assertTrue(resourceGroup.getResources().contains(worker2));
-
- /* Check worker1 is no longer in group 1. */
- assertFalse(resourceGroup1.getResources().contains(worker1));
-
- }
-
- @Test
- public void testGetResourceDailyCapacity() throws InstanceNotFoundException {
-
- /* Three workers. */
- Worker worker1 = new Worker("worker-1", "worker-1-surname",
- "11111111A", 8);
- Worker worker2 = new Worker("worker-2", "worker-2-surname",
- "22222222B", 7);
- Worker worker3 = new Worker("worker-3", "worker-3-surname",
- "33333333C", 6);
-
- /* A group of two workers. */
- ResourceGroup resourceGroup1 = new ResourceGroup();
- Worker worker4 = new Worker("worker-4", "worker-4-surname",
- "44444444D", 5);
- Worker worker5 = new Worker("worker-5", "worker-5-surname",
- "55555555E", 4);
- resourceGroup1.addResource(worker4);
- resourceGroup1.addResource(worker5);
-
- /*
- * A complex group containing the first three workers and a group with
- * the last two workers.
- */
- ResourceGroup resourceGroup2 = new ResourceGroup();
- resourceGroup2.addResource(worker1);
- resourceGroup2.addResource(worker2);
- resourceGroup2.addResource(worker3);
- resourceGroup2.addResource(resourceGroup1);
-
- /* Calculate total daily capacity. */
- int totalDailyCapacity = worker1.getDailyCapacity()
- + worker2.getDailyCapacity() + worker3.getDailyCapacity()
- + worker4.getDailyCapacity() + worker5.getDailyCapacity();
-
- /* Save the second group (and in consequence all resources). */
- resourceService.saveResource(resourceGroup2);
-
- /* Test ResourceService's getResourceDailyCapacity. */
- int resourceGroupDailyCapacity = resourceService
- .getResourceDailyCapacity(resourceGroup2.getId());
-
- assertEquals(totalDailyCapacity, resourceGroupDailyCapacity);
-
- }
-
@Test
public void testRemoveResource() throws InstanceNotFoundException {
/* A group of three workers. */
- ResourceGroup resourceGroup = new ResourceGroup();
Worker worker1 = new Worker("worker-1", "worker-2-surname",
"11111111A", 8);
Worker worker2 = new Worker("worker-2", "worker-3-surname",
"22222222B", 6);
Worker worker3 = new Worker("worker-3", "worker-3-surname",
"33333333C", 4);
- resourceGroup.addResource(worker1);
- resourceGroup.addResource(worker2);
- resourceGroup.addResource(worker3);
- resourceService.saveResource(resourceGroup);
+ resourceService.saveResource(worker1);
+ resourceService.saveResource(worker2);
+ resourceService.saveResource(worker3);
- /* Remove worker 3. */
resourceService.removeResource(worker3.getId());
- /* Check worker 3 does not exist. */
assertFalse(resourceDao.exists(worker3.getId()));
-
- /*
- * Check worker 3 is not in resource group and the other workers are
- * still in the group.
- */
- assertFalse(resourceGroup.getResources().contains(worker3));
- assertTrue(resourceGroup.getResources().contains(worker1));
- assertTrue(resourceGroup.getResources().contains(worker2));
-
- /* Remove the group. */
- resourceService.removeResource(resourceGroup.getId());
-
- /* Check the resource group does not exist. */
- assertFalse(resourceDao.exists(resourceGroup.getId()));
-
- /* Check workers still exist. */
- assertTrue(resourceDao.exists(worker1.getId()));
assertTrue(resourceDao.exists(worker2.getId()));
-
- /* Check workers do not belong to any resource group. */
- assertNull(worker1.getResourceGroup());
- assertNull(worker2.getResourceGroup());
-
- /* Remove workers. */
- resourceService.removeResource(worker1.getId());
- resourceService.removeResource(worker2.getId());
-
- /* Check workers do not exist. */
- assertFalse(resourceDao.exists(worker1.getId()));
- assertFalse(resourceDao.exists(worker2.getId()));
-
}
@Test
public void testListWorkers() throws Exception {
final int previousWorkers = resourceService.getWorkers().size();
- ResourceGroup resourceGroup = new ResourceGroup();
Worker worker1 = new Worker("worker-1", "worker-2-surname",
"11111111A", 8);
Worker worker2 = new Worker("worker-2", "worker-3-surname",
"22222222B", 6);
- Worker worker3 = new Worker("worker-3", "worker-3-surname",
+ Resource worker3 = new Worker("worker-3", "worker-3-surname",
"33333333C", 4);
- resourceGroup.addResource(worker1);
- resourceGroup.addResource(worker2);
- resourceService.saveResource(resourceGroup);
- assertEquals(
- "Two workers has been created when saving the resource group",
- previousWorkers + 2, resourceService.getWorkers().size());
+ resourceService.saveResource(worker1);
+ resourceService.saveResource(worker2);
+ assertEquals("Two workers have been created", previousWorkers + 2,
+ resourceService.getWorkers().size());
resourceService.saveResource(worker3);
assertEquals("Three workers has been created", previousWorkers + 3,
resourceService.getWorkers().size());