diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequestMapper.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequestMapper.java index 219e2c3ed0ed4b6834afbfa56e63e21370b38214..8fff61717ae74b22472b217dcc21e3ee4a3ac9d8 100644 --- a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequestMapper.java +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequestMapper.java @@ -49,8 +49,12 @@ import de.ozgcloud.command.Command; import de.ozgcloud.vorgang.vorgang.GrpcCreateCollaborationRequestData; @AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = CollaborationManagerConfiguration.COLLABORATION_REQUEST_MAPPER_NAME)) -@Mapper(uses = { - CommandMapper.class }, unmappedTargetPolicy = ReportingPolicy.WARN, unmappedSourcePolicy = ReportingPolicy.WARN, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +@Mapper(uses = { CommandMapper.class }, // + unmappedTargetPolicy = ReportingPolicy.WARN, // + unmappedSourcePolicy = ReportingPolicy.WARN, // + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, // + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, // + collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) public abstract class CollaborationRequestMapper { static final String ITEM_NAME = "CollaborationRequest"; @@ -155,10 +159,7 @@ public abstract class CollaborationRequestMapper { @SuppressWarnings("unchecked") Fachstelle getZustaendigeStelleFromItemMap(Map<String, Object> propertyMap) { - var fachstelle = (Map<String, Object>) propertyMap.get(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE); - var technicalId = getStringProperty(Fachstelle.PROPERTY_TECHNICAL_ID, fachstelle); - var collaborationLevel = getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, propertyMap); - return fachstelleService.getFachstelle(technicalId, collaborationLevel); + return fachstelleMapper.fromMap((Map<String, Object>) propertyMap.get(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE)); } int getIntProperty(String key, Map<String, Object> propertyMap) { diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapper.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapper.java index dfc9c6b47e81e77d881e7918e9be163bd1330648..a7dc28c1b65e3ea1afb6bf34acc880eb739d4bbb 100644 --- a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapper.java +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapper.java @@ -6,25 +6,28 @@ import org.mapstruct.AnnotateWith; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; import org.mapstruct.ReportingPolicy; import org.springframework.stereotype.Component; import de.ozgcloud.collaboration.CollaborationManagerConfiguration; +import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleType; import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle; import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit; -@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, // + imports = FachstelleType.class) @AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = CollaborationManagerConfiguration.FACHSTELLE_MAPPER_NAME)) public interface FachstelleMapper { @Mapping(target = "technicalId", source = "id") @Mapping(target = "subjectId", source = "mukId") - @Mapping(target = "type", constant = "EXTERNE_FACHSTELLE") + @Mapping(target = "type", expression = "java(FachstelleType.EXTERNE_FACHSTELLE)") Fachstelle fromExterneFachstelle(GrpcFachstelle externeFachstelle); @Mapping(target = "technicalId", source = "id") @Mapping(target = "subjectId", source = "xzufiId.id") - @Mapping(target = "type", constant = "ORGANISATIONS_EINHEIT") + @Mapping(target = "type", expression = "java(FachstelleType.ORGANISATIONS_EINHEIT)") Fachstelle fromOrganisationsEinheit(GrpcOrganisationsEinheit organisationsEinheit); default Map<String, Object> toMap(Fachstelle fachstelle) { @@ -33,4 +36,12 @@ public interface FachstelleMapper { Fachstelle.PROPERTY_SUBJECT_ID, fachstelle.getSubjectId(), Fachstelle.PROPERTY_TYPE, fachstelle.getType().name()); } + + default Fachstelle fromMap(Map<String, Object> fachstelleMap) { + return Fachstelle.builder() + .technicalId((String) fachstelleMap.get(Fachstelle.PROPERTY_TECHNICAL_ID)) + .subjectId((String) fachstelleMap.get(Fachstelle.PROPERTY_SUBJECT_ID)) + .type(FachstelleType.valueOf((String) fachstelleMap.get(Fachstelle.PROPERTY_TYPE))) + .build(); + } } diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestMapperTest.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestMapperTest.java index b81b562d90f1507ddd96dcc5e781a63788ba056f..87aec78c83b80e76b24f865f2542134586bee3be 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestMapperTest.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestMapperTest.java @@ -46,7 +46,6 @@ import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId; import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor; import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItem; import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItemTestFactory; -import de.ozgcloud.collaboration.fachstelle.Fachstelle; import de.ozgcloud.collaboration.fachstelle.FachstelleMapper; import de.ozgcloud.collaboration.fachstelle.FachstelleService; import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; @@ -348,16 +347,16 @@ class CollaborationRequestMapperTest { private final Map<String, Object> itemMap = CollaborationRequestTestFactory.createAsMap(); @Test - void shouldGetFachstelle() { + void shouldMapFachstelle() { mapper.getZustaendigeStelleFromItemMap(itemMap); - verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL); + verify(fachstelleMapper).fromMap(CollaborationRequestTestFactory.FACHSTELLE_MAP); } @Test void shouldReturnFachstelle() { - Fachstelle expectedFachstelle = FachstelleTestFactory.create(); - when(fachstelleService.getFachstelle(anyString(), anyInt())).thenReturn(expectedFachstelle); + var expectedFachstelle = FachstelleTestFactory.create(); + when(fachstelleMapper.fromMap(any())).thenReturn(expectedFachstelle); var actualFachstelle = mapper.getZustaendigeStelleFromItemMap(itemMap); diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestTestFactory.java index 4d1ff2c232a5ef16e46c636a7a51ed0fc62d726e..0d876d921b9ca47011a2c46ec934b4be2bdd2dae 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestTestFactory.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationRequestTestFactory.java @@ -45,6 +45,7 @@ public class CollaborationRequestTestFactory { public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString(); public static final int COLLABORATION_LEVEL = 1; public static final Fachstelle ZUSTAENDIGE_STELLE = FachstelleTestFactory.create(); + public static final Map<String, Object> FACHSTELLE_MAP = FachstelleTestFactory.createAsMap(); public static CollaborationRequest create() { return createBuilder().build(); @@ -73,6 +74,6 @@ public class CollaborationRequestTestFactory { CollaborationRequest.PROPERTY_CREATED_BY, CommandTestFactory.CREATED_BY, CollaborationRequest.PROPERTY_TITEL, TITEL, CollaborationRequest.PROPERTY_BESCHREIBUNG, BESCHREIBUNG, - CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.createAsMap()); + CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FACHSTELLE_MAP); } } diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapperTest.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapperTest.java index 5cbe67892d995458904fe69f10a224aff84309bc..62906be89475ac5a4b6d154306fcd5b7a833cb5e 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapperTest.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapperTest.java @@ -42,7 +42,7 @@ class FachstelleMapperTest { class TestToMap { @Test - void shouldMapToFachstelle() { + void shouldMapToFachstelleMap() { var expectedMap = FachstelleTestFactory.createAsMap(); var actualMap = mapper.toMap(FachstelleTestFactory.create()); @@ -50,4 +50,15 @@ class FachstelleMapperTest { assertThat(actualMap).usingRecursiveComparison().isEqualTo(expectedMap); } } + + @Nested + class TestFromMap { + + @Test + void shouldMapToFachstelle() { + var fachstelle = mapper.fromMap(FachstelleTestFactory.createAsMap()); + + assertThat(fachstelle).isEqualTo(FachstelleTestFactory.create()); + } + } }