ValidacionEProbasFuncionaisItEr48S04 : [Bug #362] Adds constraint to the value of the advance measurements.
The value must be greater than the value of the previous advance measurements. If the values are not valid are displayed error messages.
This commit is contained in:
parent
8f41cd5836
commit
50b7268f65
6 changed files with 209 additions and 48 deletions
|
|
@ -24,6 +24,7 @@ import java.math.BigDecimal;
|
|||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.BaseEntity;
|
||||
|
|
@ -134,4 +135,34 @@ public class AdvanceMeasurement extends BaseEntity {
|
|||
communicationDate = null;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "The current value must be less than the max value.")
|
||||
public boolean checkConstraintValueIsLessThanMaxValue() {
|
||||
if ((this.value == null) || (this.advanceAssignment == null)){
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.advanceAssignment instanceof DirectAdvanceAssignment) {
|
||||
BigDecimal defaultMaxValue = ((DirectAdvanceAssignment) this.advanceAssignment)
|
||||
.getMaxValue();
|
||||
return (this.value.compareTo(defaultMaxValue) <= 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "The current value must be less than the max value.")
|
||||
public boolean checkConstraintValidPrecision() {
|
||||
if ((this.value == null) || (this.advanceAssignment == null)
|
||||
|| (this.advanceAssignment.getAdvanceType() == null)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
BigDecimal precision = this.advanceAssignment.getAdvanceType()
|
||||
.getUnitPrecision();
|
||||
BigDecimal result[] = value.divideAndRemainder(precision);
|
||||
BigDecimal zero = (BigDecimal.ZERO).setScale(4);
|
||||
if (result[1].compareTo(zero) == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.business.advance.entities;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Iterator;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
|
@ -79,7 +80,9 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
|
|||
|
||||
public void setMaxValue(BigDecimal maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
this.maxValue.setScale(2);
|
||||
if (maxValue != null) {
|
||||
this.maxValue.setScale(2);
|
||||
}
|
||||
}
|
||||
|
||||
public SortedSet<AdvanceMeasurement> getAdvanceMeasurements() {
|
||||
|
|
@ -150,6 +153,28 @@ public class DirectAdvanceAssignment extends AdvanceAssignment {
|
|||
return null;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "The previous advance measurements must have a value less than the value of the posterior advance measurements.")
|
||||
public boolean checkConstraintValidAdvanceMeasurements() {
|
||||
if (advanceMeasurements.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Iterator<AdvanceMeasurement> iterator = advanceMeasurements.iterator();
|
||||
AdvanceMeasurement currentAdvance = iterator.next();
|
||||
while (iterator.hasNext()) {
|
||||
AdvanceMeasurement nextAdvance = iterator.next();
|
||||
if ((currentAdvance.getValue() != null)
|
||||
&& (nextAdvance.getValue() != null)
|
||||
&& (currentAdvance.getDate() != null)
|
||||
&& (nextAdvance.getDate() != null)
|
||||
&& (currentAdvance.getValue().compareTo(
|
||||
nextAdvance.getValue()) < 0)) {
|
||||
return false;
|
||||
}
|
||||
currentAdvance = nextAdvance;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setFake(boolean fake) {
|
||||
this.fake = fake;
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ public interface IManageOrderElementAdvancesModel {
|
|||
|
||||
public void cleanAdvance();
|
||||
|
||||
public boolean isPrecisionValid(BigDecimal value);
|
||||
public boolean isPrecisionValid(AdvanceMeasurement advanceMeasurement);
|
||||
|
||||
public boolean greatThanMaxValue(BigDecimal value);
|
||||
public boolean greatThanMaxValue(AdvanceMeasurement advanceMeasurement);
|
||||
|
||||
public boolean isDistinctValidDate(Date value,
|
||||
AdvanceMeasurement newAdvanceMeasurement);
|
||||
|
|
@ -98,4 +98,5 @@ public interface IManageOrderElementAdvancesModel {
|
|||
|
||||
public boolean isQualityForm(AdvanceAssignment advance);
|
||||
|
||||
public boolean lessThanPreviousMeasurements();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
private Listbox editAdvances;
|
||||
|
||||
public void prepareEditAdvanceMeasurements(AdvanceAssignment advanceAssignment) {
|
||||
validateListAdvanceMeasurement();
|
||||
manageOrderElementAdvancesModel
|
||||
.prepareEditAdvanceMeasurements(advanceAssignment);
|
||||
this.indexSelectedItem = editAdvances.getIndexOfItem(editAdvances.getSelectedItem());
|
||||
|
|
@ -382,6 +383,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
Listcell listCell = new Listcell();
|
||||
listCell.appendChild(maxValue);
|
||||
listItem.appendChild(listCell);
|
||||
maxValue.setConstraint(checkMaxValue());
|
||||
}
|
||||
|
||||
private void appendDecimalBoxValue(final Listitem listItem){
|
||||
|
|
@ -562,6 +564,25 @@ public class ManageOrderElementAdvancesController extends
|
|||
}
|
||||
}
|
||||
|
||||
private Constraint checkMaxValue() {
|
||||
return new Constraint() {
|
||||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
Listitem item = (Listitem) comp.getParent().getParent();
|
||||
DirectAdvanceAssignment advance = (DirectAdvanceAssignment) item
|
||||
.getValue();
|
||||
if (value == null) {
|
||||
((Decimalbox) comp).setValue(advance.getMaxValue());
|
||||
((Decimalbox) comp).invalidate();
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("The max value must be not empty"));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setPercentage(){
|
||||
if ((this.indexSelectedItem < editAdvances.getItemCount())
|
||||
&& (this.indexSelectedItem >= 0)) {
|
||||
|
|
@ -586,6 +607,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
.getPercentageAdvanceMeasurement(
|
||||
greatAdvanceMeasurement).toString()
|
||||
+ " %");
|
||||
((Label) percentage.getFirstChild()).invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -609,6 +631,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
Listcell value = (Listcell)selectedItem.getChildren().get(2);
|
||||
((Decimalbox) value.getFirstChild())
|
||||
.setValue(greatAdvanceMeasurement.getValue());
|
||||
((Decimalbox) value.getFirstChild()).invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -691,7 +714,8 @@ public class ManageOrderElementAdvancesController extends
|
|||
AdvanceAssignment advance = (AdvanceAssignment) listItem
|
||||
.getValue();
|
||||
if (advance.getAdvanceType() == null) {
|
||||
return false;
|
||||
throw new WrongValueException(getComboboxTypeBy(listItem),
|
||||
_("Value is not valid, the type must be not empty"));
|
||||
}
|
||||
|
||||
DirectAdvanceAssignment directAdvanceAssignment;
|
||||
|
|
@ -703,7 +727,9 @@ public class ManageOrderElementAdvancesController extends
|
|||
}
|
||||
if (directAdvanceAssignment != null
|
||||
&& directAdvanceAssignment.getMaxValue() == null) {
|
||||
return false;
|
||||
throw new WrongValueException(
|
||||
getDecimalboxMaxValueBy(listItem),
|
||||
_("Value is not valid, the current value must be not empty"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -716,14 +742,43 @@ public class ManageOrderElementAdvancesController extends
|
|||
Listitem listItem = (Listitem) editAdvancesMeasurement.getChildren().get(i);
|
||||
AdvanceMeasurement advance = (AdvanceMeasurement) listItem
|
||||
.getValue();
|
||||
if (advance.getValue() == null || advance.getDate() == null) {
|
||||
return false;
|
||||
|
||||
// Validate the value of the advance measurement
|
||||
Decimalbox valueBox = getDecimalboxBy(listItem);
|
||||
valueBox.setValue(advance.getValue());
|
||||
|
||||
// Validate the value of the advance measurement
|
||||
Datebox dateBox = getDateboxBy(listItem);
|
||||
if (advance.getDate() == null) {
|
||||
dateBox.setValue(null);
|
||||
} else {
|
||||
dateBox.setValue(advance.getDate().toDateTimeAtStartOfDay()
|
||||
.toDate());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Combobox getComboboxTypeBy(Listitem item) {
|
||||
return (Combobox) ((Listcell) item.getChildren().get(0))
|
||||
.getFirstChild();
|
||||
}
|
||||
|
||||
private Combobox getDecimalboxMaxValueBy(Listitem item) {
|
||||
return (Combobox) ((Listcell) item.getChildren().get(1))
|
||||
.getFirstChild();
|
||||
}
|
||||
|
||||
private Decimalbox getDecimalboxBy(Listitem item) {
|
||||
return (Decimalbox) ((Listcell) item.getChildren().get(0))
|
||||
.getFirstChild();
|
||||
}
|
||||
|
||||
private Datebox getDateboxBy(Listitem item) {
|
||||
return (Datebox) ((Listcell) item.getChildren().get(2)).getFirstChild();
|
||||
}
|
||||
|
||||
private boolean validateReportGlobalAdvance(){
|
||||
boolean existItems = false;
|
||||
for(int i=0; i< editAdvances.getChildren().size(); i++){
|
||||
|
|
@ -767,7 +822,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
listcell.appendChild(value);
|
||||
listitem.appendChild(listcell);
|
||||
|
||||
value.setScale(2);
|
||||
value.setScale(4);
|
||||
value.setDisabled(isReadOnlyAdvanceMeasurements());
|
||||
value.addEventListener(Events.ON_CHANGE, new EventListener() {
|
||||
|
||||
|
|
@ -776,7 +831,6 @@ public class ManageOrderElementAdvancesController extends
|
|||
updatesValue(value);
|
||||
}
|
||||
});
|
||||
value.setConstraint(checkValidValue());
|
||||
|
||||
Util.bind(value, new Util.Getter<BigDecimal>() {
|
||||
|
||||
|
|
@ -793,6 +847,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
Util.reloadBindings(editAdvances);
|
||||
}
|
||||
});
|
||||
value.setConstraint(checkValidValue());
|
||||
}
|
||||
|
||||
private void appendLabelPercentage(final Listitem listitem) {
|
||||
|
|
@ -825,7 +880,6 @@ public class ManageOrderElementAdvancesController extends
|
|||
setCurrentDate(listitem);
|
||||
}
|
||||
});
|
||||
date.setConstraint(checkValidDate());
|
||||
|
||||
Util.bind(date, new Util.Getter<Date>() {
|
||||
|
||||
|
|
@ -847,6 +901,7 @@ public class ManageOrderElementAdvancesController extends
|
|||
Util.reloadBindings(self);
|
||||
}
|
||||
});
|
||||
date.setConstraint(checkValidDate());
|
||||
}
|
||||
|
||||
private Constraint checkValidValue() {
|
||||
|
|
@ -854,20 +909,34 @@ public class ManageOrderElementAdvancesController extends
|
|||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
if (((BigDecimal) value) != null) {
|
||||
if (manageOrderElementAdvancesModel
|
||||
.greatThanMaxValue((BigDecimal) value)) {
|
||||
AdvanceMeasurement advanceMeasurement = getAdvanceMeasurementByComponent(comp);
|
||||
if (advanceMeasurement != null) {
|
||||
advanceMeasurement.setValue((BigDecimal) value);
|
||||
if (((BigDecimal) value) == null) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("Value is not valid, the current value must be less than max value"));
|
||||
}
|
||||
if (!(manageOrderElementAdvancesModel
|
||||
.isPrecisionValid((BigDecimal) value))) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("Value is not valid, the Precision value must be exact "
|
||||
_("Value is not valid, the current value must be not empty"));
|
||||
} else {
|
||||
if (manageOrderElementAdvancesModel
|
||||
.greatThanMaxValue(advanceMeasurement)) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("Value is not valid, the current value must be less than max value"));
|
||||
}
|
||||
if (!manageOrderElementAdvancesModel
|
||||
.isPrecisionValid(advanceMeasurement)) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("Value is not valid, the Precision value must be exact "
|
||||
+ manageOrderElementAdvancesModel
|
||||
.getUnitPrecision()));
|
||||
}
|
||||
if (manageOrderElementAdvancesModel
|
||||
.lessThanPreviousMeasurements()) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("Value is not valid, the value must be greater than the value of the previous advances."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -875,16 +944,28 @@ public class ManageOrderElementAdvancesController extends
|
|||
return newConstraint;
|
||||
}
|
||||
|
||||
private AdvanceMeasurement getAdvanceMeasurementByComponent(
|
||||
Component comp) {
|
||||
try {
|
||||
Listitem item = (Listitem) comp.getParent().getParent();
|
||||
return (AdvanceMeasurement) item.getValue();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Constraint checkValidDate() {
|
||||
Constraint newConstraint = new Constraint() {
|
||||
@Override
|
||||
public void validate(Component comp, Object value)
|
||||
throws WrongValueException {
|
||||
if (((Date) value) != null) {
|
||||
Listitem listitem = (Listitem) comp.getParent()
|
||||
.getParent();
|
||||
AdvanceMeasurement advanceMeasurement = (AdvanceMeasurement) listitem
|
||||
.getValue();
|
||||
AdvanceMeasurement advanceMeasurement = getAdvanceMeasurementByComponent(comp);
|
||||
if (((Date) value) == null) {
|
||||
advanceMeasurement.setDate(null);
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("The date is not valid, the date must be not empty"));
|
||||
} else {
|
||||
if (!manageOrderElementAdvancesModel
|
||||
.isDistinctValidDate((Date) value,
|
||||
advanceMeasurement)) {
|
||||
|
|
@ -892,6 +973,18 @@ public class ManageOrderElementAdvancesController extends
|
|||
comp,
|
||||
_("The date is not valid, the date must be unique for this advanced assignment"));
|
||||
}
|
||||
if (advanceMeasurement != null) {
|
||||
advanceMeasurement.setDate(new LocalDate(
|
||||
(Date) value));
|
||||
manageOrderElementAdvancesModel
|
||||
.sortListAdvanceMeasurement();
|
||||
if (manageOrderElementAdvancesModel
|
||||
.lessThanPreviousMeasurements()) {
|
||||
throw new WrongValueException(
|
||||
comp,
|
||||
_("Value is not valid, the value must be greater than the value of the previous advances."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -380,30 +380,30 @@ public class ManageOrderElementAdvancesModel implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrecisionValid(BigDecimal value){
|
||||
public boolean isPrecisionValid(AdvanceMeasurement advanceMeasurement) {
|
||||
if ((this.advanceAssignment != null)
|
||||
&& (this.advanceAssignment.getAdvanceType() != null)) {
|
||||
BigDecimal precision = this.advanceAssignment.getAdvanceType()
|
||||
.getUnitPrecision();
|
||||
BigDecimal result[] = value.divideAndRemainder(precision);
|
||||
if(result[1].compareTo(BigDecimal.ZERO) == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return advanceMeasurement.checkConstraintValidPrecision();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean greatThanMaxValue(BigDecimal value){
|
||||
public boolean greatThanMaxValue(AdvanceMeasurement advanceMeasurement) {
|
||||
if (this.advanceAssignment == null
|
||||
|| this.advanceAssignment.getMaxValue() == null) {
|
||||
return false;
|
||||
}
|
||||
if (value.compareTo(this.advanceAssignment.getMaxValue()) > 0) {
|
||||
return true;
|
||||
return !(advanceMeasurement.checkConstraintValueIsLessThanMaxValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lessThanPreviousMeasurements() {
|
||||
if (this.advanceAssignment == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return !(this.advanceAssignment
|
||||
.checkConstraintValidAdvanceMeasurements());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -448,7 +448,6 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
final boolean couldSave = save();
|
||||
if (couldSave) {
|
||||
if(orderModel.userCanRead(order, SecurityUtils.getSessionUserLoginName())) {
|
||||
selectTab(getCurrentTab().getId());
|
||||
orderModel.initEdit(order);
|
||||
checkWritePermissions(order);
|
||||
if(order.getState() == OrderStatusEnum.STORED) {
|
||||
|
|
@ -459,6 +458,12 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
initialStatus = order.getState();
|
||||
initializeTabs();
|
||||
showWindow(editWindow);
|
||||
|
||||
// come back to the current tab after initialize all tabs.
|
||||
selectTab(getCurrentTab().getId());
|
||||
Events.sendEvent(new SelectEvent(Events.ON_SELECT,
|
||||
getCurrentTab(), null));
|
||||
|
||||
if (isNewObject) {
|
||||
this.planningControllerEntryPoints.goToOrderDetails(order);
|
||||
}
|
||||
|
|
@ -476,6 +481,7 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public void saveAndExit() {
|
||||
setCurrentTab();
|
||||
final boolean couldSave = save();
|
||||
if (couldSave) {
|
||||
goToList();
|
||||
|
|
@ -483,20 +489,28 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
private boolean save() {
|
||||
|
||||
if ((manageOrderElementAdvancesController != null)
|
||||
&& (!manageOrderElementAdvancesController.save())) {
|
||||
if (manageOrderElementAdvancesController != null) {
|
||||
selectTab("tabAdvances");
|
||||
if (!manageOrderElementAdvancesController.save()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((assignedCriterionRequirementController != null)
|
||||
&& (!assignedCriterionRequirementController.close())) {
|
||||
if (assignedCriterionRequirementController != null) {
|
||||
selectTab("tabRequirements");
|
||||
if (!assignedCriterionRequirementController.close()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((assignedTaskQualityFormController != null)
|
||||
&& (!assignedTaskQualityFormController.confirm())) {
|
||||
if (assignedTaskQualityFormController != null) {
|
||||
selectTab("tabTaskQualityForm");
|
||||
if (!assignedTaskQualityFormController.confirm()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// come back to the current tab after validate other tabs.
|
||||
selectTab(getCurrentTab().getId());
|
||||
|
||||
try {
|
||||
orderModel.save();
|
||||
saveOrderAuthorizations();
|
||||
|
|
@ -507,7 +521,6 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (ValidationException e) {
|
||||
messagesForUser.showInvalidValues(e, new LabelCreatorForInvalidValues());
|
||||
|
|
@ -553,8 +566,6 @@ public class OrderCRUDController extends GenericForwardComposer {
|
|||
}
|
||||
|
||||
public void reloadHoursGroupOrder() {
|
||||
assignedCriterionRequirementController
|
||||
.openWindow(getOrderElementModel());
|
||||
assignedCriterionRequirementController.reload();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue