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

OZG-7350 fix CollaborationRequestMapper

parent aca581f9
No related branches found
No related tags found
No related merge requests found
...@@ -49,8 +49,12 @@ import de.ozgcloud.command.Command; ...@@ -49,8 +49,12 @@ import de.ozgcloud.command.Command;
import de.ozgcloud.vorgang.vorgang.GrpcCreateCollaborationRequestData; import de.ozgcloud.vorgang.vorgang.GrpcCreateCollaborationRequestData;
@AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = CollaborationManagerConfiguration.COLLABORATION_REQUEST_MAPPER_NAME)) @AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = CollaborationManagerConfiguration.COLLABORATION_REQUEST_MAPPER_NAME))
@Mapper(uses = { @Mapper(uses = { CommandMapper.class }, //
CommandMapper.class }, unmappedTargetPolicy = ReportingPolicy.WARN, unmappedSourcePolicy = ReportingPolicy.WARN, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) unmappedTargetPolicy = ReportingPolicy.WARN, //
unmappedSourcePolicy = ReportingPolicy.WARN, //
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, //
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, //
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public abstract class CollaborationRequestMapper { public abstract class CollaborationRequestMapper {
static final String ITEM_NAME = "CollaborationRequest"; static final String ITEM_NAME = "CollaborationRequest";
...@@ -155,10 +159,7 @@ public abstract class CollaborationRequestMapper { ...@@ -155,10 +159,7 @@ public abstract class CollaborationRequestMapper {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Fachstelle getZustaendigeStelleFromItemMap(Map<String, Object> propertyMap) { Fachstelle getZustaendigeStelleFromItemMap(Map<String, Object> propertyMap) {
var fachstelle = (Map<String, Object>) propertyMap.get(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE); return fachstelleMapper.fromMap((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) { int getIntProperty(String key, Map<String, Object> propertyMap) {
......
...@@ -6,25 +6,28 @@ import org.mapstruct.AnnotateWith; ...@@ -6,25 +6,28 @@ import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.mapstruct.ReportingPolicy; import org.mapstruct.ReportingPolicy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import de.ozgcloud.collaboration.CollaborationManagerConfiguration; import de.ozgcloud.collaboration.CollaborationManagerConfiguration;
import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleType;
import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle; import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle;
import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit; 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)) @AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = CollaborationManagerConfiguration.FACHSTELLE_MAPPER_NAME))
public interface FachstelleMapper { public interface FachstelleMapper {
@Mapping(target = "technicalId", source = "id") @Mapping(target = "technicalId", source = "id")
@Mapping(target = "subjectId", source = "mukId") @Mapping(target = "subjectId", source = "mukId")
@Mapping(target = "type", constant = "EXTERNE_FACHSTELLE") @Mapping(target = "type", expression = "java(FachstelleType.EXTERNE_FACHSTELLE)")
Fachstelle fromExterneFachstelle(GrpcFachstelle externeFachstelle); Fachstelle fromExterneFachstelle(GrpcFachstelle externeFachstelle);
@Mapping(target = "technicalId", source = "id") @Mapping(target = "technicalId", source = "id")
@Mapping(target = "subjectId", source = "xzufiId.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); Fachstelle fromOrganisationsEinheit(GrpcOrganisationsEinheit organisationsEinheit);
default Map<String, Object> toMap(Fachstelle fachstelle) { default Map<String, Object> toMap(Fachstelle fachstelle) {
...@@ -33,4 +36,12 @@ public interface FachstelleMapper { ...@@ -33,4 +36,12 @@ public interface FachstelleMapper {
Fachstelle.PROPERTY_SUBJECT_ID, fachstelle.getSubjectId(), Fachstelle.PROPERTY_SUBJECT_ID, fachstelle.getSubjectId(),
Fachstelle.PROPERTY_TYPE, fachstelle.getType().name()); 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();
}
} }
...@@ -46,7 +46,6 @@ import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId; ...@@ -46,7 +46,6 @@ 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;
...@@ -348,16 +347,16 @@ class CollaborationRequestMapperTest { ...@@ -348,16 +347,16 @@ class CollaborationRequestMapperTest {
private final Map<String, Object> itemMap = CollaborationRequestTestFactory.createAsMap(); private final Map<String, Object> itemMap = CollaborationRequestTestFactory.createAsMap();
@Test @Test
void shouldGetFachstelle() { void shouldMapFachstelle() {
mapper.getZustaendigeStelleFromItemMap(itemMap); mapper.getZustaendigeStelleFromItemMap(itemMap);
verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL); verify(fachstelleMapper).fromMap(CollaborationRequestTestFactory.FACHSTELLE_MAP);
} }
@Test @Test
void shouldReturnFachstelle() { void shouldReturnFachstelle() {
Fachstelle expectedFachstelle = FachstelleTestFactory.create(); var expectedFachstelle = FachstelleTestFactory.create();
when(fachstelleService.getFachstelle(anyString(), anyInt())).thenReturn(expectedFachstelle); when(fachstelleMapper.fromMap(any())).thenReturn(expectedFachstelle);
var actualFachstelle = mapper.getZustaendigeStelleFromItemMap(itemMap); var actualFachstelle = mapper.getZustaendigeStelleFromItemMap(itemMap);
......
...@@ -45,6 +45,7 @@ public class CollaborationRequestTestFactory { ...@@ -45,6 +45,7 @@ public class CollaborationRequestTestFactory {
public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString(); public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString();
public static final int COLLABORATION_LEVEL = 1; public static final int COLLABORATION_LEVEL = 1;
public static final Fachstelle ZUSTAENDIGE_STELLE = FachstelleTestFactory.create(); public static final Fachstelle ZUSTAENDIGE_STELLE = FachstelleTestFactory.create();
public static final Map<String, Object> FACHSTELLE_MAP = FachstelleTestFactory.createAsMap();
public static CollaborationRequest create() { public static CollaborationRequest create() {
return createBuilder().build(); return createBuilder().build();
...@@ -73,6 +74,6 @@ public class CollaborationRequestTestFactory { ...@@ -73,6 +74,6 @@ public class CollaborationRequestTestFactory {
CollaborationRequest.PROPERTY_CREATED_BY, CommandTestFactory.CREATED_BY, CollaborationRequest.PROPERTY_CREATED_BY, CommandTestFactory.CREATED_BY,
CollaborationRequest.PROPERTY_TITEL, TITEL, CollaborationRequest.PROPERTY_TITEL, TITEL,
CollaborationRequest.PROPERTY_BESCHREIBUNG, BESCHREIBUNG, CollaborationRequest.PROPERTY_BESCHREIBUNG, BESCHREIBUNG,
CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.createAsMap()); CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FACHSTELLE_MAP);
} }
} }
...@@ -42,7 +42,7 @@ class FachstelleMapperTest { ...@@ -42,7 +42,7 @@ class FachstelleMapperTest {
class TestToMap { class TestToMap {
@Test @Test
void shouldMapToFachstelle() { void shouldMapToFachstelleMap() {
var expectedMap = FachstelleTestFactory.createAsMap(); var expectedMap = FachstelleTestFactory.createAsMap();
var actualMap = mapper.toMap(FachstelleTestFactory.create()); var actualMap = mapper.toMap(FachstelleTestFactory.create());
...@@ -50,4 +50,15 @@ class FachstelleMapperTest { ...@@ -50,4 +50,15 @@ class FachstelleMapperTest {
assertThat(actualMap).usingRecursiveComparison().isEqualTo(expectedMap); assertThat(actualMap).usingRecursiveComparison().isEqualTo(expectedMap);
} }
} }
@Nested
class TestFromMap {
@Test
void shouldMapToFachstelle() {
var fachstelle = mapper.fromMap(FachstelleTestFactory.createAsMap());
assertThat(fachstelle).isEqualTo(FachstelleTestFactory.create());
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment