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();