Search in sources :

Example 1 with Criterion

use of org.asqatasun.entity.reference.Criterion in project Asqatasun by Asqatasun.

the class AnalyserImpl method computeCriterionStatisticsFromDb.

/**
     *
     * @param wrStatistics
     * @return
     */
private WebResourceStatistics computeCriterionStatisticsFromDb(WebResourceStatistics wrStatistics) {
    for (Criterion cr : criterionMap.keySet()) {
        CriterionStatistics criterionStatistics = criterionStatisticsDataService.create();
        criterionStatistics.setCriterion(cr);
        int nbOfFailed = criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.FAILED, cr).intValue();
        criterionStatistics.setNbOfFailed(nbOfFailed);
        int nbOfNa = criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.NOT_APPLICABLE, cr).intValue();
        criterionStatistics.setNbOfNa(nbOfNa);
        int nbOfPassed = criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.PASSED, cr).intValue();
        criterionStatistics.setNbOfPassed(nbOfPassed);
        int nbOfNmi = criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.NEED_MORE_INFO, cr).intValue();
        nbOfNmi += criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.SUSPECTED_FAILED, cr).intValue();
        nbOfNmi += criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.SUSPECTED_PASSED, cr).intValue();
        nbOfNmi += criterionStatisticsDataService.getResultCountByResultTypeAndCriterion(webResource, TestSolution.DETECTED, cr).intValue();
        criterionStatistics.setNbOfNmi(nbOfNmi);
        int criterionTestListSize = criterionMap.get(cr);
        criterionStatistics.setNbOfNotTested(criterionTestListSize * nbOfWr - nbOfFailed - nbOfNa - nbOfNmi - nbOfPassed);
        computeCriterionResult(criterionStatistics);
        wrStatistics.addCriterionStatistics(criterionStatistics);
    }
    return wrStatistics;
}
Also used : Criterion(org.asqatasun.entity.reference.Criterion) CriterionStatistics(org.asqatasun.entity.statistics.CriterionStatistics)

Example 2 with Criterion

use of org.asqatasun.entity.reference.Criterion in project Asqatasun by Asqatasun.

the class AnalyserImpl method extractThemeAndCriterionSet.

/**
     * This method extracts a collection of themes for a given audit
     *
     * @return
     */
private void extractThemeAndCriterionSet() {
    themeMap = new HashMap();
    criterionMap = new HashMap();
    for (Test test : testSet) {
        //Collect criterions given the set of tests for the audit, and keep
        // the number of tests for each criterion (needed to calculate the
        // not tested
        Criterion criterion = test.getCriterion();
        if (criterionMap.containsKey(criterion)) {
            Integer testCounter = criterionMap.get(criterion) + 1;
            criterionMap.put(criterion, testCounter);
        } else {
            criterionMap.put(criterion, 1);
        }
        //Collect themes given the set of tests for the audit, and keep
        // the number of tests for each criterion (needed to calculate the
        // not tested
        Theme theme = criterion.getTheme();
        if (themeMap.containsKey(theme)) {
            Integer testCounter = themeMap.get(theme) + 1;
            themeMap.put(theme, testCounter);
        } else {
            themeMap.put(theme, 1);
        }
    }
}
Also used : Test(org.asqatasun.entity.reference.Test) Criterion(org.asqatasun.entity.reference.Criterion) Theme(org.asqatasun.entity.reference.Theme)

Example 3 with Criterion

use of org.asqatasun.entity.reference.Criterion 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)

Example 4 with Criterion

use of org.asqatasun.entity.reference.Criterion in project Asqatasun by Asqatasun.

the class AuditResultController method displayCriterionResult.

/**
     *
     * @param webresourceId
     * @param criterionId
     * @param model
     * @return the test-result view name
     */
