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

OZG-5681 create call context providers

parent deb1d8d5
No related branches found
No related tags found
No related merge requests found
/*
* 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.bescheid;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.grpc.CommandMapper;
import de.ozgcloud.apilib.common.command.grpc.GrpcOzgCloudCommandService;
import de.ozgcloud.bescheid.common.callcontext.BescheidManagerCallContextProvider;
import de.ozgcloud.vorgang.grpc.command.CommandServiceGrpc;
import net.devh.boot.grpc.client.inject.GrpcClient;
@Configuration
public class BescheidManagerConfiguration {
@GrpcClient("ozgcloud-command-manager")
private CommandServiceGrpc.CommandServiceBlockingStub commandServiceStub;
@Bean("bescheid_OzgCloudCommandService")
OzgCloudCommandService grpcOzgCloudCommandService(CommandMapper commandMapper, BescheidManagerCallContextProvider contextProvider) {
return new GrpcOzgCloudCommandService(commandServiceStub, commandMapper, contextProvider,
GrpcOzgCloudCommandService.DEFAULT_COMMAND_REQUEST_THRESHOLD_MILLIS);
}
}
......@@ -35,6 +35,8 @@ import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
......@@ -45,11 +47,9 @@ import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor;
import de.ozgcloud.bescheid.vorgang.VorgangId;
import de.ozgcloud.command.Command;
import de.ozgcloud.common.errorhandling.TechnicalException;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@Service
@RequiredArgsConstructor
@Log4j2
public class AttachedItemService {
......@@ -61,9 +61,13 @@ public class AttachedItemService {
private static final Predicate<String> notExpectedSendByValue = sendBy -> !ArrayUtils.contains(Bescheid.SendBy.values(), sendBy);
private final OzgCloudCommandService commandService;
private final VorgangAttachedItemRemoteService remoteService;
private final CommandMapper commandMapper;
@Autowired
@Qualifier("bescheid_OzgCloudCommandService")
private OzgCloudCommandService commandService;
@Autowired
private VorgangAttachedItemRemoteService remoteService;
@Autowired
private CommandMapper commandMapper;
public Optional<AttachedItem> findBescheidItem(String vorgangId) {
return remoteService.findBescheidDraft(vorgangId);
......
......@@ -23,15 +23,17 @@
*/
package de.ozgcloud.bescheid.common.callcontext;
import java.util.Optional;
import org.springframework.stereotype.Component;
import de.ozgcloud.apilib.common.callcontext.CallContext;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider;
import de.ozgcloud.apilib.user.OzgCloudUserId;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor;
import lombok.RequiredArgsConstructor;
@Component("bescheid_BescheidManagerCallContextProvider")
@Component
@RequiredArgsConstructor
public class BescheidManagerCallContextProvider implements OzgCloudCallContextProvider {
......@@ -39,14 +41,12 @@ public class BescheidManagerCallContextProvider implements OzgCloudCallContextPr
@Override
public CallContext provideContext() {
return CallContext.builder()
.userId(getUserId())
.clientName(currentUserService.getUser().getClientName())
.build();
var callContextBuilder = CallContext.builder().clientName(BescheidCallContextAttachingInterceptor.BESCHEID_MANAGER_CLIENT_NAME);
getUserId().ifPresent(callContextBuilder::userId);
return callContextBuilder.build();
}
OzgCloudUserId getUserId() {
return currentUserService.getUser().getUserId().map(OzgCloudUserId::from)
.orElseThrow(() -> new TechnicalException("No user id found in current user profile"));
Optional<OzgCloudUserId> getUserId() {
return currentUserService.getUser().getUserId().map(OzgCloudUserId::from);
}
}
......@@ -8,6 +8,8 @@ import java.util.Optional;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
......@@ -19,12 +21,10 @@ import de.ozgcloud.common.errorhandling.TechnicalException;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@Service
@Log4j2
@RequiredArgsConstructor
public class NachrichtService {
public static final String SEND_POSTFACH_NACHRICHT_ORDER = "SEND_POSTFACH_NACHRICHT";
......@@ -35,10 +35,15 @@ public class NachrichtService {
static final String FIELD_MAIL_BODY = "mailBody";
static final String FIELD_ATTACHMENTS = "attachments";
private final NachrichtRemoteService remoteService;
private final Configuration freemarkerCfg;
private final OzgCloudCommandService commandService;
private final CommandMapper commandMapper;
@Autowired
private NachrichtRemoteService remoteService;
@Autowired
private Configuration freemarkerCfg;
@Autowired
@Qualifier("bescheid_OzgCloudCommandService")
private OzgCloudCommandService commandService;
@Autowired
private CommandMapper commandMapper;
static final String SUBJECT = "Ihr Antrag";
......
package de.ozgcloud.bescheid.vorgang;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.grpc.CommandMapper;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Service("bescheid_VorgangService")
@RequiredArgsConstructor
public class VorgangService {
static final String VORGANG_BESCHEIDEN = "VORGANG_BESCHEIDEN";
private final VorgangRemoteService remoteService;
private final OzgCloudCommandService commandService;
private final CommandMapper commandMapper;
@Autowired
private VorgangRemoteService remoteService;
@Autowired
@Qualifier("bescheid_OzgCloudCommandService")
private OzgCloudCommandService commandService;
@Autowired
private CommandMapper commandMapper;
public Vorgang getById(@NonNull VorgangId id) {
return remoteService.getById(id);
......
......@@ -31,6 +31,8 @@ import java.util.Optional;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
......@@ -42,10 +44,8 @@ import de.ozgcloud.bescheid.attacheditem.AttachedItem;
import de.ozgcloud.bescheid.attacheditem.AttachedItemService;
import de.ozgcloud.command.Command;
import de.ozgcloud.common.errorhandling.TechnicalException;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class DocumentService {
public static final String DOCUMENT_ITEM_NAME = "Document";
......@@ -56,10 +56,15 @@ public class DocumentService {
public static final String FIELD_DOCUMENT_FILE = "documentFile";
public static final String FIELD_NACHRICHT_TEXT = "nachrichtText";
private final AttachedItemService attachedItemService;
private final OzgCloudCommandService commandService;
private final CommandMapper commandMapper;
private final DocumentMapper documentMapper;
@Autowired
private AttachedItemService attachedItemService;
@Autowired
@Qualifier("bescheid_OzgCloudCommandService")
private OzgCloudCommandService commandService;
@Autowired
private CommandMapper commandMapper;
@Autowired
private DocumentMapper documentMapper;
public String createBescheidDocument(Command command) {
return createBescheidDocument(command, buildItemMap(command));
......
......@@ -28,7 +28,6 @@ import static org.mockito.Mockito.*;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
......@@ -37,7 +36,7 @@ import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.apilib.user.OzgCloudUserId;
import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.bescheid.BescheidCallContextAttachingInterceptor;
class BescheidManagerCallContextProviderTest {
......@@ -52,20 +51,12 @@ class BescheidManagerCallContextProviderTest {
@Mock
private OzgCloudUserId userId;
@BeforeEach
void init() {
when(currentUserService.getUser()).thenReturn(contextUser);
}
@Nested
class TestProvideContext {
private static final String CLIENT_NAME = "clientName";
@BeforeEach
void init() {
doReturn(userId).when(provider).getUserId();
when(contextUser.getClientName()).thenReturn(CLIENT_NAME);
doReturn(Optional.of(userId)).when(provider).getUserId();
}
@Test
......@@ -86,7 +77,7 @@ class BescheidManagerCallContextProviderTest {
void shouldSetClientName() {
var result = provider.provideContext();
assertThat(result.getClientName()).isEqualTo(CLIENT_NAME);
assertThat(result.getClientName()).isEqualTo(BescheidCallContextAttachingInterceptor.BESCHEID_MANAGER_CLIENT_NAME);
}
}
......@@ -95,18 +86,19 @@ class BescheidManagerCallContextProviderTest {
private static final String USER_ID = "userId";
@BeforeEach
void init() {
when(currentUserService.getUser()).thenReturn(contextUser);
}
@Test
void shouldReturnUserId() {
when(contextUser.getUserId()).thenReturn(Optional.of(USER_ID));
var result = provider.getUserId();
assertThat(result).hasToString(USER_ID);
assertThat(result).isPresent().get().hasToString(USER_ID);
}
@Test
void shouldThrowExceptionWhenUserIdMissing() {
Assertions.assertThrows(TechnicalException.class, provider::getUserId);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment