orpiske commented on code in PR #15911: URL: https://github.com/apache/camel/pull/15911#discussion_r1798352604
########## components/camel-flowable/src/main/java/org/apache/camel/component/flowable/CamelChannelModelProcessor.java: ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.flowable; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.lang3.StringUtils; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.eventregistry.api.ChannelModelProcessor; +import org.flowable.eventregistry.api.EventRegistry; +import org.flowable.eventregistry.api.EventRepositoryService; +import org.flowable.eventregistry.api.OutboundEventChannelAdapter; +import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration; +import org.flowable.eventregistry.impl.util.CommandContextUtil; +import org.flowable.eventregistry.model.CamelInboundChannelModel; +import org.flowable.eventregistry.model.CamelOutboundChannelModel; +import org.flowable.eventregistry.model.ChannelModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CamelChannelModelProcessor implements ChannelModelProcessor { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + protected CamelContext camelContext; + + public CamelChannelModelProcessor(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + public boolean canProcess(ChannelModel channelModel) { + return channelModel instanceof CamelInboundChannelModel || channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public boolean canProcessIfChannelModelAlreadyRegistered(ChannelModel channelModel) { + return channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public void registerChannelModel( + ChannelModel channelModel, String tenantId, EventRegistry eventRegistry, + EventRepositoryService eventRepositoryService, + boolean fallbackToDefaultTenant) { + + if (channelModel instanceof CamelInboundChannelModel) { + CamelInboundChannelModel camelInboundChannelModel = (CamelInboundChannelModel) channelModel; + logger.info("Starting to register inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processInboundDefinition(camelInboundChannelModel, tenantId); + logger.info("Finished registering inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + + } else if (channelModel instanceof CamelOutboundChannelModel) { + logger.info("Starting to register outbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processOutboundDefinition((CamelOutboundChannelModel) channelModel, tenantId); + logger.info("Finished registering outbound channel {} in tenant {}", channelModel.getKey(), tenantId); + } + } + + protected void processInboundDefinition(CamelInboundChannelModel channelModel, String tenantId) { + EventRegistryEngineConfiguration eventRegistryEngineConfiguration = CommandContextUtil.getEventRegistryConfiguration(); + try (FlowableEndpoint endpoint + = new FlowableEndpoint(channelModel, eventRegistryEngineConfiguration, camelContext)) { + + camelContext.addEndpoint(endpoint.getEndpointUri(), endpoint); + if (StringUtils.isNotEmpty(channelModel.getSourceUri())) { + camelContext.addRoutes(new RouteBuilder() { + + @Override + public void configure() throws Exception { + from(channelModel.getSourceUri()).routeId(channelModel.getKey()).to(endpoint.getEndpointUri()); + } + }); + } + + } catch (Exception e) { + logger.error("Error creating producer for inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + throw new FlowableException( + "Error creating producer for inbound channel " + channelModel.getKey() + " in tenant " + tenantId); + } + } + + protected void processOutboundDefinition(CamelOutboundChannelModel channelModel, String tenantId) { + String destination = channelModel.getDestination(); + if (channelModel.getOutboundEventChannelAdapter() == null && StringUtils.isNotEmpty(destination)) { + channelModel.setOutboundEventChannelAdapter(createOutboundEventChannelAdapter(channelModel, tenantId)); + } + } + + protected OutboundEventChannelAdapter<String> createOutboundEventChannelAdapter( Review Comment: I am not entirely sure I understand what exactly needs to happen here. I am under the impression you should be doing something different instead of dynamically resolving and adding routes. ########## components/camel-flowable/src/test/java/org/apache/camel/component/flowable/FlowableInboundChannelHeaderTest.java: ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.flowable; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.camel.Exchange; +import org.apache.camel.ProducerTemplate; +import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.task.api.Task; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class FlowableInboundChannelHeaderTest extends CamelFlowableTestCase { + + @BeforeEach + public void deployEventRegistryModels() throws Exception { + eventRegistryEngineConfiguration.getEventRepositoryService().createDeployment() + .addClasspathResource("channel/userHeaderChannel.channel") + .addClasspathResource("event/userWithHeaderEvent.event") + .deploy(); + } + + @Test + public void testStartProcessWithHeaderEvent() throws Exception { + String deploymentId = deployProcessDefinition("process/startWithHeader.bpmn20.xml"); + try { + ProducerTemplate tpl = context.createProducerTemplate(); Review Comment: TIP: you can pick the `ProducerTemplate` instance already provided by `CamelTestSupport`. ########## components/camel-flowable/src/main/java/org/apache/camel/component/flowable/CamelChannelModelProcessor.java: ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.flowable; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.lang3.StringUtils; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.eventregistry.api.ChannelModelProcessor; +import org.flowable.eventregistry.api.EventRegistry; +import org.flowable.eventregistry.api.EventRepositoryService; +import org.flowable.eventregistry.api.OutboundEventChannelAdapter; +import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration; +import org.flowable.eventregistry.impl.util.CommandContextUtil; +import org.flowable.eventregistry.model.CamelInboundChannelModel; +import org.flowable.eventregistry.model.CamelOutboundChannelModel; +import org.flowable.eventregistry.model.ChannelModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CamelChannelModelProcessor implements ChannelModelProcessor { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + protected CamelContext camelContext; + + public CamelChannelModelProcessor(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + public boolean canProcess(ChannelModel channelModel) { + return channelModel instanceof CamelInboundChannelModel || channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public boolean canProcessIfChannelModelAlreadyRegistered(ChannelModel channelModel) { + return channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public void registerChannelModel( + ChannelModel channelModel, String tenantId, EventRegistry eventRegistry, + EventRepositoryService eventRepositoryService, + boolean fallbackToDefaultTenant) { + + if (channelModel instanceof CamelInboundChannelModel) { + CamelInboundChannelModel camelInboundChannelModel = (CamelInboundChannelModel) channelModel; + logger.info("Starting to register inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processInboundDefinition(camelInboundChannelModel, tenantId); + logger.info("Finished registering inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + + } else if (channelModel instanceof CamelOutboundChannelModel) { + logger.info("Starting to register outbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processOutboundDefinition((CamelOutboundChannelModel) channelModel, tenantId); + logger.info("Finished registering outbound channel {} in tenant {}", channelModel.getKey(), tenantId); + } Review Comment: You can use pattern matching for instance here and in other places to make the code cleaner. ########## components/camel-flowable/src/main/java/org/apache/camel/component/flowable/CamelChannelModelProcessor.java: ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.flowable; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.lang3.StringUtils; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.eventregistry.api.ChannelModelProcessor; +import org.flowable.eventregistry.api.EventRegistry; +import org.flowable.eventregistry.api.EventRepositoryService; +import org.flowable.eventregistry.api.OutboundEventChannelAdapter; +import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration; +import org.flowable.eventregistry.impl.util.CommandContextUtil; +import org.flowable.eventregistry.model.CamelInboundChannelModel; +import org.flowable.eventregistry.model.CamelOutboundChannelModel; +import org.flowable.eventregistry.model.ChannelModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CamelChannelModelProcessor implements ChannelModelProcessor { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + protected CamelContext camelContext; + + public CamelChannelModelProcessor(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + public boolean canProcess(ChannelModel channelModel) { + return channelModel instanceof CamelInboundChannelModel || channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public boolean canProcessIfChannelModelAlreadyRegistered(ChannelModel channelModel) { + return channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public void registerChannelModel( + ChannelModel channelModel, String tenantId, EventRegistry eventRegistry, + EventRepositoryService eventRepositoryService, + boolean fallbackToDefaultTenant) { + + if (channelModel instanceof CamelInboundChannelModel) { + CamelInboundChannelModel camelInboundChannelModel = (CamelInboundChannelModel) channelModel; + logger.info("Starting to register inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processInboundDefinition(camelInboundChannelModel, tenantId); + logger.info("Finished registering inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + + } else if (channelModel instanceof CamelOutboundChannelModel) { + logger.info("Starting to register outbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processOutboundDefinition((CamelOutboundChannelModel) channelModel, tenantId); + logger.info("Finished registering outbound channel {} in tenant {}", channelModel.getKey(), tenantId); + } + } + + protected void processInboundDefinition(CamelInboundChannelModel channelModel, String tenantId) { + EventRegistryEngineConfiguration eventRegistryEngineConfiguration = CommandContextUtil.getEventRegistryConfiguration(); + try (FlowableEndpoint endpoint + = new FlowableEndpoint(channelModel, eventRegistryEngineConfiguration, camelContext)) { + + camelContext.addEndpoint(endpoint.getEndpointUri(), endpoint); + if (StringUtils.isNotEmpty(channelModel.getSourceUri())) { + camelContext.addRoutes(new RouteBuilder() { + + @Override + public void configure() throws Exception { + from(channelModel.getSourceUri()).routeId(channelModel.getKey()).to(endpoint.getEndpointUri()); + } + }); + } + + } catch (Exception e) { + logger.error("Error creating producer for inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + throw new FlowableException( + "Error creating producer for inbound channel " + channelModel.getKey() + " in tenant " + tenantId); Review Comment: Please, do not log and throw. Use either one or the other. ########## components/camel-flowable/src/main/java/org/apache/camel/component/flowable/CamelChannelModelProcessor.java: ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.flowable; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.commons.lang3.StringUtils; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.eventregistry.api.ChannelModelProcessor; +import org.flowable.eventregistry.api.EventRegistry; +import org.flowable.eventregistry.api.EventRepositoryService; +import org.flowable.eventregistry.api.OutboundEventChannelAdapter; +import org.flowable.eventregistry.impl.EventRegistryEngineConfiguration; +import org.flowable.eventregistry.impl.util.CommandContextUtil; +import org.flowable.eventregistry.model.CamelInboundChannelModel; +import org.flowable.eventregistry.model.CamelOutboundChannelModel; +import org.flowable.eventregistry.model.ChannelModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CamelChannelModelProcessor implements ChannelModelProcessor { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + protected CamelContext camelContext; + + public CamelChannelModelProcessor(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override + public boolean canProcess(ChannelModel channelModel) { + return channelModel instanceof CamelInboundChannelModel || channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public boolean canProcessIfChannelModelAlreadyRegistered(ChannelModel channelModel) { + return channelModel instanceof CamelOutboundChannelModel; + } + + @Override + public void registerChannelModel( + ChannelModel channelModel, String tenantId, EventRegistry eventRegistry, + EventRepositoryService eventRepositoryService, + boolean fallbackToDefaultTenant) { + + if (channelModel instanceof CamelInboundChannelModel) { + CamelInboundChannelModel camelInboundChannelModel = (CamelInboundChannelModel) channelModel; + logger.info("Starting to register inbound channel {} in tenant {}", channelModel.getKey(), tenantId); + processInboundDefinition(camelInboundChannelModel, tenantId); + logger.info("Finished registering inbound channel {} in tenant {}", channelModel.getKey(), tenantId); Review Comment: It feels like there's a bit too much `info` level logging here. Maybe decrease it to debug or reduce logging. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org