diff --git a/.github/workflows/app.skattekort-service.yml b/.github/workflows/app.skattekort-service.yml new file mode 100644 index 00000000000..363346f819b --- /dev/null +++ b/.github/workflows/app.skattekort-service.yml @@ -0,0 +1,22 @@ +name: skattekort-service + +on: + push: + paths: + - libs/reactive-core + - libs/reactive-security + - libs/security-core + - libs/data-transfer-objects + - apps/skattekort-service/** + - .github/workflows/app.skattekort-service.yml + +jobs: + workflow: + uses: ./.github/workflows/common.workflow.backend.yml + with: + working-directory: "apps/skattekort-service" + deploy-tag: "#deploy-skattekort-service" + permissions: + contents: read + id-token: write + secrets: inherit diff --git a/apps/skattekort-service/Dockerfile b/apps/skattekort-service/Dockerfile new file mode 100644 index 00000000000..372253b99f6 --- /dev/null +++ b/apps/skattekort-service/Dockerfile @@ -0,0 +1,8 @@ +FROM ghcr.io/navikt/baseimages/temurin:21 +LABEL maintainer="Team Dolly" + +ENV JAVA_OPTS="-Dspring.profiles.active=prod --add-opens java.base/java.lang=ALL-UNNAMED" + +COPY build/libs/app.jar app.jar + +EXPOSE 8080 \ No newline at end of file diff --git a/apps/skattekort-service/README.md b/apps/skattekort-service/README.md new file mode 100644 index 00000000000..531252dfbd0 --- /dev/null +++ b/apps/skattekort-service/README.md @@ -0,0 +1,25 @@ +--- +layout: default +title: testnav-skattekort-service +parent: Applikasjoner +--- + +# skattekort-service + +Tjeneste for å legge til skattekort i os-eskatt ved innsending til deres eget API for test. + +## Bruk + +Applikasjonen omformer JSON-request til XML-request og sender inn på overnevnte endepunkt. + + +## Lokal kjøring + +Ha naisdevice kjørende og kjør SkattekortServiceApplicationStarter med følgende argumenter: + +``` +--add-opens java.base/java.lang=ALL-UNNAMED +-Dspring.profiles.active=dev +-Dspring.cloud.vault.token=[vault-token] +``` + diff --git a/apps/skattekort-service/build.gradle b/apps/skattekort-service/build.gradle new file mode 100644 index 00000000000..a798e1c8744 --- /dev/null +++ b/apps/skattekort-service/build.gradle @@ -0,0 +1,99 @@ +plugins { + id 'java' + id "org.sonarqube" version "4.4.1.3373" + id 'org.springframework.boot' version "3.2.1" + id 'io.spring.dependency-management' version "1.1.4" + id "jacoco" + id 'org.unbroken-dome.xjc' version '2.0.0' +} + +sonarqube { + properties { + property "sonar.dynamicAnalysis", "reuseReports" + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.java.coveragePlugin", "jacoco" + property "sonar.language", "java" + property "sonar.token", System.getenv("SONAR_TOKEN") + property "sonar.organization", "navikt" + property "sonar.project.monorepo.enabled", true + property "sonar.projectKey", "testnav-skattekort-service" + property "sonar.projectName", "testnav-skattekort-service" + property "sonar.sourceEncoding", "UTF-8" + } +} + +bootJar { + archiveFileName = "app.jar" + mainClass = 'no.nav.skattekortservice.SkattekortServiceApplicationStarter' + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} + +dependencyManagement { + applyMavenExclusions = false + imports { + mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2023.0.0' + } +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +sourceSets { + main { + xjcBinding.srcDirs = ['resources/xjb'] + } +} + +xjc { + xjcVersion = '3.0' + srcDirName = 'resources/schema' +} + +repositories { + mavenCentral() + maven { + name = "GitHubPackages" + url = uri('https://maven.pkg.github.com/navikt/maven-release') + credentials(PasswordCredentials) { + password System.getenv("NAV_TOKEN") + username 'token' + } + } +} + +dependencies { + implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0' + implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.0' + implementation 'org.json:json:20231013' + + implementation 'no.nav.testnav.libs:security-core' + implementation 'no.nav.testnav.libs:reactive-core' + implementation 'no.nav.testnav.libs:reactive-security' + implementation 'no.nav.testnav.libs:data-transfer-objects' + + implementation 'org.springframework.boot:spring-boot-starter-webflux' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + + implementation 'org.springframework.cloud:spring-cloud-starter-vault-config' + implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + + implementation 'io.micrometer:micrometer-registry-prometheus' + implementation 'org.hibernate.validator:hibernate-validator' + + implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.3.0' + implementation 'io.swagger.core.v3:swagger-annotations-jakarta:2.2.20' + implementation 'net.logstash.logback:logstash-logback-encoder:7.4' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' + + implementation 'ma.glasnost.orika:orika-core:1.5.4' + annotationProcessor 'org.projectlombok:lombok' + implementation 'org.projectlombok:lombok' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} \ No newline at end of file diff --git a/apps/skattekort-service/config.yml b/apps/skattekort-service/config.yml new file mode 100644 index 00000000000..f040ef425d6 --- /dev/null +++ b/apps/skattekort-service/config.yml @@ -0,0 +1,51 @@ +apiVersion: "nais.io/v1alpha1" +kind: "Application" +metadata: + name: testnav-skattekort-service + namespace: dolly + labels: + team: dolly +spec: + image: "{{image}}" + port: 8080 + webproxy: true + tokenx: + enabled: true + azure: + application: + allowAllUsers: true + enabled: true + tenant: nav.no + accessPolicy: + inbound: + rules: + - application: dolly-backend + - application: dolly-frontend + - application: dolly-idporten + - application: testnav-oversikt-frontend + outbound: + external: + - host: sokos-skattekort-dolly.dev-fss-pub.nais.io + liveness: + path: /internal/isAlive + periodSeconds: 30 + initialDelay: 30 + readiness: + path: /internal/isReady + initialDelay: 30 + prometheus: + enabled: true + path: /internal/metrics + replicas: + min: 1 + max: 1 + vault: + enabled: true + resources: + limits: + memory: 2048Mi + requests: + cpu: 200m + memory: 1024Mi + ingresses: + - "https://testnav-skattekort-service.intern.dev.nav.no" \ No newline at end of file diff --git a/apps/skattekort-service/gradle/wrapper/gradle-wrapper.jar b/apps/skattekort-service/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..7454180f2ae Binary files /dev/null and b/apps/skattekort-service/gradle/wrapper/gradle-wrapper.jar differ diff --git a/apps/skattekort-service/gradle/wrapper/gradle-wrapper.properties b/apps/skattekort-service/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..a5952066425 --- /dev/null +++ b/apps/skattekort-service/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/apps/skattekort-service/gradlew b/apps/skattekort-service/gradlew new file mode 100755 index 00000000000..3da45c161b0 --- /dev/null +++ b/apps/skattekort-service/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright ? 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions ?$var?, ?${var}?, ?${var:-default}?, ?${var+SET}?, +# ?${var#prefix}?, ?${var%suffix}?, and ?$( cmd )?; +# * compound commands having a testable exit status, especially ?case?; +# * various built-in commands including ?command?, ?set?, and ?ulimit?. +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/apps/skattekort-service/gradlew.bat b/apps/skattekort-service/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/apps/skattekort-service/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/apps/skattekort-service/settings.gradle b/apps/skattekort-service/settings.gradle new file mode 100644 index 00000000000..b42e15f1e9a --- /dev/null +++ b/apps/skattekort-service/settings.gradle @@ -0,0 +1,17 @@ +plugins { + id "com.gradle.enterprise" version "3.12.3" +} + +rootProject.name = 'skattekort-service' + +includeBuild '../../libs/security-core' +includeBuild '../../libs/reactive-core' +includeBuild '../../libs/reactive-security' +includeBuild '../../libs/data-transfer-objects' + +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/SkattekortServiceApplicationStarter.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/SkattekortServiceApplicationStarter.java new file mode 100644 index 00000000000..1c714ebb8b7 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/SkattekortServiceApplicationStarter.java @@ -0,0 +1,13 @@ +package no.nav.skattekortservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SkattekortServiceApplicationStarter { + + public static void main(String[] args) { + + SpringApplication.run(SkattekortServiceApplicationStarter.class, args); + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/AppConfig.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/AppConfig.java new file mode 100644 index 00000000000..3e608f9bcac --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/AppConfig.java @@ -0,0 +1,14 @@ +package no.nav.skattekortservice.config; + +import no.nav.testnav.libs.reactivecore.config.CoreConfig; +import no.nav.testnav.libs.reactivesecurity.config.SecureOAuth2ServerToServerConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@Import({ CoreConfig.class, + SecureOAuth2ServerToServerConfiguration.class +}) +public class AppConfig { + +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/Consumers.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/Consumers.java new file mode 100644 index 00000000000..1362d28ca2d --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/Consumers.java @@ -0,0 +1,19 @@ +package no.nav.skattekortservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties sokosSkattekort; +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/DevConfig.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/DevConfig.java new file mode 100644 index 00000000000..c2d763946ef --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/DevConfig.java @@ -0,0 +1,37 @@ +package no.nav.skattekortservice.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.vault.annotation.VaultPropertySource; +import org.springframework.vault.authentication.ClientAuthentication; +import org.springframework.vault.authentication.TokenAuthentication; +import org.springframework.vault.client.VaultEndpoint; +import org.springframework.vault.config.AbstractVaultConfiguration; + +import static io.micrometer.common.util.StringUtils.isBlank; + +@Configuration +@Profile("dev") +@VaultPropertySource(value = "secret/dolly/lokal", ignoreSecretNotFound = false) +public class DevConfig extends AbstractVaultConfiguration { + + private static final String VAULT_PROPERTY = "spring.cloud.vault.token"; + + @Override + public VaultEndpoint vaultEndpoint() { + return VaultEndpoint.create("vault.adeo.no", 443); + } + + @Override + public ClientAuthentication clientAuthentication() { + + if (System.getenv().containsKey("VAULT_TOKEN")) { + System.setProperty(VAULT_PROPERTY, System.getenv("VAULT_TOKEN")); + } + var token = System.getProperty(VAULT_PROPERTY); + if (isBlank(token)) { + throw new IllegalArgumentException("Påkrevet property '%s' er ikke satt.".formatted(VAULT_PROPERTY)); + } + return new TokenAuthentication(System.getProperty(VAULT_PROPERTY)); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/JsonMapperConfig.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/JsonMapperConfig.java new file mode 100644 index 00000000000..7fa0431e597 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/JsonMapperConfig.java @@ -0,0 +1,106 @@ +package no.nav.skattekortservice.config; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.YearMonthSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.io.IOException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.YearMonth; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import static org.apache.commons.lang3.StringUtils.isBlank; + +@Configuration +public class JsonMapperConfig { + + private static final String YEAR_MONTH = "yyyy-MM"; + + @Bean + public ObjectMapper objectMapper() { + + var simpleModule = new SimpleModule() + .addDeserializer(LocalDateTime.class, new DollyLocalDateTimeDeserializer()) + .addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ISO_DATE_TIME)) + .addDeserializer(LocalDate.class, new DollyLocalDateDeserializer()) + .addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ISO_DATE)) + .addDeserializer(YearMonth.class, new DollyYearMonthDeserializer()) + .addSerializer(YearMonth.class, new YearMonthSerializer(DateTimeFormatter.ofPattern(YEAR_MONTH))) + .addDeserializer(ZonedDateTime.class, new DollyZonedDateTimeDeserializer()) + .addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer(DateTimeFormatter.ISO_DATE_TIME)); + return JsonMapper + .builder() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) + .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) + .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .build() + .registerModule(simpleModule); + } + + private static class DollyYearMonthDeserializer extends JsonDeserializer { + + @Override + public YearMonth deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + if (isBlank(node.asText())) { + return null; + } + return YearMonth.parse(node.asText(), DateTimeFormatter.ofPattern(YEAR_MONTH)); + } + } + + private static class DollyZonedDateTimeDeserializer extends JsonDeserializer { + + @Override + public ZonedDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + if (isBlank(node.asText())) { + return null; + } + return ZonedDateTime.parse(node.asText(), DateTimeFormatter.ISO_DATE_TIME); + } + } + + private static class DollyLocalDateDeserializer extends JsonDeserializer { + + @Override + public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + if (isBlank(node.asText())) { + return null; + } + var dateTime = node.asText().length() > 10 ? node.asText().substring(0, 10) : node.asText(); + return LocalDate.parse(dateTime); + } + } + + private static class DollyLocalDateTimeDeserializer extends JsonDeserializer { + + @Override + public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + if (isBlank(node.asText())) { + return null; + } + var dateTime = node.asText().length() > 19 ? node.asText().substring(0, 19) : node.asText(); + return dateTime.length() > 10 ? LocalDateTime.parse(dateTime) : LocalDate.parse(dateTime).atStartOfDay(); + } + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/MapperFacadeConfig.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/MapperFacadeConfig.java new file mode 100644 index 00000000000..05f2dbc344d --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/MapperFacadeConfig.java @@ -0,0 +1,36 @@ +package no.nav.skattekortservice.config; + +import ma.glasnost.orika.CustomConverter; +import ma.glasnost.orika.MapperFacade; +import ma.glasnost.orika.impl.DefaultMapperFactory; +import no.nav.skattekortservice.mapper.MappingStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +import static java.util.Objects.nonNull; + +@Configuration +@SuppressWarnings("java:S3740") +public class MapperFacadeConfig { + + @Bean + MapperFacade mapperFacade(List mappingStrategies, List customConverters) { + DefaultMapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); + + if (nonNull(mappingStrategies)) { + for (MappingStrategy mapper : mappingStrategies) { + mapper.register(mapperFactory); + } + } + + if (nonNull(customConverters)) { + for (CustomConverter converter : customConverters) { + mapperFactory.getConverterFactory().registerConverter(converter); + } + } + + return mapperFactory.getMapperFacade(); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/OpenApiConfig.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/OpenApiConfig.java new file mode 100644 index 00000000000..87492773906 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/OpenApiConfig.java @@ -0,0 +1,65 @@ +package no.nav.skattekortservice.config; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import no.nav.testnav.libs.reactivecore.config.ApplicationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebFilter; +import org.springframework.web.server.WebFilterChain; +import reactor.core.publisher.Mono; + +import java.util.Arrays; + +@Configuration +public class OpenApiConfig implements WebFilter { + + @Bean + public OpenAPI openApi(ApplicationProperties applicationProperties) { + return new OpenAPI() + .components(new Components().addSecuritySchemes("bearer-jwt", new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .scheme("bearer") + .bearerFormat("JWT") + .in(SecurityScheme.In.HEADER) + .name(HttpHeaders.AUTHORIZATION) + )) + .addSecurityItem( + new SecurityRequirement().addList("bearer-jwt", Arrays.asList("read", "write"))) + .info(new Info() + .title(applicationProperties.getName()) + .version(applicationProperties.getVersion()) + .description(applicationProperties.getDescription()) + .termsOfService("https://nav.no") + .contact(new Contact() + .url("https://nav-it.slack.com/archives/CA3P9NGA2") + .email("dolly@nav.no") + .name("Team Dolly") + ) + .license(new License() + .name("MIT License") + .url("https://opensource.org/licenses/MIT") + ) + ); + } + + @Override + public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { + if (exchange.getRequest().getURI().getPath().equals("/swagger")) { + return chain + .filter(exchange.mutate() + .request(exchange.getRequest() + .mutate().path("/swagger-ui.html").build()) + .build()); + } + + return chain.filter(exchange); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/SecurityConfig.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/SecurityConfig.java new file mode 100644 index 00000000000..b3e3cfd4fc8 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/config/SecurityConfig.java @@ -0,0 +1,38 @@ +package no.nav.skattekortservice.config; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import no.nav.testnav.libs.reactivesecurity.manager.JwtReactiveAuthenticationManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; + +@Slf4j +@Configuration +@EnableWebFluxSecurity +@EnableReactiveMethodSecurity +@RequiredArgsConstructor +public class SecurityConfig { + + private final JwtReactiveAuthenticationManager jwtReactiveAuthenticationManager; + + @Bean + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity httpSecurity) { + return httpSecurity + .csrf(ServerHttpSecurity.CsrfSpec::disable) + .authorizeExchange(authorizeConfig -> authorizeConfig.pathMatchers( + "/internal/**", + "/webjars/**", + "/v3/api-docs/**", + "/swagger-ui/**", + "/swagger", + "/error", + "/swagger-ui.html" + ).permitAll().anyExchange().authenticated()) + .oauth2ResourceServer(oauth2RSConfig -> oauth2RSConfig.jwt(jwtSpec -> jwtSpec.authenticationManager(jwtReactiveAuthenticationManager))) + .build(); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/SokosSkattekortConsumer.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/SokosSkattekortConsumer.java new file mode 100644 index 00000000000..8369eddab21 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/SokosSkattekortConsumer.java @@ -0,0 +1,43 @@ +package no.nav.skattekortservice.consumer; + +import no.nav.skattekortservice.config.Consumers; +import no.nav.skattekortservice.consumer.command.SokosGetCommand; +import no.nav.skattekortservice.consumer.command.SokosPostCommand; +import no.nav.skattekortservice.dto.SokosRequest; +import no.nav.skattekortservice.dto.SokosResponse; +import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Service +public class SokosSkattekortConsumer { + + private final WebClient webClient; + private final TokenExchange tokenExchange; + private final ServerProperties serverProperties; + + public SokosSkattekortConsumer(TokenExchange tokenExchange, Consumers consumers) { + + this.serverProperties = consumers.getSokosSkattekort(); + this.webClient = WebClient.builder() + .baseUrl(serverProperties.getUrl()) + .build(); + this.tokenExchange = tokenExchange; + } + + public Mono sendSkattekort(SokosRequest request) { + + return tokenExchange.exchange(serverProperties) + .flatMap(token -> new SokosPostCommand(webClient, request, token.getTokenValue()).call()); + } + + public Flux hentSkattekort(String ident) { + + return tokenExchange.exchange(serverProperties) + .flatMapMany(token -> new SokosGetCommand(webClient, ident, + token.getTokenValue()).call()); + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/command/SokosGetCommand.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/command/SokosGetCommand.java new file mode 100644 index 00000000000..1897f297124 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/command/SokosGetCommand.java @@ -0,0 +1,40 @@ +package no.nav.skattekortservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.skattekortservice.dto.SokosResponse; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Flux; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.UUID; +import java.util.concurrent.Callable; + +import static org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION; + +@RequiredArgsConstructor +public class SokosGetCommand implements Callable> { + + private static final String SOKOS_URL = "/api/v1/skattekort/hent/{fnr}"; + + private final WebClient webClient; + private final String ident; + private final String token; + + @Override + public Flux call() { + + return webClient + .get() + .uri(uriBuilder -> uriBuilder.path(SOKOS_URL) + .build(ident)) + .header(AUTHORIZATION, "Bearer " + token) + .header("korrelasjonsid", UUID.randomUUID().toString()) + .retrieve() + .bodyToFlux(SokosResponse.class) + .doOnError(WebClientFilter::logErrorMessage) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/command/SokosPostCommand.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/command/SokosPostCommand.java new file mode 100644 index 00000000000..e725a4dc1ce --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/consumer/command/SokosPostCommand.java @@ -0,0 +1,41 @@ +package no.nav.skattekortservice.consumer.command; + +import lombok.RequiredArgsConstructor; +import no.nav.skattekortservice.dto.SokosRequest; +import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; +import reactor.util.retry.Retry; + +import java.time.Duration; +import java.util.UUID; +import java.util.concurrent.Callable; + +import static org.apache.hc.core5.http.HttpHeaders.AUTHORIZATION; + +@RequiredArgsConstructor +public class SokosPostCommand implements Callable> { + + private static final String SOKOS_URL = "/api/v1/skattekort/opprett"; + + private final WebClient webClient; + private final SokosRequest request; + private final String token; + + @Override + public Mono call() { + + return webClient + .post() + .uri(SOKOS_URL) + .header(AUTHORIZATION, "Bearer " + token) + .header("korrelasjonsid", UUID.randomUUID().toString()) + .body(BodyInserters.fromValue(request)) + .retrieve() + .bodyToMono(String.class) + .doOnError(WebClientFilter::logErrorMessage) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(WebClientFilter::is5xxException)); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortRequest.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortRequest.java new file mode 100644 index 00000000000..c48caf17e2b --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortRequest.java @@ -0,0 +1,34 @@ +package no.nav.skattekortservice.dto; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Arbeidsgiver; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@XmlRootElement(name = "skattekortTilArbeidsgiver", + namespace = "urn:no:skatteetaten:fastsetting:formueinntekt:forskudd:skattekorttilarbeidsgiver:v3") +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "SkattekortTilArbeidsgiver", propOrder = { + "arbeidsgiver" +}) +public class SkattekortRequest { + + @XmlElement(required = true) + private List arbeidsgiver; + + public List getArbeidsgiver() { + + if (isNull(arbeidsgiver)) { + arbeidsgiver = new ArrayList<>(); + } + return arbeidsgiver; + } +} + diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortResponsIntermediate.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortResponsIntermediate.java new file mode 100644 index 00000000000..dcf4a91927e --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortResponsIntermediate.java @@ -0,0 +1,229 @@ +package no.nav.skattekortservice.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.dto.skattekortservice.v1.IdentifikatorForEnhetEllerPerson; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@SuppressWarnings("java:S115") +public class SkattekortResponsIntermediate { + + private SkattekortTilArbeidsgiver skattekortTilArbeidsgiver; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class SkattekortTilArbeidsgiver { + + private List arbeidsgiver; + + public List getArbeidsgiver() { + + if (isNull(arbeidsgiver)) { + arbeidsgiver = new ArrayList<>(); + } + return arbeidsgiver; + } + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Arbeidsgiver { + + private IdentifikatorForEnhetEllerPerson arbeidsgiveridentifikator; + private List arbeidstaker; + + public List getArbeidstaker() { + + if (isNull(arbeidstaker)) { + arbeidstaker = new ArrayList<>(); + } + return arbeidstaker; + } + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Skattekortmelding { + + private String arbeidstakeridentifikator; + private Resultatstatus resultatPaaForespoersel; + private Skattekort skattekort; + private List tilleggsopplysning; + private Integer inntektsaar; + + public List getTilleggsopplysning() { + + if (isNull(tilleggsopplysning)) { + tilleggsopplysning = new ArrayList<>(); + } + return tilleggsopplysning; + } + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Skattekort { + + private LocalDate utstedtDato; + private Long skattekortidentifikator; + private List forskuddstrekk; + private List frikort; + private List trekktabell; + private List trekkprosent; + + public List getForskuddstrekk() { + + if (isNull(forskuddstrekk)) { + forskuddstrekk = new ArrayList<>(); + } + return forskuddstrekk; + } + + public List getFrikort() { + + if (isNull(frikort)) { + frikort = new ArrayList<>(); + } + return frikort; + } + + public List getTrekktabell() { + + if (isNull(trekktabell)) { + trekktabell = new ArrayList<>(); + } + return trekktabell; + } + + public List getTrekkprosent() { + + if (isNull(trekkprosent)) { + trekkprosent = new ArrayList<>(); + } + return trekkprosent; + } + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Forskuddstrekk { + + private Trekkode trekkode; + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Frikort { + + private Trekkode trekkode; + + private Integer frikortbeloep; + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Trekktabell { + + private Trekkode trekkode; + + private Tabelltype tabelltype; + private String tabellnummer; + private Integer prosentsats; + private Integer antallMaanederForTrekk; + } + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class Trekkprosent { + + private Trekkode trekkode; + + private Integer prosentsats; + private Integer antallMaanederForTrekk; + } + + @Getter + @RequiredArgsConstructor + public enum Resultatstatus { + + ikkeSkattekort("IKKE_SKATTEKORT"), + vurderArbeidstillatelse("VURDER_ARBEIDSTILLATELSE"), + ikkeTrekkplikt("IKKE_TREKKPLIKT"), + skattekortopplysningerOK("SKATTEKORTOPPLYSNINGER_OK"), + ugyldigOrganisasjonsnummer("UGYLDIG_ORGANISASJONSNUMMER"), + ugyldigFoedselsEllerDnummer("UGYLDIG_FOEDSELS_ELLER_DNUMMER"), + utgaattDnummerSkattekortForFoedselsnummerErLevert("UTGAATT_DNUMMER_SKATTEKORT_FOR_FOEDSELSNUMMER_ER_LEVERT"); + + private final String value; + } + + @Getter + @RequiredArgsConstructor + public enum Tilleggsopplysning { + + oppholdPaaSvalbard("OPPHOLD_PAA_SVALBARD"), + kildeskattpensjonist("KILDESKATTPENSJONIST"), + oppholdITiltakssone("OPPHOLD_I_TILTAKSSONE"), + kildeskattPaaLoenn("KILDESKATT_PAA_LOENN"); + + private final String value; + } + + @Getter + @RequiredArgsConstructor + public enum Tabelltype { + + trekktabellForPensjon("TREKKTABELL_FOR_PENSJON"), + trekktabellForLoenn("TREKKTABELL_FOR_LOENN"); + + private final String value; + } + + @Getter + @RequiredArgsConstructor + public enum Trekkode { + + loennFraHovedarbeidsgiver("LOENN_FRA_HOVEDARBEIDSGIVER"), + loennFraBiarbeidsgiver("LOENN_FRA_BIARBEIDSGIVER"), + loennFraNAV("LOENN_FRA_NAV"), + pensjon("PENSJON"), + pensjonFraNAV("PENSJON_FRA_NAV"), + loennTilUtenrikstjenestemann("LOENN_TIL_UTENRIKSTJENESTEMANN"), + loennKunTrygdeavgiftTilUtenlandskBorger("LOENN_KUN_TRYGDEAVGIFT_TIL_UTENLANDSK_BORGER"), + loennKunTrygdeavgiftTilUtenlandskBorgerSomGrensegjenger("LOENN_KUN_TRYGDEAVGIFT_TIL_UTENLANDSK_BORGER_SOM_GRENSEGJENGER"), + ufoeretrygdFraNAV("UFOERETRYGD_FRA_NAV"), + ufoereytelserFraAndre("UFOEREYTELSER_FRA_ANDRE"), + introduksjonsstoenad("INTRODUKSJONSSTOENAD"); + + private final String value; + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortResponse.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortResponse.java new file mode 100644 index 00000000000..76b2ef5d19d --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SkattekortResponse.java @@ -0,0 +1,38 @@ +package no.nav.skattekortservice.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import no.nav.testnav.libs.dto.skattekortservice.v1.Arbeidsgiver; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SkattekortResponse { + + private SkattekortTilArbeidsgiver skattekortTilArbeidsgiver; + + @Data + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class SkattekortTilArbeidsgiver { + + private List arbeidsgiver; + + public List getArbeidsgiver() { + + if (isNull(arbeidsgiver)) { + arbeidsgiver = new ArrayList<>(); + } + return arbeidsgiver; + } + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SokosRequest.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SokosRequest.java new file mode 100644 index 00000000000..1496c07a0ea --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SokosRequest.java @@ -0,0 +1,17 @@ +package no.nav.skattekortservice.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SokosRequest { + + private String fnr; + private String inntektsar; + private String skattekort; +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SokosResponse.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SokosResponse.java new file mode 100644 index 00000000000..f477a439414 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/dto/SokosResponse.java @@ -0,0 +1,17 @@ +package no.nav.skattekortservice.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SokosResponse { + + private String fnr; + private String inntektsar; + private String skattekort; +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/ArbeidsgiverMappingStrategy.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/ArbeidsgiverMappingStrategy.java new file mode 100644 index 00000000000..28348b1e7ff --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/ArbeidsgiverMappingStrategy.java @@ -0,0 +1,89 @@ +package no.nav.skattekortservice.mapper; + +import lombok.extern.slf4j.Slf4j; +import ma.glasnost.orika.CustomMapper; +import ma.glasnost.orika.MapperFactory; +import ma.glasnost.orika.MappingContext; +import no.nav.skattekortservice.dto.SkattekortResponsIntermediate; +import no.nav.testnav.libs.dto.skattekortservice.v1.Forskuddstrekk; +import no.nav.testnav.libs.dto.skattekortservice.v1.Frikort; +import no.nav.testnav.libs.dto.skattekortservice.v1.Resultatstatus; +import no.nav.testnav.libs.dto.skattekortservice.v1.Skattekort; +import no.nav.testnav.libs.dto.skattekortservice.v1.Skattekortmelding; +import no.nav.testnav.libs.dto.skattekortservice.v1.Tabelltype; +import no.nav.testnav.libs.dto.skattekortservice.v1.Tilleggsopplysning; +import no.nav.testnav.libs.dto.skattekortservice.v1.Trekkode; +import no.nav.testnav.libs.dto.skattekortservice.v1.Trekkprosent; +import no.nav.testnav.libs.dto.skattekortservice.v1.Trekktabell; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class ArbeidsgiverMappingStrategy implements MappingStrategy { + @Override + public void register(MapperFactory factory) { + + factory.classMap(SkattekortResponsIntermediate.Skattekortmelding.class, Skattekortmelding.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(SkattekortResponsIntermediate.Skattekortmelding source, Skattekortmelding target, MappingContext context) { + + target.setResultatPaaForespoersel(Resultatstatus.valueOf(source.getResultatPaaForespoersel().getValue())); + target.setArbeidstakeridentifikator(source.getArbeidstakeridentifikator()); + target.setSkattekort(mapperFacade.map(source.getSkattekort(), Skattekort.class)); + target.setTilleggsopplysning(source.getTilleggsopplysning().stream() + .map(tilleggsopplysning -> Tilleggsopplysning.valueOf(tilleggsopplysning.getValue())) + .toList()); + target.setInntektsaar(source.getInntektsaar()); + } + }) + .register(); + + factory.classMap(SkattekortResponsIntermediate.Forskuddstrekk.class, Forskuddstrekk.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(SkattekortResponsIntermediate.Forskuddstrekk source, Forskuddstrekk target, MappingContext context) { + + target.setTrekkode(Trekkode.valueOf(source.getTrekkode().getValue())); + } + }) + .register(); + + factory.classMap(SkattekortResponsIntermediate.Frikort.class, Frikort.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(SkattekortResponsIntermediate.Frikort source, Frikort target, MappingContext context) { + + target.setTrekkode(Trekkode.valueOf(source.getTrekkode().getValue())); + target.setFrikortbeloep(source.getFrikortbeloep()); + } + }) + .register(); + + factory.classMap(SkattekortResponsIntermediate.Trekktabell.class, Trekktabell.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(SkattekortResponsIntermediate.Trekktabell source, Trekktabell target, MappingContext context) { + + target.setTrekkode(Trekkode.valueOf(source.getTrekkode().getValue())); + target.setTabelltype(Tabelltype.valueOf(source.getTabelltype().getValue())); + target.setTabellnummer(source.getTabellnummer()); + target.setProsentsats(source.getProsentsats()); + target.setAntallMaanederForTrekk(source.getAntallMaanederForTrekk()); + } + }) + .register(); + + factory.classMap(SkattekortResponsIntermediate.Trekkprosent.class, Trekkprosent.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(SkattekortResponsIntermediate.Trekkprosent source, Trekkprosent target, MappingContext context) { + + target.setTrekkode(Trekkode.valueOf(target.getTrekkode().getValue())); + target.setProsentsats(source.getProsentsats()); + target.setAntallMaanederForTrekk(source.getAntallMaanederForTrekk()); + } + }) + .register(); + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/MappingStrategy.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/MappingStrategy.java new file mode 100644 index 00000000000..f5431abea8d --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/MappingStrategy.java @@ -0,0 +1,19 @@ +package no.nav.skattekortservice.mapper; + +import ma.glasnost.orika.MapperFactory; + +@FunctionalInterface +public interface MappingStrategy { + + /** + * A callback for registering criteria on the provided {@link MapperFactory}. + *

+ *

{@code
+     *
+     * @Override public void register(MapperFactory factory) {
+     * factory.registerMapper(arbeidsfordelingToRestArbeidsfordeling());
+     * }
+     * }
+ */ + void register(MapperFactory factory); +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/TrekktypeMappingStrategy.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/TrekktypeMappingStrategy.java new file mode 100644 index 00000000000..0d6d81dfd77 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/TrekktypeMappingStrategy.java @@ -0,0 +1,85 @@ +package no.nav.skattekortservice.mapper; + +import ma.glasnost.orika.CustomMapper; +import ma.glasnost.orika.MapperFactory; +import ma.glasnost.orika.MappingContext; +import no.nav.skattekortservice.dto.SkattekortResponsIntermediate; +import no.nav.testnav.libs.dto.skattekortservice.v1.Forskuddstrekk; +import no.nav.testnav.libs.dto.skattekortservice.v1.Frikort; +import no.nav.testnav.libs.dto.skattekortservice.v1.Skattekort; +import no.nav.testnav.libs.dto.skattekortservice.v1.Trekkprosent; +import no.nav.testnav.libs.dto.skattekortservice.v1.Trekktabell; +import no.nav.testnav.libs.dto.skattekortservice.v1.Trekktype; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +import static java.util.Objects.nonNull; + +@Component +public class TrekktypeMappingStrategy implements MappingStrategy { + @Override + public void register(MapperFactory factory) { + + factory.classMap(Skattekort.class, no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Skattekort.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(Skattekort skattekort, no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Skattekort skattekort2, MappingContext context) { + + skattekort2.getForskuddstrekk().addAll(skattekort.getTrekktype().stream() + .map(trekktype -> { + if (nonNull(trekktype.getFrikort())) { + return mapperFacade.map(trekktype.getFrikort(), + no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Frikort.class); + } else if (nonNull(trekktype.getTrekktabell())) { + return mapperFacade.map(trekktype.getTrekktabell(), + no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Trekktabell.class); + } else if (nonNull(trekktype.getTrekkprosent())) { + return mapperFacade.map(trekktype.getTrekkprosent(), + no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Trekkprosent.class); + } else if (nonNull(trekktype.getForskuddstrekk())) { + return mapperFacade.map(trekktype.getForskuddstrekk(), + no.skatteetaten.fastsetting.formueinntekt.forskudd.skattekorttilarbeidsgiver.v3.Forskuddstrekk.class); + } else { + return null; + } + }) + .filter(Objects::nonNull) + .toList()); + } + }) + .exclude("trekktype") + .byDefault() + .register(); + + factory.classMap(SkattekortResponsIntermediate.Skattekort.class, Skattekort.class) + .customize(new CustomMapper<>() { + @Override + public void mapAtoB(SkattekortResponsIntermediate.Skattekort skattekort, Skattekort skattekort2, MappingContext context) { + + skattekort2.getTrekktype().addAll(skattekort.getFrikort().stream() + .map(frikort -> Trekktype.builder() + .frikort(mapperFacade.map(frikort, Frikort.class)) + .build()) + .toList()); + skattekort2.getTrekktype().addAll(skattekort.getForskuddstrekk().stream() + .map(forskuddstrekk -> Trekktype.builder() + .forskuddstrekk(mapperFacade.map(forskuddstrekk, Forskuddstrekk.class)) + .build()) + .toList()); + skattekort2.getTrekktype().addAll(skattekort.getTrekkprosent().stream() + .map(trekkprosent -> Trekktype.builder() + .trekkprosent(mapperFacade.map(trekkprosent, Trekkprosent.class)) + .build()) + .toList()); + skattekort2.getTrekktype().addAll(skattekort.getTrekktabell().stream() + .map(trekktabell -> Trekktype.builder() + .trekktabell(mapperFacade.map(trekktabell, Trekktabell.class)) + .build()) + .toList()); + } + }) + .byDefault() + .register(); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/XmlGregorianCalendarCustomMapping.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/XmlGregorianCalendarCustomMapping.java new file mode 100644 index 00000000000..5ca39529333 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/mapper/XmlGregorianCalendarCustomMapping.java @@ -0,0 +1,40 @@ +package no.nav.skattekortservice.mapper; + +import lombok.extern.slf4j.Slf4j; +import ma.glasnost.orika.MappingContext; +import ma.glasnost.orika.converter.BidirectionalConverter; +import ma.glasnost.orika.metadata.Type; +import org.springframework.stereotype.Component; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import java.time.LocalDate; + +@Slf4j +@Component +public class XmlGregorianCalendarCustomMapping extends BidirectionalConverter { + + @Override + public LocalDate convertTo(XMLGregorianCalendar calendar, Type type, MappingContext mappingContext) { + + return LocalDate.of(calendar.getYear(), calendar.getMonth(), calendar.getDay()); + } + + @Override + public XMLGregorianCalendar convertFrom(LocalDate dateTime, Type type, MappingContext mappingContext) { + + try { + XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(); + xmlGregorianCalendar.setYear(dateTime.getYear()); + xmlGregorianCalendar.setMonth(dateTime.getMonthValue()); + xmlGregorianCalendar.setDay(dateTime.getDayOfMonth()); + + return xmlGregorianCalendar; + + } catch (DatatypeConfigurationException e) { + log.debug("XmlGregorianCalendar to LocalDateTime conversion error", e); + } + return null; + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/provider/KodeverkController.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/provider/KodeverkController.java new file mode 100644 index 00000000000..1a98e608881 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/provider/KodeverkController.java @@ -0,0 +1,25 @@ +package no.nav.skattekortservice.provider; + +import lombok.RequiredArgsConstructor; +import no.nav.skattekortservice.service.KodeverkService; +import no.nav.testnav.libs.dto.skattekortservice.v1.KodeverkTyper; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/api/v1/kodeverk") +@RequiredArgsConstructor +public class KodeverkController { + + private final KodeverkService kodeverkService; + + @GetMapping + public Map getKodeverk(@RequestParam KodeverkTyper kodeverkstype) { + + return kodeverkService.getType(kodeverkstype); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/provider/SkattekortController.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/provider/SkattekortController.java new file mode 100644 index 00000000000..b72716cb42f --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/provider/SkattekortController.java @@ -0,0 +1,35 @@ +package no.nav.skattekortservice.provider; + +import lombok.RequiredArgsConstructor; +import no.nav.skattekortservice.service.SkattekortService; +import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortRequestDTO; +import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortResponseDTO; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/skattekort") +public class SkattekortController { + + private final SkattekortService skattekortService; + + @PostMapping(produces = MediaType.ALL_VALUE) + public Mono sendSkattekort(@RequestBody SkattekortRequestDTO skattekort) { + + return skattekortService.sendSkattekort(skattekort); + } + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public Flux hentSkattekort(@RequestParam String ident) { + + return skattekortService.hentSkattekort(ident); + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/service/KodeverkService.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/service/KodeverkService.java new file mode 100644 index 00000000000..60360677e05 --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/service/KodeverkService.java @@ -0,0 +1,49 @@ +package no.nav.skattekortservice.service; + +import lombok.Builder; +import lombok.Data; +import no.nav.testnav.libs.dto.skattekortservice.v1.KodeverkTyper; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; +import java.util.stream.Collectors; + +@Service +public class KodeverkService { + public Map getType(KodeverkTyper kodeverkstype) { + + return new TreeMap<>( + Arrays.stream(kodeverkstype.getValue().getEnumConstants()) + .map(Objects::toString) + .map(type -> type.split(",")) + .map(splitType -> Mapping.builder() + .key(getValue(splitType[1])) + .value(splitType[0]) + .build()) + .collect(Collectors.toMap(Mapping::getKey, Mapping::getValue)) + ); + } + + private static String getValue(String rawValue) { + + var value = String.join(" ", StringUtils.splitByCharacterTypeCamelCase(rawValue)); + return value.substring(0, 1).toUpperCase() + value.substring(1).toLowerCase() + .replace("oe", "ø") + .replace("aa", "å") + .replace("ok", "OK") + .replace("nav", "NAV") + .replace("svalbard", "Svalbard"); + } + + @Data + @Builder + public static class Mapping { + + private String key; + private String value; + } +} diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/service/SkattekortService.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/service/SkattekortService.java new file mode 100644 index 00000000000..c116642a81f --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/service/SkattekortService.java @@ -0,0 +1,116 @@ +package no.nav.skattekortservice.service; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import ma.glasnost.orika.MapperFacade; +import no.nav.skattekortservice.consumer.SokosSkattekortConsumer; +import no.nav.skattekortservice.dto.SkattekortRequest; +import no.nav.skattekortservice.dto.SkattekortResponsIntermediate; +import no.nav.skattekortservice.dto.SokosRequest; +import no.nav.skattekortservice.dto.SokosResponse; +import no.nav.skattekortservice.utility.SkattekortValidator; +import no.nav.testnav.libs.dto.skattekortservice.v1.Arbeidsgiver; +import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortRequestDTO; +import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortResponseDTO; +import org.json.XML; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.List; + +@Slf4j +@Service +public class SkattekortService { + + private final JAXBContext jaxbContext; + private final MapperFacade mapperFacade; + private final SokosSkattekortConsumer skattekortConsumer; + private final ObjectMapper objectMapper; + + public SkattekortService(MapperFacade mapperFacade, + SokosSkattekortConsumer skattekortConsumer, + ObjectMapper objectMapper) throws JAXBException { + this.jaxbContext = JAXBContext.newInstance(SkattekortRequest.class); + this.mapperFacade = mapperFacade; + this.skattekortConsumer = skattekortConsumer; + this.objectMapper = objectMapper; + } + + @SneakyThrows + public Mono sendSkattekort(SkattekortRequestDTO skattekort) { + + SkattekortValidator.validate(skattekort); + + var arbeidstaker = skattekort.getArbeidsgiver().getFirst() + .getArbeidstaker().getFirst(); + + return Mono.just(mapperFacade.map(skattekort, SkattekortRequest.class)) + .map(this::marshallToXml) + .doOnNext(xmlRequest -> log.info("XML Request: {}", xmlRequest)) + .map(this::encodeRequest) + .doOnNext(encodedXml -> log.info("Base64 encoded request: {}", encodedXml)) + .map(encodedXml -> SokosRequest.builder() + .fnr(arbeidstaker.getArbeidstakeridentifikator()) + .inntektsar(arbeidstaker.getInntektsaar().toString()) + .skattekort(encodedXml) + .build()) + .flatMap(skattekortConsumer::sendSkattekort); + } + + public Flux hentSkattekort(String ident) { + + return skattekortConsumer.hentSkattekort(ident) + .doOnNext(response -> log.info("Hentet resultat fra Sokos {}", response)) + .map(this::convertResponse); + } + + @SneakyThrows + private String marshallToXml(SkattekortRequest melding) { + + var marshaller = jaxbContext.createMarshaller(); + var writer = new StringWriter(); + marshaller.marshal(melding, writer); + return writer.toString() + .replace(":ns2", "") + .replace("ns2:", ""); + } + + private String encodeRequest(String request) { + + return Base64.getEncoder() + .encodeToString(request.getBytes(StandardCharsets.UTF_8)); + } + + private SkattekortResponseDTO convertResponse(SokosResponse response) { + + var decoded = decodeRequest(response.getSkattekort()); + var unmarshalled = unmarshal(decoded); + return SkattekortResponseDTO.builder() + .ident(response.getFnr()) + .inntektsaar(response.getInntektsar()) + .arbeidsgiver(unmarshalled) + .skattekortXml(decoded) + .build(); + } + + private String decodeRequest(String request) { + + return new String(Base64.getDecoder().decode(request), StandardCharsets.UTF_8) + .replaceAll("\n *", ""); + } + + @SneakyThrows + private List unmarshal(String xmlData) { + + var jsonRoot = XML.toJSONObject(xmlData); + var intermediate = objectMapper.readValue(jsonRoot.toString(), SkattekortResponsIntermediate.class); + return mapperFacade.mapAsList(intermediate.getSkattekortTilArbeidsgiver().getArbeidsgiver(), Arbeidsgiver.class); + } +} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/java/no/nav/skattekortservice/utility/SkattekortValidator.java b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/utility/SkattekortValidator.java new file mode 100644 index 00000000000..6c4a87dc66a --- /dev/null +++ b/apps/skattekort-service/src/main/java/no/nav/skattekortservice/utility/SkattekortValidator.java @@ -0,0 +1,77 @@ +package no.nav.skattekortservice.utility; + +import lombok.experimental.UtilityClass; +import no.nav.testnav.libs.dto.skattekortservice.v1.Arbeidsgiver; +import no.nav.testnav.libs.dto.skattekortservice.v1.Skattekort; +import no.nav.testnav.libs.dto.skattekortservice.v1.SkattekortRequestDTO; +import no.nav.testnav.libs.dto.skattekortservice.v1.Skattekortmelding; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +import java.util.Collection; + +@UtilityClass +public class SkattekortValidator { + + public static void validate(SkattekortRequestDTO skattekort) { + + validateArbeidsgiver(skattekort); + + validateArbeidstager(skattekort); + + validateSkattekort(skattekort); + } + + private static void validateSkattekort(SkattekortRequestDTO skattekort) { + + skattekort.getArbeidsgiver().stream() + .map(Arbeidsgiver::getArbeidstaker) + .flatMap(Collection::stream) + .map(Skattekortmelding::getSkattekort) + .map(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(SkattekortRequestDTO skattekort) { + + skattekort.getArbeidsgiver().stream() + .map(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(SkattekortRequestDTO skattekort) { + + skattekort.getArbeidsgiver().stream() + .map(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"); + } + }); + } +} diff --git a/apps/skattekort-service/src/main/resources/application-prod.yaml b/apps/skattekort-service/src/main/resources/application-prod.yaml new file mode 100644 index 00000000000..0311ce578e3 --- /dev/null +++ b/apps/skattekort-service/src/main/resources/application-prod.yaml @@ -0,0 +1,8 @@ +spring: + security: + oauth2: + resourceserver: + tokenx: + issuer-uri: ${TOKEN_X_ISSUER} + jwk-set-uri: ${TOKEN_X_JWKS_URI} + accepted-audience: ${TOKEN_X_CLIENT_ID} \ No newline at end of file diff --git a/apps/skattekort-service/src/main/resources/application.yaml b/apps/skattekort-service/src/main/resources/application.yaml new file mode 100644 index 00000000000..b4e0d63057f --- /dev/null +++ b/apps/skattekort-service/src/main/resources/application.yaml @@ -0,0 +1,51 @@ +AAD_ISSUER_URI: https://login.microsoftonline.com/62366534-1ec3-4962-8869-9b5535279d0b + +spring: + application: + name: Testnav-Skattekort-Service + version: 1.0 + description: Service for å sende inn skattekort + cloud: + vault: + enabled: false + security: + oauth2: + resourceserver: + aad: + issuer-uri: ${AAD_ISSUER_URI}/v2.0 + jwk-set-uri: ${AAD_ISSUER_URI}/discovery/v2.0/keys + accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} + +springdoc: + swagger-ui: + disable-swagger-default-url: true + url: /v3/api-docs + +management: + endpoints: + enabled-by-default: true + web: + base-path: /internal + exposure.include: prometheus,heapdump,health + path-mapping: + prometheus: metrics + endpoint: + prometheus.enabled: true + heapdump.enabled: true + prometheus: + metrics: + export: + enabled: true +server: + servlet: + encoding: + charset: UTF-8 + error: + include-message: always + +consumers: + sokos-skattekort: + url: https://sokos-skattekort-dolly.dev-fss-pub.nais.io + cluster: dev-fss + name: sokos-skattekort-dolly + namespace: okonomi diff --git a/apps/skattekort-service/src/main/resources/bootstrap.yml b/apps/skattekort-service/src/main/resources/bootstrap.yml new file mode 100644 index 00000000000..0451449ca23 --- /dev/null +++ b/apps/skattekort-service/src/main/resources/bootstrap.yml @@ -0,0 +1,4 @@ +spring: + cloud: + vault: + enabled: false \ No newline at end of file diff --git a/apps/skattekort-service/src/main/resources/logback-spring.xml b/apps/skattekort-service/src/main/resources/logback-spring.xml new file mode 100644 index 00000000000..ca13d7d7df4 --- /dev/null +++ b/apps/skattekort-service/src/main/resources/logback-spring.xml @@ -0,0 +1,39 @@ + + + + + + + true + 256 + 10280 + 20 + ^sun\.reflect\..*\.invoke + ^net\.sf\.cglib\.proxy\.MethodProxy\.invoke + java\.util\.concurrent\..* + org\.apache\.catalina\..* + org\.apache\.coyote\..* + org\.apache\.tomcat\..* + + + + + + + + + + + + + %d{HH:mm:ss.SSS} | %5p | %logger{25} | %m%n + + utf8 + + + + + + + + diff --git a/apps/skattekort-service/src/main/resources/schema/skattekorttilarbeidsgiver_v3.0.xsd b/apps/skattekort-service/src/main/resources/schema/skattekorttilarbeidsgiver_v3.0.xsd new file mode 100644 index 00000000000..781613dcf98 --- /dev/null +++ b/apps/skattekort-service/src/main/resources/schema/skattekorttilarbeidsgiver_v3.0.xsd @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/skattekort-service/src/main/resources/xjb/global-binding.xjb b/apps/skattekort-service/src/main/resources/xjb/global-binding.xjb new file mode 100644 index 00000000000..c293dd047e9 --- /dev/null +++ b/apps/skattekort-service/src/main/resources/xjb/global-binding.xjb @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/skattekort-service/src/test/java/no/nav/skattekortservice/ApplicationContextTest.java b/apps/skattekort-service/src/test/java/no/nav/skattekortservice/ApplicationContextTest.java new file mode 100644 index 00000000000..32aa46b1bf2 --- /dev/null +++ b/apps/skattekort-service/src/test/java/no/nav/skattekortservice/ApplicationContextTest.java @@ -0,0 +1,18 @@ +package no.nav.skattekortservice; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@ActiveProfiles("test") +@SpringBootTest +class ApplicationContextTest { + + @Test + @SuppressWarnings("java:S2699") + void load_app_context() { + assertThat(true).isTrue(); + } +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Arbeidsgiver.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Arbeidsgiver.java new file mode 100644 index 00000000000..24de5895b0f --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Arbeidsgiver.java @@ -0,0 +1,29 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Arbeidsgiver { + + private IdentifikatorForEnhetEllerPerson arbeidsgiveridentifikator; + private List arbeidstaker; + + public List getArbeidstaker() { + + if (isNull(arbeidstaker)) { + arbeidstaker = new ArrayList<>(); + } + return arbeidstaker; + } +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Forskuddstrekk.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Forskuddstrekk.java new file mode 100644 index 00000000000..0d2dc40687a --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Forskuddstrekk.java @@ -0,0 +1,15 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Forskuddstrekk { + + private Trekkode trekkode; +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Frikort.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Frikort.java new file mode 100644 index 00000000000..2029b546afa --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Frikort.java @@ -0,0 +1,17 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Frikort { + + private Trekkode trekkode; + + private Integer frikortbeloep; +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/IdentifikatorForEnhetEllerPerson.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/IdentifikatorForEnhetEllerPerson.java new file mode 100644 index 00000000000..8591384cc47 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/IdentifikatorForEnhetEllerPerson.java @@ -0,0 +1,34 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class IdentifikatorForEnhetEllerPerson { + + private String organisasjonsnummer; + private String personidentifikator; + + @JsonIgnore + public boolean isAllEmpty() { + + return isBlank(organisasjonsnummer) && + isBlank(personidentifikator); + } + + @JsonIgnore + public boolean isAmbiguous() { + + return isNotBlank(organisasjonsnummer) && + isNotBlank(personidentifikator); + } +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/KodeverkTyper.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/KodeverkTyper.java new file mode 100644 index 00000000000..79fc879e739 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/KodeverkTyper.java @@ -0,0 +1,16 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum KodeverkTyper { + + RESULTATSTATUS(Resultatstatus.class), + TABELLTYPE(Tabelltype.class), + TILLEGGSOPPLYSNING(Tilleggsopplysning.class), + TREKKODE(Trekkode.class); + + private final Class value; +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Resultatstatus.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Resultatstatus.java new file mode 100644 index 00000000000..836643e2b3d --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Resultatstatus.java @@ -0,0 +1,24 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Resultatstatus { + + IKKE_SKATTEKORT("ikkeSkattekort"), + VURDER_ARBEIDSTILLATELSE("vurderArbeidstillatelse"), + IKKE_TREKKPLIKT("ikkeTrekkplikt"), + SKATTEKORTOPPLYSNINGER_OK("skattekortopplysningerOK"), + UGYLDIG_ORGANISASJONSNUMMER("ugyldigOrganisasjonsnummer"), + UGYLDIG_FOEDSELS_ELLER_DNUMMER("ugyldigFoedselsEllerDnummer"), + UTGAATT_DNUMMER_SKATTEKORT_FOR_FOEDSELSNUMMER_ER_LEVERT("utgaattDnummerSkattekortForFoedselsnummerErLevert"); + + private final String value; + + @Override + public String toString() { + return this.name() + "," + value; + } +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Skattekort.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Skattekort.java new file mode 100644 index 00000000000..b7f872e60a1 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Skattekort.java @@ -0,0 +1,32 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Skattekort { + + private LocalDate utstedtDato; + private Long skattekortidentifikator; + private List trekktype; + + public List getTrekktype() { + + if (isNull(trekktype)) { + trekktype = new ArrayList<>(); + } + return trekktype; + + } +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/SkattekortRequestDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/SkattekortRequestDTO.java new file mode 100644 index 00000000000..0aa629dd051 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/SkattekortRequestDTO.java @@ -0,0 +1,28 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SkattekortRequestDTO { + + private List arbeidsgiver; + + public List getArbeidsgiver() { + + if (isNull(arbeidsgiver)) { + arbeidsgiver = new ArrayList<>(); + } + return arbeidsgiver; + } +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/SkattekortResponseDTO.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/SkattekortResponseDTO.java new file mode 100644 index 00000000000..e0a95fe06c9 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/SkattekortResponseDTO.java @@ -0,0 +1,31 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SkattekortResponseDTO { + + private String ident; + private String inntektsaar; + private List arbeidsgiver; + private String skattekortXml; + + public List getArbeidsgiver() { + + if (isNull(arbeidsgiver)) { + arbeidsgiver = new ArrayList<>(); + } + return arbeidsgiver; + } +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Skattekortmelding.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Skattekortmelding.java new file mode 100644 index 00000000000..4eaf33d4d27 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Skattekortmelding.java @@ -0,0 +1,47 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +import static java.util.Objects.isNull; +import static org.apache.commons.lang3.StringUtils.isBlank; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Skattekortmelding { + + + private String arbeidstakeridentifikator; + private Resultatstatus resultatPaaForespoersel; + private Skattekort skattekort; + private List tilleggsopplysning; + private Integer inntektsaar; + + public List getTilleggsopplysning() { + + if (isNull(tilleggsopplysning)) { + tilleggsopplysning = new ArrayList<>(); + } + return tilleggsopplysning; + } + + @JsonIgnore + public boolean isEmptyArbeidstakeridentifikator() { + + return isBlank(arbeidstakeridentifikator); + } + + @JsonIgnore + public boolean isEmptyInntektsaar() { + + return isNull(inntektsaar); + } +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Tabelltype.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Tabelltype.java new file mode 100644 index 00000000000..ac5b7220f94 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Tabelltype.java @@ -0,0 +1,19 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Tabelltype { + + TREKKTABELL_FOR_PENSJON("trekktabellForPensjon"), + TREKKTABELL_FOR_LOENN("trekktabellForLoenn"); + + private final String value; + + @Override + public String toString() { + return this.name() + "," + value; + } +} diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Tilleggsopplysning.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Tilleggsopplysning.java new file mode 100644 index 00000000000..2270c7afebd --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Tilleggsopplysning.java @@ -0,0 +1,21 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Tilleggsopplysning { + + OPPHOLD_PAA_SVALBARD("oppholdPaaSvalbard"), + KILDESKATTPENSJONIST("kildeskattpensjonist"), + OPPHOLD_I_TILTAKSSONE("oppholdITiltakssone"), + KILDESKATT_PAA_LOENN("kildeskattPaaLoenn"); + + private final String value; + + @Override + public String toString() { + return this.name() + "," + value; + } +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekkode.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekkode.java new file mode 100644 index 00000000000..14ce2270ff6 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekkode.java @@ -0,0 +1,29 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Trekkode { + + LOENN_FRA_HOVEDARBEIDSGIVER("loennFraHovedarbeidsgiver"), + LOENN_FRA_BIARBEIDSGIVER("loennFraBiarbeidsgiver"), + LOENN_FRA_NAV("loennFraNAV"), + PENSJON("pensjon"), + PENSJON_FRA_NAV("pensjonFraNAV"), + LOENN_TIL_UTENRIKSTJENESTEMANN("loennTilUtenrikstjenestemann"), + LOENN_KUN_TRYGDEAVGIFT_TIL_UTENLANDSK_BORGER("loennKunTrygdeavgiftTilUtenlandskBorger"), + LOENN_KUN_TRYGDEAVGIFT_TIL_UTENLANDSK_BORGER_SOM_GRENSEGJENGER("loennKunTrygdeavgiftTilUtenlandskBorgerSomGrensegjenger"), + UFOERETRYGD_FRA_NAV("ufoeretrygdFraNAV"), + UFOEREYTELSER_FRA_ANDRE("ufoereytelserFraAndre"), + INTRODUKSJONSSTOENAD("introduksjonsstoenad"); + + private final String value; + + @Override + public String toString() { + return this.name() + "," + value; + } +} + diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekkprosent.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekkprosent.java new file mode 100644 index 00000000000..ede4353e030 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekkprosent.java @@ -0,0 +1,18 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Trekkprosent { + + private Trekkode trekkode; + + private Integer prosentsats; + private Integer antallMaanederForTrekk; +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekktabell.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekktabell.java new file mode 100644 index 00000000000..550b135c901 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekktabell.java @@ -0,0 +1,20 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Trekktabell { + + private Trekkode trekkode; + + private Tabelltype tabelltype; + private String tabellnummer; + private Integer prosentsats; + private Integer antallMaanederForTrekk; +} \ No newline at end of file diff --git a/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekktype.java b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekktype.java new file mode 100644 index 00000000000..5042a2e4870 --- /dev/null +++ b/libs/data-transfer-objects/src/main/java/no/nav/testnav/libs/dto/skattekortservice/v1/Trekktype.java @@ -0,0 +1,47 @@ +package no.nav.testnav.libs.dto.skattekortservice.v1; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.util.Arrays; +import java.util.Objects; + +@Data +@SuperBuilder +@NoArgsConstructor +public class Trekktype { + + private Forskuddstrekk forskuddstrekk; + private Frikort frikort; + private Trekktabell trekktabell; + private Trekkprosent trekkprosent; + + @JsonIgnore + public boolean isAllEmpty() { + + return contentsCount() == 0; + } + + @JsonIgnore + public boolean isAmbiguous() { + + return contentsCount() > 1; + } + + private long contentsCount() { + + return Arrays.stream(getClass().getDeclaredFields()) + .map(field -> { + try { + field.setAccessible(true); + return field.get(this); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + }) + .filter(Objects::nonNull) + .count(); + } +} diff --git a/settings.gradle b/settings.gradle index 9c5dda9f214..21529e70cd8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -122,6 +122,8 @@ includeBuild './apps/tilbakemelding-api' includeBuild './apps/tps-messaging-service' includeBuild './apps/udi-stub' includeBuild './apps/varslinger-service' +includeBuild './apps/dollystatus' +includeBuild './apps/skattekort-service' includeBuild './xsd/arbeidsforhold-xsd'