Search in sources :

Example 1 with CsvDataFormat

use of org.apache.camel.dataformat.csv.CsvDataFormat in project camel by apache.

the class CsvDataFormatAutoConfiguration method configureCsvDataFormatFactory.

@Bean(name = "csv-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(CsvDataFormat.class)
public DataFormatFactory configureCsvDataFormatFactory(final CamelContext camelContext, final CsvDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            CsvDataFormat dataformat = new CsvDataFormat();
            if (CamelContextAware.class.isAssignableFrom(CsvDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) RuntimeCamelException(org.apache.camel.RuntimeCamelException) CsvDataFormat(org.apache.camel.dataformat.csv.CsvDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with CsvDataFormat

use of org.apache.camel.dataformat.csv.CsvDataFormat in project camel by apache.

the class AnalyticsApiIntegrationTest method doCreateRouteBuilder.

@Override
protected RouteBuilder doCreateRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // get Report SObject by DeveloperName
            from("direct:queryReport").to("salesforce:query?sObjectClass=" + QueryRecordsReport.class.getName());
            from("direct:getRecentReports").to("salesforce:getRecentReports");
            from("direct:getReportDescription").to("salesforce:getReportDescription");
            from("direct:executeSyncReport").to("salesforce:executeSyncReport");
            from("direct:executeAsyncReport").to("salesforce:executeAsyncReport?includeDetails=true");
            from("direct:getReportInstances").to("salesforce:getReportInstances");
            from("direct:getReportResults").to("salesforce:getReportResults");
            CsvDataFormat csv = new CsvDataFormat(CSVFormat.EXCEL);
            // type converter test
            from("direct:convertResults").convertBodyTo(List.class).marshal(csv);
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) List(java.util.List) CsvDataFormat(org.apache.camel.dataformat.csv.CsvDataFormat)

Aggregations

CsvDataFormat (org.apache.camel.dataformat.csv.CsvDataFormat)2 HashMap (java.util.HashMap)1 List (java.util.List)1 CamelContextAware (org.apache.camel.CamelContextAware)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1