diff --git a/collaboration-manager-server/pom.xml b/collaboration-manager-server/pom.xml index beaed663dc2161ae4280ba5c6b2a50ad825b6dae..a11db1da56b094988cfba7fa9c12d995cc18ab24 100644 --- a/collaboration-manager-server/pom.xml +++ b/collaboration-manager-server/pom.xml @@ -41,6 +41,7 @@ <properties> <vorgang-manager.version>2.18.0</vorgang-manager.version> + <zufi-manager.version>1.6.0</zufi-manager.version> <api-lib.version>0.13.0</api-lib.version> </properties> @@ -61,6 +62,11 @@ <artifactId>vorgang-manager-interface</artifactId> <version>${vorgang-manager.version}</version> </dependency> + <dependency> + <groupId>de.ozgcloud.zufi</groupId> + <artifactId>zufi-manager-interface</artifactId> + <version>${zufi-manager.version}</version> + </dependency> <dependency> <groupId>de.ozgcloud.api-lib</groupId> <artifactId>api-lib-core</artifactId> diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationManagerConfiguration.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationManagerConfiguration.java index 331b155a60b7e4ca3fbd112ab4ad99e487d69e5f..de0c54bb9e850ae50cd294cfd434b937f4665c1e 100644 --- a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationManagerConfiguration.java +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationManagerConfiguration.java @@ -73,6 +73,7 @@ public class CollaborationManagerConfiguration { public static final String GRPC_COMMAND_MANAGER_NAME = "command-manager"; public static final String GRPC_FILE_MANAGER_NAME = "file-manager"; public static final String GRPC_USER_MANAGER_NAME = "user-manager"; + public static final String GRPC_ZUFI_MANAGER_NAME = "zufi-manager"; @GrpcClient(GRPC_COMMAND_MANAGER_NAME) private CommandServiceBlockingStub commandServiceStub; diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequest.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequest.java index 6d35a03c2e4eb4dab323b1da4eff525aa7e2d865..05cff61ad6237e0c79833f0aa3ed99bf32618d24 100644 --- a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequest.java +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationRequest.java @@ -23,8 +23,10 @@ */ package de.ozgcloud.collaboration; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import de.ozgcloud.collaboration.fachstelle.Fachstelle; import de.ozgcloud.collaboration.request.CollaborationRequestId; import lombok.Builder; import lombok.Getter; @@ -59,6 +61,6 @@ public class CollaborationRequest { private String titel; @NotBlank private String beschreibung; - @NotBlank - private String zustaendigeStelle; + @Valid + private Fachstelle zustaendigeStelle; } 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 ceb92801df5721006f223d56334170fae306465a..1dce316e320bd5e2cda0fd6e9c3cac5d8226ce57 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 @@ -28,54 +28,51 @@ import java.util.Map; import org.apache.commons.collections.MapUtils; import org.mapstruct.AnnotateWith; import org.mapstruct.CollectionMappingStrategy; -import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValuePropertyMappingStrategy; import org.mapstruct.ReportingPolicy; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.mapstruct.NullValueCheckStrategy; -import org.mapstruct.NullValuePropertyMappingStrategy; -import org.mapstruct.ReportingPolicy; import de.ozgcloud.apilib.common.command.OzgCloudCommand; import de.ozgcloud.apilib.common.command.grpc.CommandMapper; import de.ozgcloud.collaboration.common.callcontext.CollaborationManagerCallContextGrpcClientInterceptor; import de.ozgcloud.collaboration.common.vorgang.attached_item.VorgangAttachedItem; +import de.ozgcloud.collaboration.fachstelle.Fachstelle; +import de.ozgcloud.collaboration.fachstelle.FachstelleMapper; +import de.ozgcloud.collaboration.fachstelle.FachstelleService; import de.ozgcloud.collaboration.request.CollaborationRequestId; import de.ozgcloud.collaboration.request.GrpcCollaborationRequest; 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) -public interface CollaborationRequestMapper { +@Mapper(uses = { + CommandMapper.class }, unmappedTargetPolicy = ReportingPolicy.WARN, unmappedSourcePolicy = ReportingPolicy.WARN, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public abstract class CollaborationRequestMapper { - String ITEM_NAME = "CollaborationRequest"; + static final String ITEM_NAME = "CollaborationRequest"; - String FIELD_ITEM_CLIENT = "client"; - String FIELD_ITEM_VORGANG_ID = "vorgangId"; - String FIELD_ITEM_NAME = "itemName"; - String FIELD_ITEM_BODY = "item"; + static final String FIELD_ITEM_CLIENT = "client"; + static final String FIELD_ITEM_VORGANG_ID = "vorgangId"; + static final String FIELD_ITEM_NAME = "itemName"; + static final String FIELD_ITEM_BODY = "item"; + + @Autowired + private FachstelleService fachstelleService; + @Autowired + private FachstelleMapper fachstelleMapper; @Mapping(target = "collaborationVorgangId", ignore = true) @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(getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, command.getBodyObject()))") + @Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelle(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()))") - CollaborationRequest toCollaborationRequest(Command command); - - default String getStringProperty(String key, Map<String, Object> propertyMap) { - return MapUtils.getString(propertyMap, key); - } + public abstract CollaborationRequest toCollaborationRequest(Command command); @Mapping(target = "id", ignore = true) @Mapping(target = "status", ignore = true) @@ -89,9 +86,9 @@ public interface CollaborationRequestMapper { @Mapping(target = "vorgangId", source = "request.vorgangId") @Mapping(target = "relationId", expression = "java(commandMapper.mapRelationId(request.getVorgangId()))") @Mapping(target = "bodyObject", expression = "java(toBodyObject(request))") - OzgCloudCommand toOzgCloudCommand(CollaborationRequest request, String order); + public abstract OzgCloudCommand toOzgCloudCommand(CollaborationRequest request, String order); - default Map<String, Object> toBodyObject(CollaborationRequest request) { + Map<String, Object> toBodyObject(CollaborationRequest request) { return Map.of( FIELD_ITEM_VORGANG_ID, request.getVorgangId(), FIELD_ITEM_CLIENT, CollaborationManagerCallContextGrpcClientInterceptor.COLLABORATION_MANAGER_CLIENT_NAME, @@ -99,16 +96,17 @@ public interface CollaborationRequestMapper { FIELD_ITEM_BODY, toItemMap(request)); } - default Map<String, Object> toItemMap(CollaborationRequest request) { + Map<String, Object> toItemMap(CollaborationRequest request) { return Map.of( CollaborationRequest.PROPERTY_TITEL, request.getTitel(), CollaborationRequest.PROPERTY_BESCHREIBUNG, request.getBeschreibung(), - CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, request.getZustaendigeStelle(), + CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, fachstelleMapper.toMap(request.getZustaendigeStelle()), CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, request.getCollaborationLevel(), CollaborationRequest.PROPERTY_COLLABORATION_VORGANG_ID, request.getCollaborationVorgangId()); } @Mapping(target = "titel", source = "titel") + @Mapping(target = "zustaendigeStelle", source = "zustaendigeStelle.technicalId") @Mapping(target = "idBytes", ignore = true) @Mapping(target = "mergeFrom", ignore = true) @Mapping(target = "clearField", ignore = true) @@ -121,8 +119,9 @@ public interface CollaborationRequestMapper { @Mapping(target = "unknownFields", ignore = true) @Mapping(target = "zustaendigeStelleBytes", ignore = true) @Mapping(target = "allFields", ignore = true) - GrpcCollaborationRequest toGrpcCollaborationRequest(CollaborationRequest request); + public abstract GrpcCollaborationRequest toGrpcCollaborationRequest(CollaborationRequest request); + @Mapping(target = "zustaendigeStelle", source = "zustaendigeStelle.subjectId") @Mapping(target = "mergeFrom", ignore = true) @Mapping(target = "clearField", ignore = true) @Mapping(target = "clearOneof", ignore = true) @@ -131,7 +130,7 @@ public interface CollaborationRequestMapper { @Mapping(target = "vorgangIdBytes", ignore = true) @Mapping(target = "zustaendigeStelleBytes", ignore = true) @Mapping(target = "allFields", ignore = true) - GrpcCreateCollaborationRequestData toGrpcCreateCollaborationRequestData(CollaborationRequest request); + public abstract GrpcCreateCollaborationRequestData toGrpcCreateCollaborationRequestData(CollaborationRequest request); @Mapping(target = "id", expression = "java(toCollaborationRequestId(getStringProperty(CollaborationRequest.PROPERTY_ID, item.getItem())))") @Mapping(target = "collaborationLevel", expression = "java(getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, item.getItem()))") @@ -141,14 +140,24 @@ public interface 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(getStringProperty(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, item.getItem()))") - CollaborationRequest mapFromVorgangAttachedItem(VorgangAttachedItem item); + @Mapping(target = "zustaendigeStelle", expression = "java(getZustaendigeStelle(item.getItem()))") + public abstract CollaborationRequest mapFromVorgangAttachedItem(VorgangAttachedItem item); - default CollaborationRequestId toCollaborationRequestId(String id) { + CollaborationRequestId toCollaborationRequestId(String id) { return CollaborationRequestId.from(id); } - default int getIntProperty(String key, Map<String, Object> propertyMap) { + 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); + var collaborationLevel = getIntProperty(CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, propertyMap); + return fachstelleService.getFachstelle(technicalId, collaborationLevel); + } + + String getStringProperty(String key, Map<String, Object> propertyMap) { + return MapUtils.getString(propertyMap, key); + } } diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationService.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationService.java index ba4460a230898252854fdf2a6087c36ad999bf1d..4a2ff75986e7c8e9bcfb497999b94a2ee56a62ba 100644 --- a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationService.java +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/CollaborationService.java @@ -132,7 +132,7 @@ public class CollaborationService { } OzgCloudCommand buildSendPostfachNachrichtCommand(CollaborationRequest collaborationRequest) { - var bodyObject = buildPostfachSendNachrichtCommandBody(buildMukPostfachAddress(collaborationRequest.getZustaendigeStelle()), + var bodyObject = buildPostfachSendNachrichtCommandBody(buildMukPostfachAddress(collaborationRequest.getZustaendigeStelle().getSubjectId()), collaborationRequest.getVorgangId()); return OzgCloudCommand.builder() .vorgangId(commandMapper.toOzgCloudVorgangId(collaborationRequest.getVorgangId())) diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/Fachstelle.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/Fachstelle.java new file mode 100644 index 0000000000000000000000000000000000000000..31f8d5c2b123b5083dfdc17f01091fb930b12df5 --- /dev/null +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/Fachstelle.java @@ -0,0 +1,27 @@ +package de.ozgcloud.collaboration.fachstelle; + +import jakarta.validation.constraints.NotBlank; + +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@Builder +@Getter +@EqualsAndHashCode +public class Fachstelle { + + public static final String PROPERTY_TECHNICAL_ID = "technicalId"; + public static final String PROPERTY_SUBJECT_ID = "subjectId"; + public static final String PROPERTY_TYPE = "type"; + + @NotBlank + private String technicalId; + @NotBlank + private String subjectId; + private FachstelleType type; + + public enum FachstelleType { + EXTERNE_FACHSTELLE, ORGANISATIONS_EINHEIT; + } +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..af1774c59645e29dbf725b8ae7250d57ef9410b0 --- /dev/null +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapper.java @@ -0,0 +1,33 @@ +package de.ozgcloud.collaboration.fachstelle; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.ReportingPolicy; + +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.WARN, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) + +public interface FachstelleMapper { + + @Mapping(target = "technicalId", source = "id") + @Mapping(target = "subjectId", source = "mukId") + @Mapping(target = "type", constant = "EXTERNE_FACHSTELLE") + Fachstelle fromExterneFachstelle(GrpcFachstelle externeFachstelle); + + @Mapping(target = "technicalId", source = "id") + @Mapping(target = "subjectId", source = "xzufiId.id") + @Mapping(target = "type", constant = "ORGANISATIONS_EINHEIT") + Fachstelle fromOrganisationsEinheit(GrpcOrganisationsEinheit organisationsEinheit); + + default Map<String, Object> toMap(Fachstelle fachstelle) { + return Map.of( + Fachstelle.PROPERTY_TECHNICAL_ID, fachstelle.getTechnicalId(), + Fachstelle.PROPERTY_SUBJECT_ID, fachstelle.getSubjectId(), + Fachstelle.PROPERTY_TYPE, fachstelle.getType().name()); + } +} diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java new file mode 100644 index 0000000000000000000000000000000000000000..2ed202a976adb525df4f7aa86bf2074852e057b5 --- /dev/null +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteService.java @@ -0,0 +1,33 @@ +package de.ozgcloud.collaboration.fachstelle; + +import org.springframework.stereotype.Service; + +import de.ozgcloud.collaboration.CollaborationManagerConfiguration; +import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub; +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest; +import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub; +import lombok.RequiredArgsConstructor; +import net.devh.boot.grpc.client.inject.GrpcClient; + +@Service +@RequiredArgsConstructor +class FachstelleRemoteService { + + @GrpcClient(CollaborationManagerConfiguration.GRPC_ZUFI_MANAGER_NAME) + private final FachstelleServiceBlockingStub fachstelleServiceBlockingStub; + @GrpcClient(CollaborationManagerConfiguration.GRPC_ZUFI_MANAGER_NAME) + private final OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub; + private final FachstelleMapper fachstelleMapper; + + public Fachstelle getExterneFachstelle(String id) { + var externeFachstelle = fachstelleServiceBlockingStub.getById(GrpcFachstelleGetRequest.newBuilder().setId(id).build()).getFachstelle(); + return fachstelleMapper.fromExterneFachstelle(externeFachstelle); + } + + public Fachstelle getOrganisationsEinheit(String id) { + var organisationsEinheit = organisationsEinheitServiceBlockingStub.getById(GrpcOrganisationsEinheitGetRequest.newBuilder().setId(id).build()) + .getOrganisationsEinheit(); + return fachstelleMapper.fromOrganisationsEinheit(organisationsEinheit); + } +} diff --git a/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleService.java b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleService.java new file mode 100644 index 0000000000000000000000000000000000000000..dd5ffd6bb72685362ba19d7e91ef721778139b86 --- /dev/null +++ b/collaboration-manager-server/src/main/java/de/ozgcloud/collaboration/fachstelle/FachstelleService.java @@ -0,0 +1,23 @@ +package de.ozgcloud.collaboration.fachstelle; + +import org.springframework.stereotype.Service; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class FachstelleService { + + private final FachstelleRemoteService remoteService; + + public Fachstelle getFachstelle(String technicalId, int collaborationLevel) { + if (collaborationLevel == 1) { + return remoteService.getOrganisationsEinheit(technicalId); + } + if (collaborationLevel == 4) { + return remoteService.getExterneFachstelle(technicalId); + } + throw new IllegalArgumentException( + "Unknown collaboration level! Collaboration level has to be either 1 or 4, but was %s.".formatted(collaborationLevel)); + } +} 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 afd2e169858f290758dbef4d7d724d48d60c2edf..53bd55ae81e711c88f18ad4cea81df129b2625ea 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 @@ -44,7 +44,13 @@ import de.ozgcloud.apilib.common.datatypes.GenericId; import de.ozgcloud.apilib.user.OzgCloudUserId; 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.FachstelleMapper; +import de.ozgcloud.collaboration.fachstelle.FachstelleService; +import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; +import de.ozgcloud.collaboration.request.GrpcCreateCollaborationRequestDataTestFactory; +import de.ozgcloud.collaboration.vorgang.GrpcCollaborationRequestTestFactory; import de.ozgcloud.collaboration.vorgang.VorgangTestFactory; import de.ozgcloud.command.Command; import de.ozgcloud.command.CommandTestFactory; @@ -58,27 +64,68 @@ class CollaborationRequestMapperTest { @Mock private CommandMapper commandMapper; + @Mock + private FachstelleService fachstelleService; + @Mock + private FachstelleMapper fachstelleMapper; @Nested class TestToCreateCollaborationRequest { + private static final Map<String, Object> BODY_OBJECT = Map.of( + CollaborationRequest.PROPERTY_TITEL, CollaborationRequestTestFactory.TITEL, + CollaborationRequest.PROPERTY_BESCHREIBUNG, CollaborationRequestTestFactory.BESCHREIBUNG, + CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID, + CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, CollaborationRequestTestFactory.COLLABORATION_LEVEL); private static final Command COMMAND = CommandTestFactory.createBuilder().bodyObject( - Map.of( - CollaborationRequest.PROPERTY_TITEL, CollaborationRequestTestFactory.TITEL, - CollaborationRequest.PROPERTY_BESCHREIBUNG, CollaborationRequestTestFactory.BESCHREIBUNG, - CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE)) + BODY_OBJECT) + .vorgangId(VorgangTestFactory.ID_STR) .build(); + @Test + void shouldCallGetZustaendigeStelle() { + mapper.toCollaborationRequest(COMMAND); + + verify(mapper).getZustaendigeStelle(BODY_OBJECT); + } + @Test void shouldMapCommand() { + doReturn(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE).when(mapper).getZustaendigeStelle(any()); + var result = mapper.toCollaborationRequest(COMMAND); assertThat(result).usingRecursiveComparison() - .ignoringFields("id", "createdBy", "vorgangId", "commandId", "collaborationVorgangId", "collaborationLevel", "createdBy") + .ignoringFields("id", "createdBy", "collaborationVorgangId") .isEqualTo(CollaborationRequestTestFactory.create()); } } + @Nested + class TestGetZustaendigeStelle { + + private static final Map<String, Object> PROPERTY_MAP = Map.of( + CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.TECHNICAL_ID, + CollaborationRequest.PROPERTY_COLLABORATION_LEVEL, CollaborationRequestTestFactory.COLLABORATION_LEVEL); + + @Test + void shouldCallFachstelleService() { + mapper.getZustaendigeStelle(PROPERTY_MAP); + + verify(fachstelleService).getFachstelle(FachstelleTestFactory.TECHNICAL_ID, CollaborationRequestTestFactory.COLLABORATION_LEVEL); + } + + @Test + void shouldReturnFachstelle() { + var expectedFachstelle = FachstelleTestFactory.create(); + when(fachstelleService.getFachstelle(any(), anyInt())).thenReturn(expectedFachstelle); + + var actualFachstelle = mapper.getZustaendigeStelle(PROPERTY_MAP); + + assertThat(actualFachstelle).isSameAs(expectedFachstelle); + } + } + @Nested class TestToOzgCloudCommand { @@ -231,11 +278,21 @@ class CollaborationRequestMapperTest { assertThat(result).containsEntry(CollaborationRequest.PROPERTY_BESCHREIBUNG, CollaborationRequestTestFactory.BESCHREIBUNG); } + @Test + void shouldCallFachstelleMapper() { + toItemMap(); + + verify(fachstelleMapper).toMap(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE); + } + @Test void shouldSetZustaendigeStelle() { + var fachstelleMap = FachstelleTestFactory.createAsMap(); + when(fachstelleMapper.toMap(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE)).thenReturn(fachstelleMap); + var result = toItemMap(); - assertThat(result).containsEntry(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE); + assertThat(result).containsEntry(CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, fachstelleMap); } @Test @@ -261,17 +318,57 @@ class CollaborationRequestMapperTest { @DisplayName("Map from vorgangAttachedItem") @Nested class TestMapFromVorgangAttachedItem { + private static final Map<String, Object> COLLABORATION_REQUEST_MAP = CollaborationRequestTestFactory.createAsMap(); + private static final VorgangAttachedItem VORGANG_ATTACHED_ITEM = VorgangAttachedItemTestFactory.createBuilder() + .itemName("CollaborationRequest") + .item(COLLABORATION_REQUEST_MAP) + .build(); + + @Test + void shouldCallGetZustaendigeStelle() { + mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM); + + verify(mapper).getZustaendigeStelle(COLLABORATION_REQUEST_MAP); + } @Test void shouldMap() { - var vorgangAttachedItem = VorgangAttachedItemTestFactory.createBuilder() - .itemName("CollaborationRequest") - .item(CollaborationRequestTestFactory.createAsMap()) - .build(); + doReturn(FachstelleTestFactory.create()).when(mapper).getZustaendigeStelle(any()); - var item = mapper.mapFromVorgangAttachedItem(vorgangAttachedItem); + var item = mapper.mapFromVorgangAttachedItem(VORGANG_ATTACHED_ITEM); assertThat(item).usingRecursiveComparison().isEqualTo(CollaborationRequestTestFactory.create()); } } + + @Nested + class TestToGrpcCollaborationRequest { + + @BeforeEach + void callCommandMapper() { + when(commandMapper.valueToString(any())).thenCallRealMethod(); + } + + @Test + void shouldMap() { + var request = mapper.toGrpcCollaborationRequest(CollaborationRequestTestFactory.create()); + + assertThat(request).isEqualTo(GrpcCollaborationRequestTestFactory.create()); + } + } + + @Nested + class TestToGrpcCreateCollaborationRequestData { + + @Test + void shouldMap() { + var expectedRequestData = GrpcCreateCollaborationRequestDataTestFactory.createBuilder() + .setVorgangId(VorgangTestFactory.ID_STR) + .build(); + + var requestData = mapper.toGrpcCreateCollaborationRequestData(CollaborationRequestTestFactory.create()); + + assertThat(requestData).isEqualTo(expectedRequestData); + } + } } \ No newline at end of file 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 4ffe6eb856eb025a2eb1f60c42e75666cdd25771..4d1ff2c232a5ef16e46c636a7a51ed0fc62d726e 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 @@ -29,6 +29,8 @@ import java.util.UUID; import com.thedeanda.lorem.LoremIpsum; import de.ozgcloud.collaboration.CollaborationRequest.CollaborationRequestBuilder; +import de.ozgcloud.collaboration.fachstelle.Fachstelle; +import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; import de.ozgcloud.collaboration.request.CollaborationRequestId; import de.ozgcloud.collaboration.vorgang.VorgangTestFactory; import de.ozgcloud.command.CommandTestFactory; @@ -40,9 +42,9 @@ public class CollaborationRequestTestFactory { public static final String TITEL = LoremIpsum.getInstance().getWords(5); public static final String BESCHREIBUNG = LoremIpsum.getInstance().getWords(10); - public static final String ZUSTAENDIGE_STELLE = UUID.randomUUID().toString(); 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 CollaborationRequest create() { return createBuilder().build(); @@ -71,6 +73,6 @@ public class CollaborationRequestTestFactory { CollaborationRequest.PROPERTY_CREATED_BY, CommandTestFactory.CREATED_BY, CollaborationRequest.PROPERTY_TITEL, TITEL, CollaborationRequest.PROPERTY_BESCHREIBUNG, BESCHREIBUNG, - CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, ZUSTAENDIGE_STELLE); + CollaborationRequest.PROPERTY_ZUSTAENDIGE_STELLE, FachstelleTestFactory.createAsMap()); } } diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceITCase.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceITCase.java index 1d0867baad9d780b636d5421070b7f824fe0f11f..a054e1b0bfa1a70307f72de9cb915dcb772ea2a9 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceITCase.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceITCase.java @@ -36,6 +36,7 @@ import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; +import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; import de.ozgcloud.common.test.ITCase; @ITCase @@ -68,12 +69,26 @@ class CollaborationServiceITCase { assertThrows(ConstraintViolationException.class, () -> service.createCollaborationRequest(request)); } + @DisplayName("should validate technicalId of zustaendigeStelle") + @ParameterizedTest(name = "fail when technicalId: \"{0}\"") + @NullAndEmptySource + @ValueSource(strings = { StringUtils.SPACE }) + void shouldValidateCollaborationZustaendigeStelleTechnicalId(String technicalId) { + var request = CollaborationRequestTestFactory.createBuilder() + .zustaendigeStelle(FachstelleTestFactory.createBuilder().technicalId(technicalId).build()) + .build(); + + assertThrows(ConstraintViolationException.class, () -> service.createCollaborationRequest(request)); + } + @DisplayName("should validate zustaendigeStelle") - @ParameterizedTest(name = "fail when zustaendigeStelle: \"{0}\"") + @ParameterizedTest(name = "fail when subjectId: \"{0}\"") @NullAndEmptySource @ValueSource(strings = { StringUtils.SPACE }) - void shouldValidateCollaborationRequestTitel(String zustaendigeStelle) { - var request = CollaborationRequestTestFactory.createBuilder().zustaendigeStelle(zustaendigeStelle).build(); + void shouldValidateCollaborationZustaendigeStelleSubjectId(String subjectId) { + var request = CollaborationRequestTestFactory.createBuilder() + .zustaendigeStelle(FachstelleTestFactory.createBuilder().subjectId(subjectId).build()) + .build(); assertThrows(ConstraintViolationException.class, () -> service.createCollaborationRequest(request)); } @@ -92,22 +107,26 @@ class CollaborationServiceITCase { assertThrows(ConstraintViolationException.class, () -> service.createFachstellenBeteiligungRequest(request)); } - @DisplayName("validate beschreibung") - @ParameterizedTest(name = "should throw exception on beschreibung: \"{0}\"") + @DisplayName("should validate technicalId of zustaendigeStelle") + @ParameterizedTest(name = "fail when technicalId: \"{0}\"") @NullAndEmptySource @ValueSource(strings = { StringUtils.SPACE }) - void shouldValidateBeschreibung(String beschreibung) { - var request = CollaborationRequestTestFactory.createBuilder().beschreibung(beschreibung).build(); + void shouldValidateCollaborationZustaendigeStelleTechnicalId(String technicalId) { + var request = CollaborationRequestTestFactory.createBuilder() + .zustaendigeStelle(FachstelleTestFactory.createBuilder().technicalId(technicalId).build()) + .build(); assertThrows(ConstraintViolationException.class, () -> service.createFachstellenBeteiligungRequest(request)); } - @DisplayName("validate zustaendigeStelle") - @ParameterizedTest(name = "should throw exception oon zustaendigeStelle: \"{0}\"") + @DisplayName("should validate zustaendigeStelle") + @ParameterizedTest(name = "fail when subjectId: \"{0}\"") @NullAndEmptySource @ValueSource(strings = { StringUtils.SPACE }) - void shouldValidateCollaborationRequestTitel(String zustaendigeStelle) { - var request = CollaborationRequestTestFactory.createBuilder().zustaendigeStelle(zustaendigeStelle).build(); + void shouldValidateCollaborationZustaendigeStelleSubjectId(String subjectId) { + var request = CollaborationRequestTestFactory.createBuilder() + .zustaendigeStelle(FachstelleTestFactory.createBuilder().subjectId(subjectId).build()) + .build(); assertThrows(ConstraintViolationException.class, () -> service.createFachstellenBeteiligungRequest(request)); } diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceTest.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceTest.java index 7b65d713753f128862cde95d7529c4bc5ddfc243..b0b742110a3a90d3084d26256834c805f94a4c04 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceTest.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/CollaborationServiceTest.java @@ -24,6 +24,7 @@ package de.ozgcloud.collaboration; import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.InstanceOfAssertFactories.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -53,9 +54,8 @@ import de.ozgcloud.collaboration.common.freemarker.TemplateHandler; import de.ozgcloud.collaboration.common.user.UserId; import de.ozgcloud.collaboration.common.user.UserProfile; import de.ozgcloud.collaboration.common.user.UserProfileService; -import de.ozgcloud.collaboration.vorgang.PostfachAddressTestFactory; +import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; import de.ozgcloud.collaboration.vorgang.ServiceKonto; -import de.ozgcloud.collaboration.vorgang.ServiceKontoTestFactory; import de.ozgcloud.collaboration.vorgang.Vorgang; import de.ozgcloud.collaboration.vorgang.VorgangService; import de.ozgcloud.collaboration.vorgang.VorgangTestFactory; @@ -410,8 +410,6 @@ class CollaborationServiceTest { class TestBuildSendPostfachNachrichtCommand { private static final CollaborationRequest COLLABORATION_REQUEST = CollaborationRequestTestFactory.create(); - private static final ServiceKonto.PostfachAddress POSTFACH_ADDRESS = PostfachAddressTestFactory.create(); - private static final ServiceKonto SERVICE_KONTO = ServiceKontoTestFactory.createBuilder().clearAddresses().address(POSTFACH_ADDRESS).build(); private static final OzgCloudUserId OZG_CLOUD_ID = OzgCloudUserId.from(CommandTestFactory.CREATED_BY); private static final Map<String, Object> OBJECT_MAP = Map.of("key", "value"); private static final OzgCloudVorgangId VORGANG_ID = OzgCloudVorgangId.from(VorgangTestFactory.ID.toString()); @@ -429,7 +427,7 @@ class CollaborationServiceTest { void shouldCallBuildPostfachAddress() { buildSendPostfachNachrichtCommand(); - verify(service).buildMukPostfachAddress(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE); + verify(service).buildMukPostfachAddress(FachstelleTestFactory.SUBJECT_ID); } @Test @@ -525,7 +523,7 @@ class CollaborationServiceTest { var result = buildPostfachAddress(); assertThat(result).extracting(ServiceKonto.PostfachAddress.FIELD_IDENTIFIER, MAP) - .containsEntry(ServiceKonto.PostfachAddress.FIELD_IDENTIFIER_POSTFACH_ID, CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE); + .containsEntry(ServiceKonto.PostfachAddress.FIELD_IDENTIFIER_POSTFACH_ID, FachstelleTestFactory.SUBJECT_ID); } @Test @@ -536,7 +534,7 @@ class CollaborationServiceTest { } private Map<String, Object> buildPostfachAddress() { - return service.buildMukPostfachAddress(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE); + return service.buildMukPostfachAddress(FachstelleTestFactory.SUBJECT_ID); } } 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 new file mode 100644 index 0000000000000000000000000000000000000000..5cbe67892d995458904fe69f10a224aff84309bc --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleMapperTest.java @@ -0,0 +1,53 @@ +package de.ozgcloud.collaboration.fachstelle; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mapstruct.factory.Mappers; + +import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleType; + +class FachstelleMapperTest { + + private final FachstelleMapper mapper = Mappers.getMapper(FachstelleMapper.class); + + @Nested + class TestFromExterneFachstelle { + + @Test + void shouldMapToFachstelle() { + var expectedFachstelle = FachstelleTestFactory.createBuilder().type(FachstelleType.EXTERNE_FACHSTELLE).build(); + + var fachstelle = mapper.fromExterneFachstelle(GrpcFachstelleTestFactory.create()); + + assertThat(fachstelle).usingRecursiveComparison().isEqualTo(expectedFachstelle); + } + } + + @Nested + class TestFromOrganisationsEinheit { + + @Test + void shouldMapToFachstelle() { + var expectedFachstelle = FachstelleTestFactory.createBuilder().type(FachstelleType.ORGANISATIONS_EINHEIT).build(); + + var fachstelle = mapper.fromOrganisationsEinheit(GrpcOrganisationsEinheitTestFactory.create()); + + assertThat(fachstelle).usingRecursiveComparison().isEqualTo(expectedFachstelle); + } + } + + @Nested + class TestToMap { + + @Test + void shouldMapToFachstelle() { + var expectedMap = FachstelleTestFactory.createAsMap(); + + var actualMap = mapper.toMap(FachstelleTestFactory.create()); + + assertThat(actualMap).usingRecursiveComparison().isEqualTo(expectedMap); + } + } +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0d8a020b2e5c6892a89c71599d37b1c026886b4b --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleRemoteServiceTest.java @@ -0,0 +1,103 @@ +package de.ozgcloud.collaboration.fachstelle; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; + +import de.ozgcloud.zufi.grpc.fachstelle.FachstelleServiceGrpc.FachstelleServiceBlockingStub; +import de.ozgcloud.zufi.grpc.organisationseinheit.OrganisationsEinheitServiceGrpc.OrganisationsEinheitServiceBlockingStub; + +class FachstelleRemoteServiceTest { + + @Spy + @InjectMocks + private FachstelleRemoteService service; + + @Mock + private FachstelleServiceBlockingStub fachstelleServiceBlockingStub; + @Mock + private OrganisationsEinheitServiceBlockingStub organisationsEinheitServiceBlockingStub; + @Mock + private FachstelleMapper fachstelleMapper; + + @Nested + class TestGetExterneFachstelle { + + @BeforeEach + void mock() { + when(fachstelleServiceBlockingStub.getById(any())).thenReturn(GrpcFachstelleGetResponseTestFactory.create()); + } + + @Test + void shouldCallFachstelleServiceBlockingStub() { + getExterneFachstelle(); + + verify(fachstelleServiceBlockingStub).getById(GrpcFachstelleGetRequestTestFactory.create()); + } + + @Test + void shouldCallFachstelleMapper() { + getExterneFachstelle(); + + verify(fachstelleMapper).fromExterneFachstelle(GrpcFachstelleGetResponseTestFactory.EXTERNE_FACHSTELLE); + } + + @Test + void shouldReturnFachstelle() { + var expectedFachstelle = FachstelleTestFactory.create(); + when(fachstelleMapper.fromExterneFachstelle(any())).thenReturn(expectedFachstelle); + + var returnFachstelle = getExterneFachstelle(); + + assertThat(returnFachstelle).isSameAs(expectedFachstelle); + } + + private Fachstelle getExterneFachstelle() { + return service.getExterneFachstelle(FachstelleTestFactory.TECHNICAL_ID); + } + } + + @Nested + class TestGetOrganisationsEinheit { + + @BeforeEach + void mock() { + when(organisationsEinheitServiceBlockingStub.getById(any())).thenReturn(GrpcOrganisationsEinheitGetResponseTestFactory.create()); + } + + @Test + void shouldCallOrganisationsEinheitServiceBlockingStub() { + getOrganisationsEinheit(); + + verify(organisationsEinheitServiceBlockingStub).getById(GrpcOrganisationsEinheitGetRequestTestFactory.create()); + } + + @Test + void shouldCallFachstelleMapper() { + getOrganisationsEinheit(); + + verify(fachstelleMapper).fromOrganisationsEinheit(GrpcOrganisationsEinheitGetResponseTestFactory.ORGANISATIONS_EINHEIT); + } + + @Test + void shouldReturnFachstelle() { + var expectedFachstelle = FachstelleTestFactory.create(); + when(fachstelleMapper.fromOrganisationsEinheit(any())).thenReturn(expectedFachstelle); + + var returnFachstelle = getOrganisationsEinheit(); + + assertThat(returnFachstelle).isSameAs(expectedFachstelle); + } + + private Fachstelle getOrganisationsEinheit() { + return service.getOrganisationsEinheit(FachstelleTestFactory.TECHNICAL_ID); + } + } +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleServiceTest.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8c364282ce37fefbc0c8ca04d79efa7ee1b321e9 --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleServiceTest.java @@ -0,0 +1,75 @@ +package de.ozgcloud.collaboration.fachstelle; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.*; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +class FachstelleServiceTest { + + @InjectMocks + private FachstelleService service; + + @Mock + private FachstelleRemoteService remoteService; + + @Nested + class TestGetFachstelle { + + @Nested + class TestOnCollaborationLevel1 { + + @Test + void shouldGetOrganisationsEinheit() { + service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 1); + + verify(remoteService).getOrganisationsEinheit(FachstelleTestFactory.TECHNICAL_ID); + } + + @Test + void shouldReturnFachstelle() { + var expectedFachstelle = FachstelleTestFactory.create(); + when(remoteService.getOrganisationsEinheit(any())).thenReturn(expectedFachstelle); + + var actualFachstelle = service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 1); + + assertThat(actualFachstelle).isSameAs(expectedFachstelle); + } + } + + @Nested + class TestOnCollaborationLevel4 { + + @Test + void shouldGetExterneFachstelle() { + service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 4); + + verify(remoteService).getExterneFachstelle(FachstelleTestFactory.TECHNICAL_ID); + } + + @Test + void shouldReturnFachstelle() { + var expectedFachstelle = FachstelleTestFactory.create(); + when(remoteService.getExterneFachstelle(any())).thenReturn(expectedFachstelle); + + var actualFachstelle = service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 4); + + assertThat(actualFachstelle).isSameAs(expectedFachstelle); + } + } + + @Nested + class TestOnUnknownCollaborationLevel { + + @Test + void shouldThrowIlleagalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> service.getFachstelle(FachstelleTestFactory.TECHNICAL_ID, 5)); + } + } + } +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..dce9ce074324f9f4f68705f4c91f65ee84125514 --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/FachstelleTestFactory.java @@ -0,0 +1,32 @@ +package de.ozgcloud.collaboration.fachstelle; + +import java.util.Map; +import java.util.UUID; + +import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleBuilder; +import de.ozgcloud.collaboration.fachstelle.Fachstelle.FachstelleType; + +public class FachstelleTestFactory { + + public static final FachstelleType TYPE = FachstelleType.ORGANISATIONS_EINHEIT; + public static final String SUBJECT_ID = UUID.randomUUID().toString(); + public static final String TECHNICAL_ID = UUID.randomUUID().toString(); + + public static Fachstelle create() { + return createBuilder().build(); + } + + public static FachstelleBuilder createBuilder() { + return Fachstelle.builder() + .subjectId(SUBJECT_ID) + .technicalId(TECHNICAL_ID) + .type(TYPE); + } + + public static Map<String, Object> createAsMap() { + return Map.of( + Fachstelle.PROPERTY_TECHNICAL_ID, TECHNICAL_ID, + Fachstelle.PROPERTY_SUBJECT_ID, SUBJECT_ID, + Fachstelle.PROPERTY_TYPE, TYPE.name()); + } +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcAnschriftTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcAnschriftTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..4354c8f28e3f30aa9c04633ca6da26820e5ec9ee --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcAnschriftTestFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den + * Ministerpräsidenten des Landes Schleswig-Holstein + * Staatskanzlei + * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung + * + * Lizenziert unter der EUPL, Version 1.2 oder - sobald + * diese von der Europäischen Kommission genehmigt wurden - + * Folgeversionen der EUPL ("Lizenz"); + * Sie dürfen dieses Werk ausschließlich gemäß + * dieser Lizenz nutzen. + * Eine Kopie der Lizenz finden Sie hier: + * + * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * Sofern nicht durch anwendbare Rechtsvorschriften + * gefordert oder in schriftlicher Form vereinbart, wird + * die unter der Lizenz verbreitete Software "so wie sie + * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - + * ausdrücklich oder stillschweigend - verbreitet. + * Die sprachspezifischen Genehmigungen und Beschränkungen + * unter der Lizenz sind dem Lizenztext zu entnehmen. + */ +package de.ozgcloud.collaboration.fachstelle; + +import java.util.Random; + +import com.thedeanda.lorem.LoremIpsum; + +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcAnschrift; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcAnschrift.Builder; + +public class GrpcAnschriftTestFactory { + public static final String PLZ = LoremIpsum.getInstance().getZipCode(); + public static final String ORT = LoremIpsum.getInstance().getCity(); + public static final String STRASSE = LoremIpsum.getInstance().getWords(2); + public static final String HAUSNUMMER = String.valueOf(new Random().nextInt()); + + public static GrpcAnschrift create() { + return createBuilder().build(); + } + + public static Builder createBuilder() { + return GrpcAnschrift.newBuilder() + .setStrasse(STRASSE) + .setHausnummer(HAUSNUMMER) + .setPlz(PLZ) + .setOrt(ORT); + } + +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleGetRequestTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleGetRequestTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..d2a90ff0e4a956e355020e684f6bc175e773b9c1 --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleGetRequestTestFactory.java @@ -0,0 +1,18 @@ +package de.ozgcloud.collaboration.fachstelle; + +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest; +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetRequest.Builder; + +public class GrpcFachstelleGetRequestTestFactory { + + private static final String ID = FachstelleTestFactory.TECHNICAL_ID; + + public static GrpcFachstelleGetRequest create() { + return createBuilder().build(); + } + + private static Builder createBuilder() { + return GrpcFachstelleGetRequest.newBuilder().setId(ID); + } + +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleGetResponseTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleGetResponseTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..e13c2a7cdcd1322dd87ffd8c4a011f881ab5f0ee --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleGetResponseTestFactory.java @@ -0,0 +1,20 @@ +package de.ozgcloud.collaboration.fachstelle; + +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle; +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetResponse; +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelleGetResponse.Builder; + +public class GrpcFachstelleGetResponseTestFactory { + + public static final GrpcFachstelle EXTERNE_FACHSTELLE = GrpcFachstelleTestFactory.create(); + + public static GrpcFachstelleGetResponse create() { + return createBuilder().build(); + } + + public static Builder createBuilder() { + return GrpcFachstelleGetResponse.newBuilder() + .setFachstelle(EXTERNE_FACHSTELLE); + } + +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..00ca89b4cb5fe9b97d12fd2f0a397ceebc577436 --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcFachstelleTestFactory.java @@ -0,0 +1,37 @@ +package de.ozgcloud.collaboration.fachstelle; + +import java.util.UUID; + +import com.thedeanda.lorem.LoremIpsum; + +import de.ozgcloud.zufi.grpc.fachstelle.GrpcFachstelle; + +public class GrpcFachstelleTestFactory { + + private static final String MUK_ID = FachstelleTestFactory.SUBJECT_ID; + private static final String ID = FachstelleTestFactory.TECHNICAL_ID; + public static final String FIRMEN_NAME = LoremIpsum.getInstance().getWords(2); + public static final String RECHTSFORM = LoremIpsum.getInstance().getWords(1); + public static final String RECHTSFORM_TEXT = LoremIpsum.getInstance().getWords(1); + public static final String REGISTER_NUMMER = UUID.randomUUID().toString(); + public static final String REGISTER_ART = LoremIpsum.getInstance().getWords(1); + public static final String EMAIL_ADRESSE = LoremIpsum.getInstance().getEmail(); + public static final String ANSCHRIFT = LoremIpsum.getInstance().getWords(5); + + public static GrpcFachstelle create() { + return createBuilder().build(); + } + + private static GrpcFachstelle.Builder createBuilder() { + return GrpcFachstelle.newBuilder() + .setId(ID) + .setMukId(MUK_ID) + .setFirmenName(FIRMEN_NAME) + .setRechtsform(RECHTSFORM) + .setRechtsformText(RECHTSFORM_TEXT) + .setRegisterNummer(REGISTER_NUMMER) + .setRegisterArt(REGISTER_ART) + .setEmailAdresse(EMAIL_ADRESSE) + .setAnschrift(ANSCHRIFT); + } +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitGetRequestTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitGetRequestTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..4c6f3f79774f04ea030e78df5ac5d83c6427ddcd --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitGetRequestTestFactory.java @@ -0,0 +1,18 @@ +package de.ozgcloud.collaboration.fachstelle; + +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetRequest.Builder; + +public class GrpcOrganisationsEinheitGetRequestTestFactory { + + private static final String ID = FachstelleTestFactory.TECHNICAL_ID; + + public static GrpcOrganisationsEinheitGetRequest create() { + return createBuilder().build(); + } + + private static Builder createBuilder() { + return GrpcOrganisationsEinheitGetRequest.newBuilder().setId(ID); + } + +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitGetResponseTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitGetResponseTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..823e7eb8794e3c31986ed1ead5dee96f835992d8 --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitGetResponseTestFactory.java @@ -0,0 +1,19 @@ +package de.ozgcloud.collaboration.fachstelle; + +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheitGetResponse.Builder; + +public class GrpcOrganisationsEinheitGetResponseTestFactory { + + public static final GrpcOrganisationsEinheit ORGANISATIONS_EINHEIT = GrpcOrganisationsEinheitTestFactory.create(); + + public static GrpcOrganisationsEinheitGetResponse create() { + return createBuilder().build(); + } + + public static Builder createBuilder() { + return GrpcOrganisationsEinheitGetResponse.newBuilder().setOrganisationsEinheit(ORGANISATIONS_EINHEIT); + } + +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..e6f2848cd4242a252b3a5635037a04c33c695f0f --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcOrganisationsEinheitTestFactory.java @@ -0,0 +1,41 @@ +package de.ozgcloud.collaboration.fachstelle; + +import com.thedeanda.lorem.LoremIpsum; + +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcAnschrift; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcOrganisationsEinheit.Builder; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcXzufiId; + +public class GrpcOrganisationsEinheitTestFactory { + public static final String ID = FachstelleTestFactory.TECHNICAL_ID; + public static final GrpcXzufiId XZUFI_ID = GrpcXzufiIdTestFactory.create(); + public static final String NAME = LoremIpsum.getInstance().getName(); + public static final String SYNONYME = LoremIpsum.getInstance().getWords(5); + public static final GrpcAnschrift ANSCHRIFT = GrpcAnschriftTestFactory.create(); + public static final String VORGANG_MANAGER_ADDRESS = LoremIpsum.getInstance().getUrl(); + + public static GrpcOrganisationsEinheit create() { + return createBuilder().build(); + } + + public static GrpcOrganisationsEinheit createWithoutSynonyme() { + return createBuilderWithoutSynonyme() + .build(); + } + + public static Builder createBuilder() { + return createBuilderWithoutSynonyme() + .setSynonyme(SYNONYME); + } + + public static Builder createBuilderWithoutSynonyme() { + return GrpcOrganisationsEinheit.newBuilder() + .setId(ID) + .setName(NAME) + .setAnschrift(ANSCHRIFT) + .setVorgangManagerAddress(VORGANG_MANAGER_ADDRESS) + .setXzufiId(XZUFI_ID); + } + +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcXzufiIdTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcXzufiIdTestFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..a9459580db55559cbac4117474f8512c756627ad --- /dev/null +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/fachstelle/GrpcXzufiIdTestFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 Das Land Schleswig-Holstein vertreten durch den + * Ministerpräsidenten des Landes Schleswig-Holstein + * Staatskanzlei + * Abteilung Digitalisierung und zentrales IT-Management der Landesregierung + * + * Lizenziert unter der EUPL, Version 1.2 oder - sobald + * diese von der Europäischen Kommission genehmigt wurden - + * Folgeversionen der EUPL ("Lizenz"); + * Sie dürfen dieses Werk ausschließlich gemäß + * dieser Lizenz nutzen. + * Eine Kopie der Lizenz finden Sie hier: + * + * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * Sofern nicht durch anwendbare Rechtsvorschriften + * gefordert oder in schriftlicher Form vereinbart, wird + * die unter der Lizenz verbreitete Software "so wie sie + * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - + * ausdrücklich oder stillschweigend - verbreitet. + * Die sprachspezifischen Genehmigungen und Beschränkungen + * unter der Lizenz sind dem Lizenztext zu entnehmen. + */ +package de.ozgcloud.collaboration.fachstelle; + +import java.util.UUID; + +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcXzufiId; +import de.ozgcloud.zufi.grpc.organisationseinheit.GrpcXzufiId.Builder; + +public class GrpcXzufiIdTestFactory { + public static final String ORGANISATIONS_EINHEIT_ID = FachstelleTestFactory.SUBJECT_ID; + public static final String SCHEME_AGENCY_ID = UUID.randomUUID().toString(); + + public static GrpcXzufiId create() { + return createBuilder().build(); + } + + public static Builder createBuilder() { + return GrpcXzufiId.newBuilder().setId(ORGANISATIONS_EINHEIT_ID).setSchemeAgencyId(SCHEME_AGENCY_ID); + } +} diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/request/GrpcCreateCollaborationRequestDataTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/request/GrpcCreateCollaborationRequestDataTestFactory.java index b9be69c7847ccd054e24e878997e2d92c0d65852..ebff716b44da20ff806a6755ad6e9e0bf7350e0c 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/request/GrpcCreateCollaborationRequestDataTestFactory.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/request/GrpcCreateCollaborationRequestDataTestFactory.java @@ -1,6 +1,7 @@ package de.ozgcloud.collaboration.request; import de.ozgcloud.collaboration.CollaborationRequestTestFactory; +import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; import de.ozgcloud.command.CommandTestFactory; import de.ozgcloud.vorgang.vorgang.GrpcCreateCollaborationRequestData; @@ -14,6 +15,6 @@ public class GrpcCreateCollaborationRequestDataTestFactory { return GrpcCreateCollaborationRequestData.newBuilder() .setCollaborationLevel(CollaborationRequestTestFactory.COLLABORATION_LEVEL) .setVorgangId(CommandTestFactory.VORGANG_ID) - .setZustaendigeStelle(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE); + .setZustaendigeStelle(FachstelleTestFactory.SUBJECT_ID); } } \ No newline at end of file diff --git a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/vorgang/GrpcCollaborationRequestTestFactory.java b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/vorgang/GrpcCollaborationRequestTestFactory.java index a7301e44d37b857b89b83f45ca95ad15717a9cd3..dc3b92673f1e654535d9a300579b09c6ff2172cf 100644 --- a/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/vorgang/GrpcCollaborationRequestTestFactory.java +++ b/collaboration-manager-server/src/test/java/de/ozgcloud/collaboration/vorgang/GrpcCollaborationRequestTestFactory.java @@ -1,6 +1,7 @@ package de.ozgcloud.collaboration.vorgang; import de.ozgcloud.collaboration.CollaborationRequestTestFactory; +import de.ozgcloud.collaboration.fachstelle.FachstelleTestFactory; import de.ozgcloud.collaboration.request.GrpcCollaborationRequest; import de.ozgcloud.command.CommandTestFactory; @@ -14,10 +15,11 @@ public class GrpcCollaborationRequestTestFactory { return GrpcCollaborationRequest.newBuilder() .setId(CollaborationRequestTestFactory.ID_STR) .setBeschreibung(CollaborationRequestTestFactory.BESCHREIBUNG) + .setTitel(CollaborationRequestTestFactory.TITEL) .setCollaborationLevel(CollaborationRequestTestFactory.COLLABORATION_LEVEL) .setCollaborationVorgangId(CollaborationRequestTestFactory.COLLABORATION_VORGANG_ID) .setCreatedBy(CommandTestFactory.CREATED_BY) - .setZustaendigeStelle(CollaborationRequestTestFactory.ZUSTAENDIGE_STELLE) + .setZustaendigeStelle(FachstelleTestFactory.TECHNICAL_ID) .setCollaborationLevel(CollaborationRequestTestFactory.COLLABORATION_LEVEL); } } diff --git a/lombok.config b/lombok.config index a06fa130e8af26b659f2d3a0cb1114cd966a9b0e..f881e23c3720b1ad363aac0f5c1fe615a66a5d90 100644 --- a/lombok.config +++ b/lombok.config @@ -28,4 +28,5 @@ lombok.log.log4j.flagUsage = ERROR lombok.data.flagUsage = ERROR lombok.nonNull.exceptionType = IllegalArgumentException lombok.addLombokGeneratedAnnotation = true -lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier \ No newline at end of file +lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier +lombok.copyableAnnotations += net.devh.boot.grpc.client.inject.GrpcClient \ No newline at end of file