Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvg committed Feb 11, 2020
1 parent ca7ed5a commit d047b8f
Showing 1 changed file with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
String fieldName = entry.getKey();
Object fieldNode = entry.getValue();
if (parseObjectOrDocumentTypeProperties(fieldName, fieldNode, parserContext, builder)
|| processField(builder, fieldName, fieldNode, parserContext)) {
|| processField(builder, fieldName, fieldNode, parserContext.indexVersionCreated())) {
iterator.remove();
}
}
Expand All @@ -147,7 +147,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext

@SuppressWarnings("unchecked")
protected boolean processField(RootObjectMapper.Builder builder, String fieldName, Object fieldNode,
ParserContext parserContext) {
Version indexVersionCreated) {
if (fieldName.equals("date_formats") || fieldName.equals("dynamic_date_formats")) {
if (fieldNode instanceof List) {
List<DateFormatter> formatters = new ArrayList<>();
Expand Down Expand Up @@ -205,7 +205,6 @@ protected boolean processField(RootObjectMapper.Builder builder, String fieldNam
}
return false;
}

}

private Explicit<DateFormatter[]> dynamicDateTimeFormatters;
Expand Down Expand Up @@ -352,7 +351,7 @@ public void validateDynamicTemplates(Mapper.TypeParser.ParserContext parserConte
private static void validateDynamicTemplate(Mapper.TypeParser.ParserContext parserContext,
DynamicTemplate dynamicTemplate) {

if (containsPlaceHolders(dynamicTemplate.getMapping(), "{name}")) {
if (containsSnippet(dynamicTemplate.getMapping(), "{name}")) {
// Can't validate template, because field names can't be guessed up front.
return;
}
Expand Down Expand Up @@ -398,53 +397,47 @@ private static void validateDynamicTemplate(Mapper.TypeParser.ParserContext pars
}
}

private static boolean containsPlaceHolders(Map<?, ?> map, String... placeHolders) {
private static boolean containsSnippet(Map<?, ?> map, String snippet) {
for (Map.Entry<?, ?> entry : map.entrySet()) {
String key = entry.getKey().toString();
for (String placeHolder : placeHolders) {
if (key.contains(placeHolder)) {
return true;
}
if (key.contains(snippet)) {
return true;
}

Object value = entry.getValue();
if (value instanceof Map) {
if (containsPlaceHolders((Map<?, ?>) value, placeHolders)) {
if (containsSnippet((Map<?, ?>) value, snippet)) {
return true;
}
} else if (value instanceof List) {
if (containsPlaceHolders((List<?>) value, placeHolders)) {
if (containsSnippet((List<?>) value, snippet)) {
return true;
}
} else if (value instanceof String) {
String valueString = (String) value;
for (String placeHolder : placeHolders) {
if (valueString.contains(placeHolder)) {
return true;
}
if (valueString.contains(snippet)) {
return true;
}
}
}

return false;
}

private static boolean containsPlaceHolders(List<?> list, String... placeHolders) {
private static boolean containsSnippet(List<?> list, String snippet) {
for (Object value : list) {
if (value instanceof Map) {
if (containsPlaceHolders((Map<?, ?>) value, placeHolders)) {
if (containsSnippet((Map<?, ?>) value, snippet)) {
return true;
}
} else if (value instanceof List) {
if (containsPlaceHolders((List<?>) value, placeHolders)) {
if (containsSnippet((List<?>) value, snippet)) {
return true;
}
} else if (value instanceof String) {
String valueString = (String) value;
for (String placeHolder : placeHolders) {
if (valueString.contains(placeHolder)) {
return true;
}
if (valueString.contains(snippet)) {
return true;
}
}
}
Expand Down

0 comments on commit d047b8f

Please sign in to comment.