From beb55a493a3b327bb7f184b65a9430b8e393b0f8 Mon Sep 17 00:00:00 2001 From: lucashimpens Date: Wed, 19 Jun 2024 14:39:41 +0200 Subject: [PATCH] feat(tagstatistic): create system to populate tagstatistic table --- .../core/crud/dao/ITagStatisticDAO.java | 78 +++++ .../core/crud/dao/impl/TagStatisticDAO.java | 267 ++++++++++++++++++ .../crud/service/ITagStatisticService.java | 53 ++++ .../core/crud/service/impl/TagService.java | 25 +- .../service/impl/TagStatisticService.java | 215 ++++++++++++++ 5 files changed, 630 insertions(+), 8 deletions(-) create mode 100644 source/src/main/java/org/cerberus/core/crud/dao/ITagStatisticDAO.java create mode 100644 source/src/main/java/org/cerberus/core/crud/dao/impl/TagStatisticDAO.java create mode 100644 source/src/main/java/org/cerberus/core/crud/service/ITagStatisticService.java create mode 100644 source/src/main/java/org/cerberus/core/crud/service/impl/TagStatisticService.java diff --git a/source/src/main/java/org/cerberus/core/crud/dao/ITagStatisticDAO.java b/source/src/main/java/org/cerberus/core/crud/dao/ITagStatisticDAO.java new file mode 100644 index 000000000..97dd093af --- /dev/null +++ b/source/src/main/java/org/cerberus/core/crud/dao/ITagStatisticDAO.java @@ -0,0 +1,78 @@ +/** + * Cerberus Copyright (C) 2013 - 2017 cerberustesting + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This file is part of Cerberus. + * + * Cerberus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cerberus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cerberus. If not, see . + */ +package org.cerberus.core.crud.dao; + +import org.cerberus.core.crud.entity.TagStatistic; +import org.cerberus.core.util.answer.Answer; +import org.cerberus.core.util.answer.AnswerList; + +import java.util.Map; + +/** + * Interface that defines the public methods to manage Application data on table + * Create Read Update Delete + * + * @author lhimpens + */ +public interface ITagStatisticDAO { + + /** + * Insert a unique line of TagStatistic in database + * @param object + * @return + */ + Answer create(TagStatistic object); + + /** + * Insert a list of tagStatistics in only one INSERT statement + * @param tagStatistics + * @return + */ + Answer createWithMap(Map tagStatistics); + + /** + * Get a TagStatistic object from database + * @param object + * @return + */ + Answer read(TagStatistic object); + + /** + * Get a TagStatistics list by tag from database + * @param tag + * @return + */ + AnswerList readByTag(String tag); + + /** + * Update a TagStatistic + * @param object + * @return + */ + Answer update(TagStatistic object); + + /** + * Delete a TagStatistic object in database + * @param tag + * @param object + * @return + */ + Answer delete(String tag, TagStatistic object); +} diff --git a/source/src/main/java/org/cerberus/core/crud/dao/impl/TagStatisticDAO.java b/source/src/main/java/org/cerberus/core/crud/dao/impl/TagStatisticDAO.java new file mode 100644 index 000000000..7fafdca6a --- /dev/null +++ b/source/src/main/java/org/cerberus/core/crud/dao/impl/TagStatisticDAO.java @@ -0,0 +1,267 @@ +/** + * Cerberus Copyright (C) 2013 - 2017 cerberustesting + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This file is part of Cerberus. + * + * Cerberus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cerberus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cerberus. If not, see . + */ +package org.cerberus.core.crud.dao.impl; + +import lombok.AllArgsConstructor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.cerberus.core.crud.dao.ITagStatisticDAO; +import org.cerberus.core.crud.entity.TagStatistic; +import org.cerberus.core.database.DatabaseSpring; +import org.cerberus.core.engine.entity.MessageEvent; +import org.cerberus.core.enums.MessageEventEnum; +import org.cerberus.core.util.ParameterParserUtil; +import org.cerberus.core.util.answer.Answer; +import org.cerberus.core.util.answer.AnswerList; +import org.springframework.stereotype.Repository; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@AllArgsConstructor +@Repository +public class TagStatisticDAO implements ITagStatisticDAO { + private static final int MAX_ROW_SELECTED = 100000; + + private final DatabaseSpring databaseSpring; + + private static final String OBJECT_NAME = "TagStatistic"; + + private static final Logger LOG = LogManager.getLogger(TagStatisticDAO.class); + + /** + * Insert a unique line of TagStatistic in database + * @param object + * @return + */ + @Override + public Answer create(TagStatistic object) { + throw new UnsupportedOperationException(); + } + + /** + * Insert a list of tagStatistics in only one INSERT statement + * @param tagStatistics + * @return + */ + @Override + public Answer createWithMap(Map tagStatistics) { + MessageEvent msg; + StringBuilder placeholders = new StringBuilder(); + String baseQuery ="INSERT INTO tagstatistic (`Tag`, `Country`, `Environment`, `Campaign`, `CampaignGroup1`, `SystemList`, `ApplicationList`, `DateStartExe`, `DateEndExe`, `NbExe`, `NbExeUsefull`, `NbOK`, `nbKO`, `nbFA`, `nbNA`, `nbNE`, `nbWE`, `nbPE`, `nbQU`, `nbQE`, `nbCA`, `UsrCreated`) VALUES "; + placeholders.append("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + if (tagStatistics.size() > 1) { + for (int i = 1; i < tagStatistics.size(); i++) { + placeholders.append(", (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + } + } + String query = baseQuery + placeholders.toString(); + + try (Connection connection = this.databaseSpring.connect(); + PreparedStatement preStat = connection.prepareStatement(query)) { + int parameterIndex = 1; + for (Map.Entry tagStatisticEntry : tagStatistics.entrySet()) { + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getTag()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getCountry()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getEnvironment()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getCampaign()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getCampaignGroup1()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getSystemList()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getApplicationList()); + preStat.setTimestamp(parameterIndex++, tagStatisticEntry.getValue().getDateStartExe()); + preStat.setTimestamp(parameterIndex++, tagStatisticEntry.getValue().getDateEndExe()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbExe()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbExeUsefull()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbOK()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbKO()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbFA()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbNA()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbNE()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbWE()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbPE()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbQU()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbQE()); + preStat.setInt(parameterIndex++, tagStatisticEntry.getValue().getNbCA()); + preStat.setString(parameterIndex++, tagStatisticEntry.getValue().getUsrCreated()); + } + + preStat.executeUpdate(); + msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); + msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT")); + + } catch (SQLException exception) { + LOG.error("Unable to execute query : {}", exception.toString()); + msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE); + msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString())); + } + return new Answer(msg); + } + + /** + * Get a TagStatistic object from database + * @param object + * @return + */ + @Override + public Answer read(TagStatistic object) { + return null; + } + + /** + * Get a TagStatistics list by tag from database + * @param tag + * @return + */ + @Override + public AnswerList readByTag(String tag) { + AnswerList response = new AnswerList<>(); + MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); + msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "")); + List tagStatistics = new ArrayList<>(); + + String query ="SELECT * FROM `tagstatistic` WHERE `tag` = ?"; + LOG.debug("SQL : {}", query); + + try (Connection connection = this.databaseSpring.connect(); + PreparedStatement preStat = connection.prepareStatement(query); + Statement stm = connection.createStatement()) { + preStat.setString(1, tag); + + try (ResultSet resultSet = preStat.executeQuery(); + ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) { + + while (resultSet.next()) { + tagStatistics.add(this.loadFromResultSet(resultSet)); + } + + int nrTotalRows = 0; + if (rowSet != null && rowSet.next()) { + nrTotalRows = rowSet.getInt(1); + } + + if (tagStatistics.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList. + LOG.error("Partial Result in the query."); + msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT); + msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED)); + } else if (tagStatistics.isEmpty()) { + msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND); + } else { + msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); + msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT")); + } + response = new AnswerList<>(tagStatistics, nrTotalRows); + } + } catch (SQLException exception) { + LOG.error("Unable to execute query : {}", exception.toString()); + msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); + msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString())); + } + response.setResultMessage(msg); + response.setDataList(tagStatistics); + return response; + } + + /** + * Update a TagStatistic + * @param object + * @return + */ + @Override + public Answer update(TagStatistic object) { + throw new UnsupportedOperationException(); + } + + /** + * Delete a TagStatistic object in database + * @param tag + * @param object + * @return + */ + @Override + public Answer delete(String tag, TagStatistic object) { + throw new UnsupportedOperationException(); + } + + /** + * Convert a database result set into entity + * @param resultSet + * @return + * @throws SQLException + */ + private TagStatistic loadFromResultSet(ResultSet resultSet) throws SQLException { + long id = ParameterParserUtil.parseLongParam(resultSet.getString("Id"), 0); + String tag = ParameterParserUtil.parseStringParam(resultSet.getString("Tag"), ""); + String country = ParameterParserUtil.parseStringParam(resultSet.getString("Country"), ""); + String environment = ParameterParserUtil.parseStringParam(resultSet.getString("Environment"), ""); + String campaign = ParameterParserUtil.parseStringParam(resultSet.getString("Campaign"), ""); + String campaignGroup1 = ParameterParserUtil.parseStringParam(resultSet.getString("CampaignGroup1"), ""); + String systemList = ParameterParserUtil.parseStringParam(resultSet.getString("SystemList"), ""); + String applicationList = ParameterParserUtil.parseStringParam(resultSet.getString("ApplicationList"), ""); + Timestamp dateStartExe = resultSet.getTimestamp("DateStartExe"); + Timestamp dateEndExe = resultSet.getTimestamp("DateEndExe"); + int nbExe = resultSet.getInt("nbExe"); + int nbExeUsefull = resultSet.getInt("nbExeUsefull"); + int nbOK = resultSet.getInt("nbOK"); + int nbKO = resultSet.getInt("nbKO"); + int nbFA = resultSet.getInt("nbFA"); + int nbNA = resultSet.getInt("nbNA"); + int nbNE = resultSet.getInt("nbNE"); + int nbWE = resultSet.getInt("nbWE"); + int nbPE = resultSet.getInt("nbPE"); + int nbQU = resultSet.getInt("nbQU"); + int nbQE = resultSet.getInt("nbQE"); + int nbCA = resultSet.getInt("nbCA"); + String usrModif = ParameterParserUtil.parseStringParam(resultSet.getString("UsrModif"), ""); + String usrCreated = ParameterParserUtil.parseStringParam(resultSet.getString("UsrCreated"), ""); + Timestamp dateModif = resultSet.getTimestamp("DateModif"); + Timestamp dateCreated = resultSet.getTimestamp("DateCreated"); + + return TagStatistic.builder() + .id(id) + .tag(tag) + .country(country) + .environment(environment) + .campaign(campaign) + .campaignGroup1(campaignGroup1) + .systemList(systemList) + .applicationList(applicationList) + .dateStartExe(dateStartExe) + .dateEndExe(dateEndExe) + .nbExe(nbExe) + .nbExeUsefull(nbExeUsefull) + .nbOK(nbOK) + .nbKO(nbKO) + .nbFA(nbFA) + .nbNA(nbNA) + .nbNE(nbNE) + .nbWE(nbWE) + .nbPE(nbPE) + .nbQU(nbQU) + .nbQE(nbQE) + .nbCA(nbCA) + .usrCreated(usrCreated) + .usrModif(usrModif) + .dateCreated(dateCreated) + .dateModif(dateModif) + .build(); + } +} diff --git a/source/src/main/java/org/cerberus/core/crud/service/ITagStatisticService.java b/source/src/main/java/org/cerberus/core/crud/service/ITagStatisticService.java new file mode 100644 index 000000000..7a25f947b --- /dev/null +++ b/source/src/main/java/org/cerberus/core/crud/service/ITagStatisticService.java @@ -0,0 +1,53 @@ +/** + * Cerberus Copyright (C) 2013 - 2017 cerberustesting + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This file is part of Cerberus. + * + * Cerberus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cerberus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cerberus. If not, see . + */ +package org.cerberus.core.crud.service; + +import org.cerberus.core.crud.entity.Tag; +import org.cerberus.core.crud.entity.TagStatistic; +import org.cerberus.core.crud.entity.TestCaseExecution; +import org.cerberus.core.util.answer.AnswerList; + +import java.util.List; +import java.util.Map; +public interface ITagStatisticService { + + /** + * @param tag + * @return AnswerList that contains data from database + */ + AnswerList readByTag(String tag); + + /** + * Initialize TagStatistics objects + * @param tag + * @param executions + * @return Map with TagStatistics initialized + */ + Map initTagStatistics(Tag tag, List executions); + + /** + * Populate TagStatistics objects with aggregated data + * @param tagStatistics + * @param executions + * @param tag + */ + void populateTagStatisticsMap(Map tagStatistics, List executions, Tag tag); + +} diff --git a/source/src/main/java/org/cerberus/core/crud/service/impl/TagService.java b/source/src/main/java/org/cerberus/core/crud/service/impl/TagService.java index 9b433a50a..e32fe8f5b 100644 --- a/source/src/main/java/org/cerberus/core/crud/service/impl/TagService.java +++ b/source/src/main/java/org/cerberus/core/crud/service/impl/TagService.java @@ -22,15 +22,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.cerberus.core.crud.dao.ITagDAO; -import org.cerberus.core.crud.entity.Campaign; -import org.cerberus.core.crud.entity.EventHook; -import org.cerberus.core.crud.entity.Tag; -import org.cerberus.core.crud.entity.TestCaseExecution; +import org.cerberus.core.crud.entity.*; import org.cerberus.core.crud.factory.IFactoryTag; -import org.cerberus.core.crud.service.ICampaignService; -import org.cerberus.core.crud.service.ITagService; -import org.cerberus.core.crud.service.ITestCaseExecutionQueueService; -import org.cerberus.core.crud.service.ITestCaseExecutionService; +import org.cerberus.core.crud.service.*; import org.cerberus.core.engine.entity.MessageGeneral; import org.cerberus.core.enums.MessageEventEnum; import org.cerberus.core.enums.MessageGeneralEnum; @@ -81,6 +75,10 @@ public class TagService implements ITagService { private IEventService eventService; @Autowired private ICampaignService campaignService; + @Autowired + private IParameterService parameterService; + @Autowired + private ITagStatisticService tagStatisticService; private static final Logger LOG = LogManager.getLogger("TagService"); @@ -221,6 +219,17 @@ public Answer updateEndOfQueueData(String tag) { } } + //TagStatistics, only if it's a campaign and if parameter is activated + if (StringUtil.isNotEmpty(mytag.getCampaign()) && parameterService.getParameterBooleanByKey(Parameter.VALUE_cerberus_featureflipping_tagstatistics_enable, "", false )) { + LOG.info("TagStatistics creation for tag {} started.", tag); + tagStatisticService.populateTagStatisticsMap( + tagStatisticService.initTagStatistics(mytag, executions), + executions, + mytag + ); + LOG.info("TagStatistics creation for tag {} finished.", tag); + } + return tagDAO.updateDateEndQueue(mytag); } catch (CerberusException ex) { diff --git a/source/src/main/java/org/cerberus/core/crud/service/impl/TagStatisticService.java b/source/src/main/java/org/cerberus/core/crud/service/impl/TagStatisticService.java new file mode 100644 index 000000000..60a19a9ed --- /dev/null +++ b/source/src/main/java/org/cerberus/core/crud/service/impl/TagStatisticService.java @@ -0,0 +1,215 @@ +/** + * Cerberus Copyright (C) 2013 - 2017 cerberustesting + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This file is part of Cerberus. + * + * Cerberus is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cerberus is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cerberus. If not, see . + */ +package org.cerberus.core.crud.service.impl; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.cerberus.core.crud.dao.ITagStatisticDAO; +import org.cerberus.core.crud.entity.Tag; +import org.cerberus.core.crud.entity.TagStatistic; +import org.cerberus.core.crud.entity.TestCaseExecution; +import org.cerberus.core.crud.service.ICampaignService; +import org.cerberus.core.crud.service.ITagStatisticService; +import org.cerberus.core.exception.CerberusException; +import org.cerberus.core.util.answer.AnswerList; +import org.json.JSONArray; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class TagStatisticService implements ITagStatisticService { + + private static final Logger LOG = LogManager.getLogger("TagStatisticService"); + + @Autowired + private ITagStatisticDAO tagStatisticDAO; + + @Autowired + private ICampaignService campaignService; + + /** + * @param tag + * @return AnswerList that contains data from database + */ + public AnswerList readByTag(String tag) { + return tagStatisticDAO.readByTag(tag); + } + + /** + * Initialize TagStatistics objects + * @param tag + * @param executions + * @return Map with TagStatistics initialized + */ + public HashMap initTagStatistics(Tag tag, List executions) { + + String campaignGroup1 = getCampaignGroup1(tag.getCampaign()); + HashMap tagStatistics = new HashMap<>(); + + for (TestCaseExecution execution : executions) { + String key = String.format("%s_%s", execution.getEnvironment(), execution.getCountry()); + if (!tagStatistics.containsKey(key)) { + tagStatistics.put( + key, + TagStatistic.builder() + .tag(tag.getTag()) + .country(execution.getCountry()) + .environment(execution.getEnvironment()) + .campaign(tag.getCampaign()) + .dateStartExe(new Timestamp(0)) + .dateEndExe(new Timestamp(0)) + .campaignGroup1(campaignGroup1) + .executions(new ArrayList<>()) + .build()); + } + tagStatistics.get(key).getExecutions().add(execution); + } + return tagStatistics; + } + + /** + * Populate TagStatistics objects with aggregated data + * @param tagStatistics + * @param executions + * @param tag + */ + public void populateTagStatisticsMap(Map tagStatistics, List executions, Tag tag) { + for (Map.Entry tagStatisticEntry : tagStatistics.entrySet()) { + TagStatistic tagStatistic = tagStatisticEntry.getValue(); + List systems = new ArrayList<>(); + List applications = new ArrayList<>(); + + for (TestCaseExecution execution : tagStatistic.getExecutions()) { + calculateExecutionDates(tagStatistic, execution); + calculateNumberExecutionsByStatus(tagStatistic, execution); + populateSystemList(systems, execution); + populateApplicationList(applications, execution); + } + tagStatistic.setSystemList(new JSONArray(systems).toString()); + tagStatistic.setApplicationList(new JSONArray(applications).toString()); + tagStatistic.setUsrCreated(tag.getUsrCreated()); + tagStatistic.setExecutions(null); + } + tagStatisticDAO.createWithMap(tagStatistics); + } + + /** + * Used to calculate the start and end date for each TagStatistic + * @param tagStatistic + * @param execution + */ + private void calculateExecutionDates(TagStatistic tagStatistic, TestCaseExecution execution) { + if (tagStatistic.getDateStartExe().getTime() == 0 || (execution.getStart() < tagStatistic.getDateStartExe().getTime())) { + tagStatistic.setDateStartExe(new Timestamp(execution.getStart())); + } + if (tagStatistic.getDateEndExe().getTime() == 0 ||(execution.getEnd() > tagStatistic.getDateEndExe().getTime())) { + tagStatistic.setDateEndExe(new Timestamp(execution.getEnd())); + } + } + + /** + * Used to calculate number of executions by status for each TagStatistics + * @param tagStatistic + * @param execution + */ + private void calculateNumberExecutionsByStatus(TagStatistic tagStatistic, TestCaseExecution execution) { + int nbRetries = execution.getNbExecutions() - 1; + tagStatistic.setNbExe(tagStatistic.getNbExe() + execution.getNbExecutions()); + tagStatistic.setNbExeUsefull(tagStatistic.getNbExeUsefull() + (execution.getNbExecutions() - nbRetries)); + + switch(execution.getControlStatus()) { + case "OK": + tagStatistic.incrementNbOK(); + break; + case "KO": + tagStatistic.incrementNbKO(); + break; + case "FA": + tagStatistic.incrementNbFA(); + break; + case "NA": + tagStatistic.incrementNbNA(); + break; + case "NE": + tagStatistic.incrementNbNE(); + break; + case "WE": + tagStatistic.incrementNbWE(); + break; + case "PE": + tagStatistic.incrementNbPE(); + break; + case "QU": + tagStatistic.incrementNbQU(); + break; + case "QE": + tagStatistic.incrementNbQE(); + break; + case "CA": + tagStatistic.incrementNbCA(); + break; + default: + break; + } + } + + /** + * Populate the systems list for each TagStatistic object + * @param systems + * @param execution + */ + private void populateSystemList(List systems, TestCaseExecution execution) { + if (!systems.contains(execution.getSystem())) { + systems.add(execution.getSystem()); + } + } + + /** + * Populate the applications list for each TagStatistic object + * @param applications + * @param execution + */ + private void populateApplicationList(List applications, TestCaseExecution execution) { + if (!applications.contains(execution.getApplication())) { + applications.add(execution.getApplication()); + } + } + + /** + * Retrieve campaign group 1 + * @param campaign + * @return + */ + private String getCampaignGroup1(String campaign) { + String campaignGroup1 = ""; + try { + campaignGroup1 = campaignService.convert(campaignService.readByKey(campaign)).getGroup1(); + } catch (CerberusException exception) { + LOG.error("Unable to get campaign owner: ", exception); + } + return campaignGroup1; + } +}