From e801c9f494cbf99ea93df0168fb07e87a1c102d5 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 1 Jun 2023 15:15:02 +0200 Subject: [PATCH 01/21] feat: add tenantName and agencyName to registration stats --- api/statisticsservice.yaml | 12 ++++++++++++ .../StatisticsServiceApplication.java | 4 ++++ .../statistics/listener/RegistrationListener.java | 2 ++ .../statisticsevent/meta/RegistrationMetaData.java | 2 ++ .../api/testhelper/TestConstants.java | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index 22b53de..62d988f 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -258,6 +258,9 @@ components: format: int64 description: The id of the tenant example: 1 + tenantName: + type: string + example: 'Tenant name' registrationDate: type: string example: '2022-08-15T21:11:29' @@ -281,6 +284,9 @@ components: postalCode: type: string example: '99999' + agencyName: + type: string + example: "Dortmund Beratungstelle" RegistrationStatisticsListResponseDTO: type: object @@ -324,6 +330,12 @@ components: postalCode: type: string example: '99999' + tenantName: + type: string + example: 'Tenant name' + agencyName: + type: string + example: "Dortmund Beratungstelle" BookingCreatedStatisticsEventMessage: type: object diff --git a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java index ab78a20..184e804 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java +++ b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java @@ -7,6 +7,10 @@ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class StatisticsServiceApplication { + static { + System.setProperty("os.arch", "i686_64"); + } + public static void main(String[] args) { SpringApplication.run(StatisticsServiceApplication.class, args); } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java index 37a758b..6ffd112 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java @@ -49,6 +49,8 @@ public void receiveMessage(RegistrationStatisticsEventMessage eventMessage) { private RegistrationMetaData buildMetaData(RegistrationStatisticsEventMessage eventMessage) { return RegistrationMetaData.builder() .tenantId(eventMessage.getTenantId()) + .tenantName(eventMessage.getTenantName()) + .agencyName(eventMessage.getAgencyName()) .registrationDate(eventMessage.getRegistrationDate()) .age(eventMessage.getAge()) .gender(eventMessage.getGender()) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java index c261de6..c222708 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java @@ -13,6 +13,8 @@ public class RegistrationMetaData { private Long tenantId; + private String tenantName; + private String agencyName; private String registrationDate; private Integer age; private String gender; diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java b/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java index ad29c5b..d47c25f 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java @@ -48,6 +48,9 @@ private TestConstants() {} .mainTopicInternalAttribute("angeho01") .topicsInternalAttributes(List.of("angeho01", "angeho13")) .postalCode("99999") + .tenantName("tenanName") + .agencyName("agencyName") + ).addRegistrationStatisticsItem(new RegistrationStatisticsResponseDTO() .userId(ASKER_ID) .registrationDate("2022-08-15T21:11:29") @@ -57,6 +60,8 @@ private TestConstants() {} .mainTopicInternalAttribute("angeho13") .topicsInternalAttributes(List.of("angeho01", "angeho13")) .postalCode("11111") + .tenantName("tenanName") + .agencyName("agencyName") ); } From 2218bd493dbe2d1f35afe43d0cc43303c6bb1298 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 1 Jun 2023 15:56:54 +0200 Subject: [PATCH 02/21] feat: add tenantName and agencyName to registration stats --- .../api/helper/RegistrationStatisticsDTOConverter.java | 2 ++ .../api/helper/RegistrationStatisticsDTOConverterTest.java | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index dbeebdd..706d9ac 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -21,6 +21,8 @@ public RegistrationStatisticsResponseDTO convertStatisticsEvent( .userId(rawEvent.getUser().getId()) .registrationDate(metadata.getRegistrationDate()) .age(metadata.getAge()) + .tenantName(metadata.getTenantName()) + .agencyName(metadata.getAgencyName()) .gender(metadata.getGender()) .counsellingRelation(metadata.getCounsellingRelation()) .mainTopicInternalAttribute(metadata.getMainTopicInternalAttribute()) diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 324a091..43eedbd 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -62,6 +62,10 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { assertThat(result.getPostalCode(), is("12345")); assertThat(result.getCounsellingRelation(), is("SELF_COUNSELLING")); + assertThat(result.getTenantName(), + is("tenantName")); + assertThat(result.getAgencyName(), + is("agencyName")); } @Test @@ -129,6 +133,8 @@ private void givenValidStatisticEvent(Long sessionId) { .postalCode("12345") .tenantId(1L) .counsellingRelation("SELF_COUNSELLING") + .tenantName("tenantName") + .agencyName("agencyName") .build(); testEvent = StatisticsEvent.builder() .sessionId(sessionId) From 3ab8b9f1f13bdeb7f37b855d797e0bc8b9da71bb Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 28 Jun 2023 09:52:59 +0200 Subject: [PATCH 03/21] feat: add referer to registration stats --- api/statisticsservice.yaml | 6 ++++++ .../api/helper/RegistrationStatisticsDTOConverter.java | 3 ++- .../api/statistics/listener/RegistrationListener.java | 1 + .../model/statisticsevent/meta/RegistrationMetaData.java | 1 + .../api/helper/RegistrationStatisticsDTOConverterTest.java | 3 +++ .../api/statistics/listener/RegistrationListenerTest.java | 2 ++ .../cob/statisticsservice/api/testhelper/TestConstants.java | 2 ++ 7 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index 62d988f..cb98b05 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -287,6 +287,9 @@ components: agencyName: type: string example: "Dortmund Beratungstelle" + referer: + type: string + example: "referer" RegistrationStatisticsListResponseDTO: type: object @@ -336,6 +339,9 @@ components: agencyName: type: string example: "Dortmund Beratungstelle" + referer: + type: string + example: "referer" BookingCreatedStatisticsEventMessage: type: object diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 706d9ac..d8c3b98 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -28,7 +28,8 @@ public RegistrationStatisticsResponseDTO convertStatisticsEvent( .mainTopicInternalAttribute(metadata.getMainTopicInternalAttribute()) .topicsInternalAttributes(metadata.getTopicsInternalAttributes()) .endDate(findEndDate(rawEvent.getSessionId(), archiveSessionEvents)) - .postalCode(metadata.getPostalCode()); + .postalCode(metadata.getPostalCode()) + .referer(metadata.getReferer()); } private String findEndDate(Long sessionId, List archiveSessionEvents) { diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java index 6ffd112..e0b30df 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListener.java @@ -58,6 +58,7 @@ private RegistrationMetaData buildMetaData(RegistrationStatisticsEventMessage ev .topicsInternalAttributes(eventMessage.getTopicsInternalAttributes()) .mainTopicInternalAttribute(eventMessage.getMainTopicInternalAttribute()) .postalCode(eventMessage.getPostalCode()) + .referer(eventMessage.getReferer()) .build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java index c222708..67c3854 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java @@ -22,5 +22,6 @@ public class RegistrationMetaData { private List topicsInternalAttributes = null; private String mainTopicInternalAttribute; private String postalCode; + private String referer; } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 43eedbd..3171031 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -66,6 +66,8 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { is("tenantName")); assertThat(result.getAgencyName(), is("agencyName")); + assertThat(result.getReferer(), + is("aReferer")); } @Test @@ -135,6 +137,7 @@ private void givenValidStatisticEvent(Long sessionId) { .counsellingRelation("SELF_COUNSELLING") .tenantName("tenantName") .agencyName("agencyName") + .referer("aReferer") .build(); testEvent = StatisticsEvent.builder() .sessionId(sessionId) diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java index 9c2303b..25273ed 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java @@ -95,6 +95,7 @@ private RegistrationStatisticsEventMessage buildEventMessage() { .topicsInternalAttributes(List.of("angeho01", "angeho13")) .mainTopicInternalAttribute("angeho01") .postalCode("99999") + .referer("aReferer") .timestamp(OffsetDateTime.now()); } @@ -109,6 +110,7 @@ private RegistrationMetaData buildMetaData(RegistrationStatisticsEventMessage ev .topicsInternalAttributes(eventMessage.getTopicsInternalAttributes()) .mainTopicInternalAttribute(eventMessage.getMainTopicInternalAttribute()) .postalCode(eventMessage.getPostalCode()) + .referer(eventMessage.getReferer()) .build(); } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java b/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java index d47c25f..5598cc3 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/testhelper/TestConstants.java @@ -50,6 +50,7 @@ private TestConstants() {} .postalCode("99999") .tenantName("tenanName") .agencyName("agencyName") + .referer("https://www.caritas.de/") ).addRegistrationStatisticsItem(new RegistrationStatisticsResponseDTO() .userId(ASKER_ID) @@ -62,6 +63,7 @@ private TestConstants() {} .postalCode("11111") .tenantName("tenanName") .agencyName("agencyName") + .referer("https://www.caritas.de/") ); } From 8d9ffafcae442a0f56b798954cdcf13c2f9d97b6 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 6 Jul 2023 10:43:50 +0200 Subject: [PATCH 04/21] fix: fix object comparision bug for statistics --- .../api/helper/RegistrationStatisticsDTOConverter.java | 2 +- .../api/helper/RegistrationStatisticsDTOConverterTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index dbeebdd..9f104ae 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -40,7 +40,7 @@ private String findEndDate(Long sessionId, List archiveSessionE private Optional findMaxArchiveSessionEvent(Long sessionId, List archiveSessionEvents) { return nonNull(archiveSessionEvents) ? archiveSessionEvents.stream() - .filter(event -> event.getSessionId() == sessionId) + .filter(event -> event.getSessionId() != null && event.getSessionId().equals(sessionId)) .max(comparing(StatisticsEvent::getTimestamp)) : Optional.empty(); } } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 324a091..585422d 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -80,7 +80,7 @@ void convertStatisticsEvent_Should_notFail_When_archiveSessionEventsAreNull() { @Test void convertStatisticsEvent_Should_addNewestArchiveSessionEndDate_When_multipleArchiveSessionEventsAreAvailable() { // given - givenValidStatisticEvent(1L); + givenValidStatisticEvent(new Long(1L)); givenValidArchiveStatisticEvents(); // when @@ -143,7 +143,7 @@ private void givenValidStatisticEvent(Long sessionId) { private void givenValidArchiveStatisticEvents() { archiveSessionEvents = List.of(archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), - archiveEvent(1L, "2022-10-18T10:00:00.00Z", "2 end date for session 1"), + archiveEvent(new Long(1), "2022-10-18T10:00:00.00Z", "2 end date for session 1"), archiveEvent(2L, "2022-10-18T10:00:00.00Z", "end date for session 2"), archiveEvent(999L, "2022-10-19T10:00:00.00Z", "dummy end date")); } From 27246a5e0c3002ef6d31fa1bbff1613ce21986b2 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Mon, 10 Jul 2023 11:03:56 +0200 Subject: [PATCH 05/21] feat: add account deletion listener --- api/statisticsservice.yaml | 23 ++++++++ .../AccountDeletionSessionListener.java | 53 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index 22b53de..35d7f97 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -109,6 +109,7 @@ components: enum: - "ASSIGN_SESSION" - "ARCHIVE_SESSION" + - "DELETE_ACCOUNT" - "CREATE_MESSAGE" - "START_VIDEO_CALL" - "STOP_VIDEO_CALL" @@ -188,6 +189,28 @@ components: type: string example: '2022-08-15T21:11:29' + DeleteAccountStatisticsEventMessage: + type: object + required: + - sessionId + - endDate + allOf: + - $ref: '#/components/schemas/StatisticsEventMessage' + - type: object + properties: + tenantId: + type: integer + format: int64 + description: The id of the tenant + example: 1 + userId: + type: string + description: The keycloak id of the consultant + example: d63f4cc0-215d-40e2-a866-2d3e910f0590 + deletionDate: + type: string + example: '2022-08-15T21:11:29' + CreateMessageStatisticsEventMessage: type: object required: diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java new file mode 100644 index 0000000..8cea795 --- /dev/null +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java @@ -0,0 +1,53 @@ +package de.caritas.cob.statisticsservice.api.statistics.listener; + +import de.caritas.cob.statisticsservice.api.model.ArchiveSessionStatisticsEventMessage; +import de.caritas.cob.statisticsservice.api.service.UserStatisticsService; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEventBuilder; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.stereotype.Service; + +/** + * AMQP Listener for archive session statistics event. + */ +@Service +@RequiredArgsConstructor +public class AccountDeletionSessionListener { + + private final @NonNull MongoTemplate mongoTemplate; + private final @NonNull UserStatisticsService userStatisticsService; + + /** + * Consumer for archive session message statistics event. + * + * @param eventMessage the {@link ArchiveSessionStatisticsEventMessage} instance + */ + @RabbitListener( + id = "delete-account-event-listener", + queues = "#{rabbitMqConfig.QUEUE_NAME_DELETE_ACCOUNT}", + containerFactory = "simpleRabbitListenerContainerFactory") + public void receiveMessage(ArchiveSessionStatisticsEventMessage eventMessage) { + + StatisticsEvent statisticsEvent = StatisticsEvent.builder() + .eventType(eventMessage.getEventType()) + .timestamp(eventMessage.getTimestamp().toInstant()) + .user(User.builder().userRole(eventMessage.getUserRole()).id(eventMessage.getUserId()) + .build()) + .metaData(buildMetaData(eventMessage)) + .build(); + + mongoTemplate.insert(statisticsEvent); + } + + private ArchiveMetaData buildMetaData(ArchiveSessionStatisticsEventMessage eventMessage) { + return ArchiveMetaData.builder() + .endDate(eventMessage.getEndDate()) + .tenantId(eventMessage.getTenantId()) + .build(); + } +} From d9a20a42f9993f7598de18e61ae0eee24c5a148c Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Mon, 10 Jul 2023 13:32:10 +0200 Subject: [PATCH 06/21] feat: enrichment of betend if account was deleted --- api/statisticsservice.yaml | 2 +- .../RegistrationStatisticsDTOConverter.java | 20 +++++++-- ...java => DeleteAccountSessionListener.java} | 14 +++---- .../meta/DeleteAccountMetaData.java | 12 ++++++ .../repository/StatisticsEventRepository.java | 3 ++ .../StatisticsEventTenantAwareRepository.java | 3 ++ .../RegistrationStatisticsService.java | 22 +++++++++- .../config/RabbitMqConfig.java | 11 ++++- ...egistrationStatisticsDTOConverterTest.java | 41 ++++++++++++++++--- .../RegistrationStatisticsServiceTest.java | 18 +++++++- 10 files changed, 126 insertions(+), 20 deletions(-) rename src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/{AccountDeletionSessionListener.java => DeleteAccountSessionListener.java} (79%) create mode 100644 src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/DeleteAccountMetaData.java diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index b842a8c..11030de 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -207,7 +207,7 @@ components: type: string description: The keycloak id of the consultant example: d63f4cc0-215d-40e2-a866-2d3e910f0590 - deletionDate: + deleteDate: type: string example: '2022-08-15T21:11:29' diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 7b17706..81133b1 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -6,6 +6,7 @@ import de.caritas.cob.statisticsservice.api.model.RegistrationStatisticsResponseDTO; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; import java.util.List; import java.util.Optional; @@ -15,8 +16,10 @@ public class RegistrationStatisticsDTOConverter { public RegistrationStatisticsResponseDTO convertStatisticsEvent( - StatisticsEvent rawEvent, List archiveSessionEvents) { + StatisticsEvent rawEvent, List archiveSessionEvents, List deleteAccountEvents) { RegistrationMetaData metadata = (RegistrationMetaData) rawEvent.getMetaData(); + String maxArchiveDate = findMaxArchiveDate(rawEvent.getSessionId(), archiveSessionEvents); + String deleteAccountDate = findDeleteAccountDate(rawEvent.getUser().getId(), deleteAccountEvents); return new RegistrationStatisticsResponseDTO() .userId(rawEvent.getUser().getId()) .registrationDate(metadata.getRegistrationDate()) @@ -27,12 +30,23 @@ public RegistrationStatisticsResponseDTO convertStatisticsEvent( .counsellingRelation(metadata.getCounsellingRelation()) .mainTopicInternalAttribute(metadata.getMainTopicInternalAttribute()) .topicsInternalAttributes(metadata.getTopicsInternalAttributes()) - .endDate(findEndDate(rawEvent.getSessionId(), archiveSessionEvents)) + .endDate(getEndDate(maxArchiveDate, deleteAccountDate)) .postalCode(metadata.getPostalCode()) .referer(metadata.getReferer()); } - private String findEndDate(Long sessionId, List archiveSessionEvents) { + private String getEndDate(String maxArchiveDate, String deleteAccountDate) { + return deleteAccountDate != null ? deleteAccountDate : maxArchiveDate; + } + + private String findDeleteAccountDate(String userId, List deleteAccountEvents) { + return nonNull(deleteAccountEvents) ? deleteAccountEvents.stream() + .filter(event -> event.getUser() != null && event.getUser().getId().equals(userId)) + .map(event -> ((DeleteAccountMetaData) event.getMetaData()).getDeleteDate()) + .findFirst().orElse(null) : null; + } + + private String findMaxArchiveDate(Long sessionId, List archiveSessionEvents) { var maxArchiveEvent = findMaxArchiveSessionEvent(sessionId, archiveSessionEvents); if (maxArchiveEvent.isPresent()) { ArchiveMetaData metaData = (ArchiveMetaData) maxArchiveEvent.get().getMetaData(); diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java similarity index 79% rename from src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java rename to src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java index 8cea795..9cf19bf 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/AccountDeletionSessionListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java @@ -1,11 +1,11 @@ package de.caritas.cob.statisticsservice.api.statistics.listener; import de.caritas.cob.statisticsservice.api.model.ArchiveSessionStatisticsEventMessage; +import de.caritas.cob.statisticsservice.api.model.DeleteAccountStatisticsEventMessage; import de.caritas.cob.statisticsservice.api.service.UserStatisticsService; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; -import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEventBuilder; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; -import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.amqp.rabbit.annotation.RabbitListener; @@ -17,7 +17,7 @@ */ @Service @RequiredArgsConstructor -public class AccountDeletionSessionListener { +public class DeleteAccountSessionListener { private final @NonNull MongoTemplate mongoTemplate; private final @NonNull UserStatisticsService userStatisticsService; @@ -31,7 +31,7 @@ public class AccountDeletionSessionListener { id = "delete-account-event-listener", queues = "#{rabbitMqConfig.QUEUE_NAME_DELETE_ACCOUNT}", containerFactory = "simpleRabbitListenerContainerFactory") - public void receiveMessage(ArchiveSessionStatisticsEventMessage eventMessage) { + public void receiveMessage(DeleteAccountStatisticsEventMessage eventMessage) { StatisticsEvent statisticsEvent = StatisticsEvent.builder() .eventType(eventMessage.getEventType()) @@ -44,9 +44,9 @@ public void receiveMessage(ArchiveSessionStatisticsEventMessage eventMessage) { mongoTemplate.insert(statisticsEvent); } - private ArchiveMetaData buildMetaData(ArchiveSessionStatisticsEventMessage eventMessage) { - return ArchiveMetaData.builder() - .endDate(eventMessage.getEndDate()) + private DeleteAccountMetaData buildMetaData(DeleteAccountStatisticsEventMessage eventMessage) { + return DeleteAccountMetaData.builder() + .deleteDate(eventMessage.getDeleteDate()) .tenantId(eventMessage.getTenantId()) .build(); } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/DeleteAccountMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/DeleteAccountMetaData.java new file mode 100644 index 0000000..1689458 --- /dev/null +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/DeleteAccountMetaData.java @@ -0,0 +1,12 @@ +package de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta; + +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class DeleteAccountMetaData { + + private String deleteDate; + private Long tenantId; +} diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java index 4ae98f7..f126b24 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java @@ -86,6 +86,9 @@ class Duration { @Query(value = "{'eventType': 'ARCHIVE_SESSION'}") List getAllArchiveSessionEvents(); + @Query(value = "{'eventType': 'DELETE_ACCOUNT'}") + List getAllDeleteAccountSessionEvents(); + /** * Calculate the number of done appointments. * Done mean that the endTime of the appointment or the endTime of the latest reschedule has been reached, and it was not canceled diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java index b8e6a80..d555d4a 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java @@ -12,4 +12,7 @@ public interface StatisticsEventTenantAwareRepository extends MongoRepository getAllArchiveSessionEvents(Long tenantId); + + @Query(value = "{'eventType': 'DELETE_ACCOUNT', 'metaData.tenantId': ?0}") + List getAllDeleteAccountSessionEvents(Long tenantId); } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java index 2c880cf..90ada4e 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java @@ -36,11 +36,12 @@ public RegistrationStatisticsListResponseDTO fetchRegistrationStatisticsData() { private RegistrationStatisticsListResponseDTO buildResponseDTO() { List archiveSessionEvents = getArchiveSessionEvents(); + List deleteAcccountEvents = getDeleteAccountEvents(); RegistrationStatisticsListResponseDTO registrationStatisticsList = new RegistrationStatisticsListResponseDTO(); getRegistrationStatistics() .stream() - .map(rawEvent -> registrationStatisticsDTOConverter.convertStatisticsEvent(rawEvent, archiveSessionEvents)) + .map(rawEvent -> registrationStatisticsDTOConverter.convertStatisticsEvent(rawEvent, archiveSessionEvents, deleteAcccountEvents)) .forEach(registrationStatisticsList::addRegistrationStatisticsItem); return registrationStatisticsList; @@ -62,6 +63,24 @@ private List getArchiveSessionEvents() { } } + private List getDeleteAccountEvents() { + if (isAllTenantAccessContext()) { + return getDeleteAccountEventsForAllTenants(); + } else { + return getDeleteAccountEventsForCurrentTenant(); + } + } + + private List getDeleteAccountEventsForAllTenants() { + log.info("Gathering delete account events for all tenants"); + return statisticsEventRepository.getAllDeleteAccountSessionEvents(); + } + + private List getDeleteAccountEventsForCurrentTenant() { + log.info("Gathering delete account events for all tenants"); + return statisticsEventTenantAwareRepository.getAllDeleteAccountSessionEvents(TenantContext.getCurrentTenant()); + } + private List getRegistrationStatisticsForCurrentTenant() { log.info("Gathering registration statistics for tenant with id {}", TenantContext.getCurrentTenant()); return statisticsEventTenantAwareRepository.getAllRegistrationStatistics( @@ -91,3 +110,4 @@ private boolean multitenancyIsDisabled() { return !multitenancyEnabled; } } + diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/RabbitMqConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/RabbitMqConfig.java index 08d341c..c860a3f 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/config/RabbitMqConfig.java +++ b/src/main/java/de/caritas/cob/statisticsservice/config/RabbitMqConfig.java @@ -53,6 +53,8 @@ public class RabbitMqConfig { public static final String QUEUE_NAME_BOOKING_RESCHEDULED = QUEUE_PREFIX + EventType.BOOKING_RESCHEDULED; public static final String QUEUE_NAME_BOOKING_CANCELED = QUEUE_PREFIX + EventType.BOOKING_CANCELLED; + public static final String QUEUE_NAME_DELETE_ACCOUNT = QUEUE_PREFIX + EventType.DELETE_ACCOUNT; + @Value("${spring.rabbitmq.listener.simple.retry.max-attempts}") private int retryMaxAttempts; @Value("${spring.rabbitmq.listener.simple.retry.initial-interval}") @@ -75,6 +77,8 @@ public Declarables topicBindings() { var bookingCreatedStatisticsEventQueue = buildQueue(QUEUE_NAME_BOOKING_CREATED); var bookingRescheduledStatisticsEventQueue = buildQueue(QUEUE_NAME_BOOKING_RESCHEDULED); var bookingCanceledStatisticsEventQueue = buildQueue(QUEUE_NAME_BOOKING_CANCELED); + var deleteAccountStatisticsEventQueue = buildQueue(QUEUE_NAME_DELETE_ACCOUNT); + var deadLetterExchange = new DirectExchange(DEAD_LETTER_EXCHANGE_NAME, true, false); var topicExchange = new TopicExchange(STATISTICS_EXCHANGE_NAME, true, false); @@ -119,7 +123,12 @@ public Declarables topicBindings() { bookingCanceledStatisticsEventQueue, BindingBuilder.bind(bookingCanceledStatisticsEventQueue) .to(topicExchange) - .with(EventType.BOOKING_CANCELLED)); + .with(EventType.BOOKING_CANCELLED), + deleteAccountStatisticsEventQueue, + BindingBuilder.bind(deleteAccountStatisticsEventQueue) + .to(topicExchange) + .with(EventType.DELETE_ACCOUNT) + ); } private Queue buildQueue(String queueName) { diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 4a79150..d0cfcbc 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -15,6 +15,7 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; import java.time.Instant; import java.util.List; @@ -34,6 +35,8 @@ class RegistrationStatisticsDTOConverterTest { private List archiveSessionEvents; + private List deleteAccountEvents; + @AfterEach void teardownEach() { testEvent = null; @@ -47,7 +50,7 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, null); + testEvent, null, null); // then assertThat(result.getUserId(), is(ASKER_ID)); @@ -77,7 +80,7 @@ void convertStatisticsEvent_Should_notFail_When_archiveSessionEventsAreNull() { // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, null); + testEvent, null, null); // then assertThat(result.getEndDate(), is(nullValue())); @@ -91,12 +94,27 @@ void convertStatisticsEvent_Should_addNewestArchiveSessionEndDate_When_multipleA // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents); + testEvent, archiveSessionEvents, null); // then assertThat(result.getEndDate(), is("2 end date for session 1")); } + @Test + void convertStatisticsEvent_Should_takeDeleteDateAsSessionEndDate_When_multipleArchiveSessionEventsAreAvailableAndDeleteDateExists() { + // given + givenValidStatisticEvent(new Long(1L)); + givenValidArchiveStatisticEvents(); + givenAccountDeleteStatisticEvents(); + + // when + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( + testEvent, archiveSessionEvents, deleteAccountEvents); + + // then + assertThat(result.getEndDate(), is("delete date for user 1")); + } + @Test void convertStatisticsEvent_Should_addArchiveSessionEndDate_When_onlyOneArchiveSessionEventIsAvailable() { // given @@ -105,7 +123,7 @@ void convertStatisticsEvent_Should_addArchiveSessionEndDate_When_onlyOneArchiveS // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents); + testEvent, archiveSessionEvents, null); // then assertThat(result.getEndDate(), is("end date for session 2")); @@ -119,7 +137,7 @@ void convertStatisticsEvent_Should_notAddArchiveSessionEndDate_When_noMatchingAr // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents); + testEvent, archiveSessionEvents, null); // then assertThat(result.getEndDate(), is(nullValue())); @@ -150,6 +168,12 @@ private void givenValidStatisticEvent(Long sessionId) { .build(); } + private void givenAccountDeleteStatisticEvents() { + deleteAccountEvents = List.of(deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"), + deleteEvent("user 2", "2022-10-17T10:00:00.00Z", "delete date for user 2")); + } + + private void givenValidArchiveStatisticEvents() { archiveSessionEvents = List.of(archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), archiveEvent(new Long(1), "2022-10-18T10:00:00.00Z", "2 end date for session 1"), @@ -161,4 +185,11 @@ private StatisticsEvent archiveEvent(Long sessionId, String timestampString, Str Object metaData = ArchiveMetaData.builder().endDate(endDate).build(); return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId).metaData(metaData).build(); } + + private StatisticsEvent deleteEvent(String userId, String timestampString, String deleteDate) { + Object metaData = DeleteAccountMetaData.builder().deleteDate(deleteDate).build(); + User user = new User(); + user.setId(userId); + return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user).metaData(metaData).build(); + } } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java index a7e00b7..b89180a 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java @@ -20,6 +20,7 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventTenantAwareRepository; @@ -93,7 +94,7 @@ void fetchRegistrationStatisticsData_Should_RetrieveExpectedData_When_matchingSt var result = registrationStatisticsService.fetchRegistrationStatisticsData(); // then - verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), anyList()); + verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), anyList(), anyList()); assertThat(result.getRegistrationStatistics().get(0).getUserId(), is(ASKER_ID)); assertThat(result.getRegistrationStatistics().get(0).getRegistrationDate(), @@ -119,7 +120,7 @@ void fetchRegistrationStatisticsData_Should_addEndDate() { var result = registrationStatisticsService.fetchRegistrationStatisticsData(); // then - verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), anyList()); + verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), anyList(), anyList()); assertThat(result.getRegistrationStatistics().get(0).getEndDate(), is("end date 1")); @@ -157,8 +158,21 @@ private void givenArchiveSessionEvents() { when(statisticsEventRepository.getAllArchiveSessionEvents()).thenReturn(archiveEvents); } + private void givenDeleteSessionEvents() { + List deleteAccountEvents = List.of(archiveSessionEvent(1L, "end date 1"), + archiveSessionEvent(99L, "end date 2")); + when(statisticsEventRepository.getAllDeleteAccountSessionEvents()).thenReturn(deleteAccountEvents); + } + private StatisticsEvent archiveSessionEvent(Long sessionId, String endDate) { Object metaData = ArchiveMetaData.builder().endDate(endDate).build(); return StatisticsEvent.builder().sessionId(sessionId).metaData(metaData).build(); } + + private StatisticsEvent deleteAccountEvents(String userId, String deleteDate) { + User user = new User(); + user.setId(userId); + Object metaData = DeleteAccountMetaData.builder().deleteDate(deleteDate).build(); + return StatisticsEvent.builder().user(user).metaData(metaData).build(); + } } From a7d54240f3687953be5142611624e9caf92a05ba Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 13 Jul 2023 10:18:16 +0200 Subject: [PATCH 07/21] fix: fix log information --- .../api/statistics/service/RegistrationStatisticsService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java index 90ada4e..b3bb65a 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java @@ -77,7 +77,7 @@ private List getDeleteAccountEventsForAllTenants() { } private List getDeleteAccountEventsForCurrentTenant() { - log.info("Gathering delete account events for all tenants"); + log.info("Gathering delete account events for current tenant"); return statisticsEventTenantAwareRepository.getAllDeleteAccountSessionEvents(TenantContext.getCurrentTenant()); } From 195b62644e60c4f75958c8fc245c30778081a5a8 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 13 Jul 2023 10:25:39 +0200 Subject: [PATCH 08/21] fix: null check convention --- .../api/helper/RegistrationStatisticsDTOConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 81133b1..0e15641 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -40,7 +40,7 @@ private String getEndDate(String maxArchiveDate, String deleteAccountDate) { } private String findDeleteAccountDate(String userId, List deleteAccountEvents) { - return nonNull(deleteAccountEvents) ? deleteAccountEvents.stream() + return deleteAccountEvents != null ? deleteAccountEvents.stream() .filter(event -> event.getUser() != null && event.getUser().getId().equals(userId)) .map(event -> ((DeleteAccountMetaData) event.getMetaData()).getDeleteDate()) .findFirst().orElse(null) : null; From c9c7dfbef1fcf75022b6a1c1ca985bf5dee309d3 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Mon, 24 Jul 2023 16:39:36 +0200 Subject: [PATCH 09/21] fix: betend should be set for session delete testcase --- api/statisticsservice.yaml | 2 +- ...ener.java => ArchiveOrDeleteSessionListener.java} | 10 +++++----- .../listener/DeleteAccountSessionListener.java | 3 +-- ....java => ArchiveOrDeleteSessionListenerTest.java} | 12 ++++++------ 4 files changed, 13 insertions(+), 14 deletions(-) rename src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/{ArchiveSessionListener.java => ArchiveOrDeleteSessionListener.java} (81%) rename src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/{ArchiveSessionListenerTest.java => ArchiveOrDeleteSessionListenerTest.java} (88%) diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index 11030de..152a3bd 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -166,7 +166,7 @@ components: description: The id of the session example: 12345 - ArchiveSessionStatisticsEventMessage: + ArchiveOrDeleteSessionStatisticsEventMessage: type: object required: - sessionId diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveSessionListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListener.java similarity index 81% rename from src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveSessionListener.java rename to src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListener.java index 57619f4..2ec00ab 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveSessionListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListener.java @@ -1,6 +1,6 @@ package de.caritas.cob.statisticsservice.api.statistics.listener; -import de.caritas.cob.statisticsservice.api.model.ArchiveSessionStatisticsEventMessage; +import de.caritas.cob.statisticsservice.api.model.ArchiveOrDeleteSessionStatisticsEventMessage; import de.caritas.cob.statisticsservice.api.service.UserStatisticsService; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEventBuilder; @@ -16,7 +16,7 @@ */ @Service @RequiredArgsConstructor -public class ArchiveSessionListener { +public class ArchiveOrDeleteSessionListener { private final @NonNull MongoTemplate mongoTemplate; private final @NonNull UserStatisticsService userStatisticsService; @@ -24,13 +24,13 @@ public class ArchiveSessionListener { /** * Consumer for archive session message statistics event. * - * @param eventMessage the {@link ArchiveSessionStatisticsEventMessage} instance + * @param eventMessage the {@link ArchiveOrDeleteSessionStatisticsEventMessage} instance */ @RabbitListener( id = "archive-session-event-listener", queues = "#{rabbitMqConfig.QUEUE_NAME_ARCHIVE_SESSION}", containerFactory = "simpleRabbitListenerContainerFactory") - public void receiveMessage(ArchiveSessionStatisticsEventMessage eventMessage) { + public void receiveMessage(ArchiveOrDeleteSessionStatisticsEventMessage eventMessage) { StatisticsEvent statisticsEvent = StatisticsEventBuilder.getInstance( @@ -45,7 +45,7 @@ public void receiveMessage(ArchiveSessionStatisticsEventMessage eventMessage) { mongoTemplate.insert(statisticsEvent); } - private ArchiveMetaData buildMetaData(ArchiveSessionStatisticsEventMessage eventMessage) { + private ArchiveMetaData buildMetaData(ArchiveOrDeleteSessionStatisticsEventMessage eventMessage) { return ArchiveMetaData.builder() .endDate(eventMessage.getEndDate()) .tenantId(eventMessage.getTenantId()) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java index 9cf19bf..55bfa54 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/DeleteAccountSessionListener.java @@ -1,6 +1,5 @@ package de.caritas.cob.statisticsservice.api.statistics.listener; -import de.caritas.cob.statisticsservice.api.model.ArchiveSessionStatisticsEventMessage; import de.caritas.cob.statisticsservice.api.model.DeleteAccountStatisticsEventMessage; import de.caritas.cob.statisticsservice.api.service.UserStatisticsService; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; @@ -25,7 +24,7 @@ public class DeleteAccountSessionListener { /** * Consumer for archive session message statistics event. * - * @param eventMessage the {@link ArchiveSessionStatisticsEventMessage} instance + * @param eventMessage the {@link de.caritas.cob.statisticsservice.api.model.ArchiveOrDeleteSessionStatisticsEventMessage} instance */ @RabbitListener( id = "delete-account-event-listener", diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveSessionListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java similarity index 88% rename from src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveSessionListenerTest.java rename to src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java index f1e7b99..7e57a23 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveSessionListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java @@ -11,7 +11,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import de.caritas.cob.statisticsservice.api.model.ArchiveSessionStatisticsEventMessage; +import de.caritas.cob.statisticsservice.api.model.ArchiveOrDeleteSessionStatisticsEventMessage; import de.caritas.cob.statisticsservice.api.model.EventType; import de.caritas.cob.statisticsservice.api.model.UserRole; import de.caritas.cob.statisticsservice.api.service.UserStatisticsService; @@ -29,10 +29,10 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -public class ArchiveSessionListenerTest { +public class ArchiveOrDeleteSessionListenerTest { @InjectMocks - ArchiveSessionListener archiveSessionListener; + ArchiveOrDeleteSessionListener archiveSessionListener; @Mock MongoTemplate mongoTemplate; @Mock @@ -48,7 +48,7 @@ public void receiveMessage_Should_saveEventToMongoDb() { .thenReturn(sessionStatisticsResultDTO); OffsetDateTime timestamp = OffsetDateTime.now(); - ArchiveSessionStatisticsEventMessage archiveSessionStatisticsEventMessage = buildEventMessage(timestamp); + ArchiveOrDeleteSessionStatisticsEventMessage archiveSessionStatisticsEventMessage = buildEventMessage(timestamp); // when archiveSessionListener.receiveMessage(archiveSessionStatisticsEventMessage); @@ -76,8 +76,8 @@ private SessionStatisticsResultDTO buildResultDto() { .rcGroupId(RC_GROUP_ID); } - private ArchiveSessionStatisticsEventMessage buildEventMessage(OffsetDateTime timestamp) { - return new ArchiveSessionStatisticsEventMessage() + private ArchiveOrDeleteSessionStatisticsEventMessage buildEventMessage(OffsetDateTime timestamp) { + return new ArchiveOrDeleteSessionStatisticsEventMessage() .sessionId(SESSION_ID) .tenantId(TENANT_ID) .eventType(EventType.ARCHIVE_SESSION) From 235ede8db9e76bdf965b27d2a6b4241df64171de Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 30 Aug 2023 11:55:54 +0200 Subject: [PATCH 10/21] feat: extended statistics for registration --- api/statisticsservice.yaml | 15 +++++ .../RegistrationStatisticsDTOConverter.java | 40 +++++++++--- .../listener/BookingCreatedListener.java | 1 + .../listener/StartVideoCallListener.java | 1 + .../StatisticEventsContainer.java | 19 ++++++ .../meta/AdviceSeekerAwareMetaData.java | 6 ++ .../meta/BookingCreatedMetaData.java | 4 +- .../meta/RegistrationMetaData.java | 2 +- .../meta/StartVideoCallMetaData.java | 3 +- .../repository/StatisticsEventRepository.java | 7 +++ .../StatisticsEventTenantAwareRepository.java | 6 ++ .../RegistrationStatisticsService.java | 62 ++++++++++++++++--- ...egistrationStatisticsDTOConverterTest.java | 28 ++++++--- .../RegistrationStatisticsServiceTest.java | 6 +- 14 files changed, 170 insertions(+), 30 deletions(-) create mode 100644 src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java create mode 100644 src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/AdviceSeekerAwareMetaData.java diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index 152a3bd..b71b43c 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -243,6 +243,9 @@ components: format: int64 description: The id of the session example: 12345 + adviceSeekerId: + type: string + description: The id of the adviceseeker videoCallUuid: type: string description: The uuid of the video call @@ -365,6 +368,16 @@ components: referer: type: string example: "referer" + appointmentsBookedCount: + type: integer + example: "4" + attendedVideoCallsCount: + type: integer + example: "6" + consultantMessagesCount: + type: integer + example: "72" + description: "Total number of messages sent by all consultants to this adviceseeker" BookingCreatedStatisticsEventMessage: type: object @@ -384,6 +397,8 @@ components: type: string bookingId: type: integer + adviceSeekerId: + type: string BookingRescheduledStatisticsEventMessage: type: object diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 0e15641..389ad76 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -4,11 +4,13 @@ import static java.util.Objects.nonNull; import de.caritas.cob.statisticsservice.api.model.RegistrationStatisticsResponseDTO; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticEventsContainer; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.AdviceSeekerAwareMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; -import java.util.List; +import java.util.Collection; import java.util.Optional; import org.springframework.stereotype.Component; @@ -16,10 +18,11 @@ public class RegistrationStatisticsDTOConverter { public RegistrationStatisticsResponseDTO convertStatisticsEvent( - StatisticsEvent rawEvent, List archiveSessionEvents, List deleteAccountEvents) { + StatisticsEvent rawEvent, StatisticEventsContainer statisticEventsContainer) { RegistrationMetaData metadata = (RegistrationMetaData) rawEvent.getMetaData(); - String maxArchiveDate = findMaxArchiveDate(rawEvent.getSessionId(), archiveSessionEvents); - String deleteAccountDate = findDeleteAccountDate(rawEvent.getUser().getId(), deleteAccountEvents); + String maxArchiveDate = findMaxArchiveDate(rawEvent.getSessionId(), statisticEventsContainer.getArchiveSessionEvents()); + String deleteAccountDate = findDeleteAccountDate(rawEvent.getUser().getId(), statisticEventsContainer.getDeleteAccountEvents()); + return new RegistrationStatisticsResponseDTO() .userId(rawEvent.getUser().getId()) .registrationDate(metadata.getRegistrationDate()) @@ -32,21 +35,42 @@ public RegistrationStatisticsResponseDTO convertStatisticsEvent( .topicsInternalAttributes(metadata.getTopicsInternalAttributes()) .endDate(getEndDate(maxArchiveDate, deleteAccountDate)) .postalCode(metadata.getPostalCode()) - .referer(metadata.getReferer()); + .referer(metadata.getReferer()) + .attendedVideoCallsCount( + countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getVideoCallStartedEvents())) + .appointmentsBookedCount(countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getBookingCreatedEvents())); + } + + private Integer countEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, + Collection events) { + + return events != null + ? (int) getCountOfEventsPerAdviceSeekerMatchingOnMetadata(adviceSeekerId, events) : 0; + } + + private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, + Collection videoCallStartedEvents) { + return videoCallStartedEvents.stream() + .filter(event -> { + AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData(); + return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId() + .equals(adviceSeekerId); + }) + .count(); } private String getEndDate(String maxArchiveDate, String deleteAccountDate) { return deleteAccountDate != null ? deleteAccountDate : maxArchiveDate; } - private String findDeleteAccountDate(String userId, List deleteAccountEvents) { + private String findDeleteAccountDate(String userId, Collection deleteAccountEvents) { return deleteAccountEvents != null ? deleteAccountEvents.stream() .filter(event -> event.getUser() != null && event.getUser().getId().equals(userId)) .map(event -> ((DeleteAccountMetaData) event.getMetaData()).getDeleteDate()) .findFirst().orElse(null) : null; } - private String findMaxArchiveDate(Long sessionId, List archiveSessionEvents) { + private String findMaxArchiveDate(Long sessionId, Collection archiveSessionEvents) { var maxArchiveEvent = findMaxArchiveSessionEvent(sessionId, archiveSessionEvents); if (maxArchiveEvent.isPresent()) { ArchiveMetaData metaData = (ArchiveMetaData) maxArchiveEvent.get().getMetaData(); @@ -55,7 +79,7 @@ private String findMaxArchiveDate(Long sessionId, List archiveS return null; } - private Optional findMaxArchiveSessionEvent(Long sessionId, List archiveSessionEvents) { + private Optional findMaxArchiveSessionEvent(Long sessionId, Collection archiveSessionEvents) { return nonNull(archiveSessionEvents) ? archiveSessionEvents.stream() .filter(event -> event.getSessionId() != null && event.getSessionId().equals(sessionId)) .max(comparing(StatisticsEvent::getTimestamp)) : Optional.empty(); diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java index 24ecb03..b247fe7 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java @@ -51,6 +51,7 @@ private BookingCreatedMetaData buildMetaData(BookingCreatedStatisticsEventMessag .uid(eventMessage.getUid()) .bookingId(eventMessage.getBookingId()) .currentBookingId(eventMessage.getBookingId()) + .adviceSeekerId(eventMessage.getAdviceSeekerId()) .build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java index 2dd8965..22e10bb 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java @@ -55,6 +55,7 @@ private StartVideoCallMetaData buildMetaData(StartVideoCallStatisticsEventMessag .duration(0) .timestampStop(null) .status(VideoCallStatus.ONGOING) + .adviceSeekerId(eventMessage.getAdviceSeekerId()) .build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java new file mode 100644 index 0000000..e54e78c --- /dev/null +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java @@ -0,0 +1,19 @@ +package de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent; + +import java.util.Collection; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class StatisticEventsContainer { + + private Collection archiveSessionEvents; + private Collection deleteAccountEvents; + private Collection videoCallStartedEvents; + private Collection bookingCreatedEvents; +} diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/AdviceSeekerAwareMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/AdviceSeekerAwareMetaData.java new file mode 100644 index 0000000..efa4a82 --- /dev/null +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/AdviceSeekerAwareMetaData.java @@ -0,0 +1,6 @@ +package de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta; + +public interface AdviceSeekerAwareMetaData { + + String getAdviceSeekerId(); +} diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java index 04816ba..646addb 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java @@ -10,7 +10,7 @@ @Data @NoArgsConstructor @AllArgsConstructor -public class BookingCreatedMetaData { +public class BookingCreatedMetaData implements AdviceSeekerAwareMetaData { private String type; private String title; @@ -20,4 +20,6 @@ public class BookingCreatedMetaData { private Integer bookingId; private Integer currentBookingId; + private String adviceSeekerId; + } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java index 67c3854..d0bf119 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/RegistrationMetaData.java @@ -19,7 +19,7 @@ public class RegistrationMetaData { private Integer age; private String gender; private String counsellingRelation; - private List topicsInternalAttributes = null; + private List topicsInternalAttributes; private String mainTopicInternalAttribute; private String postalCode; private String referer; diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java index 000ae9a..7811e3a 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java @@ -10,11 +10,12 @@ @Data @NoArgsConstructor @AllArgsConstructor -public class StartVideoCallMetaData { +public class StartVideoCallMetaData implements AdviceSeekerAwareMetaData { private String videoCallUuid; private long duration; private Instant timestampStop; private VideoCallStatus status; + private String adviceSeekerId; } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java index f126b24..90b02eb 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java @@ -83,9 +83,16 @@ class Duration { @Query(value = "{'eventType': 'REGISTRATION'}") List getAllRegistrationStatistics(); + @Query(value = "{'eventType': 'START_VIDEO_CALL'}") + List getAllStartVideoCallSessionEvents(); + @Query(value = "{'eventType': 'ARCHIVE_SESSION'}") List getAllArchiveSessionEvents(); + @Query(value = "{'eventType': 'BOOKING_CREATED'}") + List getAllBookingCreatedEvents(); + + @Query(value = "{'eventType': 'DELETE_ACCOUNT'}") List getAllDeleteAccountSessionEvents(); diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java index d555d4a..37bd357 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java @@ -15,4 +15,10 @@ public interface StatisticsEventTenantAwareRepository extends MongoRepository getAllDeleteAccountSessionEvents(Long tenantId); + + @Query(value = "{'eventType': 'START_VIDEO_CALL', 'metaData.tenantId': ?0}") + List getAllStartVideoCallSessionEvents(Long tenantId); + + @Query(value = "{'eventType': 'BOOKING_CREATED', 'metaData.tenantId': ?0}") + List getAllBookingCreatedEvents(Long currentTenant); } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java index b3bb65a..7619f1a 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java @@ -2,10 +2,12 @@ import de.caritas.cob.statisticsservice.api.helper.RegistrationStatisticsDTOConverter; import de.caritas.cob.statisticsservice.api.model.RegistrationStatisticsListResponseDTO; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticEventsContainer; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventTenantAwareRepository; import de.caritas.cob.statisticsservice.api.tenant.TenantContext; +import java.util.Collection; import java.util.List; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -35,18 +37,48 @@ public RegistrationStatisticsListResponseDTO fetchRegistrationStatisticsData() { } private RegistrationStatisticsListResponseDTO buildResponseDTO() { - List archiveSessionEvents = getArchiveSessionEvents(); - List deleteAcccountEvents = getDeleteAccountEvents(); + StatisticEventsContainer statisticEventsContainer = new StatisticEventsContainer( + getArchiveSessionEvents(), getDeleteAccountEvents(), getVideoCallStartedEvents(), + getAllBookingCreatedEvents()); RegistrationStatisticsListResponseDTO registrationStatisticsList = new RegistrationStatisticsListResponseDTO(); getRegistrationStatistics() .stream() - .map(rawEvent -> registrationStatisticsDTOConverter.convertStatisticsEvent(rawEvent, archiveSessionEvents, deleteAcccountEvents)) + .map(rawEvent -> registrationStatisticsDTOConverter.convertStatisticsEvent(rawEvent, + statisticEventsContainer)) .forEach(registrationStatisticsList::addRegistrationStatisticsItem); return registrationStatisticsList; } + private Collection getAllBookingCreatedEvents() { + if (isAllTenantAccessContext()) { + return getBookingCreatedEventsForAllTenants(); + } else { + return getBookingCreatedEventsForCurrentTenant(); + } + } + + private List getVideoCallStartedEvents() { + if (isAllTenantAccessContext()) { + return getVideoCallStartedEventsAllTenants(); + } else { + return getVideoCallStartedEventsForCurrentTenant(); + } + } + + private List getVideoCallStartedEventsForCurrentTenant() { + log.info("Gathering video call started events for all tenants"); + return statisticsEventTenantAwareRepository.getAllStartVideoCallSessionEvents( + TenantContext.getCurrentTenant()); + } + + private List getVideoCallStartedEventsAllTenants() { + log.info("Gathering video call started events for all tenants"); + return statisticsEventRepository.getAllStartVideoCallSessionEvents(); + + } + private List getRegistrationStatistics() { if (isAllTenantAccessContext()) { return getRegistrationStatisticsForAllTenants(); @@ -78,11 +110,13 @@ private List getDeleteAccountEventsForAllTenants() { private List getDeleteAccountEventsForCurrentTenant() { log.info("Gathering delete account events for current tenant"); - return statisticsEventTenantAwareRepository.getAllDeleteAccountSessionEvents(TenantContext.getCurrentTenant()); + return statisticsEventTenantAwareRepository.getAllDeleteAccountSessionEvents( + TenantContext.getCurrentTenant()); } private List getRegistrationStatisticsForCurrentTenant() { - log.info("Gathering registration statistics for tenant with id {}", TenantContext.getCurrentTenant()); + log.info("Gathering registration statistics for tenant with id {}", + TenantContext.getCurrentTenant()); return statisticsEventTenantAwareRepository.getAllRegistrationStatistics( TenantContext.getCurrentTenant()); } @@ -97,9 +131,23 @@ private List getArchiveSessionEventsForAllTenants() { return statisticsEventRepository.getAllArchiveSessionEvents(); } + private List getBookingCreatedEventsForAllTenants() { + log.info("Gathering booked appointments events for all tenants"); + return statisticsEventRepository.getAllBookingCreatedEvents(); + } + + private List getBookingCreatedEventsForCurrentTenant() { + log.info("Gathering booked appointments events for tenant with id {}", + TenantContext.getCurrentTenant()); + return statisticsEventTenantAwareRepository.getAllBookingCreatedEvents( + TenantContext.getCurrentTenant()); + } + private List getArchiveSessionEventsForCurrentTenant() { - log.info("Gathering archive session events for tenant with id {}", TenantContext.getCurrentTenant()); - return statisticsEventTenantAwareRepository.getAllArchiveSessionEvents(TenantContext.getCurrentTenant()); + log.info("Gathering archive session events for tenant with id {}", + TenantContext.getCurrentTenant()); + return statisticsEventTenantAwareRepository.getAllArchiveSessionEvents( + TenantContext.getCurrentTenant()); } private boolean isAllTenantAccessContext() { diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index d0cfcbc..0b82549 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -12,6 +12,7 @@ import de.caritas.cob.statisticsservice.api.model.UserRole; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.Agency; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.ConsultingType; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticEventsContainer; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; @@ -49,8 +50,7 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { givenValidStatisticEvent(1L); // when - RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, null, null); + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, new StatisticEventsContainer()); // then assertThat(result.getUserId(), is(ASKER_ID)); @@ -80,7 +80,7 @@ void convertStatisticsEvent_Should_notFail_When_archiveSessionEventsAreNull() { // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, null, null); + testEvent, new StatisticEventsContainer()); // then assertThat(result.getEndDate(), is(nullValue())); @@ -89,12 +89,13 @@ void convertStatisticsEvent_Should_notFail_When_archiveSessionEventsAreNull() { @Test void convertStatisticsEvent_Should_addNewestArchiveSessionEndDate_When_multipleArchiveSessionEventsAreAvailable() { // given - givenValidStatisticEvent(new Long(1L)); + givenValidStatisticEvent(1L); givenValidArchiveStatisticEvents(); // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents, null); + testEvent, StatisticEventsContainer.builder() + .archiveSessionEvents(archiveSessionEvents).build()); // then assertThat(result.getEndDate(), is("2 end date for session 1")); @@ -103,13 +104,16 @@ void convertStatisticsEvent_Should_addNewestArchiveSessionEndDate_When_multipleA @Test void convertStatisticsEvent_Should_takeDeleteDateAsSessionEndDate_When_multipleArchiveSessionEventsAreAvailableAndDeleteDateExists() { // given - givenValidStatisticEvent(new Long(1L)); + givenValidStatisticEvent(1L); givenValidArchiveStatisticEvents(); givenAccountDeleteStatisticEvents(); // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents, deleteAccountEvents); + testEvent, StatisticEventsContainer.builder() + .archiveSessionEvents(archiveSessionEvents) + .deleteAccountEvents(deleteAccountEvents) + .build()); // then assertThat(result.getEndDate(), is("delete date for user 1")); @@ -123,7 +127,9 @@ void convertStatisticsEvent_Should_addArchiveSessionEndDate_When_onlyOneArchiveS // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents, null); + testEvent, StatisticEventsContainer.builder() + .archiveSessionEvents(archiveSessionEvents) + .build()); // then assertThat(result.getEndDate(), is("end date for session 2")); @@ -137,7 +143,9 @@ void convertStatisticsEvent_Should_notAddArchiveSessionEndDate_When_noMatchingAr // when RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( - testEvent, archiveSessionEvents, null); + testEvent, StatisticEventsContainer.builder() + .archiveSessionEvents(archiveSessionEvents) + .build()); // then assertThat(result.getEndDate(), is(nullValue())); @@ -176,7 +184,7 @@ private void givenAccountDeleteStatisticEvents() { private void givenValidArchiveStatisticEvents() { archiveSessionEvents = List.of(archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), - archiveEvent(new Long(1), "2022-10-18T10:00:00.00Z", "2 end date for session 1"), + archiveEvent(1L, "2022-10-18T10:00:00.00Z", "2 end date for session 1"), archiveEvent(2L, "2022-10-18T10:00:00.00Z", "end date for session 2"), archiveEvent(999L, "2022-10-19T10:00:00.00Z", "dummy end date")); } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java index b89180a..5129040 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java @@ -17,6 +17,7 @@ import de.caritas.cob.statisticsservice.api.model.UserRole; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.Agency; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.ConsultingType; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticEventsContainer; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; @@ -94,7 +95,8 @@ void fetchRegistrationStatisticsData_Should_RetrieveExpectedData_When_matchingSt var result = registrationStatisticsService.fetchRegistrationStatisticsData(); // then - verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), anyList(), anyList()); + verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), any( + StatisticEventsContainer.class)); assertThat(result.getRegistrationStatistics().get(0).getUserId(), is(ASKER_ID)); assertThat(result.getRegistrationStatistics().get(0).getRegistrationDate(), @@ -120,7 +122,7 @@ void fetchRegistrationStatisticsData_Should_addEndDate() { var result = registrationStatisticsService.fetchRegistrationStatisticsData(); // then - verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), anyList(), anyList()); + verify(registrationStatisticsDTOConverter).convertStatisticsEvent(any(StatisticsEvent.class), any(StatisticEventsContainer.class)); assertThat(result.getRegistrationStatistics().get(0).getEndDate(), is("end date 1")); From e2dda36446a69c6e78fd827cce8fba3d56eaf0c1 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Fri, 1 Sep 2023 15:10:57 +0200 Subject: [PATCH 11/21] feat: extended statistics for registration --- api/statisticsservice.yaml | 3 +++ .../RegistrationStatisticsDTOConverter.java | 26 ++++++++++++++++--- .../listener/CreateMessageListener.java | 2 +- .../StatisticEventsContainer.java | 2 ++ .../meta/CreateMessageMetaData.java | 1 + .../repository/StatisticsEventRepository.java | 4 ++- .../StatisticsEventTenantAwareRepository.java | 3 +++ .../RegistrationStatisticsService.java | 22 +++++++++++++++- 8 files changed, 57 insertions(+), 6 deletions(-) diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index b71b43c..79fbe5d 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -228,6 +228,9 @@ components: type: boolean description: indicates whether the message has an attachment example: true + receiverId: + type: string + description: receiving user id of the message (taken from session). Can be null for groupchat. StartVideoCallStatisticsEventMessage: type: object diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 389ad76..bb87237 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -8,6 +8,7 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.AdviceSeekerAwareMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; +import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.CreateMessageMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; import java.util.Collection; @@ -38,7 +39,8 @@ public RegistrationStatisticsResponseDTO convertStatisticsEvent( .referer(metadata.getReferer()) .attendedVideoCallsCount( countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getVideoCallStartedEvents())) - .appointmentsBookedCount(countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getBookingCreatedEvents())); + .appointmentsBookedCount(countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getBookingCreatedEvents())) + .consultantMessagesCount(countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(rawEvent.getUser().getId(), statisticEventsContainer.getConsultantMessageCreatedEvents())); } private Integer countEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, @@ -48,9 +50,16 @@ private Integer countEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeeker ? (int) getCountOfEventsPerAdviceSeekerMatchingOnMetadata(adviceSeekerId, events) : 0; } + private Integer countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String adviceSeekerId, + Collection events) { + + return events != null + ? (int) getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(adviceSeekerId, events) : 0; + } + private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, - Collection videoCallStartedEvents) { - return videoCallStartedEvents.stream() + Collection statisticsEvents) { + return statisticsEvents.stream() .filter(event -> { AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData(); return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId() @@ -59,6 +68,17 @@ private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeek .count(); } + private long getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String adviceSeekerId, + Collection createMessageEvents) { + return createMessageEvents.stream() + .filter(event -> { + CreateMessageMetaData metaData = (CreateMessageMetaData) event.getMetaData(); + return metaData.getReceiverId() != null && metaData.getReceiverId() + .equals(adviceSeekerId); + }) + .count(); + } + private String getEndDate(String maxArchiveDate, String deleteAccountDate) { return deleteAccountDate != null ? deleteAccountDate : maxArchiveDate; } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java index 7923e76..6c997ae 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java @@ -45,6 +45,6 @@ public void receiveMessage(CreateMessageStatisticsEventMessage eventMessage) { } private CreateMessageMetaData buildMetaData(CreateMessageStatisticsEventMessage eventMessage) { - return CreateMessageMetaData.builder().hasAttachment(eventMessage.getHasAttachment()).build(); + return CreateMessageMetaData.builder().receiverId(eventMessage.getReceiverId()).hasAttachment(eventMessage.getHasAttachment()).build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java index e54e78c..17efb61 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/StatisticEventsContainer.java @@ -16,4 +16,6 @@ public class StatisticEventsContainer { private Collection deleteAccountEvents; private Collection videoCallStartedEvents; private Collection bookingCreatedEvents; + private Collection consultantMessageCreatedEvents; + } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java index 1adf636..0065602 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java @@ -12,5 +12,6 @@ public class CreateMessageMetaData { private boolean hasAttachment; + private String receiverId; } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java index 90b02eb..e69c4c1 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepository.java @@ -92,10 +92,12 @@ class Duration { @Query(value = "{'eventType': 'BOOKING_CREATED'}") List getAllBookingCreatedEvents(); - @Query(value = "{'eventType': 'DELETE_ACCOUNT'}") List getAllDeleteAccountSessionEvents(); + @Query(value = "{'eventType': 'CREATE_MESSAGE', 'user.userRole': 'CONSULTANT'}") + List getConsultantMessageCreatedEvents(); + /** * Calculate the number of done appointments. * Done mean that the endTime of the appointment or the endTime of the latest reschedule has been reached, and it was not canceled diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java index 37bd357..1d48f7f 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepository.java @@ -21,4 +21,7 @@ public interface StatisticsEventTenantAwareRepository extends MongoRepository getAllBookingCreatedEvents(Long currentTenant); + + @Query(value = "{'eventType': 'CREATE_MESSAGE', 'user.userRole': 'CONSULTANT', 'metaData.tenantId': ?0}") + List getConsultantMessageCreatedEvents(Long currentTenant); } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java index 7619f1a..2662e22 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsService.java @@ -1,6 +1,7 @@ package de.caritas.cob.statisticsservice.api.statistics.service; import de.caritas.cob.statisticsservice.api.helper.RegistrationStatisticsDTOConverter; +import de.caritas.cob.statisticsservice.api.model.EventType; import de.caritas.cob.statisticsservice.api.model.RegistrationStatisticsListResponseDTO; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticEventsContainer; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; @@ -39,7 +40,7 @@ public RegistrationStatisticsListResponseDTO fetchRegistrationStatisticsData() { private RegistrationStatisticsListResponseDTO buildResponseDTO() { StatisticEventsContainer statisticEventsContainer = new StatisticEventsContainer( getArchiveSessionEvents(), getDeleteAccountEvents(), getVideoCallStartedEvents(), - getAllBookingCreatedEvents()); + getAllBookingCreatedEvents(), getAllMessageCreatedEvents()); RegistrationStatisticsListResponseDTO registrationStatisticsList = new RegistrationStatisticsListResponseDTO(); getRegistrationStatistics() @@ -51,6 +52,14 @@ private RegistrationStatisticsListResponseDTO buildResponseDTO() { return registrationStatisticsList; } + private Collection getAllMessageCreatedEvents() { + if (isAllTenantAccessContext()) { + return getMessageCreatedEventsForAllTenants(); + } else { + return getMessageCreatedEventsForCurrentTenant(); + } + } + private Collection getAllBookingCreatedEvents() { if (isAllTenantAccessContext()) { return getBookingCreatedEventsForAllTenants(); @@ -131,11 +140,22 @@ private List getArchiveSessionEventsForAllTenants() { return statisticsEventRepository.getAllArchiveSessionEvents(); } + private List getMessageCreatedEventsForAllTenants() { + log.info("Gathering message created events for all tenants"); + return statisticsEventRepository.getConsultantMessageCreatedEvents(); + } + private List getBookingCreatedEventsForAllTenants() { log.info("Gathering booked appointments events for all tenants"); return statisticsEventRepository.getAllBookingCreatedEvents(); } + private List getMessageCreatedEventsForCurrentTenant() { + log.info("Gathering message created events for tenant with id {}", + TenantContext.getCurrentTenant()); + return statisticsEventTenantAwareRepository.getConsultantMessageCreatedEvents(TenantContext.getCurrentTenant()); + } + private List getBookingCreatedEventsForCurrentTenant() { log.info("Gathering booked appointments events for tenant with id {}", TenantContext.getCurrentTenant()); From e1479d4c2bbb26c6d70d7a964d0ca8602ceb2e25 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 13 Sep 2023 22:37:15 +0200 Subject: [PATCH 12/21] fix: stateless api client for call to userservice --- .../api/service/UserStatisticsService.java | 5 ++- .../SecurityHeaderSupplier.java | 19 --------- .../UserStatisticsApiControllerFactory.java | 28 +++++++++++++ .../UserStatisticsControllerApiConfig.java | 41 ------------------- 4 files changed, 31 insertions(+), 62 deletions(-) create mode 100644 src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsApiControllerFactory.java delete mode 100644 src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsControllerApiConfig.java diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsService.java b/src/main/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsService.java index 05ac9a4..787bce7 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsService.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsService.java @@ -1,8 +1,8 @@ package de.caritas.cob.statisticsservice.api.service; import de.caritas.cob.statisticsservice.api.service.securityheader.TenantHeaderSupplier; +import de.caritas.cob.statisticsservice.config.apiclient.UserStatisticsApiControllerFactory; import de.caritas.cob.statisticsservice.config.cache.CacheManagerConfig; -import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.UserStatisticsControllerApi; import de.caritas.cob.statisticsservice.api.service.securityheader.SecurityHeaderSupplier; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; import lombok.NonNull; @@ -14,7 +14,7 @@ @RequiredArgsConstructor public class UserStatisticsService { - private final @NonNull UserStatisticsControllerApi userStatisticsControllerApi; + private final @NonNull UserStatisticsApiControllerFactory userStatisticsApiControllerFactory; private final @NonNull SecurityHeaderSupplier securityHeaderSupplier; private final @NonNull TenantHeaderSupplier tenantHeaderSupplier; @@ -41,6 +41,7 @@ public SessionStatisticsResultDTO retrieveSessionViaRcGroupId(String rcGroupId) } private SessionStatisticsResultDTO retrieveSession(Long sessionId, String rcGroupId) { + var userStatisticsControllerApi = userStatisticsApiControllerFactory.createControllerApi(); addDefaultHeaders(userStatisticsControllerApi.getApiClient()); return userStatisticsControllerApi .getSession(sessionId, rcGroupId); diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/service/securityheader/SecurityHeaderSupplier.java b/src/main/java/de/caritas/cob/statisticsservice/api/service/securityheader/SecurityHeaderSupplier.java index cd10b2a..727a116 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/service/securityheader/SecurityHeaderSupplier.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/service/securityheader/SecurityHeaderSupplier.java @@ -21,35 +21,16 @@ public class SecurityHeaderSupplier { @Value("${csrf.cookie.property}") private String csrfCookieProperty; - /** - * Creates the headers containing keycloak token and csrf headers {@link HttpHeaders} object. - * - * @return the created {@link HttpHeaders} - */ - public HttpHeaders getKeycloakAndCsrfHttpHeaders() { - var header = getCsrfHttpHeaders(); - this.addKeycloakAuthorizationHeader(header); - - return header; - } - public HttpHeaders getCsrfHttpHeaders() { var httpHeaders = new HttpHeaders(); - return this.addCsrfValues(httpHeaders); } private HttpHeaders addCsrfValues(HttpHeaders httpHeaders) { var csrfToken = UUID.randomUUID().toString(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.add("Cookie", csrfCookieProperty + "=" + csrfToken); httpHeaders.add(csrfHeaderProperty, csrfToken); - return httpHeaders; } - - private void addKeycloakAuthorizationHeader(HttpHeaders httpHeaders) { - httpHeaders.add("Authorization", "Bearer " + authenticatedUser.getAccessToken()); - } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsApiControllerFactory.java b/src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsApiControllerFactory.java new file mode 100644 index 0000000..35dca2c --- /dev/null +++ b/src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsApiControllerFactory.java @@ -0,0 +1,28 @@ +package de.caritas.cob.statisticsservice.config.apiclient; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +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; +import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.UserStatisticsControllerApi; +import de.caritas.cob.statisticsservice.userstatisticsservice.generated.ApiClient; + +@Component +@RequiredArgsConstructor +public class UserStatisticsApiControllerFactory { + + @Value("${user.statistics.service.api.url}") + private String userStatisticsServiceApiUrl; + + @Autowired + private RestTemplate restTemplate; + + private final ObjectMapper objectMapper; + + public UserStatisticsControllerApi createControllerApi() { + var apiClient = new ApiClient(restTemplate).setBasePath(this.userStatisticsServiceApiUrl); + return new UserStatisticsControllerApi(apiClient); + } +} diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsControllerApiConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsControllerApiConfig.java deleted file mode 100644 index db039f5..0000000 --- a/src/main/java/de/caritas/cob/statisticsservice/config/apiclient/UserStatisticsControllerApiConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.caritas.cob.statisticsservice.config.apiclient; - -import de.caritas.cob.statisticsservice.userstatisticsservice.generated.ApiClient; -import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.UserStatisticsControllerApi; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - -@Component -public class UserStatisticsControllerApiConfig { - - @Value("${user.statistics.service.api.url}") - private String userStatisticsServiceApiUrl; - - /** - * UserStatisticsService controller bean. - * - * @param apiClient {@link ApiClient} - * @return the UserStatisticsService controller {@link UserStatisticsControllerApi} - */ - @Bean - public UserStatisticsControllerApi userStatisticsControllerApi( - ApiClient apiClient) { - return new UserStatisticsControllerApi(apiClient); - } - - /** - * ConsultingTypeService API client bean. - * - * @param restTemplate {@link RestTemplate} - * @return the ConsultingTypeService {@link ApiClient} - */ - @Bean - @Primary - public ApiClient userStatisticsApiClient(RestTemplate restTemplate) { - return new ApiClient(restTemplate).setBasePath(this.userStatisticsServiceApiUrl); - } - -} From 96382f088265eed88fdb535486b424b9e6a632e3 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 14 Sep 2023 16:32:43 +0200 Subject: [PATCH 13/21] fix: store tenant id in metadata to enable filtering by tenant id --- api/statisticsservice.yaml | 13 +++++++++++++ .../statistics/listener/BookingCreatedListener.java | 1 + .../statistics/listener/CreateMessageListener.java | 6 +++++- .../statistics/listener/StartVideoCallListener.java | 2 ++ .../meta/BookingCreatedMetaData.java | 2 +- .../statisticsevent/meta/CreateMessageMetaData.java | 2 ++ .../meta/StartVideoCallMetaData.java | 2 ++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/statisticsservice.yaml b/api/statisticsservice.yaml index 79fbe5d..d3b3f0c 100644 --- a/api/statisticsservice.yaml +++ b/api/statisticsservice.yaml @@ -231,6 +231,11 @@ components: receiverId: type: string description: receiving user id of the message (taken from session). Can be null for groupchat. + tenantId: + type: integer + format: int64 + description: The id of the tenant + example: 1 StartVideoCallStatisticsEventMessage: type: object @@ -253,6 +258,10 @@ components: type: string description: The uuid of the video call example: 123e4567-e89b-12d3-a456-556642440000 + tenantId: + type: integer + format: int64 + description: The id of the tenant StopVideoCallStatisticsEventMessage: type: object @@ -402,6 +411,10 @@ components: type: integer adviceSeekerId: type: string + tenantId: + type: integer + format: int64 + description: The id of the tenant BookingRescheduledStatisticsEventMessage: type: object diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java index b247fe7..b5be145 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/BookingCreatedListener.java @@ -52,6 +52,7 @@ private BookingCreatedMetaData buildMetaData(BookingCreatedStatisticsEventMessag .bookingId(eventMessage.getBookingId()) .currentBookingId(eventMessage.getBookingId()) .adviceSeekerId(eventMessage.getAdviceSeekerId()) + .tenantId(eventMessage.getTenantId()) .build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java index 6c997ae..64eb8d8 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListener.java @@ -45,6 +45,10 @@ public void receiveMessage(CreateMessageStatisticsEventMessage eventMessage) { } private CreateMessageMetaData buildMetaData(CreateMessageStatisticsEventMessage eventMessage) { - return CreateMessageMetaData.builder().receiverId(eventMessage.getReceiverId()).hasAttachment(eventMessage.getHasAttachment()).build(); + return CreateMessageMetaData.builder() + .receiverId(eventMessage.getReceiverId()) + .hasAttachment(eventMessage.getHasAttachment()) + .tenantId(eventMessage.getTenantId()) + .build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java index 22e10bb..d9b947c 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java @@ -52,10 +52,12 @@ public void receiveMessage(StartVideoCallStatisticsEventMessage eventMessage) { private StartVideoCallMetaData buildMetaData(StartVideoCallStatisticsEventMessage eventMessage) { return StartVideoCallMetaData.builder() .videoCallUuid(eventMessage.getVideoCallUuid()) + .tenantId(eventMessage.getTenantId()) .duration(0) .timestampStop(null) .status(VideoCallStatus.ONGOING) .adviceSeekerId(eventMessage.getAdviceSeekerId()) + .tenantId(eventMessage.getTenantId()) .build(); } } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java index 646addb..47e6188 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/BookingCreatedMetaData.java @@ -19,7 +19,7 @@ public class BookingCreatedMetaData implements AdviceSeekerAwareMetaData { private String uid; private Integer bookingId; private Integer currentBookingId; - private String adviceSeekerId; + private Long tenantId; } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java index 0065602..45af492 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/CreateMessageMetaData.java @@ -14,4 +14,6 @@ public class CreateMessageMetaData { private boolean hasAttachment; private String receiverId; + private Long tenantId; + } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java index 7811e3a..3fe9fd1 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/model/statisticsevent/meta/StartVideoCallMetaData.java @@ -18,4 +18,6 @@ public class StartVideoCallMetaData implements AdviceSeekerAwareMetaData { private VideoCallStatus status; private String adviceSeekerId; + private Long tenantId; + } From 7f66acbb5a15df66e602ce99df48fdad3df9794c Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Mon, 18 Sep 2023 10:09:11 +0200 Subject: [PATCH 14/21] fix: store tenant id in metadata to enable filtering by tenant id --- .../api/statistics/listener/StartVideoCallListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java index d9b947c..b732416 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListener.java @@ -57,7 +57,6 @@ private StartVideoCallMetaData buildMetaData(StartVideoCallStatisticsEventMessag .timestampStop(null) .status(VideoCallStatus.ONGOING) .adviceSeekerId(eventMessage.getAdviceSeekerId()) - .tenantId(eventMessage.getTenantId()) .build(); } } From 784dc57880c3502e81e4ec92dca481b6f0d5dca8 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 24 Apr 2024 08:22:17 +0200 Subject: [PATCH 15/21] fix: class cast exception for statistics --- .../RegistrationStatisticsDTOConverter.java | 8 ++-- ...egistrationStatisticsDTOConverterTest.java | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index bb87237..5ceb519 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -60,10 +60,12 @@ private Integer countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, Collection statisticsEvents) { return statisticsEvents.stream() + .filter(event -> event.getMetaData() instanceof AdviceSeekerAwareMetaData) .filter(event -> { - AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData(); - return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId() - .equals(adviceSeekerId); + AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData(); + return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId() + .equals(adviceSeekerId); + }) .count(); } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 0b82549..936587a 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; +import com.google.common.collect.Lists; import de.caritas.cob.statisticsservice.api.model.EventType; import de.caritas.cob.statisticsservice.api.model.RegistrationStatisticsResponseDTO; import de.caritas.cob.statisticsservice.api.model.UserRole; @@ -19,6 +20,7 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.DeleteAccountMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; import java.time.Instant; +import java.util.LinkedHashMap; import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -73,6 +75,47 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { is("aReferer")); } + @Test + void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithoutErrorIfMetadataIsLinkedHashMap() { + // given + givenValidStatisticEvent(1L); + + var videoCallStartedEvent = StatisticsEvent.builder() + .sessionId(1L) + .eventType(EventType.REGISTRATION) + .user(User.builder().userRole(UserRole.ASKER).id(ASKER_ID).build()) + .consultingType(ConsultingType.builder().id(CONSULTING_TYPE_ID).build()) + .agency(Agency.builder().id(AGENCY_ID).build()) + .timestamp(Instant.now()) + .metaData(new LinkedHashMap<>()) + .build(); + + var statisticEventsContainer = StatisticEventsContainer.builder().videoCallStartedEvents(Lists.newArrayList(videoCallStartedEvent)).build(); + // when + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, statisticEventsContainer); + + // then + assertThat(result.getUserId(), is(ASKER_ID)); + assertThat(result.getRegistrationDate(), + is("2022-09-15T09:14:45Z")); + assertThat(result.getAge(), is(26)); + assertThat(result.getGender(), is("FEMALE")); + assertThat(result.getMainTopicInternalAttribute(), + is("alk")); + assertThat(result.getTopicsInternalAttributes(), + is(List.of("alk", "drogen"))); + assertThat(result.getPostalCode(), is("12345")); + assertThat(result.getCounsellingRelation(), + is("SELF_COUNSELLING")); + assertThat(result.getTenantName(), + is("tenantName")); + assertThat(result.getAgencyName(), + is("agencyName")); + assertThat(result.getReferer(), + is("aReferer")); + } + + @Test void convertStatisticsEvent_Should_notFail_When_archiveSessionEventsAreNull() { // given From d8ee53788b6243bf8c59ca6eef8b6df830761cd3 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 24 Apr 2024 09:08:24 +0200 Subject: [PATCH 16/21] fix: class cast exception for statistics --- .../RegistrationStatisticsDTOConverter.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 5ceb519..568ce47 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -21,8 +21,10 @@ public class RegistrationStatisticsDTOConverter { public RegistrationStatisticsResponseDTO convertStatisticsEvent( StatisticsEvent rawEvent, StatisticEventsContainer statisticEventsContainer) { RegistrationMetaData metadata = (RegistrationMetaData) rawEvent.getMetaData(); - String maxArchiveDate = findMaxArchiveDate(rawEvent.getSessionId(), statisticEventsContainer.getArchiveSessionEvents()); - String deleteAccountDate = findDeleteAccountDate(rawEvent.getUser().getId(), statisticEventsContainer.getDeleteAccountEvents()); + String maxArchiveDate = findMaxArchiveDate(rawEvent.getSessionId(), + statisticEventsContainer.getArchiveSessionEvents()); + String deleteAccountDate = findDeleteAccountDate(rawEvent.getUser().getId(), + statisticEventsContainer.getDeleteAccountEvents()); return new RegistrationStatisticsResponseDTO() .userId(rawEvent.getUser().getId()) @@ -38,9 +40,14 @@ public RegistrationStatisticsResponseDTO convertStatisticsEvent( .postalCode(metadata.getPostalCode()) .referer(metadata.getReferer()) .attendedVideoCallsCount( - countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getVideoCallStartedEvents())) - .appointmentsBookedCount(countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), statisticEventsContainer.getBookingCreatedEvents())) - .consultantMessagesCount(countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(rawEvent.getUser().getId(), statisticEventsContainer.getConsultantMessageCreatedEvents())); + countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), + statisticEventsContainer.getVideoCallStartedEvents())) + .appointmentsBookedCount( + countEventsPerAdviceSeekerMatchingOnMetadata(rawEvent.getUser().getId(), + statisticEventsContainer.getBookingCreatedEvents())) + .consultantMessagesCount( + countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(rawEvent.getUser().getId(), + statisticEventsContainer.getConsultantMessageCreatedEvents())); } private Integer countEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, @@ -54,7 +61,8 @@ private Integer countEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String Collection events) { return events != null - ? (int) getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(adviceSeekerId, events) : 0; + ? (int) getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(adviceSeekerId, + events) : 0; } private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeekerId, @@ -62,9 +70,9 @@ private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeek return statisticsEvents.stream() .filter(event -> event.getMetaData() instanceof AdviceSeekerAwareMetaData) .filter(event -> { - AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData(); - return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId() - .equals(adviceSeekerId); + AdviceSeekerAwareMetaData metaData = (AdviceSeekerAwareMetaData) event.getMetaData(); + return metaData.getAdviceSeekerId() != null && metaData.getAdviceSeekerId() + .equals(adviceSeekerId); }) .count(); @@ -85,14 +93,16 @@ private String getEndDate(String maxArchiveDate, String deleteAccountDate) { return deleteAccountDate != null ? deleteAccountDate : maxArchiveDate; } - private String findDeleteAccountDate(String userId, Collection deleteAccountEvents) { + private String findDeleteAccountDate(String userId, + Collection deleteAccountEvents) { return deleteAccountEvents != null ? deleteAccountEvents.stream() .filter(event -> event.getUser() != null && event.getUser().getId().equals(userId)) .map(event -> ((DeleteAccountMetaData) event.getMetaData()).getDeleteDate()) .findFirst().orElse(null) : null; } - private String findMaxArchiveDate(Long sessionId, Collection archiveSessionEvents) { + private String findMaxArchiveDate(Long sessionId, + Collection archiveSessionEvents) { var maxArchiveEvent = findMaxArchiveSessionEvent(sessionId, archiveSessionEvents); if (maxArchiveEvent.isPresent()) { ArchiveMetaData metaData = (ArchiveMetaData) maxArchiveEvent.get().getMetaData(); @@ -101,7 +111,8 @@ private String findMaxArchiveDate(Long sessionId, Collection ar return null; } - private Optional findMaxArchiveSessionEvent(Long sessionId, Collection archiveSessionEvents) { + private Optional findMaxArchiveSessionEvent(Long sessionId, + Collection archiveSessionEvents) { return nonNull(archiveSessionEvents) ? archiveSessionEvents.stream() .filter(event -> event.getSessionId() != null && event.getSessionId().equals(sessionId)) .max(comparing(StatisticsEvent::getTimestamp)) : Optional.empty(); From 69757f8020b42feea90a68fbe76673fce97b95f7 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Wed, 24 Apr 2024 10:30:05 +0200 Subject: [PATCH 17/21] fix: class cast exception for statistics --- .../RegistrationStatisticsDTOConverter.java | 1 + ...egistrationStatisticsDTOConverterTest.java | 27 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 568ce47..43abae5 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -81,6 +81,7 @@ private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeek private long getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String adviceSeekerId, Collection createMessageEvents) { return createMessageEvents.stream() + .filter(event -> event.getMetaData() instanceof CreateMessageMetaData) .filter(event -> { CreateMessageMetaData metaData = (CreateMessageMetaData) event.getMetaData(); return metaData.getReceiverId() != null && metaData.getReceiverId() diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 936587a..0774200 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -52,7 +52,8 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { givenValidStatisticEvent(1L); // when - RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, new StatisticEventsContainer()); + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( + testEvent, new StatisticEventsContainer()); // then assertThat(result.getUserId(), is(ASKER_ID)); @@ -76,11 +77,11 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { } @Test - void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithoutErrorIfMetadataIsLinkedHashMap() { + void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse_SkipCounting() { // given givenValidStatisticEvent(1L); - var videoCallStartedEvent = StatisticsEvent.builder() + var eventWithInvalidMetadataType = StatisticsEvent.builder() .sessionId(1L) .eventType(EventType.REGISTRATION) .user(User.builder().userRole(UserRole.ASKER).id(ASKER_ID).build()) @@ -90,9 +91,13 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithout .metaData(new LinkedHashMap<>()) .build(); - var statisticEventsContainer = StatisticEventsContainer.builder().videoCallStartedEvents(Lists.newArrayList(videoCallStartedEvent)).build(); + var statisticEventsContainer = StatisticEventsContainer.builder() + .videoCallStartedEvents(Lists.newArrayList(eventWithInvalidMetadataType)) + .bookingCreatedEvents(Lists.newArrayList(eventWithInvalidMetadataType)) + .consultantMessageCreatedEvents(Lists.newArrayList(eventWithInvalidMetadataType)).build(); // when - RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, statisticEventsContainer); + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( + testEvent, statisticEventsContainer); // then assertThat(result.getUserId(), is(ASKER_ID)); @@ -220,13 +225,15 @@ private void givenValidStatisticEvent(Long sessionId) { } private void givenAccountDeleteStatisticEvents() { - deleteAccountEvents = List.of(deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"), + deleteAccountEvents = List.of( + deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"), deleteEvent("user 2", "2022-10-17T10:00:00.00Z", "delete date for user 2")); } private void givenValidArchiveStatisticEvents() { - archiveSessionEvents = List.of(archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), + archiveSessionEvents = List.of( + archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), archiveEvent(1L, "2022-10-18T10:00:00.00Z", "2 end date for session 1"), archiveEvent(2L, "2022-10-18T10:00:00.00Z", "end date for session 2"), archiveEvent(999L, "2022-10-19T10:00:00.00Z", "dummy end date")); @@ -234,13 +241,15 @@ private void givenValidArchiveStatisticEvents() { private StatisticsEvent archiveEvent(Long sessionId, String timestampString, String endDate) { Object metaData = ArchiveMetaData.builder().endDate(endDate).build(); - return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId).metaData(metaData).build(); + return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId) + .metaData(metaData).build(); } private StatisticsEvent deleteEvent(String userId, String timestampString, String deleteDate) { Object metaData = DeleteAccountMetaData.builder().deleteDate(deleteDate).build(); User user = new User(); user.setId(userId); - return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user).metaData(metaData).build(); + return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user) + .metaData(metaData).build(); } } From 1637afeab8c1226ac7303845d3f2fd833aafe468 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 23 May 2024 16:11:39 +0200 Subject: [PATCH 18/21] feat: upgrade to spring boot 2.7.X --- pom.xml | 51 +++--- .../StatisticsServiceApplication.java | 4 - .../CustomSwaggerUIApiResourceController.java | 20 --- .../statisticsservice/config/AppConfig.java | 12 ++ .../CustomSwaggerUIPathWebMvcConfigurer.java | 22 --- .../config/SecurityConfig.java | 8 - .../config/SpringFoxConfig.java | 109 ------------- .../resources/application-testing.properties | 4 + src/main/resources/application.properties | 4 +- .../api/authorization/AuthorityTest.java | 2 +- .../RoleAuthorizationAuthorityMapperTest.java | 3 +- .../StatisticsControllerAuthorizationIT.java | 6 +- .../controller/StatisticsControllerIT.java | 27 ++-- .../api/helper/AuthenticatedUserTest.java | 32 ++-- .../api/service/LogServiceTest.java | 101 ------------ .../service/UserStatisticsServiceTest.java | 25 ++- .../TenantHeaderSupplierTest.java | 1 - .../ArchiveOrDeleteSessionListenerTest.java | 9 +- .../listener/AssignSessionListenerTest.java | 15 +- .../listener/CreateMessageListenerTest.java | 9 +- .../listener/RegistrationListenerTest.java | 9 +- .../listener/StartVideoCallListenerTest.java | 8 +- .../listener/StopVideoCallListenerTest.java | 45 +++--- .../model/StatisticsEventBuilderTest.java | 151 ++++++++++-------- .../StatisticsEventRepositoryIT.java | 14 +- ...tatisticsEventTenantAwareRepositoryIT.java | 9 +- .../RegistrationStatisticsServiceTest.java | 1 - .../service/StatisticsServiceTest.java | 16 +- .../CustomResponseErrorHandlerTest.java | 5 +- 29 files changed, 254 insertions(+), 468 deletions(-) delete mode 100644 src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java delete mode 100644 src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java delete mode 100644 src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java delete mode 100644 src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java diff --git a/pom.xml b/pom.xml index 4663cb2..a01dd93 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ org.springframework.boot spring-boot-starter-parent - 2.5.12 + 2.7.18 @@ -30,7 +30,7 @@ 6.2.1 3.0.0 3.3.5 - 5.7.5 + 5.7.12 2.10.9.2 @@ -64,6 +64,7 @@ org.springframework.boot spring-boot-starter-data-mongodb + 2.7.5 org.springframework.data @@ -73,7 +74,6 @@ org.hibernate.validator hibernate-validator - 6.1.6.Final @@ -104,13 +104,6 @@ 4.3.1 - - - io.springfox - springfox-boot-starter - ${springfox-boot-starter.version} - - org.keycloak @@ -150,7 +143,6 @@ org.apache.commons commons-lang3 - 3.11 @@ -168,7 +160,6 @@ org.springframework.boot spring-boot-autoconfigure - 2.3.5.RELEASE @@ -195,24 +186,18 @@ - - powermock-module-junit4 - org.powermock - test - 2.0.2 - - - powermock-api-mockito2 - org.powermock - test - 2.0.2 - de.flapdoodle.embed de.flapdoodle.embed.mongo + 4.13.0 test + + de.flapdoodle.embed + de.flapdoodle.embed.mongo.spring26x + 4.13.0 + @@ -237,6 +222,24 @@ spring-boot-maven-plugin + + org.openrewrite.maven + rewrite-maven-plugin + 5.30.0 + + + org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7 + + + + + org.openrewrite.recipe + rewrite-spring + 5.9.0 + + + + org.openapitools diff --git a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java index 184e804..ab78a20 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java +++ b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java @@ -7,10 +7,6 @@ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class StatisticsServiceApplication { - static { - System.setProperty("os.arch", "i686_64"); - } - public static void main(String[] args) { SpringApplication.run(StatisticsServiceApplication.class, args); } diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java b/src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java deleted file mode 100644 index 144f217..0000000 --- a/src/main/java/de/caritas/cob/statisticsservice/api/controller/CustomSwaggerUIApiResourceController.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.caritas.cob.statisticsservice.api.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import springfox.documentation.annotations.ApiIgnore; -import springfox.documentation.swagger.web.ApiResourceController; -import springfox.documentation.swagger.web.SwaggerResourcesProvider; - -@Controller -@ApiIgnore -@RequestMapping(value = "${springfox.docuPath}" + "/swagger-resources") -public class CustomSwaggerUIApiResourceController extends ApiResourceController { - - public static final String SWAGGER_UI_BASE_URL = "/statistics/docs"; - - public CustomSwaggerUIApiResourceController(SwaggerResourcesProvider swaggerResources) { - super(swaggerResources, SWAGGER_UI_BASE_URL); - } - -} diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java index 58f0389..c0a8f9a 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java +++ b/src/main/java/de/caritas/cob/statisticsservice/config/AppConfig.java @@ -1,5 +1,7 @@ package de.caritas.cob.statisticsservice.config; +import org.keycloak.adapters.KeycloakConfigResolver; +import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; @@ -25,4 +27,14 @@ public LocalValidatorFactoryBean validator(MessageSource messageSource) { return validatorFactoryBean; } + /** + * Use the KeycloakSpringBootConfigResolver to be able to save the Keycloak settings in the spring + * application properties. + */ + @Bean + public KeycloakConfigResolver keyCloakConfigResolver() { + return new KeycloakSpringBootConfigResolver(); + } + + } diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java b/src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java deleted file mode 100644 index 49a4399..0000000 --- a/src/main/java/de/caritas/cob/statisticsservice/config/CustomSwaggerUIPathWebMvcConfigurer.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.caritas.cob.statisticsservice.config; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Component -public class CustomSwaggerUIPathWebMvcConfigurer implements WebMvcConfigurer { - - @Value("${springfox.docuPath}") - private String docuPath; - - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler(docuPath + "/swagger-ui/**") - .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); - registry.addResourceHandler(docuPath + "/**") - .addResourceLocations("classpath:/META-INF/resources/"); - } - -} diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java index 7886f37..f60ce96 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java +++ b/src/main/java/de/caritas/cob/statisticsservice/config/SecurityConfig.java @@ -93,14 +93,6 @@ protected void configure(HttpSecurity http) throws Exception { .anyRequest().denyAll(); } - /** - * Use the KeycloakSpringBootConfigResolver to be able to save the Keycloak settings in the spring - * application properties. - */ - @Bean - public KeycloakConfigResolver keyCloakConfigResolver() { - return new KeycloakSpringBootConfigResolver(); - } /** * Change springs authentication strategy to be stateless (no session is being created). diff --git a/src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java b/src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java deleted file mode 100644 index cad6032..0000000 --- a/src/main/java/de/caritas/cob/statisticsservice/config/SpringFoxConfig.java +++ /dev/null @@ -1,109 +0,0 @@ -package de.caritas.cob.statisticsservice.config; - -import static java.util.Collections.singletonList; - -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.ApiKey; -import springfox.documentation.service.AuthorizationScope; -import springfox.documentation.service.Contact; -import springfox.documentation.service.SecurityReference; -import springfox.documentation.service.SecurityScheme; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spi.service.contexts.SecurityContext; -import springfox.documentation.spring.web.plugins.Docket; - -/** - * Provides the SpringFox (API documentation generation) configuration. - * - */ -@Configuration -@Import(BeanValidatorPluginsConfiguration.class) -public class SpringFoxConfig { - - @Value("${springfox.docuTitle}") - private String docuTitle; - @Value("${springfox.docuDescription}") - private String docuDescription; - @Value("${springfox.docuVersion}") - private String docuVersion; - @Value("${springfox.docuTermsUrl}") - private String docuTermsUrl; - @Value("${springfox.docuContactName}") - private String docuContactName; - @Value("${springfox.docuContactUrl}") - private String docuContactUrl; - @Value("${springfox.docuContactEmail}") - private String docuContactEmail; - @Value("${springfox.docuLicense}") - private String docuLicense; - @Value("${springfox.docuLicenseUrl}") - private String docuLicenseUrl; - - @Bean - public Docket apiDocket() { - return new Docket(DocumentationType.SWAGGER_2).select() - .apis(RequestHandlerSelectors.basePackage("de.caritas.cob.statisticsservice.api")).build() - .consumes(getContentTypes()).produces(getContentTypes()).apiInfo(getApiInfo()) - .useDefaultResponseMessages(false).protocols(protocols()).securitySchemes(securitySchemes()) - .securityContexts(securityContexts()); - } - - private List securityContexts() { - return singletonList(SecurityContext.builder() - .forPaths(PathSelectors.any()).securityReferences(securityReferences()).build()); - } - - private List securityReferences() { - return singletonList( - SecurityReference.builder().reference("token").scopes(new AuthorizationScope[0]).build()); - } - - private List securitySchemes() { - return singletonList(new ApiKey("Bearer", "Authorization", "header")); - } - - /** - * Returns the API protocols (for documentation). - * - * @return the supported protocols - */ - private Set protocols() { - Set protocols = new HashSet<>(); - protocols.add("https"); - return protocols; - } - - /** - * Returns all content types which should be consumed/produced. - * - * @return the supported content types - */ - private Set getContentTypes() { - Set contentTypes = new HashSet<>(); - contentTypes.add("application/json"); - return contentTypes; - } - - /** - * Returns the API information (defined in application.properties). - * - * @return api information - */ - private ApiInfo getApiInfo() { - return new ApiInfo(docuTitle, docuDescription, docuVersion, docuTermsUrl, - new Contact(docuContactName, docuContactUrl, docuContactEmail), docuLicense, docuLicenseUrl, - Collections.emptyList()); - } - -} diff --git a/src/main/resources/application-testing.properties b/src/main/resources/application-testing.properties index c3d440b..e444b9f 100644 --- a/src/main/resources/application-testing.properties +++ b/src/main/resources/application-testing.properties @@ -22,4 +22,8 @@ csrf.header.property=X-CSRF-TOKEN csrf.cookie.property=CSRF-TOKEN consulting.type.service.api.url= +spring.mongodb.embedded.version=5.0.6 +spring.data.mongodb.uri=mongodb://mongodb:27017/consulting_types?retryWrites=false +de.flapdoodle.mongodb.embedded.version=5.0.6 + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 04a1950..4d07972 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -11,7 +11,7 @@ spring.data.jpa.repositories.bootstrap-mode=default # General app settings server.port=8080 -spring.mvc.locale=de_DE +spring.web.locale=de_DE spring.jackson.time-zone=Europe/Berlin # Logging: SLF4J (via Lombok) @@ -75,6 +75,6 @@ tenant.service.api.url=http://tenantservice:8080 management.endpoint.health.enabled=true management.endpoint.health.show-details=never management.endpoints.web.exposure.include=health -management.health.probes.enabled=true +management.endpoint.health.probes.enabled=true management.metrics.mongo.command.enabled=false management.metrics.mongo.connectionpool.enabled=false \ No newline at end of file diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java index 0ffe01b..970e98e 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/AuthorityTest.java @@ -7,7 +7,7 @@ import static org.hamcrest.Matchers.nullValue; import de.caritas.cob.statisticsservice.api.authorization.Authority.AuthorityValue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class AuthorityTest { diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java index 644bf58..385e7e6 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/authorization/RoleAuthorizationAuthorityMapperTest.java @@ -10,7 +10,8 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java index ca55e9b..ca17be0 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerAuthorizationIT.java @@ -9,9 +9,9 @@ import de.caritas.cob.statisticsservice.api.authorization.Authority.AuthorityValue; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventTenantAwareRepository; +import org.junit.jupiter.api.Test; + import javax.servlet.http.Cookie; -import org.junit.Test; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; @@ -24,10 +24,8 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; -@RunWith(SpringRunner.class) @TestPropertySource(properties = "spring.profiles.active=testing") @SpringBootTest(classes = {StatisticsServiceApplication.class}) @EnableAutoConfiguration(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java index 711aa61..ed1847d 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/controller/StatisticsControllerIT.java @@ -9,7 +9,6 @@ import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.DATE_TO; import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.DATE_TO_FORMATTED; import static org.mockito.Mockito.when; -import static org.powermock.reflect.Whitebox.setInternalState; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -18,15 +17,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import de.caritas.cob.statisticsservice.StatisticsServiceApplication; import de.caritas.cob.statisticsservice.api.authorization.RoleAuthorizationAuthorityMapper; import de.caritas.cob.statisticsservice.api.authorization.StatisticsFeatureAuthorisationService; import de.caritas.cob.statisticsservice.api.service.LogService; import de.caritas.cob.statisticsservice.api.statistics.service.RegistrationStatisticsService; import de.caritas.cob.statisticsservice.api.statistics.service.StatisticsService; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.keycloak.adapters.KeycloakConfigResolver; import org.mockito.Mock; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -35,15 +32,13 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.http.MediaType; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.servlet.MockMvc; -@RunWith(SpringRunner.class) @WebMvcTest(StatisticsController.class) @AutoConfigureMockMvc(addFilters = false) -@ContextConfiguration(classes = StatisticsServiceApplication.class) -public class StatisticsControllerIT { +@TestPropertySource(properties = "spring.profiles.active=testing") +class StatisticsControllerIT { @Autowired private MockMvc mvc; @@ -60,16 +55,14 @@ public class StatisticsControllerIT { @MockBean StatisticsFeatureAuthorisationService statisticsFeatureAuthorisationService; + @MockBean + KeycloakConfigResolver keycloakConfigResolver; + @Mock private Logger logger; - @Before - public void setup() { - setInternalState(LogService.class, "LOGGER", logger); - } - @Test - public void getConsultantStatistics_Should_ReturnStatisticsDataAndOk() throws Exception { + void getConsultantStatistics_Should_ReturnStatisticsDataAndOk() throws Exception { when(statisticsService.fetchStatisticsData(DATE_FROM, DATE_TO)).thenReturn(CONSULTANT_STATISTICS_RESPONSE_DTO); @@ -81,7 +74,7 @@ public void getConsultantStatistics_Should_ReturnStatisticsDataAndOk() throws Ex } @Test - public void getRegistrationStatistics_Should_ReturnStatisticsDataAndOk() throws Exception { + void getRegistrationStatistics_Should_ReturnStatisticsDataAndOk() throws Exception { when(registrationStatisticsService.fetchRegistrationStatisticsData()).thenReturn(REGISTRATION_STATISTICS_LIST_RESPONSE_DTO); diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java index 0e5afbd..103f770 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/AuthenticatedUserTest.java @@ -1,26 +1,34 @@ package de.caritas.cob.statisticsservice.api.helper; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import static org.junit.jupiter.api.Assertions.assertThrows; -@RunWith(MockitoJUnitRunner.class) +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) public class AuthenticatedUserTest { - @Test(expected = NullPointerException.class) + @Test public void AuthenticatedUser_Should_ThrowNullPointerExceptionWhenArgumentsAreNull() { - new AuthenticatedUser(null, null, null); + assertThrows(NullPointerException.class, () -> { + new AuthenticatedUser(null, null, null); + }); } - @Test(expected = NullPointerException.class) + @Test public void AuthenticatedUser_Should_ThrowNullPointerExceptionWhenUserIdIsNull() { - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - authenticatedUser.setUserId(null); + assertThrows(NullPointerException.class, () -> { + AuthenticatedUser authenticatedUser = new AuthenticatedUser(); + authenticatedUser.setUserId(null); + }); } - @Test(expected = NullPointerException.class) + @Test public void AuthenticatedUser_Should_ThrowNullPointerExceptionWhenUsernameIsNull() { - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - authenticatedUser.setUsername(null); + assertThrows(NullPointerException.class, () -> { + AuthenticatedUser authenticatedUser = new AuthenticatedUser(); + authenticatedUser.setUsername(null); + }); } } diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java deleted file mode 100644 index a7b4a64..0000000 --- a/src/test/java/de/caritas/cob/statisticsservice/api/service/LogServiceTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package de.caritas.cob.statisticsservice.api.service; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.verify; -import static org.powermock.reflect.Whitebox.setInternalState; - -import java.io.PrintWriter; -import javax.ws.rs.BadRequestException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.slf4j.Logger; -import org.springframework.http.HttpStatus; - -@RunWith(MockitoJUnitRunner.class) -public class LogServiceTest { - - @Mock - Exception exception; - - @Mock - BadRequestException badRequestException; - - @Mock - NumberFormatException numberFormatException; - - @Mock - private Logger logger; - - @Before - public void setup() { - setInternalState(LogService.class, "LOGGER", logger); - } - - @Test - public void logDatabaseError_Should_LogExceptionStackTrace() { - - LogService.logDatabaseError(exception); - verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - - @Test - public void logBadRequestException_Should_LogExceptionStackTrace() { - - LogService.logBadRequestException(badRequestException); - verify(badRequestException, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - - @Test - public void logNumberFormatException_Should_LogExceptionStackTrace() { - - LogService.logNumberFormatException(numberFormatException); - verify(numberFormatException, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - - @Test - public void logInfo_Should_LogInfoMessage() { - - LogService.logInfo("info message"); - verify(logger, atLeastOnce()).info("info message"); - } - - @Test - public void logWarning_Should_LogWarnMessage_When_onlyExceptionIsProvided() { - - LogService.logWarning(exception); - verify(logger, atLeastOnce()).warn(eq("StatisticsService API: {}"), anyString()); - verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - - @Test - public void logWarning_Should_LogWarnMessage_When_onlyExceptionAndStatusProvided() { - - LogService.logWarning(HttpStatus.MULTI_STATUS, exception); - verify(logger, atLeastOnce()).warn(eq("StatisticsService API: {}: {}"), - eq("Multi-Status"), anyString()); - verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - - @Test - public void logInternalServerError_Should_LogError() { - - LogService.logInternalServerError(exception); - verify(logger, atLeastOnce()).error(eq("StatisticsService API: 500 Internal Server Error: {}"), - anyString()); - verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - - @Test - public void logError_Should_LogError() { - LogService.logError(exception); - verify(logger, atLeastOnce()).error(eq("StatisticsService API: {}"), anyString()); - verify(exception, atLeastOnce()).printStackTrace(any(PrintWriter.class)); - } - -} diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java index a71cabc..e07b4c1 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/service/UserStatisticsServiceTest.java @@ -9,16 +9,19 @@ import de.caritas.cob.statisticsservice.api.service.securityheader.SecurityHeaderSupplier; import de.caritas.cob.statisticsservice.api.service.securityheader.TenantHeaderSupplier; +import de.caritas.cob.statisticsservice.config.apiclient.UserStatisticsApiControllerFactory; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.UserStatisticsControllerApi; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpHeaders; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringRunner.class) -public class UserStatisticsServiceTest { +@ExtendWith(MockitoExtension.class) +class UserStatisticsServiceTest { @InjectMocks UserStatisticsService userStatisticsService; @@ -29,8 +32,16 @@ public class UserStatisticsServiceTest { @Mock TenantHeaderSupplier tenantHeaderSupplier; + @Mock + UserStatisticsApiControllerFactory userStatisticsApiControllerFactory; + + @BeforeEach + void setup() { + when(userStatisticsApiControllerFactory.createControllerApi()).thenReturn(userStatisticsControllerApi); + } + @Test - public void retrieveSessionViaRcGroupId_Should_RetrieveSessionViaUserStatisticsControllerApi() { + void retrieveSessionViaRcGroupId_Should_RetrieveSessionViaUserStatisticsControllerApi() { var headers = new HttpHeaders(); when(securityHeaderSupplier.getCsrfHttpHeaders()).thenReturn(headers); @@ -40,7 +51,7 @@ public void retrieveSessionViaRcGroupId_Should_RetrieveSessionViaUserStatisticsC } @Test - public void retrieveSessionViaSessionId_Should_RetrieveSessionViaUserStatisticsControllerApi() { + void retrieveSessionViaSessionId_Should_RetrieveSessionViaUserStatisticsControllerApi() { var headers = new HttpHeaders(); when(securityHeaderSupplier.getCsrfHttpHeaders()).thenReturn(headers); diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java index 6ad62d7..cd7373e 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/service/securityheader/TenantHeaderSupplierTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpHeaders; import org.springframework.test.util.ReflectionTestUtils; diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java index 7e57a23..af89bbe 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/ArchiveOrDeleteSessionListenerTest.java @@ -18,17 +18,18 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.ArchiveMetaData; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import java.time.OffsetDateTime; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class ArchiveOrDeleteSessionListenerTest { @InjectMocks diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java index 8aeb246..58cfcc8 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/AssignSessionListenerTest.java @@ -7,14 +7,15 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; import org.apache.commons.lang3.RandomStringUtils; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.time.OffsetDateTime; import java.util.Map; @@ -32,8 +33,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) -public class AssignSessionListenerTest { +@ExtendWith(SpringExtension.class) +class AssignSessionListenerTest { @InjectMocks AssignSessionListener assignSessionListener; @@ -42,7 +43,7 @@ public class AssignSessionListenerTest { @Captor ArgumentCaptor statisticsEventCaptor; @Test - public void receiveMessage_Should_saveFullEventToMongoDb() { + void receiveMessage_Should_saveFullEventToMongoDb() { // given SessionStatisticsResultDTO sessionStatisticsResultDTO = buildResultDto(); when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)) @@ -77,7 +78,7 @@ public void receiveMessage_Should_saveFullEventToMongoDb() { } @Test - public void receiveMessage_Should_savePartialEventToMongoDb() { + void receiveMessage_Should_savePartialEventToMongoDb() { var sessionStatisticsResultDTO = buildResultDto(); when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)) .thenReturn(sessionStatisticsResultDTO); diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java index 70c2802..5bef18d 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/CreateMessageListenerTest.java @@ -17,17 +17,18 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.CreateMessageMetaData; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import java.time.OffsetDateTime; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class CreateMessageListenerTest { @InjectMocks diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java index 25273ed..8d44a6c 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/RegistrationListenerTest.java @@ -18,18 +18,19 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.RegistrationMetaData; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import java.time.OffsetDateTime; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class RegistrationListenerTest { @InjectMocks diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java index 33fbd25..3c86644 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StartVideoCallListenerTest.java @@ -8,14 +8,14 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.StartVideoCallMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.VideoCallStatus; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; @@ -32,7 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class StartVideoCallListenerTest { @InjectMocks diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java index 9a46404..7ccfbf5 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/listener/StopVideoCallListenerTest.java @@ -8,9 +8,9 @@ import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.VIDEO_CALL_UUID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; import de.caritas.cob.statisticsservice.api.model.EventType; import de.caritas.cob.statisticsservice.api.model.StopVideoCallStatisticsEventMessage; @@ -21,14 +21,15 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.User; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.StartVideoCallMetaData; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.VideoCallStatus; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import java.time.Duration; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; @@ -37,9 +38,9 @@ import org.springframework.amqp.AmqpException; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Query; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class StopVideoCallListenerTest { @InjectMocks @@ -52,7 +53,7 @@ public class StopVideoCallListenerTest { @Test public void receiveMessage_Should_saveEventToMongoDb() { // given - when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class))) + Mockito.when(mongoTemplate.find(Mockito.any(Query.class), Mockito.eq(StatisticsEvent.class))) .thenReturn(buildMongoResultWithOneStatisticsEvent()); StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage(); @@ -91,28 +92,32 @@ public void receiveMessage_Should_saveEventToMongoDb() { assertThat(startVideoCallMetaData.getDuration(), is(duration)); } - @Test(expected = AmqpException.class) + @Test public void receiveMessage_Should_ThrowAmqpException_WhenMoreThanOneStartVideoCallEventWasFound() { - // given - when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class))) - .thenReturn(buildMongoResultWithTwoStatisticsEvent()); + assertThrows(AmqpException.class, () -> { + // given + Mockito.when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class))) + .thenReturn(buildMongoResultWithTwoStatisticsEvent()); - StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage(); + StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage(); - // when, then - stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage); + // when, then + stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage); + }); } - @Test(expected = AmqpException.class) + @Test public void receiveMessage_Should_ThrowAmqpException_WhenNoStartVideoCallEventWasFound() { - // given - when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class))) - .thenReturn(Collections.emptyList()); + assertThrows(AmqpException.class, () -> { + // given + Mockito.when(mongoTemplate.find(Mockito.any(Query.class), eq(StatisticsEvent.class))) + .thenReturn(Collections.emptyList()); - StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage(); + StopVideoCallStatisticsEventMessage stopVideoCallStatisticsEventMessage = buildEventMessage(); - // when, then - stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage); + // when, then + stopVideoCallListener.receiveMessage(stopVideoCallStatisticsEventMessage); + }); } public List buildMongoResultWithOneStatisticsEvent() { diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java index 9736ce8..4b041c4 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/model/StatisticsEventBuilderTest.java @@ -7,10 +7,10 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEventBuilder; import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.meta.CreateMessageMetaData; import de.caritas.cob.statisticsservice.userstatisticsservice.generated.web.model.SessionStatisticsResultDTO; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.time.Instant; @@ -23,85 +23,96 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class StatisticsEventBuilderTest { @Mock UserStatisticsService userStatisticsService; - @Test(expected = NullPointerException.class) + @Test public void build_Should_ThrowNullPointerException_WhenEventTypeIsNull() { - - StatisticsEventBuilder builder = - StatisticsEventBuilder.getInstance( - () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); - builder - .withTimestamp(Instant.now()) - .withUserId(CONSULTANT_ID) - .withUserRole(UserRole.CONSULTANT) - .build(); + assertThrows(NullPointerException.class, () -> { + + StatisticsEventBuilder builder = + StatisticsEventBuilder.getInstance( + () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); + builder + .withTimestamp(Instant.now()) + .withUserId(CONSULTANT_ID) + .withUserRole(UserRole.CONSULTANT) + .build(); + }); } - @Test(expected = NullPointerException.class) + @Test public void build_Should_ThrowNullPointerException_WhenTimestampIsNull() { - - StatisticsEventBuilder builder = - StatisticsEventBuilder.getInstance( - () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); - builder - .withEventType(EventType.ASSIGN_SESSION) - .withUserId(CONSULTANT_ID) - .withUserRole(UserRole.CONSULTANT) - .build(); + assertThrows(NullPointerException.class, () -> { + + StatisticsEventBuilder builder = + StatisticsEventBuilder.getInstance( + () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); + builder + .withEventType(EventType.ASSIGN_SESSION) + .withUserId(CONSULTANT_ID) + .withUserRole(UserRole.CONSULTANT) + .build(); + }); } - @Test(expected = NullPointerException.class) + @Test public void build_Should_ThrowNullPointerException_WhenUserIdIsNull() { - - StatisticsEventBuilder builder = - StatisticsEventBuilder.getInstance( - () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); - builder - .withEventType(EventType.ASSIGN_SESSION) - .withTimestamp(Instant.now()) - .withUserRole(UserRole.CONSULTANT) - .build(); + assertThrows(NullPointerException.class, () -> { + + StatisticsEventBuilder builder = + StatisticsEventBuilder.getInstance( + () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); + builder + .withEventType(EventType.ASSIGN_SESSION) + .withTimestamp(Instant.now()) + .withUserRole(UserRole.CONSULTANT) + .build(); + }); } - @Test(expected = NullPointerException.class) + @Test public void build_Should_ThrowNullPointerException_WhenUserRoleIsNull() { - - StatisticsEventBuilder builder = - StatisticsEventBuilder.getInstance( - () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); - builder - .withEventType(EventType.ASSIGN_SESSION) - .withTimestamp(Instant.now()) - .withUserId(CONSULTANT_ID) - .build(); + assertThrows(NullPointerException.class, () -> { + + StatisticsEventBuilder builder = + StatisticsEventBuilder.getInstance( + () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); + builder + .withEventType(EventType.ASSIGN_SESSION) + .withTimestamp(Instant.now()) + .withUserId(CONSULTANT_ID) + .build(); + }); } - @Test(expected = NullPointerException.class) + @Test public void build_Should_ThrowNullPointerException_WhenRetrievedSessionHasNoId() { - - SessionStatisticsResultDTO session = buildSessionStatisticsResultDto(); - session.id(null); - - when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)) - .thenReturn(session); - - StatisticsEventBuilder builder = - StatisticsEventBuilder.getInstance( - () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); - builder - .withEventType(EventType.ASSIGN_SESSION) - .withTimestamp(Instant.now()) - .withUserId(CONSULTANT_ID) - .withUserRole(UserRole.CONSULTANT) - .build(); + assertThrows(NullPointerException.class, () -> { + + SessionStatisticsResultDTO session = buildSessionStatisticsResultDto(); + session.id(null); + + when(userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)) + .thenReturn(session); + + StatisticsEventBuilder builder = + StatisticsEventBuilder.getInstance( + () -> userStatisticsService.retrieveSessionViaSessionId(SESSION_ID)); + builder + .withEventType(EventType.ASSIGN_SESSION) + .withTimestamp(Instant.now()) + .withUserId(CONSULTANT_ID) + .withUserRole(UserRole.CONSULTANT) + .build(); + }); } @Test @@ -185,15 +196,17 @@ public void buildShouldNotRequestSessionFromUserServiceOnStartVideoCallEvent() { verifyNoInteractions(userStatisticsService); } - @Test(expected = IllegalArgumentException.class) + @Test public void buildShouldIllegalArgExceptionOnMissingSessionAndNotStartVideoCallEvent() { - StatisticsEventBuilder.getInstance() - .withEventType(EventType.ASSIGN_SESSION) - .withTimestamp(Instant.now()) - .withUserId(CONSULTANT_ID) - .withUserRole(UserRole.CONSULTANT) - .withMetaData(new Object()) - .build(); + assertThrows(IllegalArgumentException.class, () -> { + StatisticsEventBuilder.getInstance() + .withEventType(EventType.ASSIGN_SESSION) + .withTimestamp(Instant.now()) + .withUserId(CONSULTANT_ID) + .withUserRole(UserRole.CONSULTANT) + .withMetaData(new Object()) + .build(); + }); } private SessionStatisticsResultDTO buildSessionStatisticsResultDto() { diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java index 12d1695..733a7e1 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventRepositoryIT.java @@ -22,24 +22,22 @@ import java.time.ZoneOffset; import java.util.List; import org.bson.Document; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.core.io.ClassPathResource; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; @DataMongoTest() @ContextConfiguration(classes = StatisticsServiceApplication.class) -@RunWith(SpringRunner.class) @TestPropertySource(properties = "spring.profiles.active=testing") public class StatisticsEventRepositoryIT { + public static final String MONGODB_STATISTICS_EVENTS_JSON_FILENAME = "mongodb/StatisticsEvents.json"; private final Instant dateFromConverted = @@ -52,7 +50,7 @@ public class StatisticsEventRepositoryIT { @Autowired MongoTemplate mongoTemplate; - @Before + @BeforeEach public void preFillMongoDb() throws IOException { mongoTemplate.dropCollection(MONGO_COLLECTION_NAME); ObjectMapper objectMapper = new ObjectMapper(); @@ -139,7 +137,7 @@ public void getAllArchiveSessionEvents_Should_ReturnArchiveSessionEvents() { } @Test - @Ignore("For some reason this test is failing in this test scenario caused by the event.0.startTime and event.0.endTime filters.") + @Disabled("For some reason this test is failing in this test scenario caused by the event.0.startTime and event.0.endTime filters.") public void calculateNumberOfDoneAppointmentsForConsultant_Should_ReturnCorrectNumberOfAppointments() { Count count = statisticsEventRepository.calculateNumbersOfDoneAppointments(CONSULTANT_ID, dateFromConverted, dateToConverted, dateToConverted); diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java index 3b47815..dfb49c7 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/repository/StatisticsEventTenantAwareRepositoryIT.java @@ -10,20 +10,17 @@ import de.caritas.cob.statisticsservice.api.statistics.model.statisticsevent.StatisticsEvent; import java.io.IOException; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.core.io.ClassPathResource; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; @DataMongoTest() @ContextConfiguration(classes = StatisticsServiceApplication.class) -@RunWith(SpringRunner.class) @TestPropertySource(properties = "spring.profiles.active=testing") @TestPropertySource(properties = "multitenancy.enabled=true") public class StatisticsEventTenantAwareRepositoryIT { @@ -40,7 +37,7 @@ public class StatisticsEventTenantAwareRepositoryIT { @Autowired MongoTemplate mongoTemplate; - @Before + @BeforeEach public void preFillMongoDb() throws IOException { mongoTemplate.dropCollection(MONGO_COLLECTION_NAME); ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java index 5129040..5641b17 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/RegistrationStatisticsServiceTest.java @@ -7,7 +7,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java index 329af89..e56e4c4 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/statistics/service/StatisticsServiceTest.java @@ -5,6 +5,7 @@ import static de.caritas.cob.statisticsservice.api.testhelper.TestConstants.DATE_TO; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -17,18 +18,19 @@ import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository.Count; import de.caritas.cob.statisticsservice.api.statistics.repository.StatisticsEventRepository.Duration; +import org.junit.jupiter.api.Test; + import java.time.Instant; import java.time.LocalDate; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class StatisticsServiceTest { @InjectMocks @@ -38,9 +40,11 @@ public class StatisticsServiceTest { @Mock AuthenticatedUser authenticatedUser; - @Test(expected = BadRequestException.class) + @Test public void fetchStatisticsData_Should_ThrowBadRequestException_WhenDateFromIsAfterDateTo() { - statisticsService.fetchStatisticsData(DATE_TO, DATE_FROM); + assertThrows(BadRequestException.class, () -> { + statisticsService.fetchStatisticsData(DATE_TO, DATE_FROM); + }); } @Test diff --git a/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java b/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java index 60432bc..0cbf7a8 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/config/resttemplate/CustomResponseErrorHandlerTest.java @@ -2,13 +2,14 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.IOException; import java.net.URI; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; From e40c740e82cab079e7985dc2d798214369189263 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 23 May 2024 16:56:30 +0200 Subject: [PATCH 19/21] feat: upgrade to spring boot 2.7.X --- .../cob/statisticsservice/StatisticsServiceApplication.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java index ab78a20..184e804 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java +++ b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java @@ -7,6 +7,10 @@ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class StatisticsServiceApplication { + static { + System.setProperty("os.arch", "i686_64"); + } + public static void main(String[] args) { SpringApplication.run(StatisticsServiceApplication.class, args); } From ba0fcebe22142100b8f3a4d3ff1c2726a82148c6 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 23 May 2024 17:01:16 +0200 Subject: [PATCH 20/21] feat: upgrade to spring boot 2.7.X --- .github/workflows/dockerImage.yml | 2 +- .../cob/statisticsservice/StatisticsServiceApplication.java | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/dockerImage.yml b/.github/workflows/dockerImage.yml index c14a636..2b1adfc 100644 --- a/.github/workflows/dockerImage.yml +++ b/.github/workflows/dockerImage.yml @@ -64,7 +64,7 @@ jobs: push_to_registry: strategy: matrix: - registry: ["docker.pkg.github.com", "ghcr.io"] + registry: ["ghcr.io"] needs: [test] name: Push Docker image to GitHub Packages runs-on: ubuntu-latest diff --git a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java index 184e804..39c5405 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java +++ b/src/main/java/de/caritas/cob/statisticsservice/StatisticsServiceApplication.java @@ -6,11 +6,6 @@ @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class StatisticsServiceApplication { - - static { - System.setProperty("os.arch", "i686_64"); - } - public static void main(String[] args) { SpringApplication.run(StatisticsServiceApplication.class, args); } From 85a9a49bb903df6d3a9093bfcb6961f1331e9a4c Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Fri, 24 May 2024 10:15:47 +0200 Subject: [PATCH 21/21] feat: upgrade to spring boot 2.7.X --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index a01dd93..1a14054 100644 --- a/pom.xml +++ b/pom.xml @@ -199,6 +199,12 @@ 4.13.0 + + commons-io + commons-io + 2.16.1 + + org.jeasy