ItEr50S13AdaptacionServiciosRESTItEr49S18 : Adds class validations.
Adds the checks of the constraints about labels and description field values in WorkReport and WorkReportLine.
This commit is contained in:
parent
caab8074ca
commit
fce8818b41
2 changed files with 167 additions and 0 deletions
|
|
@ -25,12 +25,15 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.hibernate.validator.Valid;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.workreports.daos.IWorkReportDAO;
|
||||
|
|
@ -234,6 +237,85 @@ public class WorkReport extends IntegrationEntity {
|
|||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "label type:the work report have not assigned this label type")
|
||||
public boolean checkConstraintAssignedLabelTypes() {
|
||||
if (this.workReportType == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.workReportType.getHeadingLabels().size() != this.labels.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (WorkReportLabelTypeAssigment typeAssigment : this.workReportType
|
||||
.getHeadingLabels()) {
|
||||
try {
|
||||
getLabelByType(typeAssigment.getLabelType());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "description value:the work report have not assigned the description field")
|
||||
public boolean checkConstraintAssignedDescriptionValues() {
|
||||
if (this.workReportType == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.workReportType.getHeadingFields().size() != this.descriptionValues
|
||||
.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(DescriptionField field : this.workReportType.getHeadingFields()){
|
||||
try{
|
||||
getDescriptionValueByFieldName(field.getFieldName());
|
||||
}
|
||||
catch(InstanceNotFoundException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DescriptionValue getDescriptionValueByFieldName(String fieldName)
|
||||
throws InstanceNotFoundException {
|
||||
|
||||
if (StringUtils.isBlank(fieldName)) {
|
||||
throw new InstanceNotFoundException(fieldName,
|
||||
DescriptionValue.class.getName());
|
||||
}
|
||||
|
||||
for (DescriptionValue v : this.descriptionValues) {
|
||||
if (v.getFieldName().equalsIgnoreCase(StringUtils.trim(fieldName))) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InstanceNotFoundException(fieldName, DescriptionValue.class
|
||||
.getName());
|
||||
}
|
||||
|
||||
public Label getLabelByType(LabelType type)
|
||||
throws InstanceNotFoundException {
|
||||
|
||||
if (type == null) {
|
||||
throw new InstanceNotFoundException(type, LabelType.class.getName());
|
||||
}
|
||||
|
||||
for (Label l : this.labels) {
|
||||
if (l.getType().getId().equals(type.getId())) {
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InstanceNotFoundException(type, LabelType.class.getName());
|
||||
}
|
||||
|
||||
private void updateItsFieldsAndLabels(WorkReportType workReportType) {
|
||||
assignItsDescriptionValues(workReportType);
|
||||
assignItsLabels(workReportType);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotNull;
|
||||
import org.hibernate.validator.Valid;
|
||||
|
|
@ -31,8 +32,10 @@ import org.joda.time.Hours;
|
|||
import org.joda.time.LocalTime;
|
||||
import org.navalplanner.business.common.IntegrationEntity;
|
||||
import org.navalplanner.business.common.Registry;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.costcategories.entities.TypeOfWorkHours;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.labels.entities.LabelType;
|
||||
import org.navalplanner.business.orders.entities.OrderElement;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.workreports.daos.IWorkReportLineDAO;
|
||||
|
|
@ -391,4 +394,86 @@ public class WorkReportLine extends IntegrationEntity implements Comparable {
|
|||
&& (orderElement != null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "label type:the work report have not assigned this label type")
|
||||
public boolean checkConstraintAssignedLabelTypes() {
|
||||
if (this.workReport == null
|
||||
|| this.workReport.getWorkReportType() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.workReport.getWorkReportType().getLineLabels().size() != this.labels
|
||||
.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (WorkReportLabelTypeAssigment typeAssigment : this.workReport
|
||||
.getWorkReportType().getLineLabels()) {
|
||||
try {
|
||||
getLabelByType(typeAssigment.getLabelType());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@AssertTrue(message = "description value:the work report have not assigned the description field")
|
||||
public boolean checkConstraintAssignedDescriptionValues() {
|
||||
if (this.workReport == null
|
||||
|| this.workReport.getWorkReportType() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.workReport.getWorkReportType().getLineFields().size() != this.descriptionValues
|
||||
.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (DescriptionField field : this.workReport.getWorkReportType()
|
||||
.getLineFields()) {
|
||||
try {
|
||||
getDescriptionValueByFieldName(field.getFieldName());
|
||||
} catch (InstanceNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DescriptionValue getDescriptionValueByFieldName(String fieldName)
|
||||
throws InstanceNotFoundException {
|
||||
|
||||
if (StringUtils.isBlank(fieldName)) {
|
||||
throw new InstanceNotFoundException(fieldName,
|
||||
DescriptionValue.class.getName());
|
||||
}
|
||||
|
||||
for (DescriptionValue v : this.descriptionValues) {
|
||||
if (v.getFieldName().equalsIgnoreCase(StringUtils.trim(fieldName))) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InstanceNotFoundException(fieldName, DescriptionValue.class
|
||||
.getName());
|
||||
}
|
||||
|
||||
public Label getLabelByType(LabelType type)
|
||||
throws InstanceNotFoundException {
|
||||
|
||||
if (type == null) {
|
||||
throw new InstanceNotFoundException(type, LabelType.class.getName());
|
||||
}
|
||||
|
||||
for (Label l : this.labels) {
|
||||
if (l.getType().getId().equals(type.getId())) {
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InstanceNotFoundException(type, LabelType.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue