[Bug #975] Set last stretch with 100% completition as read-only
This stretch is never added to the list of stretches, that means, it won't be saved. On the contrary, is inferred from the endDate of the task. FEA: ItEr74S04BugFixing
This commit is contained in:
parent
efa5cafb82
commit
da9fe42415
5 changed files with 47 additions and 31 deletions
|
|
@ -80,7 +80,13 @@ public class Stretch {
|
|||
}
|
||||
|
||||
public static Stretch copy(Stretch stretch) {
|
||||
return create(stretch.date, stretch.lengthPercentage, stretch.amountWorkPercentage);
|
||||
Stretch result = new Stretch();
|
||||
result.date = stretch.date;
|
||||
result.lengthPercentage = stretch.lengthPercentage;
|
||||
result.amountWorkPercentage = stretch.amountWorkPercentage;
|
||||
result.consolidated = stretch.consolidated;
|
||||
result.readOnly = stretch.readOnly;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Stretch buildFromConsolidatedProgress(ResourceAllocation<? extends DayAssignment> resourceAllocation) {
|
||||
|
|
@ -172,7 +178,7 @@ public class Stretch {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("(%s, %s, %s) ", date, lengthPercentage, amountWorkPercentage);
|
||||
return String.format("(%s, %s, %s, readOnly: %s) ", date, lengthPercentage, amountWorkPercentage, readOnly);
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
|
|
|
|||
|
|
@ -207,6 +207,9 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
// Transient. Calculated from resourceAllocation
|
||||
private Stretch consolidatedStretch;
|
||||
|
||||
// Transient. Used to calculate read-only last stretch
|
||||
private LocalDate taskEndDate;
|
||||
|
||||
public static StretchesFunction create() {
|
||||
return (StretchesFunction) create(new StretchesFunction());
|
||||
}
|
||||
|
|
@ -249,34 +252,35 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
result.type = type;
|
||||
result.desiredType = desiredType;
|
||||
result.consolidatedStretch = consolidatedStretch;
|
||||
result.taskEndDate = taskEndDate;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void resetToStrechesFrom(StretchesFunction from) {
|
||||
this.removeAllStretches();
|
||||
for (Stretch each : from.getStretches()) {
|
||||
for (Stretch each : from.getStretchesDefinedByUser()) {
|
||||
this.addStretch(Stretch.copy(each));
|
||||
}
|
||||
this.consolidatedStretch = from.consolidatedStretch;
|
||||
}
|
||||
|
||||
public void setStretches(List<Stretch> stretches) {
|
||||
this.stretches = stretches;
|
||||
}
|
||||
|
||||
private void sortStretches() {
|
||||
Collections.sort(stretches, new Comparator<Stretch>() {
|
||||
@Override
|
||||
public int compare(Stretch o1, Stretch o2) {
|
||||
return o1.getDate().compareTo(o2.getDate());
|
||||
}
|
||||
});
|
||||
public List<Stretch> getStretchesDefinedByUser() {
|
||||
return Collections.unmodifiableList(Stretch.sortByDate(stretches));
|
||||
}
|
||||
|
||||
@Valid
|
||||
public List<Stretch> getStretches() {
|
||||
sortStretches();
|
||||
return Collections.unmodifiableList(stretches);
|
||||
List<Stretch> result = new ArrayList<Stretch>(stretches);
|
||||
if (taskEndDate != null) {
|
||||
result.add(getLastStretch());
|
||||
}
|
||||
return Collections.unmodifiableList(Stretch.sortByDate(result));
|
||||
}
|
||||
|
||||
private Stretch getLastStretch() {
|
||||
Stretch result = Stretch.create(taskEndDate, BigDecimal.ONE, BigDecimal.ONE);
|
||||
result.readOnly(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public StretchesFunctionTypeEnum getType() {
|
||||
|
|
@ -338,7 +342,7 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
|
||||
public List<Stretch> getStretchesPlusConsolidated() {
|
||||
List<Stretch> result = new ArrayList<Stretch>();
|
||||
result.addAll(stretches);
|
||||
result.addAll(getStretches());
|
||||
if (consolidatedStretch != null) {
|
||||
result.add(consolidatedStretch);
|
||||
}
|
||||
|
|
@ -348,11 +352,10 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
@AssertTrue(message = "Last stretch should have one hundred percent for "
|
||||
+ "length and amount of work percentage")
|
||||
public boolean checkOneHundredPercent() {
|
||||
List<Stretch> stretches = getStretchesPlusConsolidated();
|
||||
if (stretches.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
sortStretches();
|
||||
|
||||
Stretch lastStretch = stretches.get(stretches.size() - 1);
|
||||
if (lastStretch.getLengthPercentage().compareTo(BigDecimal.ONE) != 0) {
|
||||
return false;
|
||||
|
|
@ -360,7 +363,6 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
if (lastStretch.getAmountWorkPercentage().compareTo(BigDecimal.ONE) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -373,10 +375,15 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
if (resourceAllocation.getFirstNonConsolidatedDate() == null) {
|
||||
return;
|
||||
}
|
||||
taskEndDate = getTaskEndDate(resourceAllocation);
|
||||
getDesiredType().applyTo(resourceAllocation, this);
|
||||
type = getDesiredType();
|
||||
}
|
||||
|
||||
private LocalDate getTaskEndDate(ResourceAllocation<?> resourceAllocation) {
|
||||
return resourceAllocation.getTask().getEndAsLocalDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (StretchesFunctionTypeEnum.INTERPOLATED.equals(type)) {
|
||||
|
|
@ -401,6 +408,7 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
}
|
||||
|
||||
private void checkStretchesSumOneHundredPercent() {
|
||||
List<Stretch> stretches = getStretchesPlusConsolidated();
|
||||
BigDecimal sumOfProportions = stretches.isEmpty() ? BigDecimal.ZERO
|
||||
: last(stretches).getAmountWorkPercentage();
|
||||
BigDecimal left = calculateLeftFor(sumOfProportions);
|
||||
|
|
@ -441,4 +449,8 @@ public class StretchesFunction extends AssignmentFunction {
|
|||
return consolidatedStretch;
|
||||
}
|
||||
|
||||
public void setTaskEndDate(LocalDate taskEndDate) {
|
||||
this.taskEndDate = taskEndDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,4 +58,11 @@
|
|||
<modifyDataType tableName="criterion_satisfaction" columnName="finish_date" newDataType="DATE"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="remove-stretches-with-amountWorkPercentage-equal-100" author="dpino">
|
||||
<comment>Removes all stretches which amountWorkPercentage value is 100 as now these stretches will be created automatically and never stored into DB</comment>
|
||||
<sql>
|
||||
DELETE FROM stretches WHERE amount_work_percentage = 1.00;
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
|
|
|||
|
|
@ -94,10 +94,7 @@ public abstract class StrechesFunctionConfiguration implements
|
|||
|
||||
@Override
|
||||
public void applyOn(ResourceAllocation<?> resourceAllocation) {
|
||||
StretchesFunction stretchesFunction = StretchesFunctionModel
|
||||
.createDefaultStretchesFunction(resourceAllocation.getTask()
|
||||
.getEndAsLocalDate());
|
||||
resourceAllocation.setAssignmentFunction(stretchesFunction);
|
||||
resourceAllocation.setAssignmentFunction(StretchesFunction.create());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,13 +63,6 @@ import org.zkoss.util.Locales;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class StretchesFunctionModel implements IStretchesFunctionModel {
|
||||
|
||||
public static StretchesFunction createDefaultStretchesFunction(LocalDate endDate) {
|
||||
StretchesFunction stretchesFunction = StretchesFunction.create();
|
||||
stretchesFunction.addStretch(Stretch.create(endDate, BigDecimal.ONE,
|
||||
BigDecimal.ONE));
|
||||
return stretchesFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversation state
|
||||
*/
|
||||
|
|
@ -108,6 +101,7 @@ public class StretchesFunctionModel implements IStretchesFunctionModel {
|
|||
this.taskEndDate = task.getEndDate();
|
||||
|
||||
// Initialize stretchesFunction
|
||||
stretchesFunction.setTaskEndDate(task.getEndAsLocalDate());
|
||||
this.originalStretchesFunction = stretchesFunction;
|
||||
this.stretchesFunction = stretchesFunction.copy();
|
||||
this.stretchesFunction.changeTypeTo(type);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue