Search in sources :

Example 1 with WebResourceStatisticsDAO

use of org.asqatasun.entity.dao.statistics.WebResourceStatisticsDAO in project Asqatasun by Asqatasun.

the class WebResourceStatisticsDataServiceImpl method createWebResourceStatisticsForManualAudit.

@Override
public WebResourceStatistics createWebResourceStatisticsForManualAudit(Audit audit, WebResource webResource, List<ProcessResult> netResultList) {
    boolean isNewWebRs = false;
    WebResourceStatistics wrStats = ((WebResourceStatisticsDAO) entityDao).findWebResourceStatisticsByWebResource(webResource, true);
    if (wrStats == null) {
        wrStats = this.create();
        isNewWebRs = true;
    }
    Map<Criterion, CriterionStatistics> csMap = new HashMap<>();
    Map<Theme, ThemeStatistics> tsMap = new HashMap<>();
    //        Map<Theme, List<ProcessResult>> mapProcessResultBytheme = new HashMap<Theme, List<ProcessResult>>();
    int nbOfPassed = 0;
    int nbOfFailed = 0;
    int nbOfNmi = 0;
    int nbOfNa = 0;
    int nbOfDetected = 0;
    int nbOfSuspected = 0;
    int nbOfNt = 0;
    for (ProcessResult pr : netResultList) {
        // l'audit est manual
        if (pr.getManualValue() != null) {
            TestSolution prResult = (TestSolution) pr.getManualValue();
            switch(prResult) {
                case PASSED:
                    nbOfPassed++;
                    break;
                case FAILED:
                    nbOfFailed++;
                    break;
                case NOT_APPLICABLE:
                    nbOfNa++;
                    break;
                case NEED_MORE_INFO:
                case DETECTED:
                case SUSPECTED_FAILED:
                case SUSPECTED_PASSED:
                    nbOfNmi++;
                    break;
                case NOT_TESTED:
                    nbOfNt++;
                    break;
            }
            addResultToCriterionCounterMap(prResult, pr.getTest().getCriterion(), wrStats, csMap);
            addResultToThemeCounterMap(prResult, pr.getTest().getCriterion().getTheme(), wrStats, tsMap);
        } else {
            addResultToCriterionCounterMap(TestSolution.NOT_TESTED, pr.getTest().getCriterion(), wrStats, csMap);
            addResultToThemeCounterMap(TestSolution.NOT_TESTED, pr.getTest().getCriterion().getTheme(), wrStats, tsMap);
            nbOfNt++;
        }
    }
    wrStats.setNbOfFailed(wrStats.getNbOfFailed() + nbOfFailed);
    wrStats.setNbOfInvalidTest(wrStats.getNbOfInvalidTest() + nbOfFailed);
    wrStats.setNbOfPassed(wrStats.getNbOfPassed() + nbOfPassed);
    wrStats.setNbOfNmi(wrStats.getNbOfNmi() + nbOfNmi);
    wrStats.setNbOfNa(wrStats.getNbOfNa() + nbOfNa);
    wrStats.setNbOfDetected(wrStats.getNbOfDetected() + nbOfDetected);
    wrStats.setNbOfSuspected(wrStats.getNbOfSuspected() + nbOfSuspected);
    wrStats.setNbOfNotTested(wrStats.getNbOfNotTested() + nbOfNt);
    setWeightedResult(wrStats, webResource);
    wrStats.setHttpStatusCode(getHttpStatusCodeByWebResource(webResource.getId()));
    wrStats = computeMark(wrStats);
    wrStats = computeRawMark(wrStats);
    wrStats = computeNumberOfFailedOccurrences(wrStats, webResource, true);
    wrStats.setAudit(audit);
    wrStats.setWebResource(webResource);
    wrStats.setIsManualAuditStatistics(1);
    // criterionStatistics to the current webResourceStatistics
    if (isNewWebRs) {
        for (CriterionStatistics cs : csMap.values()) {
            computeCriterionResult(cs);
            wrStats.addCriterionStatistics(cs);
        }
        // Link each themeStatistics to the current webResourceStatistics
        for (ThemeStatistics ts : tsMap.values()) {
            wrStats.addThemeStatistics(ts);
        }
    } else {
        //recuperer les Crtiterion à partir de wrstat et id_criterion pour MAJ
        for (CriterionStatistics css : csMap.values()) {
            CriterionStatistics criterionStatisticsFromMap = csMap.get(css.getCriterion());
            CriterionStatistics criterionStatisticsDb = criterionStatisticsDAO.findCriterionStatisticsByWebResource(css.getCriterion(), wrStats);
            if (criterionStatisticsDb == null) {
                criterionStatisticsDb = criterionStatisticsDataService.create();
                criterionStatisticsDb.setWebResourceStatistics(wrStats);
                criterionStatisticsDb.setCriterion(css.getCriterion());
            }
            populateCriterionStatistics(criterionStatisticsDb, criterionStatisticsFromMap);
            computeCriterionResult(criterionStatisticsDb);
            criterionStatisticsDAO.saveOrUpdate(criterionStatisticsDb);
        }
        for (ThemeStatistics ts : tsMap.values()) {
            ThemeStatistics themeStatisticsFromMap = tsMap.get(ts.getTheme());
            ThemeStatistics themeStatisticsDb = themeStatisticsDAO.findThemeStatisticsByWebResource(ts.getTheme(), wrStats);
            if (themeStatisticsDb == null) {
                themeStatisticsDb = themeStatisticsDataService.create();
                themeStatisticsDb.setWebResourceStatistics(wrStats);
                themeStatisticsDb.setTheme(ts.getTheme());
            }
            populateThemeStatistics(themeStatisticsDb, themeStatisticsFromMap);
            themeStatisticsDAO.saveOrUpdate(themeStatisticsDb);
        }
    }
    this.saveOrUpdate(wrStats);
    return wrStats;
}
Also used : WebResourceStatisticsDAO(org.asqatasun.entity.dao.statistics.WebResourceStatisticsDAO) HashMap(java.util.HashMap) TestSolution(org.asqatasun.entity.audit.TestSolution) ProcessResult(org.asqatasun.entity.audit.ProcessResult) WebResourceStatistics(org.asqatasun.entity.statistics.WebResourceStatistics) Criterion(org.asqatasun.entity.reference.Criterion) Theme(org.asqatasun.entity.reference.Theme) ThemeStatistics(org.asqatasun.entity.statistics.ThemeStatistics) CriterionStatistics(org.asqatasun.entity.statistics.CriterionStatistics)

Aggregations

HashMap (java.util.HashMap)1 ProcessResult (org.asqatasun.entity.audit.ProcessResult)1 TestSolution (org.asqatasun.entity.audit.TestSolution)1 WebResourceStatisticsDAO (org.asqatasun.entity.dao.statistics.WebResourceStatisticsDAO)1 Criterion (org.asqatasun.entity.reference.Criterion)1 Theme (org.asqatasun.entity.reference.Theme)1 CriterionStatistics (org.asqatasun.entity.statistics.CriterionStatistics)1 ThemeStatistics (org.asqatasun.entity.statistics.ThemeStatistics)1 WebResourceStatistics (org.asqatasun.entity.statistics.WebResourceStatistics)1