Search in sources :

Example 56 with NoResultException

use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.

the class WebResourceStatisticsDAOImpl method findWeightedResultCountByResultType.

@Override
public BigDecimal findWeightedResultCountByResultType(Long webresourceId, Collection<Parameter> paramSet, TestSolution testSolution, boolean isManualAudit) {
    if (webresourceId == null) {
        return null;
    }
    String queryStringForAutomatic = "SELECT t FROM " + getWebResourceEntityClass().getName() + " r" + JOIN_PROCESS_RESULT + JOIN_TEST + " WHERE (r.id=:id OR r.parent.id=:id)" + " AND pr.definiteValue = :value";
    String queryStringForManual = "SELECT t FROM " + getWebResourceEntityClass().getName() + " r" + JOIN_PROCESS_RESULT + JOIN_TEST + " WHERE (r.id=:id OR r.parent.id=:id)" + " AND pr.manualDefiniteValue = :value";
    Query query;
    if (isManualAudit) {
        query = entityManager.createQuery(queryStringForManual);
    } else {
        query = entityManager.createQuery(queryStringForAutomatic);
    }
    query.setParameter("id", webresourceId);
    query.setParameter("value", testSolution);
    try {
        return computeWeightedCountFromTestList((List<Test>) query.getResultList(), paramSet);
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) Test(org.asqatasun.entity.reference.Test) NoResultException(javax.persistence.NoResultException)

Example 57 with NoResultException

use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.

the class WebResourceStatisticsDAOImpl method findNumberOfOccurrencesByWebResourceAndResultType.

@Override
public Long findNumberOfOccurrencesByWebResourceAndResultType(Long webresourceId, TestSolution testSolution, boolean isManualAudit) {
    if (webresourceId == null) {
        return null;
    }
    String queryStringForAutomatic = "SELECT count(pk.id) FROM " + getWebResourceEntityClass().getName() + " r" + JOIN_PROCESS_RESULT + " JOIN pr.remarkSet pk" + " WHERE (r.id=:id OR r.parent.id=:id)" + " AND pr.definiteValue = :value" + " AND pk.issue = :value";
    String queryStringForManual = "SELECT count(pk.id) FROM " + getWebResourceEntityClass().getName() + " r" + JOIN_PROCESS_RESULT + " JOIN pr.remarkSet pk" + " WHERE (r.id=:id OR r.parent.id=:id)" + " AND pr.manualDefiniteValue = :value" + " AND pk.issue = :value";
    Query query;
    if (isManualAudit) {
        query = entityManager.createQuery(queryStringForManual);
    } else {
        query = entityManager.createQuery(queryStringForAutomatic);
    }
    query.setParameter("id", webresourceId);
    query.setParameter("value", testSolution);
    try {
        return (Long) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 58 with NoResultException

use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.

the class WebResourceStatisticsDAOImpl method findResultCountByResultType.

@Override
public Long findResultCountByResultType(Long webresourceId, TestSolution testSolution) {
    if (webresourceId == null) {
        return null;
    }
    Query query = entityManager.createQuery("SELECT count (pr.id) FROM " + getWebResourceEntityClass().getName() + " r" + JOIN_PROCESS_RESULT + " WHERE (r.id=:id OR r.parent.id=:id)" + " AND pr.definiteValue = :value");
    query.setParameter("id", webresourceId);
    query.setParameter("value", testSolution);
    try {
        return (Long) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 59 with NoResultException

use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.

the class StatisticsDAOImpl method findWebResourceCountByAuditAndHttpStatusCode.

/**
     * Native sql query :
     * SELECT count(Id_Web_Resource_Statistics)
     * FROM WEB_RESOURCE_STATISTICS as wrs, WEB_RESOURCE as w 
     *       WHERE wrs.Id_Audit=:idAudit 
     *       AND wrs.Id_Web_Resource=w.Id_Web_Resource 
     *       AND wrs.Http_Status_Code like :httpStatusCode
     *       AND w.Url like %:containingValue%;
     *
     * The condition applied on the web resource is optionnal, depending on
     * if the given sequence is not null or empty
     *
     * @param idAudit
     * @param httpStatusCode
     * @param containingValue
     * @return
     *      the number of webresource for given audit, webresource and http return
     *      status code.
     */
@Override
public Long findWebResourceCountByAuditAndHttpStatusCode(Long idAudit, HttpStatusCodeFamily httpStatusCode, String invalidTestLabel, String containingValue) {
    boolean hasContainingValue = false;
    boolean hasInvalidTestConstraint = false;
    if (containingValue != null && !containingValue.isEmpty()) {
        hasContainingValue = true;
    }
    if (invalidTestLabel != null) {
        hasInvalidTestConstraint = true;
    }
    StringBuilder queryString = new StringBuilder();
    queryString.append(SELECT_STR);
    queryString.append(WEB_RESOURCE_STAT_COUNT);
    queryString.append(W_WRS_JOINTURE);
    if (hasInvalidTestConstraint) {
        queryString.append(PR_T_JOINTURE);
    }
    queryString.append(AUDIT_AND_STATUS_CODE_CONDITION);
    // HttpStatusCodeFamily.CODE4xx instance is passed as argument.
    if (httpStatusCode.equals(HttpStatusCodeFamily.f4xx)) {
        queryString.append(EXTRA_HTTP_STATUS_CODE_CONDITION);
    } else {
        queryString.append(')');
    }
    if (hasContainingValue) {
        queryString.append(CONTAINING_VALUE_CONDITION);
    }
    if (hasInvalidTestConstraint) {
        queryString.append(INVALID_TEST_CONDITION);
    }
    Query query = entityManager.createNativeQuery(queryString.toString());
    query.setParameter("httpStatusCode", httpStatusCode.getCode() + "%");
    if (httpStatusCode.equals(HttpStatusCodeFamily.f4xx)) {
        query.setParameter("extraHttpStatusCode", HttpStatusCodeFamily.f5xx.getCode() + "%");
    }
    query.setParameter("idAudit", idAudit);
    if (hasContainingValue) {
        query.setParameter("containingValue", "%" + containingValue + "%");
    }
    if (hasInvalidTestConstraint) {
        query.setParameter("invalidTestLabel", invalidTestLabel);
    }
    try {
        return (((BigInteger) query.getSingleResult()).longValue());
    } catch (NoResultException e) {
        return (long) 0;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 60 with NoResultException

use of javax.persistence.NoResultException in project Asqatasun by Asqatasun.

the class StatisticsDAOImpl method findWebResourceByAuditAndHttpStatusCode.

/**
     * Native sql query :
     * SELECT w.Url, w.Rank, wrs.Mark, wrs.Id_Web_Resource, wrs.Http_Status_Code
     * FROM WEB_RESOURCE_STATISTICS as wrs, WEB_RESOURCE as w
     *       WHERE wrs.Id_Audit=:idAudit
     *       AND wrs.Id_Web_Resource=w.Id_Web_Resource
     *       AND wrs.Http_Status_Code like :httpStatusCode
     *       AND w.Url like %:containingValue%;
     *       ORDER BY $orderValue
     *       $sortDirection
     *       LIMIT :nbOfResult,:window 
     *
     * The condition applied on the web resource is optional, depending on
     * if the given sequence is not null or empty
     *
     * The $orderValue can be set to "wrs.Mark" (if "mark" is passed as argument),
     * to "wrs.Http_Status_Code" (if "httpStatusCode is passed as arguement) and
     * to "w.Url" (default value).
     *
     * The $sortDirection can be to DESC (if "2" is passed as argument) or ASC
     * (default value).
     *
     * The limitation is disables when window is set to -1.
     *
     * @param idAudit
     * @param httpStatusCode
     * @param invalidTestLabel
     * @param window
     * @param nbOfResult
     * @param sortDirection
     * @param sortCriterion
     * @param containingValue
     * @return
     */
@Override
public Collection<PageResult> findWebResourceByAuditAndHttpStatusCode(Long idAudit, HttpStatusCodeFamily httpStatusCode, String invalidTestLabel, int window, int nbOfResult, SortOrderEnum sortDirection, String sortCriterion, String containingValue) {
    boolean hasContainingValue = false;
    boolean hasInvalidTestConstraint = false;
    if (containingValue != null && !containingValue.isEmpty()) {
        hasContainingValue = true;
    }
    if (invalidTestLabel != null) {
        hasInvalidTestConstraint = true;
    }
    StringBuilder queryString = new StringBuilder();
    queryString.append(SELECT_STR);
    queryString.append(URL_FIELD_STR);
    queryString.append(COMA_CHAR);
    queryString.append("w.Rank");
    queryString.append(COMA_CHAR);
    queryString.append("wrs.Mark");
    queryString.append(COMA_CHAR);
    queryString.append("wrs.Raw_Mark");
    queryString.append(COMA_CHAR);
    queryString.append("wrs.Id_Web_Resource");
    queryString.append(COMA_CHAR);
    queryString.append("wrs.Http_Status_Code");
    queryString.append(W_WRS_JOINTURE);
    if (hasInvalidTestConstraint) {
        queryString.append(PR_T_JOINTURE);
    }
    queryString.append(AUDIT_AND_STATUS_CODE_CONDITION);
    // HttpStatusCodeFamily.CODE4xx instance is passed as argument.
    if (httpStatusCode.equals(HttpStatusCodeFamily.f4xx)) {
        queryString.append(EXTRA_HTTP_STATUS_CODE_CONDITION);
    } else {
        queryString.append(')');
    }
    if (hasContainingValue) {
        queryString.append(CONTAINING_VALUE_CONDITION);
    }
    if (hasInvalidTestConstraint) {
        queryString.append(INVALID_TEST_CONDITION);
    }
    queryString.append(ORDER_BY_STR);
    if (sortCriterion.equalsIgnoreCase("weightedMark")) {
        queryString.append("wrs.Mark");
    } else if (sortCriterion.equalsIgnoreCase("rawMark")) {
        queryString.append("wrs.Raw_Mark");
    } else if (sortCriterion.equalsIgnoreCase("httpStatusCode")) {
        queryString.append("wrs.Http_Status_Code");
    } else if (sortCriterion.equalsIgnoreCase("rank")) {
        queryString.append("w.Rank");
    } else {
        queryString.append(URL_FIELD_STR);
    }
    if (sortDirection.equals(SortOrderEnum.DESCENDING)) {
        queryString.append(DESC_STR);
    } else {
        queryString.append(ASC_STR);
    }
    if (nbOfResult != -1) {
        queryString.append(PARAMETRABLE_LIMIT_STR);
        queryString.append(PARAMETRABLE_WINDOW_STR);
    }
    Query query = entityManager.createNativeQuery(queryString.toString());
    query.setParameter("httpStatusCode", httpStatusCode.getCode() + "%");
    if (httpStatusCode.equals(HttpStatusCodeFamily.f4xx)) {
        query.setParameter("extraHttpStatusCode", HttpStatusCodeFamily.f5xx.getCode() + "%");
    }
    query.setParameter("idAudit", idAudit);
    if (nbOfResult != -1) {
        query.setParameter("nbOfResult", nbOfResult);
        query.setParameter("window", window);
    }
    if (hasContainingValue) {
        query.setParameter("containingValue", "%" + containingValue + "%");
    }
    if (hasInvalidTestConstraint) {
        query.setParameter("invalidTestLabel", invalidTestLabel);
    }
    try {
        List<Object[]> result = (List<Object[]>) query.getResultList();
        if (result.isEmpty()) {
            return Collections.emptySet();
        }
        return convertRawResultAsPageResultSet(result);
    } catch (NoResultException e) {
        return Collections.emptySet();
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)169 Query (javax.persistence.Query)130 EntityManager (javax.persistence.EntityManager)40 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 NonUniqueResultException (javax.persistence.NonUniqueResultException)15 Test (org.junit.Test)14 Transactional (org.springframework.transaction.annotation.Transactional)14 UnitOfWork (com.google.inject.persist.UnitOfWork)12 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 IOException (java.io.IOException)8 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 WebResource (org.asqatasun.entity.subject.WebResource)6 ASException (com.intel.mountwilson.as.common.ASException)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)5 UserAccount (com.jappstart.model.auth.UserAccount)5 List (java.util.List)5 Parameter (org.asqatasun.entity.parameterization.Parameter)5 Transactional (com.google.inject.persist.Transactional)4