From c4caf6301c19c02ad435250a3427a8010029c141 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Wed, 18 Dec 2024 15:30:59 +0100 Subject: [PATCH] OZG-7350 fix CollaborationRequestMapper --- .../CollaborationRequestMapper.java | 13 +++++++------ .../fachstelle/FachstelleMapper.java | 17 ++++++++++++++--- .../CollaborationRequestMapperTest.java | 9 ++++----- .../CollaborationRequestTestFactory.java | 3 ++- .../fachstelle/FachstelleMapperTest.java | 13 ++++++++++++- 5 files changed, 39 insertions(+), 16 deletions(-) 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 219e2c3..8fff617 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 dfc9c6b..a7dc28c 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 b81b562..87aec78 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 4d1ff2c..0d876d9 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 5cbe678..62906be 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()); + } + } } -- GitLab