Skip to content
Snippets Groups Projects
Commit cf22c878 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-7350 fix CollaborationRequestMapper

parent e6af2393
No related branches found
No related tags found
No related merge requests found
...@@ -69,11 +69,17 @@ public abstract class CollaborationRequestMapper { ...@@ -69,11 +69,17 @@ public abstract class CollaborationRequestMapper {
@Mapping(target = "createdBy", ignore = true) @Mapping(target = "createdBy", ignore = true)
@Mapping(target = "commandId", source = "id") @Mapping(target = "commandId", source = "id")
@Mapping(target = "titel", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_TITEL, command.getBodyObject()))") @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 = "beschreibung", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_BESCHREIBUNG, command.getBodyObject()))")
@Mapping(target = "collaborationLevel", expression = "java(getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, command.getBodyObject()))") @Mapping(target = "collaborationLevel", expression = "java(getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, command.getBodyObject()))")
public abstract CollaborationRequest toCollaborationRequest(Command command); 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 = "id", ignore = true)
@Mapping(target = "status", ignore = true) @Mapping(target = "status", ignore = true)
@Mapping(target = "relationVersion", ignore = true) @Mapping(target = "relationVersion", ignore = true)
...@@ -140,23 +146,25 @@ public abstract class CollaborationRequestMapper { ...@@ -140,23 +146,25 @@ public abstract class CollaborationRequestMapper {
@Mapping(target = "createdBy", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_CREATED_BY, item.getItem()))") @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 = "beschreibung", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_BESCHREIBUNG, item.getItem()))")
@Mapping(target = "titel", expression = "java(getStringProperty(CollaborationRequest.PROPERTY_TITEL, 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); public abstract CollaborationRequest mapFromVorgangAttachedItem(VorgangAttachedItem item);
CollaborationRequestId toCollaborationRequestId(String id) { CollaborationRequestId toCollaborationRequestId(String id) {
return CollaborationRequestId.from(id); return CollaborationRequestId.from(id);
} }
int getIntProperty(String key, Map<String, Object> propertyMap) { @SuppressWarnings("unchecked")
return MapUtils.getIntValue(propertyMap, key); 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);
Fachstelle getZustaendigeStelle(Map<String, Object> propertyMap) {
var technicalId = getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, propertyMap);
var collaborationLevel = getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, propertyMap); var collaborationLevel = getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, propertyMap);
return fachstelleService.getFachstelle(technicalId, collaborationLevel); 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) { String getStringProperty(String key, Map<String, Object> propertyMap) {
return MapUtils.getString(propertyMap, key); return MapUtils.getString(propertyMap, key);
} }
......
...@@ -46,6 +46,7 @@ import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId; ...@@ -46,6 +46,7 @@ import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor; import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor;
import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItem; import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItem;
import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItemTestFactory; 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.FachstelleMapper;
import de.ozgcloud.collaboration.fachstelle.FachstelleService; import de.ozgcloud.collaboration.fachstelle.FachstelleService;
import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory;
...@@ -86,12 +87,12 @@ class CollaborationRequestMapperTest { ...@@ -86,12 +87,12 @@ class CollaborationRequestMapperTest {
void shouldCallGetZustaendigeStelle() { void shouldCallGetZustaendigeStelle() {
mapper.toCollaborationRequest(COMMAND); mapper.toCollaborationRequest(COMMAND);
verify(mapper).getZustaendigeStelle(BODY_OBJECT); verify(mapper).getZustaendigeStelleFromCommandBody(BODY_OBJECT);
} }
@Test @Test
void shouldMapCommand() { void shouldMapCommand() {
doReturn(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE).when(mapper).getZustaendigeStelle(any()); doReturn(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE).when(mapper).getZustaendigeStelleFromCommandBody(any());
var result = mapper.toCollaborationRequest(COMMAND); var result = mapper.toCollaborationRequest(COMMAND);
...@@ -102,7 +103,7 @@ class CollaborationRequestMapperTest { ...@@ -102,7 +103,7 @@ class CollaborationRequestMapperTest {
} }
@Nested @Nested
class TestGetZustaendigeStelle { class TestGgetZustaendigeStelleFromCommandBody {
private static final Map<String, Object> PROPERTY_MAP = Map.of( private static final Map<String, Object> PROPERTY_MAP = Map.of(
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID, CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID,
...@@ -110,7 +111,7 @@ class CollaborationRequestMapperTest { ...@@ -110,7 +111,7 @@ class CollaborationRequestMapperTest {
@Test @Test
void shouldCallFachstelleService() { void shouldCallFachstelleService() {
mapper.getZustaendigeStelle(PROPERTY_MAP); mapper.getZustaendigeStelleFromCommandBody(PROPERTY_MAP);
verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL); verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL);
} }
...@@ -120,7 +121,7 @@ class CollaborationRequestMapperTest { ...@@ -120,7 +121,7 @@ class CollaborationRequestMapperTest {
var expectedFachstelle = FachstelleTestFactory.create(); var expectedFachstelle = FachstelleTestFactory.create();
when(fachstelleService.getFachstelle(any(), anyInt())).thenReturn(expectedFachstelle); when(fachstelleService.getFachstelle(any(), anyInt())).thenReturn(expectedFachstelle);
var actualFachstelle = mapper.getZustaendigeStelle(PROPERTY_MAP); var actualFachstelle = mapper.getZustaendigeStelleFromCommandBody(PROPERTY_MAP);
assertThat(actualFachstelle).isSameAs(expectedFachstelle); assertThat(actualFachstelle).isSameAs(expectedFachstelle);
} }
...@@ -325,15 +326,15 @@ class CollaborationRequestMapperTest { ...@@ -325,15 +326,15 @@ class CollaborationRequestMapperTest {
.build(); .build();
@Test @Test
void shouldCallGetZustaendigeStelle() { void shouldCallGetZustaendigeStelleFromItemMap() {
mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM); mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM);
verify(mapper).getZustaendigeStelle(COLLABORATION_REQUEST_MAP); verify(mapper).getZustaendigeStelleFromItemMap(COLLABORATION_REQUEST_MAP);
} }
@Test @Test
void shouldMap() { void shouldMap() {
doReturn(FachstelleTestFactory.create()).when(mapper).getZustaendigeStelle(any()); doReturn(FachstelleTestFactory.create()).when(mapper).getZustaendigeStelleFromItemMap(any());
var item = mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM); var item = mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM);
...@@ -341,6 +342,29 @@ class CollaborationRequestMapperTest { ...@@ -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 @Nested
class TestToGrpcCollaborationRequest { class TestToGrpcCollaborationRequest {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment