-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve mapping and logging functionalities
- Loading branch information
Showing
26 changed files
with
213 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...n/java/no/nav/registre/inntektsmeldinggeneratorservice/mapper/LocalDateCustomMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../main/java/no/nav/registre/inntektsmeldinggeneratorservice/mapper/MapperFacadeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
|
||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...main/java/no/nav/registre/inntektsmeldinggeneratorservice/mapper/MappingContextUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/no/nav/registre/inntektsmeldinggeneratorservice/mapper/MappingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...a/no/nav/registre/inntektsmeldinggeneratorservice/v20181211/dto/v1/AvsendersystemDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...va/no/nav/registre/inntektsmeldinggeneratorservice/v20181211/dto/v1/DelvisFravearDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...no/nav/registre/inntektsmeldinggeneratorservice/v20181211/dto/v1/EndringIRefusjonDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...egistre/inntektsmeldinggeneratorservice/v20181211/dto/v1/GraderingIForeldrepengerDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...a/no/nav/registre/inntektsmeldinggeneratorservice/v20181211/dto/v1/OmsorgspenegerDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.