Search in sources :

Example 66 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class OrcidSocialDaoImpl method isEnabled.

@Override
public boolean isEnabled(String orcid, OrcidSocialType type) {
    Query query = entityManager.createNativeQuery("SELECT * FROM orcid_social WHERE orcid=:orcid AND type=:type");
    query.setParameter("orcid", orcid);
    query.setParameter("type", type.name());
    try {
        query.getSingleResult();
        return true;
    } catch (NoResultException nre) {
        return false;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 67 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class InternalSSODaoImpl method verify.

@Override
public boolean verify(String orcid, String token, Date maxAge) {
    Query query = entityManager.createNativeQuery("SELECT count(*) FROM internal_sso WHERE orcid = :orcid AND token = :token AND last_modified >= :maxAge");
    query.setParameter("orcid", orcid);
    query.setParameter("token", token);
    query.setParameter("maxAge", maxAge);
    try {
        BigInteger result = (BigInteger) query.getSingleResult();
        return result.longValue() > 0;
    } catch (NoResultException nre) {
    }
    return false;
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) BigInteger(java.math.BigInteger) NoResultException(javax.persistence.NoResultException)

Example 68 with NoResultException

use of javax.persistence.NoResultException in project ORCID-Source by ORCID.

the class PeerReviewsControllerTest method testDeletePeerReview.

@Test
public void testDeletePeerReview() {
    HttpSession session = mock(HttpSession.class);
    when(servletRequest.getSession()).thenReturn(session);
    PeerReviewForm form = getForm();
    PeerReviewForm newForm = peerReviewsController.postPeerReview(form);
    assertNotNull(newForm);
    assertFalse(PojoUtil.isEmpty(newForm.getPutCode()));
    String putCode = newForm.getPutCode().getValue();
    peerReviewsController.deletePeerReviewJson(newForm);
    try {
        peerReviewsController.getPeerReviewJson(Long.valueOf(putCode));
        fail();
    } catch (NoResultException nre) {
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) PeerReviewForm(org.orcid.pojo.ajaxForm.PeerReviewForm) NoResultException(javax.persistence.NoResultException) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Example 69 with NoResultException

use of javax.persistence.NoResultException in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method disassociatePolicyGroupFromDomain.

@Override
@Transactional(readOnly = false)
public void disassociatePolicyGroupFromDomain(long domainId, long policyGroupId) throws ConfigurationStoreException {
    validateState();
    // make sure the domain exists
    final Domain domain = domainDao.getDomain(domainId);
    if (domain == null)
        throw new ConfigurationStoreException("Domain with id " + domainId + " does not exist");
    // make sure the policy group exists
    final CertPolicyGroup policyGroup = this.getPolicyGroupById(policyGroupId);
    if (policyGroup == null)
        throw new ConfigurationStoreException("Policy group with id " + policyGroup + " does not exist");
    try {
        final Query select = entityManager.createQuery("SELECT cpr from CertPolicyGroupDomainReltn cpr where cpr.domain  = ?1 " + " and cpr.certPolicyGroup = ?2 ");
        select.setParameter(1, domain);
        select.setParameter(2, policyGroup);
        final CertPolicyGroupDomainReltn reltn = (CertPolicyGroupDomainReltn) select.getSingleResult();
        entityManager.remove(reltn);
        entityManager.flush();
    } catch (NoResultException e) {
        throw new ConfigurationStoreException("Association between domain id " + domainId + " and policy group id " + policyGroupId + " does not exist", e);
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to delete policy group from domain relation.", e);
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 70 with NoResultException

use of javax.persistence.NoResultException in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method getPolicyGroupById.

@Override
@Transactional(readOnly = true)
public CertPolicyGroup getPolicyGroupById(long id) throws ConfigurationStoreException {
    validateState();
    try {
        final Query select = entityManager.createQuery("SELECT cpg from CertPolicyGroup cpg WHERE cpg.id = ?1");
        select.setParameter(1, id);
        final CertPolicyGroup rs = (CertPolicyGroup) select.getSingleResult();
        // load relationships now as they were deferred by lazy loading 
        rs.getCertPolicyGroupReltn().size();
        return rs;
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute certificate policy group DAO query.", e);
    }
}
Also used : Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

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