ItEr18S14CUAsignacionRecursosEspecificosAPlanificacion: Created business entities ResourceAllocation and SpecificResourceAllocation. Made relations with Task and Worker.

Javier Moran Rua <jmoran@igalia.com>: The commit has been ammended adding the ResourceAllocation entity to the
 navalplanner-business-spring-config-test.xml configuration file.
This commit is contained in:
Manuel Rego Casasnovas 2009-07-24 13:45:01 +02:00 committed by Javier Moran Rua
parent f73c6a1d9c
commit 5861e44f1a
7 changed files with 167 additions and 0 deletions

View file

@ -0,0 +1,74 @@
/**
*
*/
package org.navalplanner.business.planner.entities;
import java.math.BigDecimal;
import org.hibernate.validator.NotNull;
/**
* Resources are allocated to planner tasks.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public abstract class ResourceAllocation {
private Long id;
private Long version;
@NotNull
private Task task;
/**
* Allocation percentage of the resource.
*
* It's one based, instead of one hundred based.
*/
private BigDecimal percentage = new BigDecimal(0).setScale(2);
/**
* For hibernate, DO NOT USE
*/
public ResourceAllocation() {
}
public ResourceAllocation(Task task) {
this.task = task;
}
public Long getId() {
return id;
}
public Long getVersion() {
return version;
}
public Task getTask() {
return task;
}
public BigDecimal getPercentage() {
return percentage;
}
/**
* @param proportion
* It's one based, instead of one hundred based.
*/
public void setPercentage(BigDecimal proportion) {
this.percentage = proportion;
}
public boolean isTransient() {
return id == null;
}
public void makeTransientAgain() {
id = null;
version = null;
}
}

View file

@ -0,0 +1,40 @@
package org.navalplanner.business.planner.entities;
import org.hibernate.validator.NotNull;
import org.navalplanner.business.resources.entities.Worker;
/**
* Represents the relation between {@link Task} and a specific {@link Worker}.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class SpecificResourceAllocation extends ResourceAllocation {
@NotNull
private Worker worker;
/**
* For hibernate, DO NOT USE
*/
public SpecificResourceAllocation() {
}
public SpecificResourceAllocation(Task task) {
super(task);
}
public Worker getWorker() {
return worker;
}
public void setWorker(Worker worker) {
this.worker = worker;
}
public void forceLoadWorker() {
if (worker != null) {
worker.getId();
}
}
}

View file

@ -1,6 +1,9 @@
package org.navalplanner.business.planner.entities;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.NotNull;
@ -18,6 +21,8 @@ public class Task extends TaskElement {
@NotNull
private HoursGroup hoursGroup;
private Set<ResourceAllocation> resourceAllocations = new HashSet<ResourceAllocation>();
/**
* For hibernate, DO NOT USE
*/
@ -48,4 +53,20 @@ public class Task extends TaskElement {
throw new UnsupportedOperationException();
}
public Set<ResourceAllocation> getResourceAllocations() {
return Collections.unmodifiableSet(resourceAllocations);
}
public void addResourceAllocation(ResourceAllocation resourceAllocation) {
resourceAllocations.add(resourceAllocation);
}
public void removeResourceAllocation(ResourceAllocation resourceAllocation) {
resourceAllocations.remove(resourceAllocation);
}
public void forceLoadResourceAllocations() {
resourceAllocations.size();
}
}

View file

@ -29,6 +29,9 @@
<value>
org/navalplanner/business/planner/entities/Tasks.hbm.xml
</value>
<value>
org/navalplanner/business/planner/entities/ResourceAllocations.hbm.xml
</value>
<value>
org/navalplanner/business/workreports/entities/WorkReports.hbm.xml
</value>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.navalplanner.business.planner.entities"
default-access="field">
<class name="ResourceAllocation">
<id name="id" column="id" type="long">
<generator class="native" />
</id>
<version name="version" type="long" />
<property name="percentage" />
<many-to-one class="Task" name="task" column="TASK" not-null="true" />
<joined-subclass name="SpecificResourceAllocation">
<key column="RESOURCE_ALLOCATION_ID" />
<many-to-one name="worker"
class="org.navalplanner.business.resources.entities.Worker" />
</joined-subclass>
</class>
</hibernate-mapping>

View file

@ -27,6 +27,10 @@
<joined-subclass name="Task">
<key column="TASK_ELEMENT_ID"></key>
<many-to-one name="hoursGroup" cascade="none"/>
<set name="resourceAllocations" cascade="all">
<key column="TASK" />
<one-to-many class="ResourceAllocation" />
</set>
</joined-subclass>
<joined-subclass name="TaskGroup">

View file

@ -42,6 +42,9 @@
</value>
<value>
org/navalplanner/business/workreports/entities/WorkReports.hbm.xml
</value>
<value>
org/navalplanner/business/planner/entities/ResourceAllocations.hbm.xml
</value>
<value>
TestEntities.hbm.xml