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 79781c40023e8634d6454ddb0e55ef229b0b8d96..219e2c3ed0ed4b6834afbfa56e63e21370b38214 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 @@ -69,11 +69,17 @@ public abstract class CollaborationRequestMapper { @Mapping(target = "createdBy", ignore = true) @Mapping(target = "commandId", source = "id") @Mapping(target = "titel", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_TITEL, command.getBodyObject()))") - @Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelle(command.getBodyObject()))") + @Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelleFromCommandBody(command.getBodyObject()))") @Mapping(target = "beschreibung", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_BESCHREIBUNG, command.getBodyObject()))") @Mapping(target = "collaborationLevel", expression = "java(getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, command.getBodyObject()))") public abstract CollaborationRequest toCollaborationRequest(Command command); + Fachstelle getZustaendigeStelleFromCommandBody(Map<String, Object> propertyMap) { + var technicalId = getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, propertyMap); + var collaborationLevel = getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, propertyMap); + return fachstelleService.getFachstelle(technicalId, collaborationLevel); + } + @Mapping(target = "id", ignore = true) @Mapping(target = "status", ignore = true) @Mapping(target = "relationVersion", ignore = true) @@ -140,23 +146,25 @@ public abstract class CollaborationRequestMapper { @Mapping(target = "createdBy", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_CREATED_BY, item.getItem()))") @Mapping(target = "beschreibung", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_BESCHREIBUNG, item.getItem()))") @Mapping(target = "titel", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_TITEL, item.getItem()))") - @Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelle(item.getItem()))") + @Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelleFromItemMap(item.getItem()))") public abstract CollaborationRequest mapFromVorgangAttachedItem(VorgangAttachedItem item); CollaborationRequestId toCollaborationRequestId(String id) { return CollaborationRequestId.from(id); } - int getIntProperty(String key, Map<String, Object> propertyMap) { - return MapUtils.getIntValue(propertyMap, key); - } - - Fachstelle getZustaendigeStelle(Map<String, Object> propertyMap) { - var technicalId = getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, propertyMap); + @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); } + int getIntProperty(String key, Map<String, Object> propertyMap) { + return MapUtils.getIntValue(propertyMap, key); + } + String getStringProperty(String key, Map<String, Object> propertyMap) { return MapUtils.getString(propertyMap, key); } 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 53bd55ae81e711c88f18ad4cea81df129b2625ea..d233f030aaf11304f22c9f55d0390f0c0673ab3d 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,6 +46,7 @@ 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; @@ -86,12 +87,12 @@ class CollaborationRequestMapperTest { void shouldCallGetZustaendigeStelle() { mapper.toCollaborationRequest(COMMAND); - verify(mapper).getZustaendigeStelle(BODY_OBJECT); + verify(mapper).getZustaendigeStelleFromCommandBody(BODY_OBJECT); } @Test void shouldMapCommand() { - doReturn(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE).when(mapper).getZustaendigeStelle(any()); + doReturn(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE).when(mapper).getZustaendigeStelleFromCommandBody(any()); var result = mapper.toCollaborationRequest(COMMAND); @@ -102,7 +103,7 @@ class CollaborationRequestMapperTest { } @Nested - class TestGetZustaendigeStelle { + class TestGgetZustaendigeStelleFromCommandBody { private static final Map<String, Object> PROPERTY_MAP = Map.of( CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID, @@ -110,7 +111,7 @@ class CollaborationRequestMapperTest { @Test void shouldCallFachstelleService() { - mapper.getZustaendigeStelle(PROPERTY_MAP); + mapper.getZustaendigeStelleFromCommandBody(PROPERTY_MAP); verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL); } @@ -120,7 +121,7 @@ class CollaborationRequestMapperTest { var expectedFachstelle = FachstelleTestFactory.create(); when(fachstelleService.getFachstelle(any(), anyInt())).thenReturn(expectedFachstelle); - var actualFachstelle = mapper.getZustaendigeStelle(PROPERTY_MAP); + var actualFachstelle = mapper.getZustaendigeStelleFromCommandBody(PROPERTY_MAP); assertThat(actualFachstelle).isSameAs(expectedFachstelle); } @@ -325,15 +326,15 @@ class CollaborationRequestMapperTest { .build(); @Test - void shouldCallGetZustaendigeStelle() { + void shouldCallGetZustaendigeStelleFromItemMap() { mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM); - verify(mapper).getZustaendigeStelle(COLLABORATION_REQUEST_MAP); + verify(mapper).getZustaendigeStelleFromItemMap(COLLABORATION_REQUEST_MAP); } @Test void shouldMap() { - doReturn(FachstelleTestFactory.create()).when(mapper).getZustaendigeStelle(any()); + doReturn(FachstelleTestFactory.create()).when(mapper).getZustaendigeStelleFromItemMap(any()); var item = mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM); @@ -341,6 +342,29 @@ class CollaborationRequestMapperTest { } } + @Nested + class TestGetZustaendigeStelleFromItemMap { + + private final Map<String, Object> itemMap = CollaborationRequestTestFactory.createAsMap(); + + @Test + void shouldGetFachstelle() { + mapper.getZustaendigeStelleFromItemMap(itemMap); + + verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL); + } + + @Test + void shouldReturnFachstelle() { + Fachstelle expectedFachstelle = FachstelleTestFactory.create(); + when(fachstelleService.getFachstelle(anyString(), anyInt())).thenReturn(expectedFachstelle); + + var actualFachstelle = mapper.getZustaendigeStelleFromItemMap(itemMap); + + assertThat(actualFachstelle).isSameAs(expectedFachstelle); + } + } + @Nested class TestToGrpcCollaborationRequest {