Java tutorial
/* Designed and developed by Ismail E. Kartoglu Copyright 2015 King's College London Licensed 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 cognition.pipeline.commandline; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import cognition.pipeline.service.ElasticsearchService; @Component public class CommandExportToElasticsearch implements CommandProcessor { private static Logger logger = Logger.getLogger(CommandExportToElasticsearch.class); @Autowired public ElasticsearchService elasticsearchService; @Override public boolean isResponsibleFor(CommandLine cmd) { return cmd.hasOption("exportToElastic"); } @Override public void process(CommandLine cmd) { String url = null; Long port = null; try { String elasticPath = cmd.getOptionValue("exportToElastic"); String[] split = elasticPath.split(":"); url = split[0]; port = Long.parseLong(split[1]); } catch (Exception ex) { logger.error("Please make sure your elastic input is of format ipaddress:port "); ex.printStackTrace(); System.exit(-1); } elasticsearchService.exportToElastic(url, port); } @Override public void addOption(Options options) { options.addOption(OptionBuilder.withLongOpt("exportToElastic") .withDescription("Exports Cognition text to a specified Elasticsearch cluster").hasArg() .withArgName("exportToElastic").create()); } }