From 9af26db424db85b13847802db2c2f2abe60e465b Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Tue, 11 Oct 2022 16:19:12 +0200 Subject: [PATCH 01/11] fix: slogan name resolving for single domain multitenancy mode --- pom.xml | 25 ++++++ services/applicationsettingsservice.yaml | 89 +++++++++++++++++++ .../api/config/CacheManagerConfig.java | 26 +++++- .../ApplicationSettingsApiClient.java | 83 +++++++++++++++++ ...plicationSettingsApiControllerFactory.java | 23 +++++ .../ApplicationSettingsService.java | 38 ++++++++ .../emailsupplier/TenantTemplateSupplier.java | 40 ++++++++- src/main/resources/application.properties | 5 ++ .../TenantTemplateSupplierTest.java | 26 +++++- 9 files changed, 346 insertions(+), 9 deletions(-) create mode 100644 services/applicationsettingsservice.yaml create mode 100644 src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiClient.java create mode 100644 src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiControllerFactory.java create mode 100644 src/main/java/de/caritas/cob/userservice/api/service/consultingtype/ApplicationSettingsService.java diff --git a/pom.xml b/pom.xml index 1d42bc549..1b041471c 100644 --- a/pom.xml +++ b/pom.xml @@ -461,6 +461,31 @@ + + application-settings-service-client-model + generate-sources + + generate + + + + / + resttemplate + java8 + + ${project.basedir}/services/applicationsettingsservice.yaml + java + true + false + false + + ${project.groupId}.${project.artifactId}.applicationsettingsservice.generated.web + + + ${project.groupId}.${project.artifactId}.applicationsettingsservice.generated.web.model + + + user-admin-service diff --git a/services/applicationsettingsservice.yaml b/services/applicationsettingsservice.yaml new file mode 100644 index 000000000..815653b37 --- /dev/null +++ b/services/applicationsettingsservice.yaml @@ -0,0 +1,89 @@ +openapi: 3.0.1 + +info: + title: Definition for Application Settings API + description: This information will be replaced by the SpringFox config information + version: 0.0.1 + +paths: + /settings: + get: + tags: + - applicationsettings-controller + summary: 'Get all application settings' + operationId: getApplicationSettings + responses: + 200: + description: OK - successful operation + + content: + application/json: + schema: + $ref: '#/components/schemas/ApplicationSettingsDTO' + 204: + description: NO CONTENT - no content found + 400: + description: BAD REQUEST - invalid/incomplete request or body object + 401: + description: UNAUTHORIZED - no/invalid Keycloak token + 500: + description: INTERNAL SERVER ERROR - server encountered unexpected condition + +components: + schemas: + ApplicationSettingsDTO: + type: object + required: + - multitenancyWithSingleDomainEnabled + - multitenancyEnabled + properties: + multitenancyWithSingleDomainEnabled: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + multitenancyEnabled: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + useTenantService: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + enableWalkthrough: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + disableVideoAppointments: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + mainTenantSubdomainForSingleDomainMultitenancy: + allOf: + - $ref: '#/components/schemas/SettingDTO' + budibaseSSO: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + useOverviewPage: + allOf: + - $ref: '#/components/schemas/FeatureToggleDTO' + + + FeatureToggleDTO: + type: object + required: + - value + - readOnly + properties: + value: + type: boolean + example: true + readOnly: + type: boolean + example: false + SettingDTO: + type: object + required: + - value + - readOnly + properties: + value: + type: string + example: true + readOnly: + type: boolean + example: false diff --git a/src/main/java/de/caritas/cob/userservice/api/config/CacheManagerConfig.java b/src/main/java/de/caritas/cob/userservice/api/config/CacheManagerConfig.java index 7899897b4..20b994625 100644 --- a/src/main/java/de/caritas/cob/userservice/api/config/CacheManagerConfig.java +++ b/src/main/java/de/caritas/cob/userservice/api/config/CacheManagerConfig.java @@ -14,6 +14,8 @@ public class CacheManagerConfig { public static final String AGENCY_CACHE = "agencyCache"; public static final String CONSULTING_TYPE_CACHE = "consultingTypeCache"; + + public static final String APPLICATION_SETTINGS_CACHE = "applicationSettingsCache"; public static final String TENANT_CACHE = "tenantCache"; public static final String TENANT_ADMIN_CACHE = "tenantAdminCache"; public static final String TOPICS_CACHE = "topicsCache"; @@ -66,6 +68,18 @@ public class CacheManagerConfig { @Value("${cache.topic.configuration.timeToLiveSeconds}") private long topicTimeToLiveSeconds; + @Value("${cache.appsettings.configuration.maxEntriesLocalHeap}") + private long appSettingsMaxEntriesLocalHeap; + + @Value("${cache.appsettings.configuration.eternal}") + private boolean appSettingsEternal; + + @Value("${cache.appsettings.configuration.timeToIdleSeconds}") + private long appSettingsTimeToIdleSeconds; + + @Value("${cache.appsettings.configuration.timeToLiveSeconds}") + private long appSettingsTimeToLiveSeconds; + @Bean public CacheManager cacheManager() { return new EhCacheCacheManager(ehCacheManager()); @@ -79,7 +93,7 @@ public net.sf.ehcache.CacheManager ehCacheManager() { config.addCache(buildTenantCacheConfiguration()); config.addCache(buildTenantAdminCacheConfiguration()); config.addCache(buildTopicCacheConfiguration()); - + config.addCache(buildApplicationSettingsCacheConfiguration()); return net.sf.ehcache.CacheManager.newInstance(config); } @@ -132,4 +146,14 @@ private CacheConfiguration buildTopicCacheConfiguration() { topicCacheConfiguration.setTimeToLiveSeconds(topicTimeToLiveSeconds); return topicCacheConfiguration; } + + private CacheConfiguration buildApplicationSettingsCacheConfiguration() { + var appSettingsCacheConfiguration = new CacheConfiguration(); + appSettingsCacheConfiguration.setName(APPLICATION_SETTINGS_CACHE); + appSettingsCacheConfiguration.setMaxEntriesLocalHeap(appSettingsMaxEntriesLocalHeap); + appSettingsCacheConfiguration.setEternal(appSettingsEternal); + appSettingsCacheConfiguration.setTimeToIdleSeconds(appSettingsTimeToIdleSeconds); + appSettingsCacheConfiguration.setTimeToLiveSeconds(appSettingsTimeToLiveSeconds); + return appSettingsCacheConfiguration; + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiClient.java b/src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiClient.java new file mode 100644 index 000000000..131ce2442 --- /dev/null +++ b/src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiClient.java @@ -0,0 +1,83 @@ +package de.caritas.cob.userservice.api.config.apiclient; + +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; +import static org.apache.commons.lang3.StringUtils.isEmpty; + +import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.util.Arrays; +import java.util.Collection; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +/** Extension of the generated UserService API client to adapt the handling of parameter values. */ +public class ApplicationSettingsApiClient + extends de.caritas.cob.userservice.applicationsettingsservice.generated.ApiClient { + + private static final String FILTER_NAME = "filter"; + + public ApplicationSettingsApiClient(RestTemplate restTemplate) { + super(restTemplate); + } + + /** + * Changes the behavior of mapping multiple parameter values to exclude null values for objects + * which are not {@link Collection} for filter query params. + * + * @param collectionFormat The format to convert to + * @param name The name of the parameter + * @param value The parameter's value + * @return a Map containing non-null String value(s) of the input parameter + */ + @Override + public MultiValueMap parameterToMultiValueMap( + CollectionFormat collectionFormat, String name, Object value) { + + if (noValidFilterParams(name, value)) { + return super.parameterToMultiValueMap(collectionFormat, name, value); + } + + return obtainQueryParameters(value); + } + + private boolean noValidFilterParams(String queryName, Object queryValue) { + return isEmpty(queryName) || !queryName.equals(FILTER_NAME) || isNull(queryValue); + } + + private MultiValueMap obtainQueryParameters(Object queryValue) { + MultiValueMap paramMap = new LinkedMultiValueMap<>(); + + try { + Arrays.asList( + Introspector.getBeanInfo(queryValue.getClass(), Object.class) + .getPropertyDescriptors()) + .stream() + .filter(descriptor -> nonNull(descriptor.getReadMethod())) + .forEach(descriptor -> setMethodKeyValuePairs(queryValue, paramMap, descriptor)); + return paramMap; + + } catch (IntrospectionException exception) { + throw new InternalServerErrorException( + String.format("Could not obtain method properties of %s", queryValue.toString()), + exception); + } + } + + private void setMethodKeyValuePairs( + Object queryValue, MultiValueMap map, PropertyDescriptor descriptor) { + try { + Object value = descriptor.getReadMethod().invoke(queryValue); + if (nonNull(value)) { + map.add(descriptor.getName(), value.toString()); + } + } catch (Exception exception) { + throw new InternalServerErrorException( + String.format("Could not obtain method key value pairs of %s", queryValue.toString()), + exception); + } + } +} diff --git a/src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiControllerFactory.java b/src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiControllerFactory.java new file mode 100644 index 000000000..478f4d95b --- /dev/null +++ b/src/main/java/de/caritas/cob/userservice/api/config/apiclient/ApplicationSettingsApiControllerFactory.java @@ -0,0 +1,23 @@ +package de.caritas.cob.userservice.api.config.apiclient; + +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.ApplicationsettingsControllerApi; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Component +public class ApplicationSettingsApiControllerFactory { + + @Value("${consulting.type.service.api.url}") + private String applicationsettingsServiceApiUrl; + + @Autowired private RestTemplate restTemplate; + + public ApplicationsettingsControllerApi createControllerApi() { + var apiClient = + new ApplicationSettingsApiClient(restTemplate) + .setBasePath(this.applicationsettingsServiceApiUrl); + return new ApplicationsettingsControllerApi(apiClient); + } +} diff --git a/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/ApplicationSettingsService.java b/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/ApplicationSettingsService.java new file mode 100644 index 000000000..86e6bd9a6 --- /dev/null +++ b/src/main/java/de/caritas/cob/userservice/api/service/consultingtype/ApplicationSettingsService.java @@ -0,0 +1,38 @@ +package de.caritas.cob.userservice.api.service.consultingtype; + +import de.caritas.cob.userservice.api.config.CacheManagerConfig; +import de.caritas.cob.userservice.api.config.apiclient.ApplicationSettingsApiControllerFactory; +import de.caritas.cob.userservice.api.service.httpheader.SecurityHeaderSupplier; +import de.caritas.cob.userservice.api.service.httpheader.TenantHeaderSupplier; +import de.caritas.cob.userservice.applicationsettingsservice.generated.ApiClient; +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.ApplicationsettingsControllerApi; +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.model.ApplicationSettingsDTO; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +/** Service class to communicate with the ConsultingTypeService. */ +@Component +@RequiredArgsConstructor +public class ApplicationSettingsService { + + private final @NonNull ApplicationSettingsApiControllerFactory + applicationSettingsApiControllerFactory; + private final @NonNull SecurityHeaderSupplier securityHeaderSupplier; + private final @NonNull TenantHeaderSupplier tenantHeaderSupplier; + + @Cacheable(value = CacheManagerConfig.APPLICATION_SETTINGS_CACHE) + public ApplicationSettingsDTO getApplicationSettings() { + ApplicationsettingsControllerApi controllerApi = + applicationSettingsApiControllerFactory.createControllerApi(); + addDefaultHeaders(controllerApi.getApiClient()); + return controllerApi.getApplicationSettings(); + } + + private void addDefaultHeaders(ApiClient apiClient) { + var headers = this.securityHeaderSupplier.getCsrfHttpHeaders(); + tenantHeaderSupplier.addTenantHeader(headers); + headers.forEach((key, value) -> apiClient.addDefaultHeader(key, value.iterator().next())); + } +} diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplier.java index fe7f3b16a..41f9c0f2b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplier.java @@ -3,7 +3,10 @@ import static de.caritas.cob.userservice.api.tenant.TenantContext.getCurrentTenantData; import de.caritas.cob.userservice.api.admin.service.tenant.TenantService; +import de.caritas.cob.userservice.api.service.consultingtype.ApplicationSettingsService; import de.caritas.cob.userservice.api.tenant.TenantContext; +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.model.ApplicationSettingsDTO; +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.model.SettingDTO; import de.caritas.cob.userservice.mailservice.generated.web.model.TemplateDataDTO; import de.caritas.cob.userservice.tenantservice.generated.web.model.RestrictedTenantDTO; import java.net.URI; @@ -24,6 +27,8 @@ public class TenantTemplateSupplier { private static final String HTTPS = "https://"; private final @NonNull TenantService tenantService; + private final @NonNull ApplicationSettingsService applicationSettingsService; + @Value("${app.base.url}") private String applicationBaseUrl; @@ -32,16 +37,43 @@ public class TenantTemplateSupplier { public List getTemplateAttributes() { + List templateAttributes = new ArrayList<>(); RestrictedTenantDTO tenantData = getRestrictedTenantDTO(); + if (multitenancyWithSingleDomain) { + RestrictedTenantDTO rootDomainTenantData = + getRestrictedTenantDTOForSingleDomainMultitenancy(); + templateAttributes.add(getTenantName(rootDomainTenantData)); + templateAttributes.add(getTenantClaim(rootDomainTenantData)); + } else { + templateAttributes.add(getTenantName(tenantData)); + templateAttributes.add(getTenantClaim(tenantData)); + } + addUrlBasedAttributes(tenantData, templateAttributes); + return templateAttributes; + } - List templateAttributes = new ArrayList<>(); - templateAttributes.add(getTenantName(tenantData)); - templateAttributes.add(getTenantClaim(tenantData)); + private void addUrlBasedAttributes( + RestrictedTenantDTO tenantData, List templateAttributes) { String tenantBaseUrl = getTenantBaseUrl(tenantData.getSubdomain()); templateAttributes.add(new TemplateDataDTO().key("url").value(tenantBaseUrl)); templateAttributes.add(getTenantImprintUrl(tenantBaseUrl)); templateAttributes.add(getTanantPrivacyUrl(tenantBaseUrl)); - return templateAttributes; + } + + private RestrictedTenantDTO getRestrictedTenantDTOForSingleDomainMultitenancy() { + ApplicationSettingsDTO applicationSettings = + applicationSettingsService.getApplicationSettings(); + SettingDTO mainTenantSubdomainForSingleDomainMultitenancy = + applicationSettings.getMainTenantSubdomainForSingleDomainMultitenancy(); + + if (mainTenantSubdomainForSingleDomainMultitenancy == null + || mainTenantSubdomainForSingleDomainMultitenancy.getValue() == null) { + log.error("main tenant subdomain not found in app settings"); + throw new IllegalStateException("main tenant subdomain not found in app settings"); + } + + var mainTenantSubdomain = mainTenantSubdomainForSingleDomainMultitenancy.getValue(); + return tenantService.getRestrictedTenantData(mainTenantSubdomain); } private RestrictedTenantDTO getRestrictedTenantDTO() { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 928177ea3..dc7c8f825 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -135,6 +135,11 @@ cache.topic.configuration.eternal=false cache.topic.configuration.timeToIdleSeconds=0 cache.topic.configuration.timeToLiveSeconds=60 +cache.appsettings.configuration.maxEntriesLocalHeap=100 +cache.appsettings.configuration.eternal=false +cache.appsettings.configuration.timeToIdleSeconds=0 +cache.appsettings.configuration.timeToLiveSeconds=60 + # MailService API mail.service.api.url=http://mailservice:8080/service diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplierTest.java index 83025f8a7..704429b34 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/TenantTemplateSupplierTest.java @@ -6,8 +6,11 @@ import static org.mockito.Mockito.when; import de.caritas.cob.userservice.api.admin.service.tenant.TenantService; +import de.caritas.cob.userservice.api.service.consultingtype.ApplicationSettingsService; import de.caritas.cob.userservice.api.tenant.TenantContext; import de.caritas.cob.userservice.api.tenant.TenantData; +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.model.ApplicationSettingsDTO; +import de.caritas.cob.userservice.applicationsettingsservice.generated.web.model.SettingDTO; import de.caritas.cob.userservice.mailservice.generated.web.model.TemplateDataDTO; import de.caritas.cob.userservice.tenantservice.generated.web.model.RestrictedTenantDTO; import java.util.List; @@ -30,6 +33,8 @@ class TenantTemplateSupplierTest { @Mock TenantService tenantService; + @Mock ApplicationSettingsService applicationSettingsService; + private final EasyRandom easyRandom = new EasyRandom(); @AfterEach @@ -106,16 +111,24 @@ void getTemplateAttributes_ShouldProvideTenantSpecificDataForEmailTemplates() { RestrictedTenantDTO mockedTenantData = easyRandom.nextObject(RestrictedTenantDTO.class); mockedTenantData.setSubdomain(VALID_SUBDOMAIN); + RestrictedTenantDTO mainTenantSubdomainData = easyRandom.nextObject(RestrictedTenantDTO.class); + mainTenantSubdomainData.setSubdomain(VALID_SUBDOMAIN); + + when(applicationSettingsService.getApplicationSettings()) + .thenReturn( + new ApplicationSettingsDTO() + .mainTenantSubdomainForSingleDomainMultitenancy(new SettingDTO().value("app"))); + when(tenantService.getRestrictedTenantData(1L)).thenReturn(mockedTenantData); + when(tenantService.getRestrictedTenantData("app")).thenReturn(mainTenantSubdomainData); + // when - when(tenantService.getRestrictedTenantData(tenantData.getTenantId())) - .thenReturn(mockedTenantData); List templateAttributes = tenantTemplateSupplier.getTemplateAttributes(); // then assertTemplateAttributesAreCorrectWithUrl( - mockedTenantData, templateAttributes, "https://onlineberatung.net"); + mainTenantSubdomainData, templateAttributes, "https://onlineberatung.net"); - verify(tenantService, Mockito.never()).getRestrictedTenantData(tenantData.getSubdomain()); + verify(tenantService).getRestrictedTenantData("app"); verify(tenantService).getRestrictedTenantData(tenantData.getTenantId()); TenantContext.clear(); @@ -131,6 +144,11 @@ private void assertTemplateAttributesAreCorrectWithUrl( assertThat(templateAttributes.get(1).getKey(), is("tenant_claim")); assertThat(templateAttributes.get(1).getValue(), is(mockedTenantData.getContent().getClaim())); + assertUrlTemplateAttributes(templateAttributes, expectedUrl); + } + + private static void assertUrlTemplateAttributes( + List templateAttributes, String expectedUrl) { assertThat(templateAttributes.get(2).getKey(), is("url")); assertThat(templateAttributes.get(2).getValue(), is(expectedUrl)); From d005657ad3e3fbb3a1f2093108aa1a5bb6556502 Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 14:33:33 +0100 Subject: [PATCH 02/11] feat: extend session by direct-consultant flag --- .../cob/userservice/api/model/Session.java | 3 +++ .../api/service/session/SessionService.java | 1 + .../0034_changeSet.xml | 15 +++++++++++++++ .../add-consultant-directly-set-rollback.sql | 2 ++ .../add-consultant-directly-set.sql | 2 ++ .../db/changelog/userservice-dev-master.xml | 1 + .../db/changelog/userservice-local-master.xml | 1 + .../db/changelog/userservice-prod-master.xml | 1 + .../db/changelog/userservice-staging-master.xml | 1 + .../controller/UserControllerSessionE2EIT.java | 2 ++ .../ConsultantAgencyRelationCreatorServiceIT.java | 2 ++ ...AgencyRelationCreatorServiceTenantAwareIT.java | 2 ++ .../api/service/session/SessionServiceIT.java | 1 + 13 files changed, 34 insertions(+) create mode 100644 src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/0034_changeSet.xml create mode 100644 src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set-rollback.sql create mode 100644 src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set.sql diff --git a/src/main/java/de/caritas/cob/userservice/api/model/Session.java b/src/main/java/de/caritas/cob/userservice/api/model/Session.java index 1497b7e39..e947be728 100644 --- a/src/main/java/de/caritas/cob/userservice/api/model/Session.java +++ b/src/main/java/de/caritas/cob/userservice/api/model/Session.java @@ -172,6 +172,9 @@ public Session( @Column(name = "is_monitoring", columnDefinition = "tinyint(4) default '0'") private boolean monitoring; + @Column(nullable = false, columnDefinition = "bit default false") + private Boolean isConsultantDirectlySet; + public boolean hasFeedbackChat() { return isNotBlank(feedbackGroupId); } diff --git a/src/main/java/de/caritas/cob/userservice/api/service/session/SessionService.java b/src/main/java/de/caritas/cob/userservice/api/service/session/SessionService.java index 152596ff7..7947eb452 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/session/SessionService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/session/SessionService.java @@ -219,6 +219,7 @@ public Session initializeSession( .userGender(userDto.getUserGender()) .userAge(userDto.getUserAge()) .counsellingRelation(userDto.getCounsellingRelation()) + .isConsultantDirectlySet(false) .build(); session.setSessionTopics(createSessionTopics(userDto.getTopicIds(), session)); diff --git a/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/0034_changeSet.xml b/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/0034_changeSet.xml new file mode 100644 index 000000000..7bac46d33 --- /dev/null +++ b/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/0034_changeSet.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set-rollback.sql b/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set-rollback.sql new file mode 100644 index 000000000..e6685554f --- /dev/null +++ b/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set-rollback.sql @@ -0,0 +1,2 @@ +alter table userservice.session + drop is_consultant_directly_set; diff --git a/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set.sql b/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set.sql new file mode 100644 index 000000000..ab1327925 --- /dev/null +++ b/src/main/resources/db/changelog/changeset/0034_add_consultant_directly_set/add-consultant-directly-set.sql @@ -0,0 +1,2 @@ +alter table userservice.session + add is_consultant_directly_set bit default false not null after is_monitoring; diff --git a/src/main/resources/db/changelog/userservice-dev-master.xml b/src/main/resources/db/changelog/userservice-dev-master.xml index 7484c8511..744a0a6a0 100644 --- a/src/main/resources/db/changelog/userservice-dev-master.xml +++ b/src/main/resources/db/changelog/userservice-dev-master.xml @@ -39,4 +39,5 @@ + diff --git a/src/main/resources/db/changelog/userservice-local-master.xml b/src/main/resources/db/changelog/userservice-local-master.xml index d25929ff8..057334b8e 100644 --- a/src/main/resources/db/changelog/userservice-local-master.xml +++ b/src/main/resources/db/changelog/userservice-local-master.xml @@ -39,4 +39,5 @@ + diff --git a/src/main/resources/db/changelog/userservice-prod-master.xml b/src/main/resources/db/changelog/userservice-prod-master.xml index ab8d76e34..1bbb781f7 100644 --- a/src/main/resources/db/changelog/userservice-prod-master.xml +++ b/src/main/resources/db/changelog/userservice-prod-master.xml @@ -38,4 +38,5 @@ + diff --git a/src/main/resources/db/changelog/userservice-staging-master.xml b/src/main/resources/db/changelog/userservice-staging-master.xml index cc1a4b403..0dd08f4e7 100644 --- a/src/main/resources/db/changelog/userservice-staging-master.xml +++ b/src/main/resources/db/changelog/userservice-staging-master.xml @@ -37,4 +37,5 @@ + diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java index 9ca66d560..2264e09cd 100644 --- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerSessionE2EIT.java @@ -1448,6 +1448,7 @@ private void givenATeamSessionOfAColleagueInProgress() { session.setAgencyId(consultant.getConsultantAgencies().iterator().next().getAgencyId()); session.setStatus(SessionStatus.IN_PROGRESS); session.setTeamSession(true); + session.setIsConsultantDirectlySet(false); sessionRepository.save(session); deleteSession = true; @@ -1466,6 +1467,7 @@ private void givenASessionInProgress() { session.setTeamSession(false); session.setCreateDate(LocalDateTime.now()); session.setGroupId(RandomStringUtils.randomAlphabetic(17)); + session.setIsConsultantDirectlySet(false); sessionRepository.save(session); deleteSession = true; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java index b2cefdaa4..4bbc3fb1c 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java @@ -273,6 +273,8 @@ private Session createSessionWithoutConsultant(Long agencyId, SessionStatus sess session.setLanguageCode(LanguageCode.de); session.setTeamSession(true); session.setSessionTopics(Lists.newArrayList()); + session.setIsConsultantDirectlySet(false); + return this.sessionRepository.save(session); } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceTenantAwareIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceTenantAwareIT.java index 8b9ec9d91..18e846029 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceTenantAwareIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceTenantAwareIT.java @@ -186,6 +186,8 @@ private Session createSessionWithoutConsultant(Long agencyId, SessionStatus sess session.setTeamSession(true); session.setSessionTopics(Lists.newArrayList()); session.setLanguageCode(LanguageCode.de); + session.setIsConsultantDirectlySet(false); + return this.sessionRepository.save(session); } } diff --git a/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceIT.java b/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceIT.java index a7b4b8976..0bd4b84e3 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceIT.java @@ -185,6 +185,7 @@ void fetchGroupIdWithConsultantAndUser_Should_Return_BadRequestException() { session.setLanguageCode(LanguageCode.de); session.setPostcode("12345"); session.setRegistrationType(RegistrationType.ANONYMOUS); + session.setIsConsultantDirectlySet(false); sessionService.saveSession(session); assertThrows( javax.ws.rs.BadRequestException.class, From 8411b02cfd282097dad45009e8b2b87dc80bb82e Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 15:11:20 +0100 Subject: [PATCH 03/11] build: fix liquibase cve --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 08bf48c67..c064d55af 100644 --- a/pom.xml +++ b/pom.xml @@ -198,6 +198,12 @@ liquibase-maven-plugin ${liquibase-maven-plugin.version} + + org.liquibase + liquibase-core + 4.8.0 + + @@ -883,7 +889,7 @@ org.liquibase liquibase-maven-plugin - 4.1.1 + ${liquibase-maven-plugin.version} src/main/resources/liquibase.properties From ef711a84151c2d6c5758990d02a31b88e499d029 Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 15:12:56 +0100 Subject: [PATCH 04/11] build: fix spring security cve --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c064d55af..7cd90cc5d 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 4.8.0 2.1.1 2.6.6 - 5.7.1 + 5.7.5 2.4.7 2.10.0 5.3.23 From 4fce72de47c5a38b6b2b01b763eb709b87eebdd2 Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 15:17:20 +0100 Subject: [PATCH 05/11] build: fix spring beans cve --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 7cd90cc5d..0f22acdf9 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ 2.1.1 2.6.6 5.7.5 + 5.3.18 2.4.7 2.10.0 5.3.23 @@ -89,6 +90,11 @@ spring-security-core ${spring-security-core.version} + + org.springframework + spring-beans + ${spring-beans.version} + org.hibernate.validator From 9ac52ff6cb3b65c531d2fcbd4725534856ba764c Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 15:20:35 +0100 Subject: [PATCH 06/11] build: fix spring webmvc cve --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 0f22acdf9..8bc43ef01 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ 2.6.6 5.7.5 5.3.18 + 5.3.18 2.4.7 2.10.0 5.3.23 @@ -95,6 +96,11 @@ spring-beans ${spring-beans.version} + + org.springframework + spring-webmvc + ${spring-web.version} + org.hibernate.validator From 062e3dadd39bc8b8eae049da7a7ba41f51f0c0da Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 16:13:39 +0100 Subject: [PATCH 07/11] build: fix tests --- pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 8bc43ef01..dd3b8cdfa 100644 --- a/pom.xml +++ b/pom.xml @@ -43,8 +43,7 @@ 2.1.1 2.6.6 5.7.5 - 5.3.18 - 5.3.18 + 5.2.20.RELEASE 2.4.7 2.10.0 5.3.23 @@ -96,11 +95,6 @@ spring-beans ${spring-beans.version} - - org.springframework - spring-webmvc - ${spring-web.version} - org.hibernate.validator From 5db505c302a002615ab33c3ce7daba34717e04da Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 10 Nov 2022 17:02:04 +0100 Subject: [PATCH 08/11] build: fix tests --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index dd3b8cdfa..792e14829 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,8 @@ 2.6.6 5.7.5 5.2.20.RELEASE + 5.2.20.RELEASE + 5.2.20.RELEASE 2.4.7 2.10.0 5.3.23 @@ -95,6 +97,16 @@ spring-beans ${spring-beans.version} + + org.springframework + spring-webmvc + ${spring-webmvc.version} + + + org.springframework + spring-core + ${spring-core.version} + org.hibernate.validator From 6c29ea4d583bb438c21a5317c8229d2da28a100a Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Fri, 11 Nov 2022 08:58:56 +0100 Subject: [PATCH 09/11] feat: mark consultant as directly set --- .../cob/userservice/api/Messenger.java | 13 ++++++ .../web/controller/UserController.java | 11 ++++- .../api/adapters/web/dto/UserDTO.java | 7 +++ .../AnonymousUserCreatorService.java | 2 +- .../api/facade/CreateUserFacade.java | 19 ++++---- .../userservice/api/port/in/Messaging.java | 2 + .../web/controller/UserControllerE2EIT.java | 46 +++++++++++++++++-- .../api/facade/CreateUserFacadeTest.java | 12 ++--- 8 files changed, 86 insertions(+), 26 deletions(-) diff --git a/src/main/java/de/caritas/cob/userservice/api/Messenger.java b/src/main/java/de/caritas/cob/userservice/api/Messenger.java index ee9223a57..8c5c5e7e6 100644 --- a/src/main/java/de/caritas/cob/userservice/api/Messenger.java +++ b/src/main/java/de/caritas/cob/userservice/api/Messenger.java @@ -145,6 +145,19 @@ public boolean isInChat(String chatId, String chatUserId) { return chatUserIds.contains(chatUserId); } + @Override + public boolean markAsDirectConsultant(Long sessionId) { + return sessionRepository + .findById(sessionId) + .map( + session -> { + session.setIsConsultantDirectlySet(true); + var updatedSession = sessionRepository.save(session); + return updatedSession.getIsConsultantDirectlySet(); + }) + .orElse(false); + } + @Override public Optional> findSession(Long sessionId) { var session = sessionRepository.findById(sessionId); diff --git a/src/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserController.java b/src/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserController.java index d3673990a..0696dc336 100644 --- a/src/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserController.java +++ b/src/main/java/de/caritas/cob/userservice/api/adapters/web/controller/UserController.java @@ -178,9 +178,16 @@ public class UserController implements UsersApi { @Override public ResponseEntity registerUser(@Valid @RequestBody UserDTO user) { user.setNewUserAccount(true); - createUserFacade.createUserAccountWithInitializedConsultingType(user); + var sessionId = createUserFacade.createUserAccountWithInitializedConsultingType(user); - return new ResponseEntity<>(HttpStatus.CREATED); + HttpStatus status; + if (user.isConsultantSet() && !messenger.markAsDirectConsultant(sessionId)) { + status = HttpStatus.INTERNAL_SERVER_ERROR; + } else { + status = HttpStatus.CREATED; + } + + return ResponseEntity.status(status).build(); } /** diff --git a/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java b/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java index aade164b9..6f3dbb775 100644 --- a/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java +++ b/src/main/java/de/caritas/cob/userservice/api/adapters/web/dto/UserDTO.java @@ -7,7 +7,9 @@ import static de.caritas.cob.userservice.api.helper.UserHelper.STATE_REGEXP; import static de.caritas.cob.userservice.api.helper.UserHelper.TERMS_ACCEPTED_REGEXP; import static de.caritas.cob.userservice.api.helper.UserHelper.VALID_POSTCODE_REGEX; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; @@ -157,6 +159,11 @@ public UserDTO(String age, String state, String consultingType) { this.consultingType = consultingType; } + @JsonIgnore + public boolean isConsultantSet() { + return isNotBlank(consultantId); + } + @Override public String toString() { return "UserDTO{" diff --git a/src/main/java/de/caritas/cob/userservice/api/conversation/service/user/anonymous/AnonymousUserCreatorService.java b/src/main/java/de/caritas/cob/userservice/api/conversation/service/user/anonymous/AnonymousUserCreatorService.java index dbb1ef67e..ce3fc767f 100644 --- a/src/main/java/de/caritas/cob/userservice/api/conversation/service/user/anonymous/AnonymousUserCreatorService.java +++ b/src/main/java/de/caritas/cob/userservice/api/conversation/service/user/anonymous/AnonymousUserCreatorService.java @@ -42,7 +42,7 @@ public class AnonymousUserCreatorService { public AnonymousUserCredentials createAnonymousUser(UserDTO userDto) { KeycloakCreateUserResponseDTO response = identityClient.createKeycloakUser(userDto); - createUserFacade.updateKeycloakAccountAndCreateDatabaseUserAccount( + createUserFacade.updateIdentityAndCreateAccount( response.getUserId(), userDto, UserRole.ANONYMOUS); KeycloakLoginResponseDTO kcLoginResponseDTO; diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserFacade.java index cf527a59b..26b7bd37b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserFacade.java @@ -5,7 +5,6 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import de.caritas.cob.userservice.api.adapters.keycloak.dto.KeycloakCreateUserResponseDTO; -import de.caritas.cob.userservice.api.adapters.web.dto.NewRegistrationResponseDto; import de.caritas.cob.userservice.api.adapters.web.dto.UserDTO; import de.caritas.cob.userservice.api.config.auth.UserRole; import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; @@ -47,32 +46,33 @@ public class CreateUserFacade { * * @param userDTO {@link UserDTO} */ - public void createUserAccountWithInitializedConsultingType(final UserDTO userDTO) { + public Long createUserAccountWithInitializedConsultingType(final UserDTO userDTO) { userVerifier.checkIfAllRequiredAttributesAreCorrectlyFilled(userDTO); userVerifier.checkIfUsernameIsAvailable(userDTO); agencyVerifier.checkIfConsultingTypeMatchesToAgency(userDTO); KeycloakCreateUserResponseDTO response = identityClient.createKeycloakUser(userDTO); - var user = - updateKeycloakAccountAndCreateDatabaseUserAccount( - response.getUserId(), userDTO, UserRole.USER); - NewRegistrationResponseDto newRegistrationResponseDto = + var user = updateIdentityAndCreateAccount(response.getUserId(), userDTO, UserRole.USER); + var consultingTypeSettings = obtainConsultingTypeSettings(userDTO); + var registration = createNewConsultingTypeFacade.initializeNewConsultingType( - userDTO, user, obtainConsultingTypeSettings(userDTO)); + userDTO, user, consultingTypeSettings); try { RegistrationStatisticsEvent registrationEvent = new RegistrationStatisticsEvent( userDTO, user, - newRegistrationResponseDto.getSessionId(), + registration.getSessionId(), topicService.findTopicInternalIdentifier(userDTO.getMainTopicId()), topicService.findTopicsInternalAttributes(userDTO.getTopicIds())); statisticsService.fireEvent(registrationEvent); } catch (Exception e) { log.error("Could not create registration statistics event", e); } + + return registration.getSessionId(); } /** @@ -82,8 +82,7 @@ public void createUserAccountWithInitializedConsultingType(final UserDTO userDTO * @param userDTO {@link UserDTO} * @return {@link User} */ - public User updateKeycloakAccountAndCreateDatabaseUserAccount( - String userId, UserDTO userDTO, UserRole role) { + public User updateIdentityAndCreateAccount(String userId, UserDTO userDTO, UserRole role) { User user = null; try { diff --git a/src/main/java/de/caritas/cob/userservice/api/port/in/Messaging.java b/src/main/java/de/caritas/cob/userservice/api/port/in/Messaging.java index f3ab4398d..ac08c7697 100644 --- a/src/main/java/de/caritas/cob/userservice/api/port/in/Messaging.java +++ b/src/main/java/de/caritas/cob/userservice/api/port/in/Messaging.java @@ -23,4 +23,6 @@ public interface Messaging { Optional> findSession(Long sessionId); boolean isInChat(String chatId, String chatUserId); + + boolean markAsDirectConsultant(Long sessionId); } diff --git a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerE2EIT.java b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerE2EIT.java index 2f00374dd..5f4935381 100644 --- a/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerE2EIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/adapters/web/controller/UserControllerE2EIT.java @@ -1380,7 +1380,7 @@ void registerUserWithoutConsultingIdShouldSaveMonitoringAndPreferredLanguage() t } @Test - void registerUserShouldSaveDefaultPreferredLanguage() throws Exception { + void registerUserShouldReturnCreatedAndSaveDefaults() throws Exception { givenAValidTopicServiceResponse(); givenConsultingTypeServiceResponse(); givenARealmResource(); @@ -1399,9 +1399,41 @@ void registerUserShouldSaveDefaultPreferredLanguage() throws Exception { var savedUser = StreamSupport.stream(userRepository.findAll().spliterator(), true) .filter(dbUser -> userDTO.getEmail().equals(dbUser.getEmail())) - .findFirst(); - assertTrue(savedUser.isPresent()); - assertEquals("de", savedUser.get().getLanguageCode().toString()); + .findFirst() + .orElse(null); + assertNotNull(savedUser); + assertEquals("de", savedUser.getLanguageCode().toString()); + + var session = sessionRepository.findByUserUserId(savedUser.getUserId()).get(0); + assertFalse(session.getIsConsultantDirectlySet()); + } + + @Test + void registerUserShouldReturnCreatedAndMarkASetConsultant() throws Exception { + givenAValidTopicServiceResponse(); + givenConsultingTypeServiceResponse(); + givenARealmResource(); + givenAValidConsultant(); + givenAUserDTO(consultant.getId()); + + mockMvc + .perform( + post("/users/askers/new") + .cookie(CSRF_COOKIE) + .header(CSRF_HEADER, CSRF_VALUE) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(userDTO))) + .andExpect(status().isCreated()); + + var savedUser = + StreamSupport.stream(userRepository.findAll().spliterator(), true) + .filter(dbUser -> userDTO.getEmail().equals(dbUser.getEmail())) + .findFirst() + .orElse(null); + assertNotNull(savedUser); + + var session = sessionRepository.findByUserUserId(savedUser.getUserId()).get(0); + assertTrue(session.getIsConsultantDirectlySet()); } // FIXME: (for all registerUser tests) Currently, we cannot easily get the generated data. The API @@ -1529,6 +1561,10 @@ private void givenARealmResource() { } private void givenAUserDTO() { + givenAUserDTO(null); + } + + private void givenAUserDTO(String consultantId) { userDTO = easyRandom.nextObject(UserDTO.class); userDTO.setUsername(RandomStringUtils.randomAlphabetic(5, 30)); userDTO.setAge("17"); @@ -1536,7 +1572,7 @@ private void givenAUserDTO() { userDTO.setPostcode(RandomStringUtils.randomNumeric(5)); userDTO.setTermsAccepted("true"); userDTO.setConsultingType("1"); - userDTO.setConsultantId(null); + userDTO.setConsultantId(consultantId); userDTO.setAgencyId(aPositiveLong()); userDTO.setEmail(givenAValidEmail()); } diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserFacadeTest.java index 88f2c433c..d4daac168 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserFacadeTest.java @@ -164,8 +164,7 @@ public class CreateUserFacadeTest { .thenReturn(CONSULTING_TYPE_SETTINGS_KREUZBUND); doNothing().when(keycloakService).updatePassword(anyString(), anyString()); - createUserFacade.updateKeycloakAccountAndCreateDatabaseUserAccount( - USER_ID, USER_DTO_SUCHT, UserRole.USER); + createUserFacade.updateIdentityAndCreateAccount(USER_ID, USER_DTO_SUCHT, UserRole.USER); verify(keycloakService, times(1)).updateRole(any(), any(UserRole.class)); verify(keycloakService, times(1)).updatePassword(anyString(), anyString()); @@ -177,8 +176,7 @@ public class CreateUserFacadeTest { updateKeycloakAccountAndCreateDatabaseUserAccount_Should_ThrowInternalServerErrorExceptionAndRollbackUserAccount_When_UpdateKeycloakPwFails() { doThrow(new RuntimeException()).when(keycloakService).updatePassword(anyString(), anyString()); - createUserFacade.updateKeycloakAccountAndCreateDatabaseUserAccount( - USER_ID, USER_DTO_SUCHT, UserRole.USER); + createUserFacade.updateIdentityAndCreateAccount(USER_ID, USER_DTO_SUCHT, UserRole.USER); verify(rollbackFacade, times(1)).rollBackUserAccount(any()); } @@ -190,8 +188,7 @@ public class CreateUserFacadeTest { .when(keycloakService) .updateRole(anyString(), any(UserRole.class)); - createUserFacade.updateKeycloakAccountAndCreateDatabaseUserAccount( - USER_ID, USER_DTO_SUCHT, UserRole.USER); + createUserFacade.updateIdentityAndCreateAccount(USER_ID, USER_DTO_SUCHT, UserRole.USER); verify(rollbackFacade, times(1)).rollBackUserAccount(any()); } @@ -205,8 +202,7 @@ public class CreateUserFacadeTest { when(userService.createUser(any(), any(), any(), any(), anyBoolean(), any())) .thenThrow(new IllegalArgumentException()); - createUserFacade.updateKeycloakAccountAndCreateDatabaseUserAccount( - USER_ID, USER_DTO_SUCHT, UserRole.USER); + createUserFacade.updateIdentityAndCreateAccount(USER_ID, USER_DTO_SUCHT, UserRole.USER); verify(rollbackFacade, times(1)).rollBackUserAccount(any()); } From 35e385b67d6e5c2c7bc95c6adac7cf00ea606aed Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Fri, 11 Nov 2022 11:58:48 +0100 Subject: [PATCH 10/11] feat: send direct-enquiry email --- .../facade/CreateEnquiryMessageFacade.java | 12 ++- .../api/facade/EmailNotificationFacade.java | 23 +++++ .../service/emailsupplier/EmailSupplier.java | 1 + .../NewDirectEnquiryEmailSupplier.java | 92 +++++++++++++++++ .../CreateEnquiryMessageFacadeTest.java | 49 +++++++++ .../facade/EmailNotificationFacadeTest.java | 5 + .../NewDirectEnquiryEmailSupplierTest.java | 99 +++++++++++++++++++ 7 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java create mode 100644 src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java index 1b8ba12bd..e8d25176f 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java @@ -159,8 +159,16 @@ public CreateEnquiryMessageResponseDTO createEnquiryMessage(EnquiryData enquiryD rcFeedbackGroupId, createEnquiryExceptionInformation); - emailNotificationFacade.sendNewEnquiryEmailNotification( - session, TenantContext.getCurrentTenantData()); + if (session.getIsConsultantDirectlySet()) { + emailNotificationFacade.sendNewDirectEnquiryEmailNotification( + session.getConsultant().getId(), + session.getAgencyId(), + session.getPostcode(), + TenantContext.getCurrentTenantData()); + } else { + emailNotificationFacade.sendNewEnquiryEmailNotification( + session, TenantContext.getCurrentTenantData()); + } return new CreateEnquiryMessageResponseDTO() .rcGroupId(rcGroupId) diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java index 9d7bb2c18..df85c56c4 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java @@ -20,6 +20,7 @@ import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.emailsupplier.AssignEnquiryEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.EmailSupplier; +import de.caritas.cob.userservice.api.service.emailsupplier.NewDirectEnquiryEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.NewEnquiryEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.NewFeedbackEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.NewMessageEmailSupplier; @@ -63,6 +64,7 @@ public class EmailNotificationFacade { private final @NonNull IdentityClient identityClient; private final @NonNull IdentityClientConfig identityClientConfig; private final @NonNull NewEnquiryEmailSupplier newEnquiryEmailSupplier; + private final @NonNull NewDirectEnquiryEmailSupplier newDirectEnquiryEmailSupplier; private final @NonNull AssignEnquiryEmailSupplier assignEnquiryEmailSupplier; private final @NonNull TenantTemplateSupplier tenantTemplateSupplier; @@ -96,6 +98,27 @@ public void sendNewEnquiryEmailNotification(Session session, TenantData tenantDa } } + @Async + public void sendNewDirectEnquiryEmailNotification( + String consultantId, Long agencyId, String postCode, TenantData tenantData) { + log.info( + "Preparing NEW_DIRECT_ENQUIRY_EMAIL_NOTIFICATION email to consultant ({}) in " + + "agency ({})", + consultantId, + agencyId); + + try { + TenantContext.setCurrentTenantData(tenantData); + newDirectEnquiryEmailSupplier.setAgencyId(agencyId); + newDirectEnquiryEmailSupplier.setConsultantId(consultantId); + newDirectEnquiryEmailSupplier.setPostCode(postCode); + sendMailTasksToMailService(newDirectEnquiryEmailSupplier); + TenantContext.clear(); + } catch (Exception ex) { + log.error("Failed to send NEW_DIRECT_ENQUIRY_EMAIL_NOTIFICATION", ex); + } + } + private void sendMailTasksToMailService(EmailSupplier mailsToSend) throws RocketChatGetGroupMembersException { List generatedMails = mailsToSend.generateEmails(); diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/EmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/EmailSupplier.java index 7b6f7b88a..bfc5b0190 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/EmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/EmailSupplier.java @@ -9,6 +9,7 @@ public interface EmailSupplier { String TEMPLATE_NEW_ENQUIRY_NOTIFICATION = "enquiry-notification-consultant"; + String TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION = "direct-enquiry-notification-consultant"; String TEMPLATE_NEW_MESSAGE_NOTIFICATION_CONSULTANT = "message-notification-consultant"; String TEMPLATE_NEW_MESSAGE_NOTIFICATION_ASKER = "message-notification-asker"; String TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION = "feedback-message-notification"; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java new file mode 100644 index 000000000..4270175e3 --- /dev/null +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java @@ -0,0 +1,92 @@ +package de.caritas.cob.userservice.api.service.emailsupplier; + +import static de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode.fromValue; +import static java.util.Objects.nonNull; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +import de.caritas.cob.userservice.api.model.Consultant; +import de.caritas.cob.userservice.api.model.ConsultantAgency; +import de.caritas.cob.userservice.api.port.out.ConsultantAgencyRepository; +import de.caritas.cob.userservice.mailservice.generated.web.model.MailDTO; +import de.caritas.cob.userservice.mailservice.generated.web.model.TemplateDataDTO; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.transaction.Transactional; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Service; + +/** Supplier to provide mails to be sent when a new direct enquiry was created. */ +@RequiredArgsConstructor +@Service +@Slf4j +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class NewDirectEnquiryEmailSupplier implements EmailSupplier { + + private final @NonNull ConsultantAgencyRepository consultantAgencyRepository; + private final TenantTemplateSupplier tenantTemplateSupplier; + + @Value("${app.base.url}") + private String applicationBaseUrl; + + @Value("${multitenancy.enabled}") + private boolean multiTenancyEnabled; + + @Setter private Long agencyId; + + @Setter private String postCode; + + @Setter private String consultantId; + + /** + * Generates a direct-enquiry email and sends it to the set consultant. + * + * @return a list of the generated {@link MailDTO} + */ + @Override + @Transactional + public List generateEmails() { + log.info("Generating email for new direct enquiry..."); + + var consultantAgencyList = + consultantAgencyRepository.findByConsultantIdAndAgencyIdAndDeleteDateIsNull( + consultantId, agencyId); + log.info("Retrieved consultant agency list: {}", consultantAgencyList); + + return consultantAgencyList.stream() + .filter(this::validConsultantAgency) + .map(consultantAgency -> mailOf(consultantAgency.getConsultant(), postCode)) + .collect(Collectors.toList()); + } + + private Boolean validConsultantAgency(ConsultantAgency consultantAgency) { + var consultant = consultantAgency.getConsultant(); + + return nonNull(consultant) && isNotBlank(consultant.getEmail()) && !consultant.isAbsent(); + } + + @SuppressWarnings("Duplicates") + private MailDTO mailOf(Consultant consultant, String postCode) { + var templateAttributes = new ArrayList(); + templateAttributes.add(new TemplateDataDTO().key("name").value(consultant.getFullName())); + templateAttributes.add(new TemplateDataDTO().key("plz").value(postCode)); + + if (!multiTenancyEnabled) { + templateAttributes.add(new TemplateDataDTO().key("url").value(applicationBaseUrl)); + } else { + templateAttributes.addAll(tenantTemplateSupplier.getTemplateAttributes()); + } + + return new MailDTO() + .template(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION) + .email(consultant.getEmail()) + .language(fromValue(consultant.getLanguageCode().toString())) + .templateData(templateAttributes); + } +} diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java index 57264091d..933421edf 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java @@ -9,6 +9,7 @@ import static de.caritas.cob.userservice.api.testHelper.ExceptionConstants.RC_POST_MESSAGE_EXCEPTION; import static de.caritas.cob.userservice.api.testHelper.TestConstants.AGENCY_ID; import static de.caritas.cob.userservice.api.testHelper.TestConstants.CONSULTANT; +import static de.caritas.cob.userservice.api.testHelper.TestConstants.CONSULTANT_2; import static de.caritas.cob.userservice.api.testHelper.TestConstants.CONSULTING_TYPE_ID_SUCHT; import static de.caritas.cob.userservice.api.testHelper.TestConstants.EMAIL; import static de.caritas.cob.userservice.api.testHelper.TestConstants.ERROR; @@ -41,6 +42,7 @@ import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -330,6 +332,7 @@ public void createEnquiryMessage_ShouldNot_ThrowException_When_Successful() thro session.setConsultant(null); session.setEnquiryMessageDate(null); session.setAgencyId(AGENCY_ID); + session.setIsConsultantDirectlySet(false); extendedConsultingTypeResponseDTO.getWelcomeMessage().sendWelcomeMessage(false); extendedConsultingTypeResponseDTO.initializeFeedbackChat(false); groupDTO.setId(RC_GROUP_ID); @@ -375,6 +378,50 @@ public void createEnquiryMessage_ShouldNot_ThrowException_When_Successful() thro resetRequestAttributes(); } + @Test + public void createEnquiryMessage_Should_SendDirectEnquiryEmail_When_ConsultantDirectlySet() + throws Exception { + session.setUser(user); + session.setConsultingTypeId(0); + session.setConsultant(CONSULTANT_2); + session.setIsConsultantDirectlySet(true); + session.setEnquiryMessageDate(null); + session.setAgencyId(AGENCY_ID); + extendedConsultingTypeResponseDTO.getWelcomeMessage().sendWelcomeMessage(false); + extendedConsultingTypeResponseDTO.initializeFeedbackChat(false); + groupDTO.setId(RC_GROUP_ID); + groupResponseDTO.setSuccess(true); + groupResponseDTO.setGroup(groupDTO); + rocketChatUserDTO.setUsername(USERNAME); + userInfoResponseDTO.setUser(rocketChatUserDTO); + rocketChatCredentials.setRocketChatUserId(RC_USER_ID); + rocketChatCredentials.setRocketChatUsername(RC_USERNAME); + + when(sessionService.getSession(SESSION_ID)).thenReturn(Optional.of(session)); + when(consultingTypeManager.getConsultingTypeSettings(session.getConsultingTypeId())) + .thenReturn(extendedConsultingTypeResponseDTO); + + when(rocketChatService.createPrivateGroup(anyString(), any())) + .thenReturn(Optional.of(groupResponseDTO)); + when(rocketChatService.getUserInfo(RC_USER_ID)).thenReturn(userInfoResponseDTO); + when(userHelper.doUsernamesMatch(anyString(), anyString())).thenReturn(true); + when(rocketChatRoomNameGenerator.generateGroupName(any(Session.class))) + .thenReturn(session.getId().toString()); + var messageResponse = createMessageResponse(); + when(messageServiceProvider.postEnquiryMessage( + any(RocketChatData.class), any(CreateEnquiryExceptionInformation.class))) + .thenReturn(messageResponse); + + createEnquiryMessageFacade.createEnquiryMessage( + new EnquiryData(user, SESSION_ID, MESSAGE, null, rocketChatCredentials)); + + verify(emailNotificationFacade, never()).sendNewEnquiryEmailNotification(any(), any()); + verify(emailNotificationFacade) + .sendNewDirectEnquiryEmailNotification(any(), any(), any(), any()); + + resetRequestAttributes(); + } + @Test(expected = ConflictException.class) public void createEnquiryMessage_Should_ThrowConflictException_When_EnquiryMessageAlreadySaved() { @@ -616,6 +663,7 @@ public void createEnquiryMessage_Should_UpdateCorrectSessionInformation_When_Suc session.setUser(user); session.setConsultingTypeId(0); session.setConsultant(null); + session.setIsConsultantDirectlySet(false); extendedConsultingTypeResponseDTO.setInitializeFeedbackChat(true); rocketChatUserDTO.setUsername(USERNAME); userInfoResponseDTO.setUser(rocketChatUserDTO); @@ -1105,6 +1153,7 @@ public void createEnquiryMessage_Should_PostAliasOnlyMessageAndWelcomeMessage() session.setUser(user); session.setConsultingTypeId(0); + session.setIsConsultantDirectlySet(false); session.setConsultant(null); session.setEnquiryMessageDate(null); session.setAgencyId(AGENCY_ID); diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java index e273ad8f6..bf830cb70 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java @@ -58,6 +58,7 @@ import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.agency.AgencyService; import de.caritas.cob.userservice.api.service.emailsupplier.AssignEnquiryEmailSupplier; +import de.caritas.cob.userservice.api.service.emailsupplier.NewDirectEnquiryEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.NewEnquiryEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.NewFeedbackEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.NewMessageEmailSupplier; @@ -433,6 +434,10 @@ public class EmailNotificationFacadeTest { @Mock private NewEnquiryEmailSupplier newEnquiryEmailSupplier; + @SuppressWarnings("unused") + @Mock + private NewDirectEnquiryEmailSupplier newDirectEnquiryEmailSupplier; + @Spy private AssignEnquiryEmailSupplier assignEnquiryEmailSupplier; @Mock private ConsultantAgencyRepository consultantAgencyRepository; diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java new file mode 100644 index 000000000..6754e54bc --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java @@ -0,0 +1,99 @@ +package de.caritas.cob.userservice.api.service.emailsupplier; + +import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc; +import static de.caritas.cob.userservice.api.service.emailsupplier.EmailSupplier.TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION; +import static de.caritas.cob.userservice.api.testHelper.TestConstants.AGENCY_ID; +import static de.caritas.cob.userservice.api.testHelper.TestConstants.MAIN_CONSULTANT; +import static de.caritas.cob.userservice.api.testHelper.TestConstants.MAIN_CONSULTANT_ID; +import static de.caritas.cob.userservice.api.testHelper.TestConstants.POSTCODE; +import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import de.caritas.cob.userservice.api.model.Consultant; +import de.caritas.cob.userservice.api.model.ConsultantAgency; +import de.caritas.cob.userservice.api.port.out.ConsultantAgencyRepository; +import de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode; +import de.caritas.cob.userservice.mailservice.generated.web.model.MailDTO; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class NewDirectEnquiryEmailSupplierTest { + + private NewDirectEnquiryEmailSupplier newDirectEnquiryEmailSupplier; + + @Mock private ConsultantAgencyRepository consultantAgencyRepository; + + @Before + public void setup() { + newDirectEnquiryEmailSupplier = + new NewDirectEnquiryEmailSupplier(consultantAgencyRepository, null); + newDirectEnquiryEmailSupplier.setAgencyId(AGENCY_ID); + newDirectEnquiryEmailSupplier.setConsultantId(MAIN_CONSULTANT_ID); + newDirectEnquiryEmailSupplier.setPostCode(POSTCODE); + } + + @Test + public void generateEmails_Should_ReturnEmptyList_When_NoParametersAreProvided() { + List generatedMails = newDirectEnquiryEmailSupplier.generateEmails(); + + assertThat(generatedMails, hasSize(0)); + } + + @Test + public void generateEmails_Should_ReturnEmptyList_When_NoValidConsultantWasFound() { + var absentConsultant = new Consultant(); + absentConsultant.setAbsent(true); + absentConsultant.setEmail("email"); + + when(consultantAgencyRepository.findByConsultantIdAndAgencyIdAndDeleteDateIsNull( + anyString(), anyLong())) + .thenReturn( + asList( + new ConsultantAgency( + 0L, new Consultant(), 1L, nowInUtc(), nowInUtc(), nowInUtc(), null, null), + new ConsultantAgency( + 1L, absentConsultant, 1L, nowInUtc(), nowInUtc(), nowInUtc(), null, null))); + + var generatedMails = newDirectEnquiryEmailSupplier.generateEmails(); + + assertThat(generatedMails, hasSize(0)); + } + + @Test + public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantHasBeenFound() { + var consultantAgency = + new ConsultantAgency( + 0L, MAIN_CONSULTANT, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc(), null, null); + when(consultantAgencyRepository.findByConsultantIdAndAgencyIdAndDeleteDateIsNull( + eq(MAIN_CONSULTANT_ID), eq(AGENCY_ID))) + .thenReturn(List.of(consultantAgency)); + + var generatedMails = newDirectEnquiryEmailSupplier.generateEmails(); + + assertThat(generatedMails, hasSize(1)); + + var generatedMail = generatedMails.get(0); + assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION)); + assertThat(generatedMail.getEmail(), is("email@email.com")); + assertThat(generatedMail.getLanguage(), is(LanguageCode.DE)); + + var templateData = generatedMail.getTemplateData(); + assertThat(templateData, hasSize(3)); + assertThat(templateData.get(0).getKey(), is("name")); + assertThat(templateData.get(0).getValue(), is("first name last name")); + assertThat(templateData.get(1).getKey(), is("plz")); + assertThat(templateData.get(1).getValue(), is(POSTCODE)); + assertThat(templateData.get(2).getKey(), is("url")); + } +} From 631e9f2bc87721f893cd61a350487080225a6684 Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Fri, 11 Nov 2022 13:13:39 +0100 Subject: [PATCH 11/11] chore: remove smelling matcher --- .../emailsupplier/NewDirectEnquiryEmailSupplierTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java index 6754e54bc..9a3ecf983 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java @@ -12,7 +12,6 @@ import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import de.caritas.cob.userservice.api.model.Consultant; @@ -76,7 +75,7 @@ public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantHa new ConsultantAgency( 0L, MAIN_CONSULTANT, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc(), null, null); when(consultantAgencyRepository.findByConsultantIdAndAgencyIdAndDeleteDateIsNull( - eq(MAIN_CONSULTANT_ID), eq(AGENCY_ID))) + MAIN_CONSULTANT_ID, AGENCY_ID)) .thenReturn(List.of(consultantAgency)); var generatedMails = newDirectEnquiryEmailSupplier.generateEmails();