@Test(expected = InvalidCreateOperationException.class) public void testDateRangeKoNoField() throws InvalidParseOperationException, InvalidCreateOperationException { List<RangeFacetValue> ranges = new ArrayList<>(); ranges.add(new RangeFacetValue("from", "to")); Facet facet1 = dateRange("facet1", "", "yyyy", ranges); }
public static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter) throws InvalidCreateOperationException, InvalidParseOperationException { final String name = facet.get(FACETARGS.NAME.exactToken()).asText(); JsonNode dateRange = facet.get(FACET.DATE_RANGE.exactToken()); ArrayNode ranges = (ArrayNode) dateRange.get(FACETARGS.RANGES.exactToken()); String dateFormat = dateRange.get(FACETARGS.FORMAT.exactToken()).asText(); List<RangeFacetValue> rangesList = new ArrayList<>(); ranges.forEach(item -> { JsonNode from = item.get(FACETARGS.FROM.exactToken()); JsonNode to = item.get(FACETARGS.TO.exactToken()); rangesList.add(new RangeFacetValue(from != null && !from.isNull() ? from.asText() : null, to != null && !to.isNull() ? to.asText() : null)); }); String translatedNestedPath = null; if(dateRange.get(FACETARGS.SUBOBJECT.exactToken()) != null) { String nestedPath = dateRange.get(FACETARGS.SUBOBJECT.exactToken()).asText(); translatedNestedPath = adapter.getVariableName(nestedPath); if(translatedNestedPath == null) { translatedNestedPath = nestedPath; } } String fieldName = dateRange.get(FACETARGS.FIELD.exactToken()).asText(); String translatedFieldName = adapter.getVariableName(fieldName); if(translatedFieldName == null) { translatedFieldName = fieldName; } return FacetHelper.dateRange(name, translatedFieldName, translatedNestedPath, dateFormat, rangesList); }
FacetParserHelper extends FacetHelper { public static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter) throws InvalidCreateOperationException, InvalidParseOperationException { final String name = facet.get(FACETARGS.NAME.exactToken()).asText(); JsonNode dateRange = facet.get(FACET.DATE_RANGE.exactToken()); ArrayNode ranges = (ArrayNode) dateRange.get(FACETARGS.RANGES.exactToken()); String dateFormat = dateRange.get(FACETARGS.FORMAT.exactToken()).asText(); List<RangeFacetValue> rangesList = new ArrayList<>(); ranges.forEach(item -> { JsonNode from = item.get(FACETARGS.FROM.exactToken()); JsonNode to = item.get(FACETARGS.TO.exactToken()); rangesList.add(new RangeFacetValue(from != null && !from.isNull() ? from.asText() : null, to != null && !to.isNull() ? to.asText() : null)); }); String translatedNestedPath = null; if(dateRange.get(FACETARGS.SUBOBJECT.exactToken()) != null) { String nestedPath = dateRange.get(FACETARGS.SUBOBJECT.exactToken()).asText(); translatedNestedPath = adapter.getVariableName(nestedPath); if(translatedNestedPath == null) { translatedNestedPath = nestedPath; } } String fieldName = dateRange.get(FACETARGS.FIELD.exactToken()).asText(); String translatedFieldName = adapter.getVariableName(fieldName); if(translatedFieldName == null) { translatedFieldName = fieldName; } return FacetHelper.dateRange(name, translatedFieldName, translatedNestedPath, dateFormat, rangesList); } }
FacetParserHelper extends FacetHelper { public static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter) throws InvalidCreateOperationException, InvalidParseOperationException { final String name = facet.get(FACETARGS.NAME.exactToken()).asText(); JsonNode dateRange = facet.get(FACET.DATE_RANGE.exactToken()); ArrayNode ranges = (ArrayNode) dateRange.get(FACETARGS.RANGES.exactToken()); String dateFormat = dateRange.get(FACETARGS.FORMAT.exactToken()).asText(); List<RangeFacetValue> rangesList = new ArrayList<>(); ranges.forEach(item -> { JsonNode from = item.get(FACETARGS.FROM.exactToken()); JsonNode to = item.get(FACETARGS.TO.exactToken()); rangesList.add(new RangeFacetValue(from != null && !from.isNull() ? from.asText() : null, to != null && !to.isNull() ? to.asText() : null)); }); String translatedNestedPath = null; if(dateRange.get(FACETARGS.SUBOBJECT.exactToken()) != null) { String nestedPath = dateRange.get(FACETARGS.SUBOBJECT.exactToken()).asText(); translatedNestedPath = adapter.getVariableName(nestedPath); if(translatedNestedPath == null) { translatedNestedPath = nestedPath; } } String fieldName = dateRange.get(FACETARGS.FIELD.exactToken()).asText(); String translatedFieldName = adapter.getVariableName(fieldName); if(translatedFieldName == null) { translatedFieldName = fieldName; } return FacetHelper.dateRange(name, translatedFieldName, translatedNestedPath, dateFormat, rangesList); } protected  FacetParserHelper(); }
FacetParserHelper extends FacetHelper { public static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter) throws InvalidCreateOperationException, InvalidParseOperationException { final String name = facet.get(FACETARGS.NAME.exactToken()).asText(); JsonNode dateRange = facet.get(FACET.DATE_RANGE.exactToken()); ArrayNode ranges = (ArrayNode) dateRange.get(FACETARGS.RANGES.exactToken()); String dateFormat = dateRange.get(FACETARGS.FORMAT.exactToken()).asText(); List<RangeFacetValue> rangesList = new ArrayList<>(); ranges.forEach(item -> { JsonNode from = item.get(FACETARGS.FROM.exactToken()); JsonNode to = item.get(FACETARGS.TO.exactToken()); rangesList.add(new RangeFacetValue(from != null && !from.isNull() ? from.asText() : null, to != null && !to.isNull() ? to.asText() : null)); }); String translatedNestedPath = null; if(dateRange.get(FACETARGS.SUBOBJECT.exactToken()) != null) { String nestedPath = dateRange.get(FACETARGS.SUBOBJECT.exactToken()).asText(); translatedNestedPath = adapter.getVariableName(nestedPath); if(translatedNestedPath == null) { translatedNestedPath = nestedPath; } } String fieldName = dateRange.get(FACETARGS.FIELD.exactToken()).asText(); String translatedFieldName = adapter.getVariableName(fieldName); if(translatedFieldName == null) { translatedFieldName = fieldName; } return FacetHelper.dateRange(name, translatedFieldName, translatedNestedPath, dateFormat, rangesList); } protected  FacetParserHelper(); static final Facet terms(final JsonNode facet, VarNameAdapter adapter); static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter); static final Facet filters(final JsonNode facet, VarNameAdapter adapter); }
FacetParserHelper extends FacetHelper { public static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter) throws InvalidCreateOperationException, InvalidParseOperationException { final String name = facet.get(FACETARGS.NAME.exactToken()).asText(); JsonNode dateRange = facet.get(FACET.DATE_RANGE.exactToken()); ArrayNode ranges = (ArrayNode) dateRange.get(FACETARGS.RANGES.exactToken()); String dateFormat = dateRange.get(FACETARGS.FORMAT.exactToken()).asText(); List<RangeFacetValue> rangesList = new ArrayList<>(); ranges.forEach(item -> { JsonNode from = item.get(FACETARGS.FROM.exactToken()); JsonNode to = item.get(FACETARGS.TO.exactToken()); rangesList.add(new RangeFacetValue(from != null && !from.isNull() ? from.asText() : null, to != null && !to.isNull() ? to.asText() : null)); }); String translatedNestedPath = null; if(dateRange.get(FACETARGS.SUBOBJECT.exactToken()) != null) { String nestedPath = dateRange.get(FACETARGS.SUBOBJECT.exactToken()).asText(); translatedNestedPath = adapter.getVariableName(nestedPath); if(translatedNestedPath == null) { translatedNestedPath = nestedPath; } } String fieldName = dateRange.get(FACETARGS.FIELD.exactToken()).asText(); String translatedFieldName = adapter.getVariableName(fieldName); if(translatedFieldName == null) { translatedFieldName = fieldName; } return FacetHelper.dateRange(name, translatedFieldName, translatedNestedPath, dateFormat, rangesList); } protected  FacetParserHelper(); static final Facet terms(final JsonNode facet, VarNameAdapter adapter); static final Facet dateRange(final JsonNode facet, VarNameAdapter adapter); static final Facet filters(final JsonNode facet, VarNameAdapter adapter);  }