ItEr58S10CUAsignacionRecursosLimitantesItEr57S11: Fix bug consider earlierStartDateBecauseOfGantt on assigning a limiting resource queue element

This commit is contained in:
Diego Pino Garcia 2010-05-12 11:48:38 +02:00 committed by Javier Moran Rua
parent 3498909756
commit 46ed8f5ea5
5 changed files with 75 additions and 29 deletions

View file

@ -39,11 +39,15 @@ public class DateAndHour implements Comparable<DateAndHour> {
private int compareHour(int hour) {
int deltaHour = this.hour - hour;
return (deltaHour != 0) ? Math.abs(deltaHour) : 0;
return (deltaHour != 0) ? deltaHour / Math.abs(deltaHour) : 0;
}
public String toString() {
return date + "; " + hour;
}
public static DateAndHour Max(DateAndHour arg0, DateAndHour arg1) {
return (arg0.compareTo(arg1) > 0) ? arg0 : arg1;
}
}

View file

@ -35,10 +35,6 @@ public class LimitingResourceQueueElementGap {
- startHour;
int hoursInBetween = calendar.getWorkableHours(startDate
.plusDays(1), endDate.minusDays(1));
if (hoursAtStart <= 0) {
startDate = startDate.plusDays(1);
startHour = 0;
}
hoursInGap = hoursAtStart + hoursInBetween + endHour;
}
@ -61,13 +57,26 @@ public class LimitingResourceQueueElementGap {
}
/**
* Returns true if hours for this gap is big enough for fitting hours
* Returns true if the gap starts after earlierStartDateBecauseOfGantt and
* if it's big enough for fitting candidate
*
* @param hours
* @return
*/
public boolean canFit(Integer hours) {
return hoursInGap.compareTo(hours) >= 0;
public boolean canFit(LimitingResourceQueueElement candidate) {
final LocalDate earlierStartDateBecauseOfGantt = new LocalDate(
candidate.getEarlierStartDateBecauseOfGantt());
final LocalDate startDate = startTime.getDate();
if (earlierStartDateBecauseOfGantt.isBefore(startDate)
|| earlierStartDateBecauseOfGantt.isEqual(startDate)) {
return hoursInGap - candidate.getIntentedTotalHours() >= 0;
}
return false;
}
public String toString() {
return startTime.getDate() + " - " + startTime.getHour() + "; "
+ endTime.getDate() + " - " + endTime.getHour();
}
}

View file

