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;
}
}
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;
}
}
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;
}
}
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;
}
}
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();
}
}
Aggregations