@Test public void converFilterWithOneChildLevelThenReturnProperFilterPath() { List<Filter> filters = Arrays.asList(new Filter("layerCode.code", FilterOperator.Equal.getCode(), "layer code val"), new Filter("name", FilterOperator.Equal.getCode(), "ci type name val")); FilterPath path = QueryConverter.convertFilter(CiTypeDto.class, Arrays.asList("layerCode"), filters); assertThat(path.getFilters() .size(), equalTo(1)); assertThat(path.getJoinChildren() .size(), equalTo(1)); assertThat(path.getJoinChildren() .get(0) .getFilters() .size(), equalTo(1)); assertThat(path.getJoinChildren() .get(0) .getFilters() .get(0) .getField(), equalTo("code")); }
public static <T extends ResourceDto> FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters) { Map<String, List<Filter>> filterMap = new TreeMap<>(); filters.forEach(x -> { String name = x.getName(); String attrName; String path; int index = name.lastIndexOf("."); if (index == -1) { attrName = name; path = "."; } else { attrName = name.substring(index + 1); path = name.substring(0, index); } List<Filter> fs = filterMap.get(path); if (fs == null) { fs = new LinkedList<>(); } Filter attrFilter = new Filter(attrName, x.getOperator(), x.getValue()); fs.add(attrFilter); filterMap.put(path, fs); }); DtoNode rootNode = new DtoNode(".", dtoClazz, filterMap.get(".")); filterMap.forEach((k, v) -> { List<String> nodeHierachy = new LinkedList<>(); if (k.indexOf(".") == -1) { nodeHierachy.add(k); } else { String[] resHierachy = k.split("\\."); nodeHierachy = CollectionUtils.asLinkedList(resHierachy); } DtoNode curNode = getNode(rootNode, nodeHierachy, v); }); FilterPath rootFilterPath = convertDtoFilterTree(rootNode, null); return rootFilterPath; }
QueryConverter { public static <T extends ResourceDto> FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters) { Map<String, List<Filter>> filterMap = new TreeMap<>(); filters.forEach(x -> { String name = x.getName(); String attrName; String path; int index = name.lastIndexOf("."); if (index == -1) { attrName = name; path = "."; } else { attrName = name.substring(index + 1); path = name.substring(0, index); } List<Filter> fs = filterMap.get(path); if (fs == null) { fs = new LinkedList<>(); } Filter attrFilter = new Filter(attrName, x.getOperator(), x.getValue()); fs.add(attrFilter); filterMap.put(path, fs); }); DtoNode rootNode = new DtoNode(".", dtoClazz, filterMap.get(".")); filterMap.forEach((k, v) -> { List<String> nodeHierachy = new LinkedList<>(); if (k.indexOf(".") == -1) { nodeHierachy.add(k); } else { String[] resHierachy = k.split("\\."); nodeHierachy = CollectionUtils.asLinkedList(resHierachy); } DtoNode curNode = getNode(rootNode, nodeHierachy, v); }); FilterPath rootFilterPath = convertDtoFilterTree(rootNode, null); return rootFilterPath; } }
QueryConverter { public static <T extends ResourceDto> FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters) { Map<String, List<Filter>> filterMap = new TreeMap<>(); filters.forEach(x -> { String name = x.getName(); String attrName; String path; int index = name.lastIndexOf("."); if (index == -1) { attrName = name; path = "."; } else { attrName = name.substring(index + 1); path = name.substring(0, index); } List<Filter> fs = filterMap.get(path); if (fs == null) { fs = new LinkedList<>(); } Filter attrFilter = new Filter(attrName, x.getOperator(), x.getValue()); fs.add(attrFilter); filterMap.put(path, fs); }); DtoNode rootNode = new DtoNode(".", dtoClazz, filterMap.get(".")); filterMap.forEach((k, v) -> { List<String> nodeHierachy = new LinkedList<>(); if (k.indexOf(".") == -1) { nodeHierachy.add(k); } else { String[] resHierachy = k.split("\\."); nodeHierachy = CollectionUtils.asLinkedList(resHierachy); } DtoNode curNode = getNode(rootNode, nodeHierachy, v); }); FilterPath rootFilterPath = convertDtoFilterTree(rootNode, null); return rootFilterPath; }  }
QueryConverter { public static <T extends ResourceDto> FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters) { Map<String, List<Filter>> filterMap = new TreeMap<>(); filters.forEach(x -> { String name = x.getName(); String attrName; String path; int index = name.lastIndexOf("."); if (index == -1) { attrName = name; path = "."; } else { attrName = name.substring(index + 1); path = name.substring(0, index); } List<Filter> fs = filterMap.get(path); if (fs == null) { fs = new LinkedList<>(); } Filter attrFilter = new Filter(attrName, x.getOperator(), x.getValue()); fs.add(attrFilter); filterMap.put(path, fs); }); DtoNode rootNode = new DtoNode(".", dtoClazz, filterMap.get(".")); filterMap.forEach((k, v) -> { List<String> nodeHierachy = new LinkedList<>(); if (k.indexOf(".") == -1) { nodeHierachy.add(k); } else { String[] resHierachy = k.split("\\."); nodeHierachy = CollectionUtils.asLinkedList(resHierachy); } DtoNode curNode = getNode(rootNode, nodeHierachy, v); }); FilterPath rootFilterPath = convertDtoFilterTree(rootNode, null); return rootFilterPath; }  static QueryRequest convertToDomainQuery(QueryRequest dtoQueryRequest, Map<String, String> dtoToDomainFieldMap); static FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters); }
QueryConverter { public static <T extends ResourceDto> FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters) { Map<String, List<Filter>> filterMap = new TreeMap<>(); filters.forEach(x -> { String name = x.getName(); String attrName; String path; int index = name.lastIndexOf("."); if (index == -1) { attrName = name; path = "."; } else { attrName = name.substring(index + 1); path = name.substring(0, index); } List<Filter> fs = filterMap.get(path); if (fs == null) { fs = new LinkedList<>(); } Filter attrFilter = new Filter(attrName, x.getOperator(), x.getValue()); fs.add(attrFilter); filterMap.put(path, fs); }); DtoNode rootNode = new DtoNode(".", dtoClazz, filterMap.get(".")); filterMap.forEach((k, v) -> { List<String> nodeHierachy = new LinkedList<>(); if (k.indexOf(".") == -1) { nodeHierachy.add(k); } else { String[] resHierachy = k.split("\\."); nodeHierachy = CollectionUtils.asLinkedList(resHierachy); } DtoNode curNode = getNode(rootNode, nodeHierachy, v); }); FilterPath rootFilterPath = convertDtoFilterTree(rootNode, null); return rootFilterPath; }  static QueryRequest convertToDomainQuery(QueryRequest dtoQueryRequest, Map<String, String> dtoToDomainFieldMap); static FilterPath convertFilter(Class<T> dtoClazz, List<String> refResources, List<Filter> filters);  }