EventLogServiceImpl implements EventLogService { @Override public XLog getXLogWithStats(Integer logId) { XFactory factory = XFactoryRegistry.instance().currentDefault(); XAttribute parent; XLog log = getXLog(logId); XAttribute containerAttribute = factory.createAttributeLiteral(STAT_NODE_NAME, "", null); log.getAttributes().put(STAT_NODE_NAME, containerAttribute); List<Statistic> stats = getStats(logId); if (stats != null && !stats.isEmpty()) { for (int i = 0; i < stats.size(); i++) { Statistic pStat = stats.get(i); byte[] parentId = pStat.getId(); if (Arrays.equals(pStat.getPid(), PARENT_NODE_FLAG.getBytes())) { parent = factory.createAttributeLiteral(pStat.getStat_key(), pStat.getStat_value(), null); XAttributeMap attributeMap = factory.createAttributeMap(); for (int j = 1; j < stats.size(); j++) { if (i + j < stats.size()) { if (Arrays.equals(stats.get(i + j).getPid(), parentId)) { XAttribute attribute = factory.createAttributeLiteral(stats.get(i + j).getStat_key(), stats.get(i + j).getStat_value(), null); attributeMap.put(stats.get(i + j).getStat_key(), attribute); } else { i = i + j - 1; break; } } } parent.setAttributes(attributeMap); log.getAttributes().get(STAT_NODE_NAME).getAttributes().put(pStat.getCount().toString(), parent); } } } return log; } @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 getXLogWithStatsTest() { List<Statistic> stats = new ArrayList<>(); Integer logId = 001; Statistic parent = new Statistic(); parent.setId(UuidAdapter.getBytesFromUUID(UUID.randomUUID())); parent.setStat_key("parent_key"); parent.setLogid(logId); parent.setPid("0".getBytes()); parent.setStat_value("01"); parent.setCount((long) 1); stats.add(parent); Statistic child = new Statistic(); child.setId(UuidAdapter.getBytesFromUUID(UUID.randomUUID())); child.setStat_key("child_key"); child.setLogid(logId); child.setPid(parent.getId()); child.setStat_value("02"); child.setCount((long) 2); stats.add(child); Statistic parent1 = new Statistic(); parent1.setId(UuidAdapter.getBytesFromUUID(UUID.randomUUID())); parent1.setStat_key("parent_key1"); parent1.setLogid(logId); parent1.setPid("0".getBytes()); parent1.setStat_value("03"); parent1.setCount((long) 3); stats.add(parent1); Statistic child1 = new Statistic(); child1.setId(UuidAdapter.getBytesFromUUID(UUID.randomUUID())); child1.setStat_key("child_key1"); child1.setLogid(logId); child1.setPid(parent1.getId()); child1.setStat_value("04"); child1.setCount((long) 4); stats.add(child1); expect(statisticRepository.findByLogid(logId)).andReturn(stats); replay(statisticRepository); Log log = new Log(); XLog xlog = new XLogImpl(new XAttributeMapImpl()); expect(logRepository.findUniqueByID(logId)).andReturn(log); expect(logRepository.getProcessLog(log, null)).andReturn(xlog); replay(logRepository); XLog expectResult = eventLogService.getXLogWithStats(logId); verify(statisticRepository, logRepository); XAttribute statsAttribute = expectResult.getAttributes().get(STAT_NODE_NAME); assertThat(statsAttribute, equalTo(new XAttributeLiteralImpl(STAT_NODE_NAME, ""))); assertThat(statsAttribute.getAttributes().size(), equalTo(2)); assertThat(statsAttribute.getAttributes().get(parent.getCount().toString()), equalTo(new XAttributeLiteralImpl("parent_key", "01"))); assertThat(statsAttribute.getAttributes().get(parent.getCount().toString()).getAttributes().size(), equalTo(1)); assertThat(statsAttribute.getAttributes().get(parent.getCount().toString()).getAttributes().get(child.getStat_key()), equalTo(new XAttributeLiteralImpl("child_key", "02"))); }