-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from bcgov/feature/phys
Validation to ensure we're not creating physical addresses on offshore
- Loading branch information
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
api/src/main/java/ca/bc/gov/educ/api/edx/validator/CreateSchoolSagaPayloadValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ca.bc.gov.educ.api.edx.validator; | ||
|
||
import ca.bc.gov.educ.api.edx.struct.v1.CreateSchoolSagaData; | ||
import ca.bc.gov.educ.api.edx.struct.v1.School; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.FieldError; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
public class CreateSchoolSagaPayloadValidator { | ||
public List<FieldError> validateCreateSchoolSagaPayload(CreateSchoolSagaData sagaData) { | ||
List<FieldError> apiValidationErrors = new ArrayList<>(); | ||
|
||
School school = sagaData.getSchool(); | ||
|
||
if(school.getSchoolCategoryCode().equalsIgnoreCase("OFFSHORE") && school.getAddresses().stream().anyMatch(schoolAddress -> schoolAddress.getAddressTypeCode().equalsIgnoreCase("PHYSICAL"))){ | ||
String message = "Offshore schools cannot have a physical address."; | ||
apiValidationErrors.add(createFieldError("addresses", null, message)); | ||
} | ||
|
||
return apiValidationErrors; | ||
} | ||
|
||
private FieldError createFieldError(String fieldName, Object rejectedValue, String message) { | ||
return new FieldError("EdxUser", fieldName, rejectedValue, false, null, null, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters