ItEr39S05ValidacionEProbasFuncionaisItEr38S05 : Change the NotEmpty by NotNull validation of the DescriptionValue value.

This commit is contained in:
Susana Montes Pedreira 2009-12-18 10:08:26 +01:00 committed by Javier Moran Rua
parent f562a68e80
commit 52fd1bbf27
4 changed files with 8 additions and 129 deletions

View file

@ -21,6 +21,7 @@
package org.navalplanner.business.workreports.valueobjects;
import org.hibernate.validator.NotEmpty;
import org.hibernate.validator.NotNull;
import org.navalplanner.business.INewObject;
/**
@ -49,12 +50,12 @@ public class DescriptionValue implements INewObject {
public DescriptionValue(String fieldName, String value) {
this.fieldName = fieldName;
this.value = value;
setValue(value);
}
private String fieldName;
private String value;
private String value = "";
private boolean newObject = false;
@ -75,12 +76,15 @@ public class DescriptionValue implements INewObject {
this.fieldName = fieldName;
}
@NotEmpty(message = "value not specified or empty")
@NotNull(message = "value cannot be null")
public String getValue() {
return value;
}
public void setValue(String value) {
if (value == null)
value = "";
this.value = value;
}
}

View file

@ -197,18 +197,4 @@ public interface IWorkReportModel {
*/
Integer getLength(DescriptionValue descriptionValue);
/**
* Check if the {@link DescriptionValue} value assigned to current
* {@link WorkReport} is null or empty
* @return
*/
DescriptionValue validateWorkReportDescriptionValues();
/**
* Check if the {@link DescriptionValue} value assigned to
* {@link WorkReportLine} is null or empty
* @return
*/
DescriptionValue validateWorkReportLineDescriptionValues(WorkReportLine line);
}

View file

@ -68,7 +68,6 @@ import org.zkoss.zul.Intbox;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
import org.zkoss.zul.Rows;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Timebox;
@ -176,7 +175,7 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
public void saveAndContinue() {
if (save()) {
// goToEditForm(getWorkReport());
goToEditForm(getWorkReport());
}
}
@ -209,9 +208,6 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
if (value instanceof WorkReportLine) {
validateWorkReportLine((WorkReportLine) invalidValue.getBean());
}
if (value instanceof DescriptionValue) {
validateDescriptionValue((DescriptionValue) value);
}
}
}
@ -227,25 +223,6 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
}
}
/**
* Validates {@link DescriptionValue} data constraints
* @param invalidValue
*/
private void validateDescriptionValue(DescriptionValue value) {
if ((getWorkReport() != null)
&& (getWorkReport().getDescriptionValues().contains(value))) {
showInvalidWorkReportDescriptionValue(value);
} else {
for (WorkReportLine line : getWorkReport().getWorkReportLines()) {
if (line.getDescriptionValues().contains(value)) {
Row row = findWorkReportLine(listWorkReportLines.getRows()
.getChildren(), line);
showInvalidWorkReportLineDescriptionValue(row, value);
}
}
}
}
/**
* Validates {@link WorkReport} data constraints
* @param invalidValue
@ -272,66 +249,9 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
_("Order Element code cannot be null"));
return false;
}
return validateWorkReportDescriptionValues();
}
private boolean validateWorkReportDescriptionValues() {
DescriptionValue descriptionValue = workReportModel
.validateWorkReportDescriptionValues();
if (descriptionValue != null) {
showInvalidWorkReportDescriptionValue(descriptionValue);
return false;
}
return true;
}
private void showInvalidWorkReportDescriptionValue(DescriptionValue value) {
// Find which row contains the description value inside grid
Row row = findRowByWorkReportDescriptionValue(headingFieldsAndLabels
.getRows(), value);
Textbox textboxValue = (Textbox) row.getChildren().get(1);
throw new WrongValueException(textboxValue,
_("The description field valuemust be not null and not empty"));
}
private void showInvalidWorkReportLineDescriptionValue(Row row,
DescriptionValue descriptionValue) {
Integer position = findPositionByWorkReportLineDescriptionValue(descriptionValue);
if ((row != null) && (position != null)) {
Textbox textboxValue = getTextboxInPosition(row, position);
String message = _("The value must be spicified.");
showInvalidMessage(textboxValue, message);
}
}
private Row findRowByWorkReportDescriptionValue(Rows rows,
DescriptionValue value) {
List<Row> listRows = (List<Row>) rows.getChildren();
for (Row row : listRows) {
if ((row.getValue() instanceof DescriptionValue)
&& (value.equals(row.getValue()))) {
return row;
}
}
return null;
}
private Integer findPositionByWorkReportLineDescriptionValue(
DescriptionValue value) {
Columns columns = this.listWorkReportLines.getColumns();
List<Component> listColumns = columns.getChildren();
Integer position = new Integer(0);
for(Component child : listColumns){
if ((child instanceof NewDataSortableColumn)
&& (((NewDataSortableColumn) child).getLabel().equals(value
.getFieldName()))) {
return position;
}
position++;
}
return null;
}
/**
* Validates {@link WorkReportLine} data constraints
*
@ -412,13 +332,6 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
return false;
}
DescriptionValue descriptionValue = workReportModel
.validateWorkReportLineDescriptionValues(workReportLine);
if (descriptionValue != null) {
showInvalidWorkReportLineDescriptionValue(row,
descriptionValue);
return false;
}
}
}
return true;

View file

@ -448,28 +448,4 @@ public class WorkReportModel implements IWorkReportModel {
return descriptionField.getLength();
}
@Override
public DescriptionValue validateWorkReportDescriptionValues(){
for (DescriptionValue descriptionValue : getWorkReport()
.getDescriptionValues()) {
if ((descriptionValue.getValue() == null)
|| (descriptionValue.getValue().isEmpty())) {
return descriptionValue;
}
}
return null;
}
@Override
public DescriptionValue validateWorkReportLineDescriptionValues(
WorkReportLine line) {
for (DescriptionValue descriptionValue : line.getDescriptionValues()) {
if ((descriptionValue.getValue() == null)
|| (descriptionValue.getValue().isEmpty())) {
return descriptionValue;
}
}
return null;
}
}