-
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.
Add mapping strategy and Swagger adjustments
Implemented a MapperFacade configuration to handle custom mapping strategies and converters. Improved Swagger setup by refining security configurations and customizing views. Enhanced OppdragRequest DTO with additional schema information and data types for better validation and XML support. Additionally, added basic unit tests for mapping strategies and updated dependencies in the build configuration.
- Loading branch information
Showing
14 changed files
with
345 additions
and
84 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
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
36 changes: 36 additions & 0 deletions
36
...ppdrag-service/src/main/java/no/nav/testnav/oppdragservice/config/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.testnav.oppdragservice.config; | ||
|
||
import ma.glasnost.orika.CustomConverter; | ||
import ma.glasnost.orika.MapperFacade; | ||
import ma.glasnost.orika.impl.DefaultMapperFactory; | ||
import no.nav.testnav.oppdragservice.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<MappingStrategy> mappingStrategies, List<CustomConverter> customConverters) { | ||
var mapperFactory = new DefaultMapperFactory.Builder().build(); | ||
|
||
if (nonNull(mappingStrategies)) { | ||
for (var mapper : mappingStrategies) { | ||
mapper.register(mapperFactory); | ||
} | ||
} | ||
|
||
if (nonNull(customConverters)) { | ||
for (var converter : customConverters) { | ||
mapperFactory.getConverterFactory().registerConverter(converter); | ||
} | ||
} | ||
|
||
return mapperFactory.getMapperFacade(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,8 @@ | |
|
||
@Service | ||
public class OppdragConsumer { | ||
|
||
public void sendOppdrag(String xmlPayload) { | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
apps/oppdrag-service/src/main/java/no/nav/testnav/oppdragservice/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.testnav.oppdragservice.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); | ||
} |
43 changes: 43 additions & 0 deletions
43
...ice/src/main/java/no/nav/testnav/oppdragservice/mapper/OppdragRequestMappingStrategy.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,43 @@ | ||
package no.nav.testnav.oppdragservice.mapper; | ||
|
||
import ma.glasnost.orika.CustomMapper; | ||
import ma.glasnost.orika.MapperFactory; | ||
import ma.glasnost.orika.MappingContext; | ||
import no.nav.testnav.libs.dto.oppdragservice.v1.OppdragRequest; | ||
import no.nav.testnav.oppdragservice.wsdl.Oppdrag; | ||
import no.nav.testnav.oppdragservice.wsdl.SendInnOppdragRequest; | ||
import no.nav.testnav.oppdragservice.wsdl.SendInnOppdragRequest2; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OppdragRequestMappingStrategy implements MappingStrategy{ | ||
|
||
@Override | ||
public void register(MapperFactory factory) { | ||
|
||
factory.classMap(OppdragRequest.class, SendInnOppdragRequest.class) | ||
.customize(new CustomMapper<>() { | ||
@Override | ||
public void mapAtoB(OppdragRequest source, | ||
SendInnOppdragRequest destination, | ||
MappingContext context) { | ||
|
||
destination.setRequest(mapperFacade.map(source, SendInnOppdragRequest2.class, context)); | ||
} | ||
}) | ||
.register(); | ||
|
||
factory.classMap(OppdragRequest.class, Oppdrag.class) | ||
.customize(new CustomMapper<>() { | ||
@Override | ||
public void mapAtoB(OppdragRequest source, | ||
Oppdrag destination, | ||
MappingContext context) { | ||
|
||
|
||
} | ||
}) | ||
.byDefault() | ||
.register(); | ||
} | ||
} |
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
34 changes: 33 additions & 1 deletion
34
apps/oppdrag-service/src/main/java/no/nav/testnav/oppdragservice/service/OppdragService.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 |
---|---|---|
@@ -1,14 +1,46 @@ | ||
package no.nav.testnav.oppdragservice.service; | ||
|
||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBException; | ||
import lombok.SneakyThrows; | ||
import ma.glasnost.orika.MapperFacade; | ||
import no.nav.testnav.libs.dto.oppdragservice.v1.OppdragRequest; | ||
import no.nav.testnav.oppdragservice.consumer.OppdragConsumer; | ||
import no.nav.testnav.oppdragservice.wsdl.SendInnOppdragRequest; | ||
import no.nav.testnav.oppdragservice.wsdl.SendInnOppdragResponse; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.StringWriter; | ||
|
||
@Service | ||
public class OppdragService { | ||
|
||
private final JAXBContext jaxbContext; | ||
private final OppdragConsumer oppdragConsumer; | ||
private final MapperFacade mapperFacade; | ||
|
||
public OppdragService(OppdragConsumer oppdragConsumer, MapperFacade mapperFacade) throws JAXBException { | ||
this.oppdragConsumer = oppdragConsumer; | ||
this.mapperFacade = mapperFacade; | ||
this.jaxbContext = JAXBContext.newInstance(SendInnOppdragRequest.class); | ||
} | ||
|
||
public SendInnOppdragResponse sendInnOppdrag(OppdragRequest oppdragRequest) { | ||
|
||
var request = mapperFacade.map(oppdragRequest, SendInnOppdragRequest.class); | ||
var xmlRequest = marshallToXml(request); | ||
|
||
oppdragConsumer.sendOppdrag(xmlRequest); | ||
return null; | ||
} | ||
|
||
@SneakyThrows | ||
private String marshallToXml(SendInnOppdragRequest melding) { | ||
|
||
var marshaller = jaxbContext.createMarshaller(); | ||
var writer = new StringWriter(); | ||
marshaller.marshal(melding, writer); | ||
|
||
return writer.toString(); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/oppdrag-service/src/test/java/no/nav/testnav/oppdragservice/mapper/MapperTestUtils.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,27 @@ | ||
package no.nav.testnav.oppdragservice.mapper; | ||
|
||
import ma.glasnost.orika.CustomConverter; | ||
import ma.glasnost.orika.MapperFacade; | ||
import ma.glasnost.orika.impl.DefaultMapperFactory; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
public class MapperTestUtils { | ||
|
||
public static MapperFacade createMapperFacadeForMappingStrategy(MappingStrategy... strategies) { | ||
return createMapperFacadeForMappingStrategy(null, strategies); | ||
} | ||
|
||
public static MapperFacade createMapperFacadeForMappingStrategy(CustomConverter<Object, Object> converter, MappingStrategy... strategies) { | ||
DefaultMapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); | ||
|
||
for (MappingStrategy strategy : strategies) { | ||
strategy.register(mapperFactory); | ||
} | ||
|
||
if (nonNull(converter)) { | ||
mapperFactory.getConverterFactory().registerConverter(converter); | ||
} | ||
return mapperFactory.getMapperFacade(); | ||
} | ||
} |
Oops, something went wrong.