-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update data types and add Skattekort validation utility #deploy-skatt…
…ekort-service Changed the datatype of 'inntektsar' from Integer to String in SokosRequest.java. A new Java class 'SkattekortValidator' was created to validate various aspects of a Skattekort, such as Arbeitstag, Arbeitgeber, and Trekktype. Furthermore, the skattekort validation method in SkattekortService.java was replaced with the newly created SkattekortValidator. In addition, isEmpty and isAmbiguous methods were added in SkattekortTilArbeidsgiverDTO.java for additional validation.
- Loading branch information
Showing
4 changed files
with
109 additions
and
27 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
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
74 changes: 74 additions & 0 deletions
74
...kattekort-service/src/main/java/no/nav/skattekortservice/utility/SkattekortValidator.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,74 @@ | ||
package no.nav.skattekortservice.utility; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortTilArbeidsgiverDTO; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.Collection; | ||
|
||
@UtilityClass | ||
public class SkattekortValidator { | ||
|
||
public static void validate(SkattekortTilArbeidsgiverDTO skattekort) { | ||
|
||
validateArbeidsgiver(skattekort); | ||
|
||
validateArbeidstager(skattekort); | ||
|
||
validateSkattekort(skattekort); | ||
} | ||
|
||
private static void validateSkattekort(SkattekortTilArbeidsgiverDTO skattekort) { | ||
|
||
skattekort.getArbeidsgiver().stream() | ||
.map(SkattekortTilArbeidsgiverDTO.Arbeidsgiver::getArbeidstaker) | ||
.flatMap(Collection::stream) | ||
.map(SkattekortTilArbeidsgiverDTO.Skattekortmelding::getSkattekort) | ||
.map(SkattekortTilArbeidsgiverDTO.Skattekort::getTrekktype) | ||
.flatMap(Collection::stream) | ||
.forEach(trekktype -> { | ||
if (trekktype.isAllEmpty()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"En av Forskuddstrekk, Frikort, Trekkprosent og Trekktabell må angis per trekktype"); | ||
} else if (trekktype.isAmbiguous()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"Kun én av Forskuddstrekk, Frikort, Trekkprosent og Trekktabell kan angis per trekktype"); | ||
} | ||
}); | ||
} | ||
|
||
private static void validateArbeidstager(SkattekortTilArbeidsgiverDTO skattekort) { | ||
|
||
skattekort.getArbeidsgiver().stream() | ||
.map(SkattekortTilArbeidsgiverDTO.Arbeidsgiver::getArbeidstaker) | ||
.flatMap(Collection::stream) | ||
.forEach(arbeidstaker -> { | ||
if (arbeidstaker.isEmptyArbeidstakeridentifikator()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"Arbeidstakeridentifikator må være satt"); | ||
} else if (arbeidstaker.isEmptyInntektsaar()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"Inntektsår må være satt"); | ||
} | ||
}); | ||
} | ||
|
||
private static void validateArbeidsgiver(SkattekortTilArbeidsgiverDTO skattekort) { | ||
|
||
skattekort.getArbeidsgiver().stream() | ||
.map(SkattekortTilArbeidsgiverDTO.Arbeidsgiver::getArbeidsgiveridentifikator) | ||
.forEach(arbeidsgiver -> { | ||
if (arbeidsgiver.isAllEmpty()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"arbeidsgiveridentifikator må inneholde enten " + | ||
"organisasjonsnummer eller personidentifikator"); | ||
|
||
} else if (arbeidsgiver.isAmbiguous()) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"arbeidsgiveridentifikator er uklar, " + | ||
"både organisasjonsnummer og personidentifikator er angitt"); | ||
} | ||
}); | ||
} | ||
} |
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