Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AER-2979 Validating additional systems based on housing #271

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface FarmAnimalHousingValidationHelper {

boolean isValidFarmAdditionalSystemCode(String systemCode);

boolean isValidFarmAdditionalSystemCombination(String animalCode, String systemCode);
boolean isValidFarmAdditionalSystemCombination(String housingCode, String systemCode);

FarmEmissionFactorType getAnimalHousingEmissionFactorType(final String animalHousingCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private boolean validateStandardAnimalHousing(final StandardFarmAnimalHousing su
valid = false;
} else {
valid = validateNumberOfDays(subSource, sourceId) && valid;
valid = validateAdditionalSystems(subSource.getAdditionalSystems(), animalCode, sourceId) && valid;
valid = validateAdditionalSystems(subSource.getAdditionalSystems(), housingCode, sourceId) && valid;
}
return valid;
}
Expand All @@ -86,11 +86,11 @@ private boolean validateNumberOfDays(final StandardFarmAnimalHousing subSource,
return FarmEmissionFactorTypeValidatorUtil.validate(EXPECTED_EMISSION_FACTOR_TYPES, emissionFactorType, subSource, sourceId, getErrors());
}

private boolean validateAdditionalSystems(final List<AdditionalHousingSystem> additionalSystems, final String animalCode, final String sourceId) {
private boolean validateAdditionalSystems(final List<AdditionalHousingSystem> additionalSystems, final String housingCode, final String sourceId) {
boolean valid = true;
for (final AdditionalHousingSystem additionalSystem : additionalSystems) {
if (additionalSystem instanceof final StandardAdditionalHousingSystem standardSystem) {
valid = validateStandardAdditionalSystem(standardSystem, animalCode, sourceId) && valid;
valid = validateStandardAdditionalSystem(standardSystem, housingCode, sourceId) && valid;
} else if (additionalSystem instanceof final CustomAdditionalHousingSystem customSystem) {
valid = validateCustomAdditionalSystem(customSystem, sourceId) && valid;
} else {
Expand All @@ -101,15 +101,15 @@ private boolean validateAdditionalSystems(final List<AdditionalHousingSystem> ad
return valid;
}

private boolean validateStandardAdditionalSystem(final StandardAdditionalHousingSystem standardSystem, final String animalCode,
private boolean validateStandardAdditionalSystem(final StandardAdditionalHousingSystem standardSystem, final String housingCode,
final String sourceId) {
final String code = standardSystem.getAdditionalSystemCode();
boolean valid = true;
if (!validationHelper.isValidFarmAdditionalSystemCode(code)) {
getErrors().add(new AeriusException(ImaerExceptionReason.GML_UNKNOWN_ANIMAL_HOUSING_CODE, sourceId, code));
valid = false;
} else if (!validationHelper.isValidFarmAdditionalSystemCombination(animalCode, code)) {
getErrors().add(new AeriusException(ImaerExceptionReason.GML_UNSUPPORTED_ANIMAL_HOUSING_COMBINATION, sourceId, animalCode, code));
} else if (!validationHelper.isValidFarmAdditionalSystemCombination(housingCode, code)) {
getErrors().add(new AeriusException(ImaerExceptionReason.GML_UNSUPPORTED_ANIMAL_HOUSING_COMBINATION, sourceId, housingCode, code));
valid = false;
}
return valid;
Expand Down
Loading