@ -347,22 +347,27 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel {
final SortedSet<LimitingResourceQueueElement> elements = queue.getLimitingResourceQueueElements();
if (!elements.isEmpty()) {
final List<LimitingResourceQueueElementGap> gapList = buildGapList(candidate, elements);
final DateAndHour startTime = findStartTimeInGapList(candidate
.getIntentedTotalHours(), gapList);
return (startTime != null) ? startTime : afterLastElement(elements);
final DateAndHour startTime = findStartTimeInGapList(candidate, gapList);
return (startTime != null) ? startTime : afterLastElement(candidate, elements);
}
return new DateAndHour(new LocalDate(candidate.getEarlierStartDateBecauseOfGantt()), 0);
return getStartTimeBecauseOfGantt(candidate);
}
private DateAndHour afterLastElement(
private DateAndHour afterLastElement(LimitingResourceQueueElement candidate,
SortedSet<LimitingResourceQueueElement> elements) {
return elements.last().getEndTime();
final DateAndHour lastElementEndTime = elements.last().getEndTime();
final DateAndHour candidateStartTime = getStartTimeBecauseOfGantt(candidate);
return DateAndHour.Max(lastElementEndTime, candidateStartTime);
}
private DateAndHour findStartTimeInGapList(Integer hours,
private DateAndHour getStartTimeBecauseOfGantt(LimitingResourceQueueElement element) {
return new DateAndHour(new LocalDate(element.getEarlierStartDateBecauseOfGantt()), 0);
}
private DateAndHour findStartTimeInGapList(LimitingResourceQueueElement candidate,
List<LimitingResourceQueueElementGap> gapList) {
for (LimitingResourceQueueElementGap each : gapList) {
if (each.canFit(hours)) {
if (each.canFit(candidate)) {
return each.getStartTime();
}
}
@ -376,25 +381,33 @@ public class LimitingResourceQueueModel implements ILimitingResourceQueueModel {
// If start time of candidate element to fit in queue is before first
// element, create a gap between candidate and the first element of the
// queue
DateAndHour candidateTime = new DateAndHour(new LocalDate(candidate
.getEarlierStartDateBecauseOfGantt()), 0);
DateAndHour startTimeBecauseOfGantt = getStartTimeBecauseOfGantt(candidate);
final LimitingResourceQueueElement firstElement = elements.first();
if (candidateTime.compareTo(firstElement.getStartTime()) <= 0) {
result.add(createGap(firstElement.getResource(), candidateTime,
if (startTimeBecauseOfGantt.compareTo(firstElement.getStartTime()) < 0) {
result.add(createGap(firstElement.getResource(), startTimeBecauseOfGantt,
firstElement.getStartTime()));
}
LimitingResourceQueueElement current, next;
// Only include gaps from candidate start time on
for (Iterator<LimitingResourceQueueElement> i = elements.iterator(); i
.hasNext();) {
LimitingResourceQueueElement current = i.next();
current = i.next();
if (i.hasNext()) {
LimitingResourceQueueElement next = i.next();
if (candidateTime.compareTo(current.getEndTime()) > 1) {
final DateAndHour startTime = current.getEndTime();
final DateAndHour endTime = next.getStartTime();
result.add(createGap(current.getResource(), startTime, endTime));
next = i.next();
DateAndHour startTime = current.getEndTime();
final DateAndHour endTime = next.getStartTime();
if (startTime.compareTo(startTimeBecauseOfGantt) <= 0) {
if (endTime.compareTo(startTimeBecauseOfGantt) <= 0) {
// Start and end of the gap are before earlierStartDateBecauseOfGanttTime
continue;
}
// earliestStartDateBecauseOfGantt is in between
startTime = startTimeBecauseOfGantt;
}
result.add(createGap(current.getResource(), startTime, endTime));
}
}
return result;

View file

@ -34,6 +34,7 @@ import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.planner.entities.GenericResourceAllocation;
import org.navalplanner.business.planner.entities.LimitingResourceQueueElement;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.web.common.Util;
import org.navalplanner.web.limitingresources.LimitingResourcesPanel.IToolbarCommand;
import org.navalplanner.web.planner.order.BankHolidaysMarker;
@ -189,12 +190,12 @@ public class LimitingResourcesController implements Composer {
List<LimitingResourceQueueElementDTO> result = new ArrayList<LimitingResourceQueueElementDTO>();
for (LimitingResourceQueueElement each : limitingResourceQueueModel
.getUnassignedLimitingResourceQueueElements()) {
result.add(toUnassignedLimitingResourceQueueElementDTO(each));
result.add(toLimitingResourceQueueElementDTO(each));
}
return result;
}
private LimitingResourceQueueElementDTO toUnassignedLimitingResourceQueueElementDTO(
private LimitingResourceQueueElementDTO toLimitingResourceQueueElementDTO(
LimitingResourceQueueElement element) {
final Task task = element.getResourceAllocation().getTask();
final Order order = limitingResourceQueueModel.getOrderByTask(task);
@ -221,6 +222,10 @@ public class LimitingResourcesController implements Composer {
private String date;
private Integer hoursToAllocate;
private String resourceName;
public LimitingResourceQueueElementDTO(
LimitingResourceQueueElement element, String orderName,
String taskName, Date date) {
@ -228,6 +233,9 @@ public class LimitingResourcesController implements Composer {
this.orderName = orderName;
this.taskName = taskName;
this.date = DATE_FORMAT.format(date);
this.hoursToAllocate = element.getIntentedTotalHours();
final Resource resource = element.getResource();
this.resourceName = (resource != null) ? resource.getName() : "";
}
public LimitingResourceQueueElement getOriginal() {
@ -246,6 +254,14 @@ public class LimitingResourcesController implements Composer {
return date;
}
public Integer getHoursToAllocate() {
return (hoursToAllocate != null) ? hoursToAllocate : 0;
}
public String getResourceName() {
return resourceName;
}
}
public void filterBy(Order order) {
@ -278,7 +294,9 @@ public class LimitingResourcesController implements Composer {
row.appendChild(label(element.getTaskName()));
row.appendChild(label(element.getOrderName()));
row.appendChild(label(element.getResourceName()));
row.appendChild(label(element.getDate()));
row.appendChild(label(element.getHoursToAllocate().toString()));
row.appendChild(assignButton(element));
row.appendChild(automaticQueueing(element));
}

View file

@ -114,8 +114,10 @@ resourcesLoadPanel = self;
style="margin: 10px" >
<columns sizable="true">
<column label="${i18n:_('Order')}" sort="auto(orderName)"/>
<column label="${i18n:_('Task name')}" sort="auto(taskName)"/>
<column label="${i18n:_('Task')}" sort="auto(taskName)"/>
<column label="${i18n:_('Resource')}" sort="auto(resourceName)"/>
<column label="${i18n:_('Date')}" sort="auto(date)"/>
<column label="${i18n:_('Hours to allocate')}" sort="auto(hoursToAllocate)"/>
<column label="${i18n:_('Operations')}" width="100px"/>
<column label="${i18n:_('Auto queueing')}" width="100px" />
</columns>