Skip to content

Commit

Permalink
Merge pull request #157 from kbss-cvut/fix/156-fix-fault-event-constr…
Browse files Browse the repository at this point in the history
…aints

Remove unique name validation constraint for FaultEvent
  • Loading branch information
blcham authored Sep 13, 2024
2 parents 0ed6cf2 + 261d0f9 commit 34526b4
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ protected BaseDao<FaultEvent> getPrimaryDao() {
}

protected void customValidation(Object target, Errors errors, Object... validationHints ){
super.customValidation(target, errors, validationHints);
ConstraintGroupsAdapter groups = new ConstraintGroupsAdapter(validationHints);
FaultEvent instance = (FaultEvent) target;

if(groups.isCreateGroup() && exists(instance)){
errors.rejectValue("uri", "uri.exists", "The uri should be null or unique");
}
if(groups.isUpdateGroup() && !exists(instance)){
errors.rejectValue("uri", "uri.not-exists", "Uri does not refer to an existing entity");
}

if (instance.getEventType() == FtaEventType.INTERMEDIATE && (instance.getGateType() == null || instance.getGateType() == GateType.UNUSED)) {
errors.rejectValue("gateType", "gateType.invalid");
}
Expand Down

0 comments on commit 34526b4

Please sign in to comment.