int counter = 0;
String indexName = null;
boolean createNew=false;
for(String lang : languageToIndex) {
counter = counter + 1;
SiteSearchConfig config = new SiteSearchConfig();
config.setJobId(jobId);
config.setLanguage(Long.parseLong(lang));
config.setJobName(dataMap.getString("QUARTZ_JOB_NAME"));
List<Host> hosts=new ArrayList<Host>();
if(indexAll){
hosts = APILocator.getHostAPI().findAll(userToRun, true);
}else{
for(String h : indexHosts){
hosts.add(APILocator.getHostAPI().find(h, userToRun, true));
}
}
config.setHosts( hosts);
// reuse or create new indexes as needed
String indexAlias = dataMap.getString("indexAlias");
ESIndexAPI iapi=new ESIndexAPI();
Map<String,String> aliasMap=iapi.getAliasToIndexMap(APILocator.getSiteSearchAPI().listIndices());
if(counter==1){
if(indexAlias.equals(APILocator.getIndiciesAPI().loadIndicies().site_search)){
Logger.info(this, "Index Alias is DEFAULT");
indexName = APILocator.getIndiciesAPI().loadIndicies().site_search;
}
else if(indexAlias.equals("create-new")){
Logger.info(this, "Index Alias is default");
createNew=true;
indexName = SiteSearchAPI.ES_SITE_SEARCH_NAME + "_" + ESMappingAPIImpl.datetimeFormat.format(new Date());
APILocator.getSiteSearchAPI().createSiteSearchIndex(indexName, null, 1);
}
else {
indexName=aliasMap.get(indexAlias);
Logger.info(this, "Index Alias is " + indexName);
}
}
if(createNew && languageToIndex.length == counter){
config.setSwitchIndexWhenDone(true);
}
config.setIndexName(indexName);
// if it is going to be an incremental job, write the bundle to the same folder
// every time. Otherwise, create a new folder using a date stamp.
if(dataMap.get("incremental")!=null){
config.setId(StringUtils.sanitizeCamelCase(config.getJobName()));
}
else{
String x = UtilMethods.dateToJDBC(new Date()).replace(':', '-').replace(' ', '_');
config.setId(x);
}
config.setStartDate(startDate);
config.setEndDate(endDate);
config.setIncremental(incremental);
config.setUser(userToRun);
if(include) {
config.setIncludePatterns(paths);
}
else {
config.setExcludePatterns(paths);
}
APILocator.getPublisherAPI().publish(config,status);
}