Since HoursGroup extends IntegrationEntity it doesn't need its own 'code' field anymore
* Move validation unique code (Order, HoursGroup) to outer toEntity() method * HoursGroup constructor should call IntegrationEntity.create() before setting code, to avoid override its value * orderWithOrderLineWithInvalidHoursGroup() expects only 1 constraint violation as validation of code is not checked twice FEA: ItEr61S05BugFixing
This commit is contained in:
parent
998ae94e75
commit
341145a597
3 changed files with 18 additions and 20 deletions
|
|
@ -52,8 +52,6 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
|
||||
private static final Log LOG = LogFactory.getLog(HoursGroup.class);
|
||||
|
||||
private String code;
|
||||
|
||||
private ResourceEnum resourceType = ResourceEnum.WORKER;
|
||||
|
||||
private Integer workingHours = 0;
|
||||
|
|
@ -88,11 +86,11 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
|
||||
public static HoursGroup createUnvalidated(String code,
|
||||
ResourceEnum resourceType, Integer workingHours) {
|
||||
HoursGroup result = new HoursGroup();
|
||||
HoursGroup result = create(new HoursGroup());
|
||||
result.setCode(code);
|
||||
result.setResourceType(resourceType);
|
||||
result.setWorkingHours(workingHours);
|
||||
return create(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -158,7 +156,7 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
private HoursGroup(OrderLine parentOrderLine) {
|
||||
this.parentOrderLine = parentOrderLine;
|
||||
String code = parentOrderLine.getCode();
|
||||
this.code = code != null ? code : "";
|
||||
this.setCode(code != null ? code : "");
|
||||
this.setOrderLineTemplate(null);
|
||||
}
|
||||
|
||||
|
|
@ -167,15 +165,6 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
this.setParentOrderLine(null);
|
||||
}
|
||||
|
||||
@NotEmpty(message = "code not specified")
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ResourceEnum getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
|
@ -415,6 +404,13 @@ public class HoursGroup extends IntegrationEntity implements Cloneable,
|
|||
return Registry.getHoursGroupDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConstraintUniqueCode() {
|
||||
// the automatic checking of this constraint is avoided because it uses
|
||||
// the wrong code property
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void checkConstraintHoursGroupUniqueCode(OrderElement order) {
|
||||
HoursGroup repeatedHoursGroup;
|
||||
|
||||
|
|
|
|||
|
|
@ -252,9 +252,14 @@ public final class OrderElementConverter {
|
|||
}
|
||||
OrderElement orderElement = toEntityExceptCriterionRequirements(
|
||||
orderVersion, orderElementDTO, configuration);
|
||||
// Validate OrderElement.code and HoursGroup.code must be unique
|
||||
Order.checkConstraintOrderUniqueCode(orderElement);
|
||||
HoursGroup.checkConstraintHoursGroupUniqueCode(orderElement);
|
||||
|
||||
if (configuration.isCriterionRequirements()) {
|
||||
addOrCriterionRequirements(orderElement, orderElementDTO);
|
||||
}
|
||||
|
||||
return orderElement;
|
||||
}
|
||||
|
||||
|
|
@ -356,6 +361,7 @@ public final class OrderElementConverter {
|
|||
OrderElementDTO orderElementDTO,
|
||||
ConfigurationOrderElementConverter configuration)
|
||||
throws ValidationException {
|
||||
|
||||
Validate.notNull(parentOrderVersion);
|
||||
OrderElement orderElement;
|
||||
|
||||
|
|
@ -443,10 +449,6 @@ public final class OrderElementConverter {
|
|||
addAdvanceMeasurements(orderElement, orderElementDTO);
|
||||
}
|
||||
|
||||
// Validate OrderElement.code and HoursGroup.code must be unique
|
||||
Order.checkConstraintOrderUniqueCode(orderElement);
|
||||
HoursGroup.checkConstraintHoursGroupUniqueCode(orderElement);
|
||||
|
||||
return orderElement;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -339,8 +339,8 @@ public class OrderElementServiceTest {
|
|||
|
||||
List<ConstraintViolationDTO> constraintViolations = instanceConstraintViolationsList
|
||||
.get(0).constraintViolations;
|
||||
// Mandatory fields: code, workingHours
|
||||
assertThat(constraintViolations.size(), equalTo(2));
|
||||
// Mandatory fields: code
|
||||
assertThat(constraintViolations.size(), equalTo(1));
|
||||
|
||||
for (ConstraintViolationDTO constraintViolationDTO : constraintViolations) {
|
||||
assertThat(constraintViolationDTO.fieldName, anyOf(mustEnd("code"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue