jamesnetherton commented on code in PR #7247: URL: https://github.com/apache/camel-quarkus/pull/7247#discussion_r2037494010
########## extensions/dataformat/runtime/src/main/java/org/apache/camel/quarkus/component/dataformat/DataformatRecorder.java: ########## @@ -0,0 +1,108 @@ +/* + * 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.quarkus.component.dataformat; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.regex.Pattern; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.CamelContext; +import org.apache.camel.Component; +import org.apache.camel.Endpoint; +import org.apache.camel.Route; +import org.apache.camel.Service; +import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.LifecycleStrategy; +import org.apache.camel.support.PropertyBindingSupport; +import org.eclipse.microprofile.config.ConfigProvider; + +@Recorder +public class DataformatRecorder { + public void createDataformatCustomizer(final RuntimeValue<CamelContext> camelContext, final CamelDataformatConfig config) { + camelContext.getValue().addLifecycleStrategy(new LifecycleStrategy() { + + public void onDataFormatCreated(String name, DataFormat dataFormat) { + + if (ConfigProvider.getConfig().getOptionalValue("camel.component.dataformat.customizer.enabled", Boolean.class) + .orElse(true) + && ConfigProvider.getConfig().getOptionalValue("camel.component.customizer.enabled", Boolean.class) + .orElse(true)) { + + //set properties from application.properties + Map<String, String> properties = config.dataformats().get(name); + + if (properties != null) { + for (Map.Entry<String, String> entry : properties.entrySet()) { + try { + String fieldName = entry.getKey(); + //convert field name to came case + String methodName = Pattern.compile("-([a-z])") Review Comment: Best avoid `Pattern.compile` in loops and have it declared as a constant. IIRC`bind()` can also take a `Map<String, Object>` representing the options, so you may not actually need to have a loop at all. ########## extensions/dataformat/runtime/src/main/java/org/apache/camel/quarkus/component/dataformat/CamelDataformatConfig.java: ########## @@ -0,0 +1,70 @@ +/* + * 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.quarkus.component.dataformat; + +import java.util.Map; +import java.util.Optional; + +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithParentName; + +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@ConfigMapping(prefix = "camel.dataformat") +public interface CamelDataformatConfig { + + /** + * Configuration of beanio dataformat. + * + * @asciidoclet + */ + Optional<DataformatConfig> beanio(); + + /** + * Configuration of properties for any dataformat. + * (In the format camel.dataformat."dataformat_name"."property"=value + * + * i.e. + * camel.dataformat.beanio.stream-name = test-stream + * camel.dataformat.beanio.mapping = test-mapping.xml + */ + @WithParentName + Map<String, Map<String, String>> dataformats(); + + /** + * Configuration of beanio dataformat. + */ + interface DataformatConfig { Review Comment: I think you can probably remove this and the `beanio()` config. It's only for docs, right? It's already covered by the Camel component docs. ########## integration-tests/beanio/src/main/java/org/apache/camel/quarkus/component/beanio/it/BeanioResource.java: ########## @@ -50,7 +51,11 @@ @Path("/beanio") public class BeanioResource { - public static final SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd"); + public static SimpleDateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd"); + + static { + FORMATTER.setTimeZone(TimeZone.getTimeZone("CET")); + } Review Comment: Do we need this change? ########## integration-tests/beanio/src/test/java/org/apache/camel/quarkus/component/beanio/it/BeanioTest.java: ########## @@ -33,7 +33,7 @@ import org.junit.jupiter.params.provider.ValueSource; import static org.apache.camel.quarkus.component.beanio.it.BeanioResource.FORMATTER; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; Review Comment: Can we avoid `*` imports. There's only one additional import required for this change. ########## extensions/dataformat/runtime/src/main/java/org/apache/camel/quarkus/component/dataformat/DataformatRecorder.java: ########## @@ -0,0 +1,108 @@ +/* + * 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.quarkus.component.dataformat; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.regex.Pattern; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.CamelContext; +import org.apache.camel.Component; +import org.apache.camel.Endpoint; +import org.apache.camel.Route; +import org.apache.camel.Service; +import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.LifecycleStrategy; +import org.apache.camel.support.PropertyBindingSupport; +import org.eclipse.microprofile.config.ConfigProvider; + +@Recorder +public class DataformatRecorder { + public void createDataformatCustomizer(final RuntimeValue<CamelContext> camelContext, final CamelDataformatConfig config) { + camelContext.getValue().addLifecycleStrategy(new LifecycleStrategy() { Review Comment: Avoid adding as an anonymous class and instead declare a static class in `DataformatRecorder` which extends `LifecycleStrategySupport`. That way you only need to implement the methods you're interested in (`onDataFormatCreated` in this case). May also be a good idea for the class to implement `Ordered` so you can ensure the lifecycle hook runs before others that potentially mess with the config you try to set here. -- 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