Search in sources :

Example 21 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DozerTypeConverterLoader method addMapping.

/**
     * Registers Dozer <code>BeanMappingBuilder</code> in current mapper instance.
     * This method should be called instead of direct <code>mapper.addMapping()</code> invocation for Camel
     * being able to register given type conversion.
     *
     * @param beanMappingBuilder api-based mapping builder
     */
public void addMapping(BeanMappingBuilder beanMappingBuilder) {
    if (mapper == null) {
        log.warn("No mapper instance provided to " + this.getClass().getSimpleName() + ". Mapping has not been registered!");
        return;
    }
    mapper.addMapping(beanMappingBuilder);
    MappingFileData mappingFileData = beanMappingBuilder.build();
    TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
    List<ClassMap> classMaps = new ArrayList<ClassMap>();
    classMaps.addAll(mappingFileData.getClassMaps());
    registerClassMaps(registry, null, mapper, classMaps);
}
Also used : TypeConverterRegistry(org.apache.camel.spi.TypeConverterRegistry) MappingFileData(org.dozer.classmap.MappingFileData) ArrayList(java.util.ArrayList) ClassMap(org.dozer.classmap.ClassMap)

Example 22 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DozerTypeConverterLoader method loadMappings.

private List<ClassMap> loadMappings(CamelContext camelContext, String mapperId, DozerBeanMapper mapper) {
    List<ClassMap> answer = new ArrayList<ClassMap>();
    // load the class map using the class resolver so we can load from classpath in OSGi
    MappingFileReader reader = new MappingFileReader(XMLParserFactory.getInstance());
    List<String> mappingFiles = mapper.getMappingFiles();
    if (mappingFiles == null) {
        return Collections.emptyList();
    }
    for (String name : mappingFiles) {
        URL url = loadMappingFile(camelContext.getClassResolver(), name);
        if (url != null) {
            MappingFileData data = reader.read(url);
            answer.addAll(data.getClassMaps());
        }
    }
    return answer;
}
Also used : MappingFileReader(org.dozer.loader.xml.MappingFileReader) MappingFileData(org.dozer.classmap.MappingFileData) ArrayList(java.util.ArrayList) ClassMap(org.dozer.classmap.ClassMap) URL(java.net.URL)

Example 23 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiGet.

@Test
public void testMultiGet() throws Exception {
    //first, INDEX two values
    Map<String, String> map = createIndexedData();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
    headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
    template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    headers.clear();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
    headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
    template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    headers.clear();
    //now, verify MULTIGET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.MULTIGET);
    Item item1 = new Item("twitter", "tweet", "1");
    Item item2 = new Item("facebook", "status", "2");
    Item item3 = new Item("instagram", "latest", "3");
    List<Item> list = new ArrayList<Item>();
    list.add(item1);
    list.add(item2);
    list.add(item3);
    MultiGetResponse response = template.requestBodyAndHeaders("direct:start", list, headers, MultiGetResponse.class);
    MultiGetItemResponse[] responses = response.getResponses();
    assertNotNull("response should not be null", response);
    assertEquals("response should contains three multiGetResponse object", 3, response.getResponses().length);
    assertEquals("response 1 should contains tweet as type", "tweet", responses[0].getResponse().getType().toString());
    assertEquals("response 2 should contains status as type", "status", responses[1].getResponse().getType().toString());
    assertFalse("response 1 should be ok", responses[0].isFailed());
    assertFalse("response 2 should be ok", responses[1].isFailed());
    assertTrue("response 3 should be failed", responses[2].isFailed());
}
Also used : Item(org.elasticsearch.action.get.MultiGetRequest.Item) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class ElsqlEndpoint method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    ObjectHelper.notNull(resourceUri, "resourceUri", this);
    if (elSqlConfig == null && databaseVendor != null) {
        elSqlConfig = databaseVendor.asElSqlConfig();
    } else if (elSqlConfig == null) {
        elSqlConfig = ElSqlDatabaseVendor.Default.asElSqlConfig();
    }
    // there can be multiple resources
    // so we have all this lovely code to turn that into an URL[]
    final List<URL> list = new ArrayList<URL>();
    final Iterable it = ObjectHelper.createIterable(resourceUri);
    for (final Object path : it) {
        final URL url = ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(), path.toString());
        list.add(url);
    }
    final URL[] urls = list.toArray(new URL[list.size()]);
    elSql = ElSql.parse(elSqlConfig, urls);
}
Also used : ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 25 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class ElasticsearchComponent method parseTransportAddresses.

private List<InetSocketTransportAddress> parseTransportAddresses(String ipsString, ElasticsearchConfiguration config) throws UnknownHostException {
    if (ipsString == null || ipsString.isEmpty()) {
        return null;
    }
    List<String> addressesStr = Arrays.asList(ipsString.split(ElasticsearchConstants.TRANSPORT_ADDRESSES_SEPARATOR_REGEX));
    List<InetSocketTransportAddress> addressesTrAd = new ArrayList<InetSocketTransportAddress>(addressesStr.size());
    for (String address : addressesStr) {
        String[] split = address.split(ElasticsearchConstants.IP_PORT_SEPARATOR_REGEX);
        String hostname;
        if (split.length > 0) {
            hostname = split[0];
        } else {
            throw new IllegalArgumentException();
        }
        Integer port = split.length > 1 ? Integer.parseInt(split[1]) : ElasticsearchConstants.DEFAULT_PORT;
        addressesTrAd.add(new InetSocketTransportAddress(InetAddress.getByName(hostname), port));
    }
    return addressesTrAd;
}
Also used : ArrayList(java.util.ArrayList) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611