Commit 168918c2 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Update validation logic to trigger certain rules on completion only

parent 82ed1849
......@@ -31,6 +31,7 @@ import org.eclipsefoundation.persistence.model.DtoTable;
import org.eclipsefoundation.persistence.model.ParameterizedSQLStatement;
import org.eclipsefoundation.persistence.model.ParameterizedSQLStatementBuilder;
import org.eclipsefoundation.persistence.model.SortableField;
import org.eclipsefoundation.react.dto.ValidationGroups.Completion;
import org.eclipsefoundation.react.namespace.FormState;
import org.eclipsefoundation.react.namespace.MembershipFormAPIParameterNames;
import org.hibernate.annotations.GenericGenerator;
......@@ -47,7 +48,7 @@ public class MembershipForm extends BareNode implements TargetedClone<Membership
private String userID;
private String membershipLevel;
private boolean signingAuthority;
@NotBlank(message = "Purchase order state cannot be blank")
@NotBlank(message = "Purchase order state cannot be blank", groups = Completion.class)
private String purchaseOrderRequired;
private String vatNumber;
private String registrationCountry;
......
package org.eclipsefoundation.react.dto;
import javax.validation.groups.Default;
/**
* Used to differentiate some validation annotations from default to allow partial states.
*
* @author Martin Lowe
*
*/
public interface ValidationGroups {
interface Completion extends Default {
}
}
......@@ -42,6 +42,7 @@ import org.eclipsefoundation.react.dto.Contact;
import org.eclipsefoundation.react.dto.FormOrganization;
import org.eclipsefoundation.react.dto.FormWorkingGroup;
import org.eclipsefoundation.react.dto.MembershipForm;
import org.eclipsefoundation.react.dto.ValidationGroups.Completion;
import org.eclipsefoundation.react.model.ConstraintViolationWrapFactory;
import org.eclipsefoundation.react.model.ConstraintViolationWrapFactory.ConstraintViolationWrap;
import org.eclipsefoundation.react.namespace.FormState;
......@@ -215,7 +216,7 @@ public class MembershipFormResource extends AbstractRESTResource {
private <T extends BareNode> Set<ConstraintViolationWrap> recordViolations(List<T> items) {
ConstraintViolationWrapFactory factory = new ConstraintViolationWrapFactory();
return items.stream().flatMap(item -> factory.build(validator.validate(item)).stream())
return items.stream().flatMap(item -> factory.build(validator.validate(item, Completion.class)).stream())
.collect(Collectors.toSet());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment