ItEr29S06CUAsignacionGrupoRecursosAPlanificacionItEr28S06: Adding methods to merge new allocation into existing task
This commit is contained in:
parent
e702da4f3d
commit
4ce7e58bad
4 changed files with 71 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.calendars.entities.IWorkHours;
|
||||
import org.navalplanner.business.calendars.entities.SameWorkHoursEveryDay;
|
||||
|
|
@ -217,4 +218,29 @@ public class GenericResourceAllocation extends
|
|||
day, hours));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeAssignmentsAndResourcesPerDay(ResourceAllocation<?> modifications) {
|
||||
Validate.isTrue(modifications instanceof GenericResourceAllocation);
|
||||
mergeAssignments((GenericResourceAllocation) modifications);
|
||||
setResourcesPerDay(modifications.getResourcesPerDay());
|
||||
}
|
||||
|
||||
private void mergeAssignments(GenericResourceAllocation modifications) {
|
||||
Set<GenericDayAssignment> previous = modifications.genericDayAssignments;
|
||||
moveToThis(modifications.genericDayAssignments);
|
||||
clearFieldsCalculatedFromAssignments();
|
||||
detach(previous);
|
||||
}
|
||||
|
||||
private void detach(Set<GenericDayAssignment> previous) {
|
||||
for (GenericDayAssignment genericDayAssignment : previous) {
|
||||
genericDayAssignment.detach();
|
||||
}
|
||||
}
|
||||
|
||||
private void moveToThis(Set<GenericDayAssignment> assignemnts) {
|
||||
this.genericDayAssignments = GenericDayAssignment.copy(this,
|
||||
assignemnts);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -432,4 +432,6 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
return sum;
|
||||
}
|
||||
|
||||
public abstract void mergeAssignmentsAndResourcesPerDay(ResourceAllocation<?> modifications);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,4 +143,24 @@ public class SpecificResourceAllocation extends
|
|||
result.add(specific);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeAssignmentsAndResourcesPerDay(ResourceAllocation<?> modifications) {
|
||||
Validate.isTrue(modifications instanceof SpecificResourceAllocation);
|
||||
mergeAssignments((SpecificResourceAllocation) modifications);
|
||||
setResourcesPerDay(modifications.getResourcesPerDay());
|
||||
}
|
||||
|
||||
private void mergeAssignments(SpecificResourceAllocation modifications) {
|
||||
Set<SpecificDayAssignment> previous = this.specificDaysAssignment;
|
||||
this.specificDaysAssignment = SpecificDayAssignment.copy(this,
|
||||
modifications.specificDaysAssignment);
|
||||
detach(previous);
|
||||
}
|
||||
|
||||
private void detach(Set<SpecificDayAssignment> previous) {
|
||||
for (SpecificDayAssignment p : previous) {
|
||||
p.detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.NotNull;
|
||||
|
|
@ -222,4 +224,25 @@ public class Task extends TaskElement {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void mergeAllocation(CalculatedValue calculatedValue,
|
||||
Integer daysDuration, List<ResourceAllocation<?>> newAllocations,
|
||||
Map<ResourceAllocation<?>, ResourceAllocation<?>> modified) {
|
||||
this.calculatedValue = calculatedValue;
|
||||
setDaysDuration(daysDuration);
|
||||
addAllocations(newAllocations);
|
||||
for (Entry<ResourceAllocation<?>, ResourceAllocation<?>> entry : modified
|
||||
.entrySet()) {
|
||||
ResourceAllocation<?> existent = entry.getValue();
|
||||
Validate.isTrue(resourceAllocations.contains(existent));
|
||||
ResourceAllocation<?> modifications = entry.getKey();
|
||||
existent.mergeAssignmentsAndResourcesPerDay(modifications);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAllocations(List<ResourceAllocation<?>> newAllocations) {
|
||||
for (ResourceAllocation<?> resourceAllocation : newAllocations) {
|
||||
addResourceAllocation(resourceAllocation);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue