From 7c948def8c582a154454ade6e9de1b0bd03bb0bd Mon Sep 17 00:00:00 2001 From: Wataru Sawami Date: Tue, 11 Jun 2019 13:39:47 +0900 Subject: [PATCH 1/7] for v1_es6.6.1_5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bc25731..28bbc02 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ io.personium personium-lib-es-adapter jar - 1_es6.6.1_4 + 1_es6.6.1_5-SNAPSHOT The Apache Software License, Version 2.0 From c7cf7dafd816d8987d4b14b8f57a17f221a5380b Mon Sep 17 00:00:00 2001 From: Akira-Ohishi Date: Mon, 17 Jun 2019 10:52:57 +0900 Subject: [PATCH 2/7] Maintenance of checkstyle and PMD. --- .../common/es/impl/InternalEsClient.java | 506 +++++++++++------- .../response/impl/PersoniumSearchHitImpl.java | 2 +- 2 files changed, 314 insertions(+), 194 deletions(-) diff --git a/src/main/java/io/personium/common/es/impl/InternalEsClient.java b/src/main/java/io/personium/common/es/impl/InternalEsClient.java index 0969271..fab237f 100644 --- a/src/main/java/io/personium/common/es/impl/InternalEsClient.java +++ b/src/main/java/io/personium/common/es/impl/InternalEsClient.java @@ -168,7 +168,8 @@ private void prepareClient(String clusterName, String hostNames) { for (EsHost host : hostList) { try { - esTransportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(host.getName()), host.getPort())); + esTransportClient.addTransportAddress( + new TransportAddress(InetAddress.getByName(host.getName()), host.getPort())); connectedNodes = esTransportClient.connectedNodes(); } catch (UnknownHostException ex) { throw new EsClientException("Datastore Connection Error.", ex); @@ -290,10 +291,14 @@ public ActionFuture createIndex(String index, Map response = null; for (String type : mappings.keySet()) { @@ -308,9 +313,10 @@ public ActionFuture createIndex(String index, Map asyncSearch( String type, String routingId, SearchSourceBuilder builder) { - SearchRequest req = new SearchRequest(makeIndex(index, type)).types(makeType(type)).searchType(SearchType.DEFAULT).source(builder); + SearchRequest req = new SearchRequest(makeIndex(index, type)).types(makeType(type)) + .searchType(SearchType.DEFAULT).source(builder); if (routingFlag) { req = req.routing(routingId); } @@ -446,7 +453,8 @@ public ActionFuture asyncSearch( String type, String routingId, Map query) { - SearchRequest req = new SearchRequest(makeIndex(index, type)).types(makeType(type)).searchType(SearchType.DEFAULT); + SearchRequest req = new SearchRequest(makeIndex(index, type)).types(makeType(type)) + .searchType(SearchType.DEFAULT); if (query != null) { req.source(makeSearchSourceBuilder(query, type)); } @@ -715,8 +723,10 @@ public BulkResponse bulkRequest(String index, String routingId, List> ents : bulkMap.entrySet()) { for (EsBulkRequest data : ents.getValue()) { - IndexRequestBuilder req = esTransportClient. - prepareIndex(makeIndex(index, data.getType()), makeType(data.getType()), data.getId()).setSource(makeData(data.getSource(), data.getType())); + IndexRequestBuilder req = esTransportClient + .prepareIndex(makeIndex(index, data.getType()), makeType(data.getType()), data.getId()) + .setSource(makeData(data.getSource(), data.getType())); if (routingFlag) { req = req.setRouting(ents.getKey()); } @@ -814,39 +827,54 @@ public BulkByScrollResponse deleteByQuery(String index, Map dele * @return 非同期応答 */ public ActionFuture flushTransLog(String index) { - ActionFuture ret = esTransportClient.admin().indices().flush(new FlushRequest(makeIndex(index, null))); + ActionFuture ret = esTransportClient.admin().indices() + .flush(new FlushRequest(makeIndex(index, null))); this.fireEvent(Event.afterRequest, index, null, null, null, "Flush"); return ret; } /** - * ES2 -> ES6 非互換吸収のためにメソッド追加 + * ES2 -> ES6 非互換吸収のためにメソッド追加. */ - public static String makeIndex(String index, String type) - { + private static final String UNIQE_TYPE = "_doc"; + + /** + * Get index and return index. + * @param index index + * @param type type + * @return Elasticsearch index + */ + public static String makeIndex(String index, String type) { StringBuffer sb = new StringBuffer(); sb.append(index).append("."); - if (type == null) sb.append("*"); - else sb.append(type.toLowerCase()); + if (type == null) { + sb.append("*"); + } else { + sb.append(type.toLowerCase()); + } return sb.toString(); } - private static final String UNIQE_TYPE = "_doc"; - public static String makeType(String type) - { + + /** + * Get type and return it. + * @param type type + * @return Elasticsearch type + */ + public static String makeType(String type) { // NOPMD - Methods for incompatible absorption return UNIQE_TYPE; } - private static Map makeData(Map data, String type) - { + + private static Map makeData(Map data, String type) { Map newData = deepClone(1, data, type); newData.put("type", type); return newData; } - private static SearchSourceBuilder makeSearchSourceBuilder(Map map, String type) - { + + private static SearchSourceBuilder makeSearchSourceBuilder(Map map, String type) { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList()); - try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(new NamedXContentRegistry(searchModule.getNamedXContents()), null, queryMapToJSON(map, type))) - { + try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( + new NamedXContentRegistry(searchModule.getNamedXContents()), null, queryMapToJSON(map, type))) { searchSourceBuilder.parseXContent(parser); } catch (IOException ex) { throw new EsClientException("SearchBuilder Make Error.", ex); @@ -854,8 +882,8 @@ private static SearchSourceBuilder makeSearchSourceBuilder(Map m return searchSourceBuilder; } - private static QueryBuilder makeQueryBuilder(Map map, String type) - { + + private static QueryBuilder makeQueryBuilder(Map map, String type) { log.debug("#DeleteByQuerye"); com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper(); Map queryMap = null; @@ -864,234 +892,300 @@ private static QueryBuilder makeQueryBuilder(Map map, String typ } catch (IOException ex) { throw new EsClientException("QueryBuilder Make Error.", ex); } - Map query_query = (Map)getNestedMapObject(queryMap, new String[]{ "query" }, 0); - QueryBuilder queryBuilder = QueryBuilders.wrapperQuery(JSONObject.toJSONString(query_query)); + Map queryQuery = (Map) getNestedMapObject(queryMap, new String[] {"query"}, 0); + QueryBuilder queryBuilder = QueryBuilders.wrapperQuery(JSONObject.toJSONString(queryQuery)); return queryBuilder; } - private static String queryMapToJSON(Map map, String type) - { - if (log.isDebugEnabled()) log.debug("\n--- Before ---\n" + toJSON(map, false)); + + private static String queryMapToJSON(Map map, String type) { // CHECKSTYLE IGNORE + if (log.isDebugEnabled()) { + log.debug("\n--- Before ---\n" + toJSON(map, false)); + } // Convert start Map cloneMap = deepClone(1, map, type); Map newMap = new HashMap(); //version - Object version = getNestedMapObject(cloneMap, new String[]{ "version" }, 0); - if (version != null) newMap.put("version", version); + Object version = getNestedMapObject(cloneMap, new String[] {"version"}, 0); + if (version != null) { + newMap.put("version", version); + } // size - Object size = getNestedMapObject(cloneMap, new String[]{ "size" }, 0); - if (size != null) newMap.put("size", size); + Object size = getNestedMapObject(cloneMap, new String[] {"size"}, 0); + if (size != null) { + newMap.put("size", size); + } // from - Object from = getNestedMapObject(cloneMap, new String[]{ "from" }, 0); - if (from != null) newMap.put("from", from); + Object from = getNestedMapObject(cloneMap, new String[] {"from"}, 0); + if (from != null) { + newMap.put("from", from); + } // sort - Object sort = getNestedMapObject(cloneMap, new String[]{ "sort" }, 0); - if (sort != null) newMap.put("sort", sort); + Object sort = getNestedMapObject(cloneMap, new String[] {"sort"}, 0); + if (sort != null) { + newMap.put("sort", sort); + } // _source - Object _source = getNestedMapObject(cloneMap, new String[]{ "_source" }, 0); - if (_source != null) { - if (_source instanceof List) ((List)_source).add(0, "type"); - newMap.put("_source", _source); + Object source = getNestedMapObject(cloneMap, new String[] {"_source"}, 0); + if (source != null) { + if (source instanceof List) { + ((List) source).add(0, "type"); + } + newMap.put("_source", source); } // query - Map query = new HashMap(); newMap.put("query", query); - Map query_bool = new HashMap(); query.put("bool", query_bool); - Map query_bool_filter = new HashMap(); query_bool.put("filter", query_bool_filter); - Map query_bool_filter_bool = new HashMap(); query_bool_filter.put("bool", query_bool_filter_bool); - List> query_bool_must = new ArrayList>(); query_bool.put("must", query_bool_must); - List> query_bool_mustnot = new ArrayList>(); query_bool.put("must_not", query_bool_mustnot); - List> query_bool_should = new ArrayList>(); query_bool.put("should", query_bool_should); - List> query_bool_filter_bool_must = new ArrayList>(); query_bool_filter_bool.put("must", query_bool_filter_bool_must); - List> query_bool_filter_bool_mustnot = new ArrayList>(); query_bool_filter_bool.put("must_not", query_bool_filter_bool_mustnot); - List> query_bool_filter_bool_should = new ArrayList>(); query_bool_filter_bool.put("should", query_bool_filter_bool_should); + Map query = new HashMap(); + newMap.put("query", query); + Map queryBool = new HashMap(); + query.put("bool", queryBool); + Map queryBoolFilter = new HashMap(); + queryBool.put("filter", queryBoolFilter); + Map queryBoolFilterBool = new HashMap(); + queryBoolFilter.put("bool", queryBoolFilterBool); + List> queryBoolMust = new ArrayList>(); + queryBool.put("must", queryBoolMust); + List> queryBoolMustnot = new ArrayList>(); + queryBool.put("must_not", queryBoolMustnot); + List> queryBoolShould = new ArrayList>(); + queryBool.put("should", queryBoolShould); + List> queryBoolFilterBoolMust = new ArrayList>(); + queryBoolFilterBool.put("must", queryBoolFilterBoolMust); + List> queryBoolFilterBoolMustnot = new ArrayList>(); + queryBoolFilterBool.put("must_not", queryBoolFilterBoolMustnot); + List> queryBoolFilterBoolShould = new ArrayList>(); + queryBoolFilterBool.put("should", queryBoolFilterBoolShould); ///// // -query/filterd/filter - List> query_x_must = (List>)getNestedMapObject(cloneMap, new String[]{ "query", "filtered", "filter", "bool", "must" }, 0); - List> query_x_mustnot = (List>)getNestedMapObject(cloneMap, new String[]{ "query", "filtered", "filter", "bool", "must_not" }, 0); - List> query_x_should = (List>)getNestedMapObject(cloneMap, new String[]{ "query", "filtered", "filter", "bool", "should" }, 0); - if (query_x_must != null) { - for (Map tmap : query_x_must) { - query_bool_filter_bool_must.add(tmap); + List> queryXmust = (List>) getNestedMapObject(cloneMap, + new String[] {"query", "filtered", "filter", "bool", "must"}, 0); + List> queryXmustnot = (List>) getNestedMapObject(cloneMap, + new String[] {"query", "filtered", "filter", "bool", "must_not"}, 0); + List> queryXshould = (List>) getNestedMapObject(cloneMap, + new String[] {"query", "filtered", "filter", "bool", "should"}, 0); + if (queryXmust != null) { + for (Map tmap : queryXmust) { + queryBoolFilterBoolMust.add(tmap); } } - if (query_x_mustnot != null) { - for (Map tmap : query_x_mustnot) { - query_bool_filter_bool_mustnot.add(tmap); + if (queryXmustnot != null) { + for (Map tmap : queryXmustnot) { + queryBoolFilterBoolMustnot.add(tmap); } } - if (query_x_should != null) { - for (Map tmap : query_x_should) { - query_bool_filter_bool_should.add(tmap); + if (queryXshould != null) { + for (Map tmap : queryXshould) { + queryBoolFilterBoolShould.add(tmap); } } - // -query/filterd/filter other pattern - if (query_bool_filter_bool_must.isEmpty() && query_bool_filter_bool_mustnot.isEmpty() && query_bool_filter_bool_should.isEmpty()) { + // -query/filterd/filter other pattern + if (queryBoolFilterBoolMust.isEmpty() && queryBoolFilterBoolMustnot.isEmpty() + && queryBoolFilterBoolShould.isEmpty()) { // other eregular pattern - while (true) { - List> query_x_filters = (List>)getNestedMapObject(cloneMap, new String[]{ "query", "filtered", "filter", "and", "filters" }, 0); - if (query_x_filters != null) { - for (Map tmap : query_x_filters) { - query_bool_filter_bool_must.add(tmap); - } - break; + List> queryXfilters = (List>) getNestedMapObject(cloneMap, + new String[] {"query", "filtered", "filter", "and", "filters"}, 0); + if (queryXfilters != null) { + for (Map tmap : queryXfilters) { + queryBoolFilterBoolMust.add(tmap); } - Map query_x_filter = (Map)getNestedMapObject(cloneMap, new String[]{ "query", "filtered", "filter" }, 0); - if (query_x_filter != null) { - query_bool_filter_bool_must.add(query_x_filter); - break; + } else { + Map queryXfilter = (Map) getNestedMapObject(cloneMap, + new String[] {"query", "filtered", "filter"}, 0); + if (queryXfilter != null) { + queryBoolFilterBoolMust.add(queryXfilter); } - break; } } // -query/filterd/query - Object query_filtered_query = getNestedMapObject(cloneMap, new String[]{ "query", "filtered", "query" }, 0); - if (query_filtered_query != null) { - if (query_filtered_query instanceof List) { - query_bool_must.addAll((List>)query_filtered_query); - } else - if (query_filtered_query instanceof Map) { - query_bool_must.add((Map)query_filtered_query); - } + Object queryFilteredQuery = getNestedMapObject(cloneMap, new String[] {"query", "filtered", "query"}, 0); + if (queryFilteredQuery != null) { + if (queryFilteredQuery instanceof List) { + queryBoolMust.addAll((List>) queryFilteredQuery); + } else if (queryFilteredQuery instanceof Map) { + queryBoolMust.add((Map) queryFilteredQuery); + } } ///// // -filter/ids - Map filter_ids = (Map)getNestedMapObject(cloneMap, new String[]{ "filter", "ids" }, 0); - if (filter_ids != null) { + Map filterIds = (Map) getNestedMapObject(cloneMap, + new String[] {"filter", "ids"}, 0); + if (filterIds != null) { Map ids = new HashMap(); - ids.put("ids", filter_ids); - query_bool_filter_bool_must.add(ids); + ids.put("ids", filterIds); + queryBoolFilterBoolMust.add(ids); } // -filter - Map filter = (Map)getNestedMapObject(cloneMap, new String[]{ "filter" }, 0); + Map filter = (Map) getNestedMapObject(cloneMap, new String[] {"filter"}, 0); if (filter != null) { // -query - List> filter_x_querys = new ArrayList>(); - parseQueryMap(filter_x_querys, filter); - if (!filter_x_querys.isEmpty()) { - Map queryMap = new HashMap();query_bool_must.add(queryMap); - Map query_bool_must_bool = new HashMap(); queryMap.put("bool", query_bool_must_bool); - List> query_bool_must_bool_must = new ArrayList>(); query_bool_must_bool.put("must", query_bool_must_bool_must); - for(Map filter_x_query : filter_x_querys) { - if (filter_x_query instanceof List) { - query_bool_must_bool_must.addAll((List>)filter_x_query); - } else - if (filter_x_query instanceof Map) { - query_bool_must_bool_must.add((Map)filter_x_query); + List> filterXquerys = new ArrayList>(); + parseQueryMap(filterXquerys, filter); + if (!filterXquerys.isEmpty()) { + Map queryMap = new HashMap(); + queryBoolMust.add(queryMap); + Map queryBoolMustBool = new HashMap(); + queryMap.put("bool", queryBoolMustBool); + List> queryBoolMustBoolMust = new ArrayList>(); + queryBoolMustBool.put("must", queryBoolMustBoolMust); + for (Map filterXquery : filterXquerys) { + if (filterXquery instanceof List) { + queryBoolMustBoolMust.addAll((List>) filterXquery); + } else if (filterXquery instanceof Map) { + queryBoolMustBoolMust.add((Map) filterXquery); } } removeNestedMapObject(filter, "query"); } // -filter - Map filer_x_filter = parseMap(filter); - List> filter_bool_must = (List>)getNestedMapObject(filer_x_filter, new String[]{ "bool", "must" }, 0); - if (filter_bool_must != null) { - query_bool_filter_bool_must.add(filer_x_filter); + Map filerXfilter = parseMap(filter); + List> filterBoolMust = (List>) getNestedMapObject(filerXfilter, + new String[] {"bool", "must"}, 0); + if (filterBoolMust != null) { + queryBoolFilterBoolMust.add(filerXfilter); } - List> filter_bool_should = (List>)getNestedMapObject(filer_x_filter, new String[]{ "bool", "should" }, 0); - if (filter_bool_should != null) { - query_bool_filter_bool_should.add(filer_x_filter); + List> filterBoolShould = (List>) getNestedMapObject( + filerXfilter, new String[] {"bool", "should"}, 0); + if (filterBoolShould != null) { + queryBoolFilterBoolShould.add(filerXfilter); } } ///// removeNestedMapObject(newMap, "ignore_unmapped"); removeNestedMapObject(newMap, "_cache"); - if (query_bool_must.isEmpty()) query_bool.remove("must"); - if (query_bool_mustnot.isEmpty()) query_bool.remove("must_not"); - if (query_bool_should.isEmpty()) query_bool.remove("should"); - if (query_bool_filter_bool_must.isEmpty()) query_bool_filter_bool.remove("must"); - if (query_bool_filter_bool_mustnot.isEmpty()) query_bool_filter_bool.remove("must_not"); - if (query_bool_filter_bool_should.isEmpty()) query_bool_filter_bool.remove("should"); + if (queryBoolMust.isEmpty()) { + queryBool.remove("must"); + } + if (queryBoolMustnot.isEmpty()) { + queryBool.remove("must_not"); + } + if (queryBoolShould.isEmpty()) { + queryBool.remove("should"); + } + if (queryBoolFilterBoolMust.isEmpty()) { + queryBoolFilterBool.remove("must"); + } + if (queryBoolFilterBoolMustnot.isEmpty()) { + queryBoolFilterBool.remove("must_not"); + } + if (queryBoolFilterBoolShould.isEmpty()) { + queryBoolFilterBool.remove("should"); + } String jsonstr = toJSON(newMap, true); // Convert end - if (log.isDebugEnabled()) log.debug("\n--- After ---\n" + jsonstr); + if (log.isDebugEnabled()) { + log.debug("\n--- After ---\n" + jsonstr); + } return jsonstr; } + private static Map parseMap(Map map) { if (map.get("and") != null) { Object value = map.get("and"); Map and = new HashMap(); - Map bool = new HashMap(); and.put("bool", bool); - List> bool_must = new ArrayList>(); bool.put("must", bool_must); + Map bool = new HashMap(); + and.put("bool", bool); + List> bool_must = new ArrayList>(); + bool.put("must", bool_must); parseAndOrNotMap(bool_must, value); return and; } if (map.get("or") != null) { Object value = map.get("or"); Map or = new HashMap(); - Map bool = new HashMap(); or.put("bool", bool); - List> bool_should = new ArrayList>(); bool.put("should", bool_should); + Map bool = new HashMap(); + or.put("bool", bool); + List> bool_should = new ArrayList>(); + bool.put("should", bool_should); parseAndOrNotMap(bool_should, value); return or; } if (map.get("not") != null) { Object value = map.get("not"); Map not = new HashMap(); - Map bool = new HashMap(); not.put("bool", bool); - List> bool_mustnot = new ArrayList>(); bool.put("must_not", bool_mustnot); + Map bool = new HashMap(); + not.put("bool", bool); + List> bool_mustnot = new ArrayList>(); + bool.put("must_not", bool_mustnot); parseAndOrNotMap(bool_mustnot, value); return not; } if (map.get("missing") != null) { Map missing = new HashMap(); - Map bool = new HashMap(); missing.put("bool", bool); - List> bool_mustnot = new ArrayList>(); bool.put("must_not", bool_mustnot); - Map exists = new HashMap(); bool_mustnot.add(exists); + Map bool = new HashMap(); + missing.put("bool", bool); + List> bool_mustnot = new ArrayList>(); + bool.put("must_not", bool_mustnot); + Map exists = new HashMap(); + bool_mustnot.add(exists); exists.put("exists", map.get("missing")); return missing; } return map; } + private static void parseAndOrNotMap(List> listmap, Object value) { if (value instanceof List) { - List> lmap = parseListMap((List>)value); - if (!lmap.isEmpty()) listmap.addAll(lmap); - } else - if (value instanceof Map) { - Map nestedMap = (Map)value; - if (nestedMap.get("filters") != null) { - Object filters_value = nestedMap.get("filters"); - if (filters_value instanceof List) { - List> lmap = parseListMap((List>)filters_value); - if (!lmap.isEmpty()) listmap.addAll(lmap); - } else - if (filters_value instanceof Map) { - Map map = parseMap((Map)filters_value); - if (!map.isEmpty()) listmap.add(map); - } - } else - if (nestedMap.get("filter") != null) { - Object filter_value = nestedMap.get("filter"); - if (filter_value instanceof List) { - List> lmap = parseListMap((List>)filter_value); - if (!lmap.isEmpty()) listmap.addAll(lmap); - } else - if (filter_value instanceof Map) { - Map map = parseMap((Map)filter_value); - if (!map.isEmpty()) listmap.add(map); - } - } else { - Map map = parseMap((Map)value); - if (!map.isEmpty()) listmap.add(map); + List> lmap = parseListMap((List>) value); + if (!lmap.isEmpty()) { + listmap.addAll(lmap); + } + } else if (value instanceof Map) { + Map nestedMap = (Map) value; + if (nestedMap.get("filters") != null) { + Object filters_value = nestedMap.get("filters"); + if (filters_value instanceof List) { + List> lmap = parseListMap((List>) filters_value); + if (!lmap.isEmpty()) { + listmap.addAll(lmap); } + } else if (filters_value instanceof Map) { + Map map = parseMap((Map) filters_value); + if (!map.isEmpty()) { + listmap.add(map); + } + } + } else if (nestedMap.get("filter") != null) { + Object filter_value = nestedMap.get("filter"); + if (filter_value instanceof List) { + List> lmap = parseListMap((List>) filter_value); + if (!lmap.isEmpty()) { + listmap.addAll(lmap); + } + } else if (filter_value instanceof Map) { + Map map = parseMap((Map) filter_value); + if (!map.isEmpty()) { + listmap.add(map); + } + } + } else { + Map map = parseMap((Map) value); + if (!map.isEmpty()) { + listmap.add(map); + } } + } } + private static List> parseListMap(List> listmap) { List> rlistmap = new ArrayList>(); for (Map emap : listmap) { if (emap instanceof Map) { Map rmap = parseMap(emap); - if (!rmap.isEmpty()) rlistmap.add(rmap); + if (!rmap.isEmpty()) { + rlistmap.add(rmap); + } } } return rlistmap; } + private static void parseQueryMap(List> listQueryMap, Map map) { for (Entry entry : map.entrySet()) { if (entry.getKey().equals("query")) { - Map queryMap = (Map)entry.getValue(); - String type = (String)getNestedMapObject(queryMap, "type"); + Map queryMap = (Map) entry.getValue(); + String type = (String) getNestedMapObject(queryMap, "type"); if (type != null) { - Map match = (Map)getNestedMapObject(queryMap, new String[]{ "match" }, 0); + Map match = (Map) getNestedMapObject(queryMap, + new String[] {"match"}, 0); removeNestedMapObject(match, "type"); removeNestedMapObject(match, "operator"); removeNestedMapObject(queryMap, "match"); @@ -1101,17 +1195,17 @@ private static void parseQueryMap(List> listQueryMap, Map>)entry.getValue()) { + for (Object cmap : (List>) entry.getValue()) { if (cmap instanceof Map) { - parseQueryMap(listQueryMap, (Map)cmap); + parseQueryMap(listQueryMap, (Map) cmap); } } - } else - if (entry.getValue() instanceof Map) { - parseQueryMap(listQueryMap, (Map)entry.getValue()); - } + } else if (entry.getValue() instanceof Map) { + parseQueryMap(listQueryMap, (Map) entry.getValue()); + } } } + private static void removeNestedMapObject(Map map, String key) { Map queryClone = new HashMap(map); for (Entry entry : queryClone.entrySet()) { @@ -1120,17 +1214,17 @@ private static void removeNestedMapObject(Map map, String key) { continue; } if (entry.getValue() instanceof List) { - for (Object cmap : (List>)entry.getValue()) { + for (Object cmap : (List>) entry.getValue()) { if (cmap instanceof Map) { - removeNestedMapObject((Map)cmap, key); + removeNestedMapObject((Map) cmap, key); } } - } else - if (entry.getValue() instanceof Map) { - removeNestedMapObject((Map)entry.getValue(), key); - } + } else if (entry.getValue() instanceof Map) { + removeNestedMapObject((Map) entry.getValue(), key); + } } } + private static Object getNestedMapObject(Map map, String key) { Map queryClone = new HashMap(map); for (Entry entry : queryClone.entrySet()) { @@ -1138,39 +1232,49 @@ private static Object getNestedMapObject(Map map, String key) { return entry.getValue(); } if (entry.getValue() instanceof List) { - for (Object cmap : (List>)entry.getValue()) { + for (Object cmap : (List>) entry.getValue()) { if (cmap instanceof Map) { - Object cobj = getNestedMapObject((Map)cmap, key); - if (cobj != null) return cobj; + Object cobj = getNestedMapObject((Map) cmap, key); + if (cobj != null) { + return cobj; + } } } - } else - if (entry.getValue() instanceof Map) { - Object cobj = getNestedMapObject((Map)entry.getValue(), key); - if (cobj != null) return cobj; + } else if (entry.getValue() instanceof Map) { + Object cobj = getNestedMapObject((Map) entry.getValue(), key); + if (cobj != null) { + return cobj; } + } } return null; } + private static Object getNestedMapObject(Map map, String[] keys, int index) { Object obj = map.get(keys[index]); if (obj != null) { - if (index == keys.length -1) return obj; + if (index == keys.length - 1) { + return obj; + } if (obj instanceof Map) { ++index; - Object cobj = getNestedMapObject((Map)obj, keys, index); - if (cobj != null) return cobj; - } else - if (obj instanceof List) { + Object cobj = getNestedMapObject((Map) obj, keys, index); + if (cobj != null) { + return cobj; + } + } else if (obj instanceof List) { ++index; - for (Map cmap : (List>)obj) { + for (Map cmap : (List>) obj) { Object cobj = getNestedMapObject(cmap, keys, index); - if (cobj != null) return cobj; + if (cobj != null) { + return cobj; + } } } } return null; } + private static String toJSON(Map map, boolean shaping) { String json = "{}"; try { @@ -1186,6 +1290,14 @@ private static String toJSON(Map map, boolean shaping) { } return json; } + + /** + * deep clone. + * @param direction direction + * @param map map + * @param type type + * @return deep clone map + */ public static Map deepClone(int direction, Map map, String type) { try { com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper(); @@ -1197,6 +1309,14 @@ public static Map deepClone(int direction, Map m throw new EsClientException("InternalEsClient.deepClone Error.", ex); } } + + /** + * replace source. + * @param direction direction + * @param json json + * @param type type + * @return replace source string + */ public static String replaceSource(int direction, String json, String type) { if (direction > 0) { switch (direction) { diff --git a/src/main/java/io/personium/common/es/response/impl/PersoniumSearchHitImpl.java b/src/main/java/io/personium/common/es/response/impl/PersoniumSearchHitImpl.java index 22e67d0..e2739c1 100644 --- a/src/main/java/io/personium/common/es/response/impl/PersoniumSearchHitImpl.java +++ b/src/main/java/io/personium/common/es/response/impl/PersoniumSearchHitImpl.java @@ -48,7 +48,7 @@ private PersoniumSearchHitImpl() { */ private PersoniumSearchHitImpl(SearchHit hit) { this.searchHit = hit; - this.type = (String)this.searchHit.getSourceAsMap().get("type"); + this.type = (String) this.searchHit.getSourceAsMap().get("type"); this.source = this.searchHit.getSourceAsMap(); } From 72435103d7fad936d54434f93cbb6ec0f75cfcd9 Mon Sep 17 00:00:00 2001 From: Akira-Ohishi Date: Mon, 17 Jun 2019 11:40:02 +0900 Subject: [PATCH 3/7] Maintenance of checkstyle and PMD. --- .../personium/common/es/impl/EsIndexImpl.java | 2 +- .../common/es/impl/InternalEsClient.java | 44 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/personium/common/es/impl/EsIndexImpl.java b/src/main/java/io/personium/common/es/impl/EsIndexImpl.java index af0a97e..b186c08 100644 --- a/src/main/java/io/personium/common/es/impl/EsIndexImpl.java +++ b/src/main/java/io/personium/common/es/impl/EsIndexImpl.java @@ -211,7 +211,7 @@ public Void updateSettings(String index, Map settings) { */ class CreateRetryableRequest extends AbstractRetryableEsRequest { String name; - String [] types; + String[] types; Map mappings; CreateRetryableRequest(int retryCount, long retryInterval, diff --git a/src/main/java/io/personium/common/es/impl/InternalEsClient.java b/src/main/java/io/personium/common/es/impl/InternalEsClient.java index fab237f..7e07149 100644 --- a/src/main/java/io/personium/common/es/impl/InternalEsClient.java +++ b/src/main/java/io/personium/common/es/impl/InternalEsClient.java @@ -1083,9 +1083,9 @@ private static Map parseMap(Map map) { Map and = new HashMap(); Map bool = new HashMap(); and.put("bool", bool); - List> bool_must = new ArrayList>(); - bool.put("must", bool_must); - parseAndOrNotMap(bool_must, value); + List> boolMust = new ArrayList>(); + bool.put("must", boolMust); + parseAndOrNotMap(boolMust, value); return and; } if (map.get("or") != null) { @@ -1093,9 +1093,9 @@ private static Map parseMap(Map map) { Map or = new HashMap(); Map bool = new HashMap(); or.put("bool", bool); - List> bool_should = new ArrayList>(); - bool.put("should", bool_should); - parseAndOrNotMap(bool_should, value); + List> boolShould = new ArrayList>(); + bool.put("should", boolShould); + parseAndOrNotMap(boolShould, value); return or; } if (map.get("not") != null) { @@ -1103,19 +1103,19 @@ private static Map parseMap(Map map) { Map not = new HashMap(); Map bool = new HashMap(); not.put("bool", bool); - List> bool_mustnot = new ArrayList>(); - bool.put("must_not", bool_mustnot); - parseAndOrNotMap(bool_mustnot, value); + List> boolMustnot = new ArrayList>(); + bool.put("must_not", boolMustnot); + parseAndOrNotMap(boolMustnot, value); return not; } if (map.get("missing") != null) { Map missing = new HashMap(); Map bool = new HashMap(); missing.put("bool", bool); - List> bool_mustnot = new ArrayList>(); - bool.put("must_not", bool_mustnot); + List> boolMustnot = new ArrayList>(); + bool.put("must_not", boolMustnot); Map exists = new HashMap(); - bool_mustnot.add(exists); + boolMustnot.add(exists); exists.put("exists", map.get("missing")); return missing; } @@ -1131,27 +1131,27 @@ private static void parseAndOrNotMap(List> listmap, Object v } else if (value instanceof Map) { Map nestedMap = (Map) value; if (nestedMap.get("filters") != null) { - Object filters_value = nestedMap.get("filters"); - if (filters_value instanceof List) { - List> lmap = parseListMap((List>) filters_value); + Object filtersValue = nestedMap.get("filters"); + if (filtersValue instanceof List) { + List> lmap = parseListMap((List>) filtersValue); if (!lmap.isEmpty()) { listmap.addAll(lmap); } - } else if (filters_value instanceof Map) { - Map map = parseMap((Map) filters_value); + } else if (filtersValue instanceof Map) { + Map map = parseMap((Map) filtersValue); if (!map.isEmpty()) { listmap.add(map); } } } else if (nestedMap.get("filter") != null) { - Object filter_value = nestedMap.get("filter"); - if (filter_value instanceof List) { - List> lmap = parseListMap((List>) filter_value); + Object filterValue = nestedMap.get("filter"); + if (filterValue instanceof List) { + List> lmap = parseListMap((List>) filterValue); if (!lmap.isEmpty()) { listmap.addAll(lmap); } - } else if (filter_value instanceof Map) { - Map map = parseMap((Map) filter_value); + } else if (filterValue instanceof Map) { + Map map = parseMap((Map) filterValue); if (!map.isEmpty()) { listmap.add(map); } From a3cef94158ff52589c73fce9316a842dbb48e756 Mon Sep 17 00:00:00 2001 From: "Tochiori, Yasufumi" Date: Tue, 18 Jun 2019 14:23:19 +0900 Subject: [PATCH 4/7] Remove log4j2 error message https://github.com/personium/personium-lib-es-adapter/issues/52 --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 28bbc02..e74189e 100644 --- a/pom.xml +++ b/pom.xml @@ -297,5 +297,10 @@ 1.10.19 test + + org.apache.logging.log4j + log4j-to-slf4j + 2.11.2 + From 8649ad01d084b5a4e267908799b6272f26e6cf0a Mon Sep 17 00:00:00 2001 From: "Tochiori, Yasufumi" Date: Wed, 19 Jun 2019 13:31:16 +0900 Subject: [PATCH 5/7] Replace tabs with spaces --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e74189e..d08cef2 100644 --- a/pom.xml +++ b/pom.xml @@ -298,9 +298,9 @@ test - org.apache.logging.log4j - log4j-to-slf4j - 2.11.2 + org.apache.logging.log4j + log4j-to-slf4j + 2.11.2 From defc4cd42762e998d36a73d6c02ddffc8c1c9535 Mon Sep 17 00:00:00 2001 From: "Tochiori, Yasufumi" Date: Wed, 19 Jun 2019 13:48:34 +0900 Subject: [PATCH 6/7] Add comment --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index d08cef2..66b1d31 100644 --- a/pom.xml +++ b/pom.xml @@ -297,6 +297,7 @@ 1.10.19 test + org.apache.logging.log4j log4j-to-slf4j From c2ce2ca00bc739d0f9e47eaecf4daf3a481bdd38 Mon Sep 17 00:00:00 2001 From: "Tochiori, Yasufumi" Date: Fri, 21 Jun 2019 14:01:42 +0900 Subject: [PATCH 7/7] Release v1_es6.6.1-5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 66b1d31..eaf9947 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ io.personium personium-lib-es-adapter jar - 1_es6.6.1_5-SNAPSHOT + 1_es6.6.1_5 The Apache Software License, Version 2.0