Search in sources :

Example 46 with NoResultException

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

the class ProcessResultDAOImpl method retrieveProcessResultListByWebResourceAndScope.

@Override
public Collection<ProcessResult> retrieveProcessResultListByWebResourceAndScope(WebResource webResource, Scope scope, String theme, Collection<String> testSolutions) {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT pr FROM ");
    sb.append(getEntityClass().getName());
    sb.append(" pr");
    sb.append(" JOIN pr.subject w");
    sb.append(" JOIN pr.test t");
    sb.append(" JOIN pr.test.criterion.theme th");
    sb.append(" JOIN t.scope s");
    sb.append(" WHERE w=:webResource");
    sb.append(" AND (s = :scope or s.id = :pageAndSiteScope) ");
    if (theme != null && !theme.isEmpty() && !theme.equals(selectAllThemeKey)) {
        sb.append("AND (th.code = :theme)");
    }
    if (!testSolutions.isEmpty()) {
        sb.append(" AND (pr.definiteValue IN (:testSolution)) ");
    }
    Query query = entityManager.createQuery(sb.toString());
    query.setParameter("webResource", webResource);
    query.setParameter("scope", scope);
    query.setParameter("pageAndSiteScope", pageAndSiteScopeId);
    if (theme != null && !theme.isEmpty() && !theme.equals(selectAllThemeKey)) {
        query.setParameter("theme", theme);
    }
    if (!testSolutions.isEmpty()) {
        Collection<TestSolution> solutions = new ArrayList<>();
        for (String solution : testSolutions) {
            solutions.add(TestSolution.valueOf(solution));
        }
        query.setParameter("testSolution", solutions);
    }
    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException)

Example 47 with NoResultException

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

the class ProcessResultDAOImpl method hasAuditSiteScopeResult.

@Override
public boolean hasAuditSiteScopeResult(WebResource webResource, Scope scope) {
    Query query = entityManager.createQuery("SELECT count(pr.id) FROM " + getEntityClass().getName() + " pr" + " JOIN pr.subject r" + " JOIN pr.test t" + " JOIN t.scope s" + " WHERE (r.id=:id)" + " AND (s = :scope or s.id = :pageAndSiteScope)");
    query.setParameter("id", webResource.getId());
    query.setParameter("pageAndSiteScope", pageAndSiteScopeId);
    query.setParameter("scope", scope);
    query.setHint(CACHEABLE_OPTION, TRUE);
    try {
        if ((Long) query.getSingleResult() > 0) {
            return true;
        } else {
            return false;
        }
    } catch (NoResultException e) {
        return false;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 48 with NoResultException

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

the class ProcessResultDAOImpl method retrieveProcessResultListByWebResourceAndCriterion.

@Override
public Collection<ProcessResult> retrieveProcessResultListByWebResourceAndCriterion(WebResource webResource, Criterion criterion) {
    Query query = entityManager.createQuery("SELECT distinct(pr) FROM " + getEntityClass().getName() + " pr" + " LEFT JOIN FETCH pr.remarkSet pk" + " LEFT JOIN FETCH pk.elementSet el" + " JOIN pr.subject r" + " JOIN pr.test t" + " JOIN t.criterion c" + " WHERE r=:webResource" + " AND c=:criterion");
    query.setParameter("webResource", webResource);
    query.setParameter("criterion", criterion);
    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 49 with NoResultException

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

the class CriterionStatisticsDAOImpl method findCriterionStatisticsByWebResource.

@Override
public Collection<CriterionStatistics> findCriterionStatisticsByWebResource(WebResource webResource, String theme, Collection<String> testSolutions) {
    boolean hasTheme = false;
    if (theme != null && !StringUtils.equals(theme, selectAllThemeKey)) {
        hasTheme = true;
    }
    boolean hasTestSolution = false;
    if (!testSolutions.isEmpty()) {
        hasTestSolution = true;
    }
    StringBuilder strb = new StringBuilder();
    strb.append("SELECT cs FROM ");
    strb.append(getEntityClass().getName());
    strb.append(" cs ");
    strb.append(" JOIN cs.webResourceStatistics wrs ");
    if (hasTheme) {
        strb.append(" JOIN cs.criterion cr ");
    }
    strb.append(" WHERE wrs.webResource=:webResource ");
    if (hasTheme) {
        strb.append(" AND cr.theme.code=:theme ");
    }
    if (hasTestSolution) {
        strb.append(" AND cs.criterionResult IN (:testSolution) ");
    }
    Query query = entityManager.createQuery(strb.toString());
    query.setParameter("webResource", webResource);
    if (hasTestSolution) {
        Collection<TestSolution> solutions = new ArrayList<TestSolution>();
        for (String solution : testSolutions) {
            solutions.add(TestSolution.valueOf(solution));
        }
        query.setParameter("testSolution", solutions);
    }
    if (hasTheme) {
        query.setParameter("theme", theme);
    }
    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) TestSolution(org.asqatasun.entity.audit.TestSolution) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException)

Example 50 with NoResultException

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

the class TestDAOImpl method retrieveTestFromAuditAndLabel.

@Override
public Test retrieveTestFromAuditAndLabel(Audit audit, String testLabel) {
    Query query = entityManager.createQuery("SELECT t FROM " + getAuditEntityClass().getName() + " a" + " LEFT JOIN a.testList t" + " WHERE t.label=:testLabel" + " AND a = :audit");
    query.setParameter("audit", audit);
    query.setParameter("testLabel", testLabel);
    try {
        return (Test) query.getSingleResult();
    } catch (NoResultException nre) {
        return null;
    }
}
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