ItEr25S07CUAsignacionGrupoRecursosAPlanificacionItEr24S08: DayAssignment now stores a day, the number of hours and the resource it's applied to
This commit is contained in:
parent
8c4aad0133
commit
d23a8f6a2b
5 changed files with 71 additions and 31 deletions
|
|
@ -1,40 +1,46 @@
|
|||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.Min;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
public abstract class DayAssigment extends BaseEntity {
|
||||
|
||||
@Min(0)
|
||||
private int hours;
|
||||
|
||||
private Set<Worker> workers = new HashSet<Worker>();
|
||||
@NotNull
|
||||
private LocalDate day;
|
||||
|
||||
@NotNull
|
||||
private Resource resource;
|
||||
|
||||
protected DayAssigment() {
|
||||
|
||||
}
|
||||
|
||||
protected DayAssigment(int hours, Set<Worker> workers) {
|
||||
protected DayAssigment(LocalDate day, int hours, Resource resource) {
|
||||
Validate.notNull(day);
|
||||
Validate.isTrue(hours >= 0);
|
||||
Validate.notNull(resource);
|
||||
this.day = day;
|
||||
this.hours = hours;
|
||||
this.workers = workers;
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public int getHours() {
|
||||
return hours;
|
||||
}
|
||||
|
||||
public void setHours(int hours) {
|
||||
this.hours = hours;
|
||||
public Resource getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public Set<Worker> getWorkers() {
|
||||
return workers;
|
||||
}
|
||||
|
||||
public void setWorkers(Set<Worker> workers) {
|
||||
this.workers = workers;
|
||||
public LocalDate getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package org.navalplanner.business.planner.entities;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -16,11 +18,20 @@ public class GenericDayAssigment extends DayAssigment {
|
|||
|
||||
private Set<Criterion> criterions = new HashSet<Criterion>();
|
||||
|
||||
public static GenericDayAssigment create() {
|
||||
return (GenericDayAssigment) create(new GenericDayAssigment());
|
||||
public static GenericDayAssigment create(LocalDate day, int hours,
|
||||
Resource resource) {
|
||||
return (GenericDayAssigment) create(new GenericDayAssigment(day, hours,
|
||||
resource));
|
||||
}
|
||||
|
||||
protected GenericDayAssigment() {
|
||||
private GenericDayAssigment(LocalDate day, int hours, Resource resource) {
|
||||
super(day, hours, resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for hibernate. DO NOT USE!
|
||||
*/
|
||||
public GenericDayAssigment() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -10,11 +13,20 @@ public class SpecificDayAssigment extends DayAssigment {
|
|||
|
||||
private SpecificResourceAllocation specificResourceAllocation;
|
||||
|
||||
public static SpecificDayAssigment create() {
|
||||
return (SpecificDayAssigment) create(new SpecificDayAssigment());
|
||||
public static SpecificDayAssigment create(LocalDate day, int hours,
|
||||
Resource resource) {
|
||||
return (SpecificDayAssigment) create(new SpecificDayAssigment(day,
|
||||
hours, resource));
|
||||
}
|
||||
|
||||
protected SpecificDayAssigment() {
|
||||
public SpecificDayAssigment(LocalDate day, int hours, Resource resource) {
|
||||
super(day, hours, resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for hibernate. DO NOT USE!
|
||||
*/
|
||||
public SpecificDayAssigment() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,13 @@
|
|||
|
||||
<version name="version" access="property" type="long" />
|
||||
|
||||
<property name="hours"/>
|
||||
<property name="hours" not-null="true"/>
|
||||
|
||||
<set name="workers" inverse="false">
|
||||
<key column="DAY_ASSIGMENT_ID"/>
|
||||
<one-to-many class="org.navalplanner.business.resources.entities.Worker"/>
|
||||
</set>
|
||||
<property name="day" type="org.joda.time.contrib.hibernate.PersistentLocalDate" not-null="true"/>
|
||||
|
||||
<many-to-one name="resource" class="org.navalplanner.business.resources.entities.Resource"
|
||||
column="RESOURCE_ID" not-null="true">
|
||||
</many-to-one>
|
||||
|
||||
<!-- SpecificDayAssigment -->
|
||||
<subclass name="SpecificDayAssigment" discriminator-value="SPECIFIC_DAY">
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import static org.navalplanner.business.test.BusinessGlobalNames.BUSINESS_SPRING
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
|
|
@ -16,6 +17,8 @@ import org.navalplanner.business.planner.entities.DayAssigment;
|
|||
import org.navalplanner.business.planner.entities.GenericDayAssigment;
|
||||
import org.navalplanner.business.planner.entities.SpecificDayAssigment;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
|
@ -24,7 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { BUSINESS_SPRING_CONFIG_FILE,
|
||||
BUSINESS_SPRING_CONFIG_TEST_FILE })
|
||||
/*
|
||||
/**
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
*/
|
||||
@Transactional
|
||||
|
|
@ -34,20 +37,27 @@ public class DayAssigmentDAOTest {
|
|||
private IDayAssigmentDAO dayAssigmentDAO;
|
||||
|
||||
@Autowired
|
||||
IResourceDAO resourceDAO;
|
||||
private IResourceDAO resourceDAO;
|
||||
|
||||
private SpecificDayAssigment createValidSpecificDayAssigment() {
|
||||
return SpecificDayAssigment.create();
|
||||
return SpecificDayAssigment.create(new LocalDate(2009, 1, 2), 8,
|
||||
createValidResource());
|
||||
}
|
||||
|
||||
private Resource createValidResource() {
|
||||
Worker worker = Worker.create("first", "surname", "1221332132A", 5);
|
||||
resourceDAO.save(worker);
|
||||
return worker;
|
||||
}
|
||||
|
||||
private GenericDayAssigment createValidGenericDayAssigment() {
|
||||
return GenericDayAssigment.create();
|
||||
return GenericDayAssigment.create(new LocalDate(2009, 1, 2), 8,
|
||||
createValidResource());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInSpringContainer() {
|
||||
assertTrue(dayAssigmentDAO != null);
|
||||
assertTrue(resourceDAO != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue