From e8dfa15eb00b48226c6eedcfd66ab880776a7e2f Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:48:15 +0100 Subject: [PATCH] [Fix_#3337] Avoid creating duplicate consumer (#3357) --- .../codegen/process/ProcessCodegen.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java index faf545ed022..6f5ba05f7a5 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java @@ -60,6 +60,7 @@ import org.kie.kogito.codegen.core.AbstractGenerator; import org.kie.kogito.codegen.core.DashboardGeneratedFileUtils; import org.kie.kogito.codegen.process.config.ProcessConfigGenerator; +import org.kie.kogito.codegen.process.events.ProcessCloudEventMeta; import org.kie.kogito.codegen.process.events.ProcessCloudEventMetaFactoryGenerator; import org.kie.kogito.internal.SupportedExtensions; import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess; @@ -279,7 +280,7 @@ protected Collection internalGenerate() { List pis = new ArrayList<>(); List processExecutableModelGenerators = new ArrayList<>(); List rgs = new ArrayList<>(); // REST resources - List megs = new ArrayList<>(); // message endpoints/consumers + Map megs = new HashMap<>(); // message endpoints/consumers List mpgs = new ArrayList<>(); // message producers Map processIdToModelGenerator = new HashMap<>(); @@ -372,14 +373,14 @@ protected Collection internalGenerate() { // generate message consumers for processes with message start events if (trigger.getType().equals(TriggerMetaData.TriggerType.ConsumeMessage)) { - MessageConsumerGenerator messageConsumerGenerator = new MessageConsumerGenerator( - context(), - workFlowProcess, - modelClassGenerator.className(), - execModelGen.className(), - applicationCanonicalName(), - trigger); - megs.add(messageConsumerGenerator); + MessageConsumerGenerator messageConsumerGenerator = + megs.computeIfAbsent(new ProcessCloudEventMeta(workFlowProcess.getId(), trigger), k -> new MessageConsumerGenerator( + context(), + workFlowProcess, + modelClassGenerator.className(), + execModelGen.className(), + applicationCanonicalName(), + trigger)); metaData.addConsumer(trigger.getName(), messageConsumerGenerator.compilationUnit()); } else if (trigger.getType().equals(TriggerMetaData.TriggerType.ProduceMessage)) { MessageProducerGenerator messageProducerGenerator = new MessageProducerGenerator( @@ -441,7 +442,7 @@ protected Collection internalGenerate() { } } - for (MessageConsumerGenerator messageConsumerGenerator : megs) { + for (MessageConsumerGenerator messageConsumerGenerator : megs.values()) { storeFile(MESSAGE_CONSUMER_TYPE, messageConsumerGenerator.generatedFilePath(), messageConsumerGenerator.generate()); }