@RequestMapping(value = TgolKeyStore.CRITERION_RESULT_CONTRACT_URL, method = RequestMethod.GET)
public String displayCriterionResult(@RequestParam(TgolKeyStore.WEBRESOURCE_ID_KEY) String webresourceId, @RequestParam(TgolKeyStore.CRITERION_CODE_KEY) String criterionId, Model model) {
    Long wrId;
    Long critId;
    try {
        wrId = Long.valueOf(webresourceId);
        critId = Long.valueOf(criterionId);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException(getCurrentUser());
    }
    WebResource webResource = getWebResourceDataService().ligthRead(wrId);
    if (webResource == null || webResource instanceof Site) {
        throw new ForbiddenPageException();
    }
    Audit audit = getAuditFromWebResource(webResource);
    if (isUserAllowedToDisplayResult(audit)) {
        Contract contract = retrieveContractFromAudit(audit);
        // Attributes for breadcrumb
        model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId());
        model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel());
        model.addAttribute(TgolKeyStore.URL_KEY, webResource.getURL());
        Criterion crit = criterionDataService.read(critId);
        model.addAttribute(TgolKeyStore.CRITERION_LABEL_KEY, crit.getLabel());
        model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId());
        // Add a boolean used to display the breadcrumb.
        model.addAttribute(TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit));
        model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY, TestResultFactory.getInstance().getTestResultListFromCriterion(webResource, crit));
        return TgolKeyStore.CRITERION_RESULT_VIEW_NAME;
    } else {
        throw new ForbiddenPageException();
    }
}
Also used : Site(org.asqatasun.entity.subject.Site) Audit(org.asqatasun.entity.audit.Audit) Criterion(org.asqatasun.entity.reference.Criterion) WebResource(org.asqatasun.entity.subject.WebResource) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) Contract(org.asqatasun.webapp.entity.contract.Contract) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Criterion

use of org.asqatasun.entity.reference.Criterion in project Asqatasun by Asqatasun.

the class PageListControllerTest method setUpThemeDataService.

/**
     * 
     */
private void setUpThemeDataService() {
    mockThemeDataService = createMock(ThemeDataService.class);
    mockTheme = createMock(Theme.class);
    Collection<Theme> themeCollection = new ArrayList();
    themeCollection.add(mockTheme);
    Reference mockReference = createMock(Reference.class);
    Criterion mockCriterion = createMock(Criterion.class);
    Collection<Criterion> criterionCollection = new ArrayList();
    criterionCollection.add(mockCriterion);
    expect(mockThemeDataService.findAll()).andReturn(themeCollection).anyTimes();
    expect(mockTheme.getCriterionList()).andReturn(criterionCollection).anyTimes();
    expect(mockCriterion.getReference()).andReturn(mockReference).anyTimes();
    expect(mockReference.getCode()).andReturn("AW21").anyTimes();
    replay(mockTheme);
    replay(mockCriterion);
    replay(mockReference);
    replay(mockThemeDataService);
}
Also used : Criterion(org.asqatasun.entity.reference.Criterion) ThemeDataService(org.asqatasun.entity.service.reference.ThemeDataService) Reference(org.asqatasun.entity.reference.Reference) Theme(org.asqatasun.entity.reference.Theme)

Aggregations

Criterion (org.asqatasun.entity.reference.Criterion)5 Theme (org.asqatasun.entity.reference.Theme)3 CriterionStatistics (org.asqatasun.entity.statistics.CriterionStatistics)2 HashMap (java.util.HashMap)1 Audit (org.asqatasun.entity.audit.Audit)1 ProcessResult (org.asqatasun.entity.audit.ProcessResult)1 TestSolution (org.asqatasun.entity.audit.TestSolution)1 WebResourceStatisticsDAO (org.asqatasun.entity.dao.statistics.WebResourceStatisticsDAO)1 Reference (org.asqatasun.entity.reference.Reference)1 Test (org.asqatasun.entity.reference.Test)1 ThemeDataService (org.asqatasun.entity.service.reference.ThemeDataService)1 ThemeStatistics (org.asqatasun.entity.statistics.ThemeStatistics)1 WebResourceStatistics (org.asqatasun.entity.statistics.WebResourceStatistics)1 Site (org.asqatasun.entity.subject.Site)1 WebResource (org.asqatasun.entity.subject.WebResource)1 Contract (org.asqatasun.webapp.entity.contract.Contract)1 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)1 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1