Skip to content

Commit

Permalink
Improve mapping and logging functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Feb 8, 2024
1 parent 9596a50 commit 2de2e1d
Show file tree
Hide file tree
Showing 26 changed files with 213 additions and 45 deletions.
2 changes: 1 addition & 1 deletion apps/inntektsmelding-generator-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ghcr.io/navikt/baseimages/temurin:21
LABEL maintainer="Team Dolly"

ENV JAVA_OPTS="-Dspring.profiles.active=prod"
ENV JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED -Dspring.profiles.active=prod"

ADD /build/libs/app.jar /app/app.jar

Expand Down
1 change: 1 addition & 0 deletions apps/inntektsmelding-generator-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {
implementation 'javax.activation:activation:1.1.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.8'
implementation 'com.sun.xml.bind:jaxb-core:2.3.0.1'
implementation 'ma.glasnost.orika:orika-core:1.5.4'

implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
implementation 'org.apache.commons:commons-text:1.10.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package no.nav.registre.inntektsmeldinggeneratorservice.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 java.time.LocalDate;
import java.time.LocalDateTime;

@Slf4j
@Component
public class LocalDateCustomMapping extends BidirectionalConverter<LocalDateTime, LocalDate> {

@Override
public LocalDate convertTo(LocalDateTime localDateTime, Type<LocalDate> type, MappingContext mappingContext) {
return localDateTime.toLocalDate();
}

@Override
public LocalDateTime convertFrom(LocalDate localDate, Type<LocalDateTime> type, MappingContext mappingContext) {
return localDate.atStartOfDay();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package no.nav.registre.inntektsmeldinggeneratorservice.mapper;

import ma.glasnost.orika.CustomConverter;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

import static java.util.Objects.nonNull;

@Configuration
public class MapperFacadeConfig {

@Bean
MapperFacade mapperFacade(List<MappingStrategy> mappingStrategies, List<CustomConverter> 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();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package no.nav.registre.inntektsmeldinggeneratorservice.mapper;

import lombok.experimental.UtilityClass;
import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.MappingContextFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

/**
* The utility class to get {@link MappingContext} configured by Orika
* and ready to be used by {@link ma.glasnost.orika.MapperFacade#map(Object, Class)}.
*/
@UtilityClass
public final class MappingContextUtils {

private static final MappingContextFactory MAPPING_CONTEXT_FACTORY;

static {
MAPPING_CONTEXT_FACTORY = new CustomDefaultMapperFactory.Builder().build().getContextFactory();
}

/**
* Gets {@link MappingContext} ready to be used by {@link ma.glasnost.orika.MapperFacade#map(Object, Class)}.
* Manual creation of {@link MappingContext} does not work. Please see the link below.
*
* @return {@link MappingContext}
* @see <a href="https://github.com/orika-mapper/orika/issues/354">https://github.com/orika-mapper/orika/issues/354</a>
*/
public static MappingContext getMappingContext() {
return MAPPING_CONTEXT_FACTORY.getContext();
}

/**
* The custom {@link DefaultMapperFactory} to expose getter
* for {@link MappingContextFactory} so {@link MappingContext} with prefilled globalProperties can be created.
*
* @author Dmitry Lebedko ([email protected])
*/
private static class CustomDefaultMapperFactory extends DefaultMapperFactory {

/**
* Constructs a new instance of DefaultMapperFactory
*
* @param builder {@link MapperFactoryBuilder}
*/
protected CustomDefaultMapperFactory(MapperFactoryBuilder<?, ?> builder) {
super(builder);
}

/**
* Gets {@link MappingContextFactory}.
*
* @return {@link MappingContextFactory}
*/
public MappingContextFactory getContextFactory() {
return contextFactory;
}

public static class Builder extends DefaultMapperFactory.MapperFactoryBuilder<CustomDefaultMapperFactory, Builder> {

@Override
public CustomDefaultMapperFactory build() {
return new CustomDefaultMapperFactory(this);
}

@Override
protected Builder self() {
return this;
}

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package no.nav.registre.inntektsmeldinggeneratorservice.mapper;

import ma.glasnost.orika.MapperFactory;

@FunctionalInterface
public interface MappingStrategy {

/**
* A callback for registering criteria on the provided {@link MapperFactory}.
* <p/>
* <pre>{@code
*
* @Override public void register(MapperFactory factory) {
* factory.registerMapper(arbeidsfordelingToRestArbeidsfordeling());
* }
* }</pre>
*/
void register(MapperFactory factory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLArbeidsforhold;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLAvtaltFerieListe;
Expand All @@ -14,7 +14,7 @@
import java.time.LocalDate;
import java.util.List;

@Value
@Data
@NoArgsConstructor(force = true)
public class ArbeidsforholdDTO implements ToXmlElement<XMLArbeidsforhold> {
@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLArbeidsgiver;


@Value
@Data
@NoArgsConstructor(force = true)
public class ArbeidsgiverDTO implements ToXmlElement<XMLArbeidsgiver> {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLArbeidsgiverPrivat;


@Value
@Data
@NoArgsConstructor(force = true)
public class ArbeidsgiverPrivatDTO implements ToXmlElement<XMLArbeidsgiverPrivat> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLAvsendersystem;

import java.time.LocalDateTime;

@Value
@Data
@NoArgsConstructor(force = true)
public class AvsendersystemDTO implements ToXmlElement<XMLAvsendersystem> {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLDelvisFravaer;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Value
@Data
@NoArgsConstructor(force = true)
public class DelvisFravearDTO implements ToXmlElement<XMLDelvisFravaer> {
@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLEndringIRefusjon;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Value
@Data
@NoArgsConstructor(force = true)
public class EndringIRefusjonDTO implements ToXmlElement<XMLEndringIRefusjon> {
@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLGraderingIForeldrepenger;

import java.math.BigInteger;
import java.util.List;


@Value
@Data
@NoArgsConstructor(force = true)
public class GraderingIForeldrepengerDTO implements ToXmlElement<XMLGraderingIForeldrepenger> {
@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLInntekt;
import org.apache.commons.text.CaseUtils;
Expand All @@ -12,7 +12,7 @@

import static org.apache.commons.lang3.StringUtils.isBlank;

@Value
@Data
@NoArgsConstructor(force = true)
public class InntektDTO implements ToXmlElement<XMLInntekt> {
@JsonProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLGjenopptakelseNaturalytelseListe;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLInntektsmeldingM;
Expand All @@ -17,7 +17,7 @@

import static org.apache.commons.lang3.StringUtils.isBlank;

@Value
@Data
@NoArgsConstructor(force = true)
public class InntektsmeldingDTO implements ToXmlElement<XMLInntektsmeldingM> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLKontaktinformasjon;

@Value
@Data
@NoArgsConstructor(force = true)
public class KontaktinformasjonDTO implements ToXmlElement<XMLKontaktinformasjon> {
@JsonProperty(required = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLNaturalytelseDetaljer;
import org.apache.commons.text.CaseUtils;
Expand All @@ -13,7 +13,7 @@

import static org.apache.commons.lang3.StringUtils.isBlank;

@Value
@Data
@NoArgsConstructor(force = true)
public class NaturalYtelseDetaljerDTO implements ToXmlElement<XMLNaturalytelseDetaljer> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package no.nav.registre.inntektsmeldinggeneratorservice.v20181211.dto.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Value;
import no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLDelvisFravaersListe;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLFravaersPeriodeListe;
import no.seres.xsd.nav.inntektsmelding_m._20181211.XMLOmsorgspenger;

import java.util.List;


@Value
@Data
@NoArgsConstructor(force = true)
public class OmsorgspenegerDTO implements ToXmlElement<XMLOmsorgspenger> {

Expand Down
Loading

0 comments on commit 2de2e1d

Please sign in to comment.