|
9 | 9 |
|
10 | 10 | import com.appdynamics.extensions.util.AssertUtils; |
11 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; |
12 | | -import com.google.common.base.Strings; |
13 | 12 | import com.google.common.collect.Maps; |
14 | 13 |
|
15 | 14 | import java.util.List; |
16 | 15 | import java.util.Map; |
17 | 16 |
|
18 | | -/** |
19 | | - * Created by bhuvnesh.kumar on 10/5/17. |
20 | | - */ |
21 | 17 | public class ColumnGenerator { |
22 | 18 |
|
23 | 19 | public List<Column> getColumns(Map query) { |
24 | | - AssertUtils.assertNotNull(query.get("columns"),"Queries need to have columns configured."); |
25 | | - |
26 | | - Map<String, Map<String, String>> filter = Maps.newLinkedHashMap(); |
27 | | - filter = filterMap(query, "columns"); |
28 | | - final ObjectMapper mapper = new ObjectMapper(); // jackson’s objectmapper |
29 | | - final Columns columns = mapper.convertValue(filter, Columns.class); |
30 | | - return columns.getColumns(); |
31 | | - } |
| 20 | + Object columnsObj = query.get("columns"); |
| 21 | + AssertUtils.assertNotNull(columnsObj, "Queries need to have columns configured."); |
32 | 22 |
|
33 | | - private Map<String, Map<String, String>> filterMap( Map<String, Map<String, String>> mapOfMaps, String filterKey) { |
34 | | - Map<String, Map<String, String>> filteredOnKeyMap = Maps.newLinkedHashMap(); |
| 23 | + Map<String, Object> wrapper = Maps.newLinkedHashMap(); |
| 24 | + wrapper.put("columns", columnsObj); |
35 | 25 |
|
36 | | - if (Strings.isNullOrEmpty(filterKey)) |
37 | | - return filteredOnKeyMap; |
38 | | - |
39 | | - if (mapOfMaps.containsKey(filterKey)) { |
40 | | - filteredOnKeyMap.put(filterKey,mapOfMaps.get(filterKey)); |
41 | | - } |
42 | | - |
43 | | - return filteredOnKeyMap; |
| 26 | + final ObjectMapper mapper = new ObjectMapper(); |
| 27 | + final Columns columns = mapper.convertValue(wrapper, Columns.class); |
| 28 | + return columns.getColumns(); |
44 | 29 | } |
45 | 30 | } |
0 commit comments