From ff4f15b6c2c43cbcaf2cb26875c606c73d6c3be3 Mon Sep 17 00:00:00 2001 From: rudraneel-chakraborty Date: Mon, 17 Jun 2024 18:35:05 -0400 Subject: [PATCH] DATAGO-75198 more common code --- .../MessagingServiceDelegateServiceImpl.java | 11 +++++++++- ...esourceConfigurationToEventConverter.java} | 2 +- .../DynamicResourceConfigurationHelper.java | 22 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) rename service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/{EventBrokerResourceConfigToEventConverter.java => SolaceResourceConfigurationToEventConverter.java} (98%) diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java index ffd8e33d1..83e6fb306 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/MessagingServiceDelegateServiceImpl.java @@ -11,12 +11,13 @@ import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.MessagingServiceEntity; import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.ServiceAssociationsCompositeKey; import com.solace.maas.ep.event.management.agent.repository.model.mesagingservice.ServiceAssociationsEntity; +import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import jakarta.transaction.Transactional; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -74,6 +75,14 @@ public Iterable addMessagingServices(List messagingServiceIds) { + if(CollectionUtils.isEmpty(messagingServiceIds)){ + return; + } + repository.deleteAllById(messagingServiceIds); + } + /** * Retrieves a specific Messaging Service by ID. * diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/EventBrokerResourceConfigToEventConverter.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java similarity index 98% rename from service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/EventBrokerResourceConfigToEventConverter.java rename to service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java index cf9e489d1..f726c403d 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/EventBrokerResourceConfigToEventConverter.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/service/SolaceResourceConfigurationToEventConverter.java @@ -16,7 +16,7 @@ import java.util.Objects; @Service -public class EventBrokerResourceConfigToEventConverter { +public class SolaceResourceConfigurationToEventConverter { public MessagingServiceEvent mapToMessagingServiceEvent(EventBrokerResourceConfiguration eventBrokerResource) { Objects.requireNonNull(eventBrokerResource); MessagingServiceEvent serviceEvent = new MessagingServiceEvent(); diff --git a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java index 442e2b2de..e26ea01a4 100644 --- a/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java +++ b/service/application/src/main/java/com/solace/maas/ep/event/management/agent/subscriber/messageProcessors/DynamicResourceConfigurationHelper.java @@ -3,13 +3,15 @@ import com.solace.maas.ep.common.model.EventBrokerResourceConfiguration; import com.solace.maas.ep.common.model.ResourceConfigurationType; import com.solace.maas.ep.event.management.agent.event.MessagingServiceEvent; -import com.solace.maas.ep.event.management.agent.service.EventBrokerResourceConfigToEventConverter; +import com.solace.maas.ep.event.management.agent.service.SolaceResourceConfigurationToEventConverter; import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.util.List; +import java.util.stream.Collectors; @Component @Slf4j @@ -17,12 +19,12 @@ public class DynamicResourceConfigurationHelper { private final MessagingServiceDelegateServiceImpl messagingServiceDelegateService; - private final EventBrokerResourceConfigToEventConverter eventBrokerResourceConfigToEventConverter; + private final SolaceResourceConfigurationToEventConverter solaceResourceConfigurationToEventConverter; public DynamicResourceConfigurationHelper(MessagingServiceDelegateServiceImpl messagingServiceDelegateService, - EventBrokerResourceConfigToEventConverter eventBrokerResourceConfigToEventConverter) { + SolaceResourceConfigurationToEventConverter solaceResourceConfigurationToEventConverter) { this.messagingServiceDelegateService = messagingServiceDelegateService; - this.eventBrokerResourceConfigToEventConverter = eventBrokerResourceConfigToEventConverter; + this.solaceResourceConfigurationToEventConverter = solaceResourceConfigurationToEventConverter; } public void loadSolaceBrokerResourceConfigurations(List resources) { @@ -33,11 +35,19 @@ public void loadSolaceBrokerResourceConfigurations(List solaceEventBrokerResources = resources.stream() .filter(resource -> resource.getResourceConfigurationType() == ResourceConfigurationType.SOLACE) - .map(eventBrokerResourceConfigToEventConverter::mapToMessagingServiceEvent) + .map(solaceResourceConfigurationToEventConverter::mapToMessagingServiceEvent) .toList(); + + //deleteMessagingServiceByIds will delete existing stale messaging services if exists + messagingServiceDelegateService.deleteMessagingServiceByIds( + solaceEventBrokerResources.stream() + .map(MessagingServiceEvent::getId) + .filter(StringUtils::isNotEmpty) + .collect(Collectors.toSet()) + ); messagingServiceDelegateService.addMessagingServices(solaceEventBrokerResources) .forEach(messagingServiceEntity -> - log.info("Loaded [{}] resource with id: [{}] and name: [{}] from message payload.", + log.debug("Loaded [{}] resource with id: [{}] and name: [{}] from message payload.", messagingServiceEntity.getType(), messagingServiceEntity.getId(), messagingServiceEntity.getName()));