Skip to content

Commit

Permalink
Issue #532: add DocType relationship to subDocTypeFields
Browse files Browse the repository at this point in the history
  • Loading branch information
cbianco committed Jul 26, 2023
1 parent 82b9075 commit 15c5ce9
Showing 1 changed file with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ private Function<Map<String, List<DocTypeField>>, Uni<?>> _persistDocType(

docTypeFields.addAll(docTypeFieldList);

for (DocTypeField docTypeField : docTypeFields) {
docTypeField.setDocType(docType);
}
_setDocTypeToDocTypeFields(docType, docTypeFields);

docTypes.add(docType);

Expand All @@ -215,6 +213,20 @@ private Function<Map<String, List<DocTypeField>>, Uni<?>> _persistDocType(
});
}

private static void _setDocTypeToDocTypeFields(
DocType docType, Set<DocTypeField> docTypeFields) {

if (docTypeFields == null) {
return;
}

for (DocTypeField docTypeField : docTypeFields) {
docTypeField.setDocType(docType);
_setDocTypeToDocTypeFields(docType, docTypeField.getSubDocTypeFields());
}

}

private Function<Tuple2<List<DocTypeField>, List<String>>, Map<String, List<DocTypeField>>> _toDocTypeFieldMap() {
return t2 -> {

Expand Down Expand Up @@ -437,6 +449,52 @@ private static void _toDocTypeFields(

}

public static void main(String[] args) {

String json = "{\n" +
" \"properties\" : {\n" +
" \"web\" : {\n" +
" \"properties\" : {\n" +
" \"title\" : {\n" +
" \"properties\" : {\n" +
" \"i18n\" : {\n" +
" \"properties\" : {\n" +
" \"en\" : {\n" +
" \"type\" : \"text\",\n" +
" \"fields\" : {\n" +
" \"keyword\" : {\n" +
" \"type\" : \"keyword\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" },\n" +
" \"base\" : {\n" +
" \"type\" : \"text\",\n" +
" \"fields\" : {\n" +
" \"keyword\" : {\n" +
" \"type\" : \"keyword\"\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }";

;

Field field = _toFlatFields(new JsonObject(json).getMap());

List<DocTypeField> docTypeFields = _toDocTypeFields(field);

System.out.println(docTypeFields);

}


@Inject
RestHighLevelClient client;

Expand Down

0 comments on commit 15c5ce9

Please sign in to comment.