List of usage examples for org.apache.solr.handler.dataimport VariableResolver replaceTokens
public String replaceTokens(String template)
From source file:com.indexisto.dit.processor.LimitedSqlEntityProcessor.java
License:Apache License
@Override public Map<String, Object> nextRow() { if (rowIterator == null) { final String command = (String) context.getRequestParameters().get(DataImportHandler.COMMAND); final String query = command.equals(DihCommandEnum.DELTA_IMPORT.toString()) && context.isRootEntity() ? context.getEntityAttribute(DELTA_QUERY) : context.getEntityAttribute(QUERY); if (query == null || query.equals("")) { throw new MappingException(QUERY + " or " + DELTA_QUERY + " not specified"); }/* w w w. j a v a 2 s . c o m*/ final Map<String, Object> queryMap = new HashMap<String, Object>(); if (context.isRootEntity()) { final long offset = (long) context.getRequestParameters().get(OFFSET); final long limit = (long) context.getRequestParameters().get(LIMIT); queryMap.put(OFFSET_PLACEHOLDER_NAME, offset); queryMap.put(LIMIT_PLACEHOLDER_NAME, limit); } if (command.equals(DihCommandEnum.DELTA_IMPORT.toString()) && context.isRootEntity()) { final String dateFormat = context.getEntityAttribute(DATE_FORMAT_PLACEHOLDER_NAME); if (dateFormat == null || dateFormat.equals("")) throw new MappingException("No date format for delta query specified"); final Date lastIndexTime = (Date) context.getRequestParameters().get(LAST_INDEX_TIME); if (lastIndexTime == null) { throw new NotEnoughParamsException("Last index time is not specified"); } try { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); final String lastIndexTimeStr = simpleDateFormat.format(lastIndexTime); queryMap.put(LAST_INDEX_TIME_PLACEHOLDER_NAME, lastIndexTimeStr); } catch (final Exception e) { throw new MappingException("Seems like dateFormat is wrong", e); } } final VariableResolver vr = context.getVariableResolver(); vr.addNamespace(null, queryMap); initQuery(vr.replaceTokens(query)); } return getNext(); }