Skip to content

Commit

Permalink
DATAGO-75198 bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rudraneel-chakraborty committed Jun 26, 2024
1 parent 43d0bf8 commit 91b9cd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toCollection;

/**
* Manages the creation and retrieval of Messaging Service information.
*/
Expand Down Expand Up @@ -75,12 +77,24 @@ public Iterable<MessagingServiceEntity> addMessagingServices(List<MessagingServi
return repository.saveAll(messagingServiceEntities);
}


@Transactional
public void deleteMessagingServiceByIds(Set<String> messagingServiceIds) {
if(CollectionUtils.isEmpty(messagingServiceIds)){
return;
public Iterable<MessagingServiceEntity> upsertMessagingServiceEvents(List<MessagingServiceEvent> messagingServiceEvents) {
if (CollectionUtils.isEmpty(messagingServiceEvents)) {
return List.of();
}
repository.deleteAllById(messagingServiceIds);
List<MessagingServiceEntity> messagingServiceEntities = messagingServiceEvents.stream()
.map(toBeUpserted -> {
MessagingServiceEntity updated = eventToEntityConverter.convert(toBeUpserted);
Optional<MessagingServiceEntity> existing = repository.findById(toBeUpserted.getId());
if (existing.isPresent()) {
MessagingServiceEntity existingEntity = existing.get();
updated.setScanEntities(existingEntity.getScanEntities());
}
return updated;

}).collect(toCollection(ArrayList::new));
return repository.saveAll(messagingServiceEntities);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
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.SolaceResourceConfigurationToEventConverter;
import com.solace.maas.ep.event.management.agent.service.MessagingServiceDelegateServiceImpl;
import com.solace.maas.ep.event.management.agent.service.SolaceResourceConfigurationToEventConverter;
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
Expand All @@ -38,14 +36,7 @@ public void loadSolaceBrokerResourceConfigurations(List<EventBrokerResourceConfi
.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)
messagingServiceDelegateService.upsertMessagingServiceEvents(solaceEventBrokerResources)
.forEach(messagingServiceEntity ->
log.debug("Loaded [{}] resource with id: [{}] and name: [{}] from message payload.",
messagingServiceEntity.getType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
import org.springframework.test.context.ActiveProfiles;

import java.util.List;
import java.util.stream.Collectors;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -48,14 +45,8 @@ void testLoadSolaceBrokerResourceConfigurations() {
List<EventBrokerResourceConfiguration> resources = List.of(
EventBrokerResourceConfigTestHelper.buildResourceConfiguration(ResourceConfigurationType.SOLACE)
);
doNothing().when(messagingServiceDelegateServiceImpl).deleteMessagingServiceByIds(anySet());
helper.loadSolaceBrokerResourceConfigurations(resources);
verify(messagingServiceDelegateServiceImpl, times(1)).deleteMessagingServiceByIds(
resources.stream()
.map(EventBrokerResourceConfiguration::getId)
.collect(Collectors.toSet())
);
verify(messagingServiceDelegateServiceImpl, times(1)).addMessagingServices(any());
verify(messagingServiceDelegateServiceImpl, times(1)).upsertMessagingServiceEvents(any());
}


Expand Down

0 comments on commit 91b9cd6

Please sign in to comment.