ItEr38S14CUIntroducionPartesTraballoManualmenteItEr37S19 : validates that there is only assigned a label type and fixes a bug occurred for

This commit is contained in:
Susana Montes Pedreira 2009-12-11 10:49:29 +01:00 committed by Javier Moran Rua
parent a9402cb327
commit 7657706772
5 changed files with 52 additions and 6 deletions

View file

@ -72,7 +72,6 @@ public class WorkReportTypeDAO extends
WorkReportType t = findUniqueByName(workReportType);
return (t != null && t != workReportType);
} catch (InstanceNotFoundException e) {
System.out.println("Intancia not found");
return false;
}
}

View file

@ -32,6 +32,7 @@ import org.hibernate.validator.Valid;
import org.navalplanner.business.common.BaseEntity;
import org.navalplanner.business.common.Registry;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.labels.entities.LabelType;
import org.navalplanner.business.workreports.daos.IWorkReportTypeDAO;
import org.navalplanner.business.workreports.valueobjects.DescriptionField;
/**
@ -224,6 +225,38 @@ public class WorkReportType extends BaseEntity {
return true;
}
@SuppressWarnings("unused")
@AssertTrue(message = "the assigned label type can not repeat in the work report type.")
public boolean validateNotExistRepeatedLabelTypes() {
for (WorkReportLabelTypeAssigment assignedLabelType : this.workReportLabelTypeAssigments) {
if (existRepeatedLabelType(assignedLabelType)) {
return false;
}
}
return true;
}
public boolean existRepeatedLabelType(
WorkReportLabelTypeAssigment assignedLabelType) {
for (WorkReportLabelTypeAssigment oldAssignedLabelType : this.workReportLabelTypeAssigments) {
if ((!oldAssignedLabelType.equals(assignedLabelType))
&& (isTheSameLabelType(oldAssignedLabelType.getLabelType(),
assignedLabelType.getLabelType()))) {
return true;
}
}
return false;
}
public boolean isTheSameLabelType(LabelType oldLabelType,
LabelType newLabelType) {
if ((oldLabelType != null) && (newLabelType != null)
&& (oldLabelType.equals(newLabelType))) {
return true;
}
return false;
}
public boolean existSameFieldName(DescriptionField descriptionField) {
for (DescriptionField oldDescriptionField : getDescriptionFields()) {
if ((!oldDescriptionField.equals(descriptionField))

View file

@ -383,8 +383,8 @@ public class WorkReportModel implements IWorkReportModel {
}
private DescriptionField getDescriptionFieldByName(String name){
WorkReportType type = getWorkReport().getWorkReportType();
for (DescriptionField descriptionField : type.getDescriptionFields()) {
for (DescriptionField descriptionField : getWorkReportType()
.getDescriptionFields()) {
if(descriptionField.getFieldName().equals(name)){
return descriptionField;
}

View file

@ -435,7 +435,6 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
DescriptionField descriptionField) {
PositionInWorkReportEnum newPosition = (PositionInWorkReportEnum) selectedItem
.getValue();
System.out.println("**" + newPosition.name());
workReportTypeModel.changePositionDescriptionField(newPosition,
descriptionField);
}
@ -520,6 +519,8 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
public void onEvent(Event event) throws Exception {
changeLabelType(comboLabelTypes.getSelectedItem(),
workReportLabelTypeAssigment);
validateIfExistTheSameLabelType(comboLabelTypes,
workReportLabelTypeAssigment);
Util.reloadBindings(listWorkReportLabelTypeAssigments);
}
});
@ -727,6 +728,17 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
};
}
public void validateIfExistTheSameLabelType(
final Combobox comboLabelTypes,
final WorkReportLabelTypeAssigment workReportLabelTypeAssigment) throws WrongValueException {
if ((getWorkReportType() != null) && (getWorkReportType().existRepeatedLabelType(workReportLabelTypeAssigment))) {
workReportLabelTypeAssigment.setLabelType(null);
throw new WrongValueException(
comboLabelTypes,
_("This label type already is assigned to the work report type."));
}
}
public Constraint validateIfExistTheSameFieldName(
final DescriptionField descriptionField) {
return new Constraint() {
@ -790,7 +802,7 @@ public class WorkReportTypeCRUDController extends GenericForwardComposer
.validateLabelTypes();
if (labelTypeAssigment != null) {
selectTab(tabReportStructure);
String errorMessage = "The label type must not null.";
String errorMessage = "The label type must unique and not null.";
showInvalidWorkReportLabelTypeAssigment(0, errorMessage,
labelTypeAssigment);
return false;

View file

@ -408,7 +408,9 @@ public class WorkReportTypeModel implements IWorkReportTypeModel {
public WorkReportLabelTypeAssigment validateLabelTypes() {
for (WorkReportLabelTypeAssigment labelTypeAssigment : getWorkReportLabelTypeAssigments()) {
if (labelTypeAssigment.getLabelType() == null) {
if ((labelTypeAssigment.getLabelType() == null)
|| (getWorkReportType()
.existRepeatedLabelType(labelTypeAssigment))) {
return labelTypeAssigment;
}
}