EventLogServiceImpl implements EventLogService { public List<Statistic> flattenNestedStringMap(Map<String, Map<String, String>> map, Integer logId, StatType statType) { if (map == null || logId == null || statType == null) { throw new IllegalArgumentException(); } List<Statistic> statList = new ArrayList<>(); for (Map.Entry<String, Map<String, String>> option : map.entrySet()) { Statistic parent = new Statistic(); if (option.getKey() != null && option.getValue() != null) { parent.setId(UuidAdapter.getBytesFromUUID(UUID.randomUUID())); parent.setStat_key(statType.toString()); parent.setStat_value(option.getKey()); parent.setLogid(logId); parent.setPid(PARENT_NODE_FLAG.getBytes()); statList.add(parent); } HashMap<String, String> options_frequency = (HashMap<String, String>) option.getValue(); if (options_frequency != null) { for (Map.Entry<String, String> entry : options_frequency.entrySet()) { Statistic child = new Statistic(); if (entry.getKey() != null && entry.getValue() != null) { child.setId(UuidAdapter.getBytesFromUUID(UUID.randomUUID())); child.setStat_key(entry.getKey()); child.setStat_value(entry.getValue()); child.setLogid(logId); child.setPid(parent.getId()); statList.add(child); } } } } return statList; } @Inject  EventLogServiceImpl(final LogRepository logRepository, final GroupRepository groupRepository,
                               final GroupLogRepository groupLogRepository, final FolderRepository folderRepo,
                               final UserService userSrv, final UserInterfaceHelper ui,
                               final StatisticRepository statisticRepository, final ConfigBean configBean, final DashboardLayoutRepository dashboardLayoutRepository); static XLog importFromStream(XFactory factory, InputStream is, String extension); @Override SummariesType readLogSummaries(Integer folderId, String searchExpression); @Override Log importLog(String username, Integer folderId, String logName, InputStream inputStreamLog,
                         String extension, String domain, String created, boolean publicModel); @Override void updateLogMetaData(Integer logId, String logName, boolean isPublic); @Override boolean isPublicLog(Integer logId); @Override ExportLogResultType exportLog(Integer logId); @Override void cloneLog(String username, Integer folderId, String logName, Integer sourceLogId,
                  String domain, String created, boolean publicModel); @Override XLog getXLog(Integer logId); @Override XLog getXLog(Integer logId, String factoryName); @Override XLog getXLogWithStats(Integer logId); List<Statistic> getStats(Integer logId); List<?> getStatsByType(Integer logId, StatType statType); @Override boolean isStatsExists(Integer logId, StatType statType); @Override void storeStats(Map<String, Map<String, Integer>> map, Integer logId); void storeStatsByType(Map<String, Map<String, String>> map, Integer logId, StatType statType); List<Statistic> flattenNestedStringMap(Map<String, Map<String, String>> map, Integer logId,
                                                  StatType statType); List<Statistic> flattenNestedMap(Map<String, Map<String, Integer>> map, Integer logId); @Override void deleteLogs(List<Log> logs, User user); @Override void exportToStream(OutputStream outputStream, XLog log); @Override APMLog getAggregatedLog(Integer logId); String getLayoutByLogId(Integer userId, Integer logId); void saveLayoutByLogId(Integer logId, Integer userId, String layout); static final String PARENT_NODE_FLAG; static final String STAT_NODE_NAME; }
@Test public void flattenNestedStringMapTest() { Map<String, Map<String, String>> options = new HashMap<>(); Map<String, String> options_frequency = new HashMap<>(); options_frequency.put("Activity", "10"); options_frequency.put("direct:follow", "40"); options.put("concept:name", options_frequency); options.put("concept:test", options_frequency); List<Statistic> result = eventLogService.flattenNestedStringMap(options, 88, StatType.FILTER); assertThat(result.size(), equalTo(6)); assertThat(result.get(0).getPid(), equalTo("0".getBytes())); assertThat(result.get(0).getStat_key(), equalTo(StatType.FILTER.toString())); assertThat(result.get(0).getStat_value(), equalTo("concept:name")); assertThat(result.get(0).getLogid(), equalTo(88)); assertThat(result.get(1).getStat_key(), equalTo("direct:follow")); assertThat(result.get(1).getStat_value(), equalTo("40")); assertThat(result.get(1).getPid(), equalTo(result.get(0).getId())); assertThat(result.get(1).getLogid(), equalTo(88)); assertThat(result.get(2).getStat_key(), equalTo("Activity")); assertThat(result.get(2).getStat_value(), equalTo("10")); assertThat(result.get(3).getStat_key(), equalTo(StatType.FILTER.toString())); assertThat(result.get(3).getStat_value(), equalTo("concept:test")); assertThat(result.get(4).getStat_key(), equalTo("direct:follow")); assertThat(result.get(4).getStat_value(), equalTo("40")); assertThat(result.get(5).getStat_key(), equalTo("Activity")); assertThat(result.get(5).getStat_value(), equalTo("10")); }