[Bug #645] Add resource type property to GenericResourceAllocation

FEA: ItEr60S04ValidacionEProbasFuncionaisItEr59S04
This commit is contained in:
Óscar González Fernández 2010-09-20 00:40:43 +02:00
parent a5bfbac403
commit e53b263bff
2 changed files with 31 additions and 0 deletions

View file

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.Valid;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.AvailabilityTimeLine;
@ -45,6 +46,7 @@ import org.navalplanner.business.resources.entities.Criterion;
import org.navalplanner.business.resources.entities.CriterionCompounder;
import org.navalplanner.business.resources.entities.ICriterion;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.ResourceEnum;
import org.navalplanner.business.scenarios.entities.Scenario;
import org.navalplanner.business.util.deepcopy.OnCopy;
import org.navalplanner.business.util.deepcopy.Strategy;
@ -106,6 +108,9 @@ public class GenericResourceAllocation extends
@OnCopy(Strategy.SHARE_COLLECTION_ELEMENTS)
private Set<Criterion> criterions = new HashSet<Criterion>();
@OnCopy(Strategy.SHARE)
private ResourceEnum resourceType;
private Set<GenericDayAssignmentsContainer> genericDayAssignmentsContainers = new HashSet<GenericDayAssignmentsContainer>();
@Valid
@ -135,8 +140,24 @@ public class GenericResourceAllocation extends
public static GenericResourceAllocation create(Task task,
Collection<? extends Criterion> criterions) {
return create(task, inferType(criterions), criterions);
}
public static ResourceEnum inferType(
Collection<? extends Criterion> criterions) {
if (criterions.isEmpty()) {
return ResourceEnum.WORKER;
}
Criterion first = criterions.iterator().next();
return first.getType().getResource();
}
public static GenericResourceAllocation create(Task task,
ResourceEnum resourceType, Collection<? extends Criterion> criterions) {
Validate.notNull(resourceType);
GenericResourceAllocation result = new GenericResourceAllocation(task);
result.criterions = new HashSet<Criterion>(criterions);
result.resourceType = resourceType;
result.setResourcesPerDayToAmount(1);
return create(result);
}
@ -571,4 +592,8 @@ public class GenericResourceAllocation extends
}
}
public ResourceEnum getResourceType() {
return resourceType != null ? resourceType : inferType(criterions);
}
}

View file

@ -59,6 +59,12 @@
<many-to-many class="org.navalplanner.business.resources.entities.Criterion" column="criterion_id"/>
</set>
<property name="resourceType">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.navalplanner.business.resources.entities.ResourceEnum</param>
</type>
</property>
<set name="genericDayAssignmentsContainers" cascade="all-delete-orphan">
<key column="RESOURCE_ALLOCATION_ID" />
<one-to-many class="GenericDayAssignmentsContainer"/>