Search in sources :

Example 26 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 27 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 28 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)

Example 29 with NoResultException

use of javax.persistence.NoResultException in project cas by apereo.

the class GoogleAuthenticatorMongoDbTokenRepository method get.

@Override
public GoogleAuthenticatorToken get(final String uid, final Integer otp) {
    try {
        final Query query = new Query();
        query.addCriteria(Criteria.where("userId").is(uid).and("token").is(otp));
        final GoogleAuthenticatorToken r = this.mongoTemplate.findOne(query, GoogleAuthenticatorToken.class, this.collectionName);
        return r;
    } catch (final NoResultException e) {
        LOGGER.debug("No record could be found for google authenticator id [{}]", uid);
    }
    return null;
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) GoogleAuthenticatorToken(org.apereo.cas.adaptors.gauth.token.GoogleAuthenticatorToken) NoResultException(javax.persistence.NoResultException)

Example 30 with NoResultException

use of javax.persistence.NoResultException in project cas by apereo.

the class MongoDbGoogleAuthenticatorTokenCredentialRepository method get.

@Override
public OneTimeTokenAccount get(final String username) {
    try {
        final Query query = new Query();
        query.addCriteria(Criteria.where("username").is(username));
        final GoogleAuthenticatorAccount r = this.mongoTemplate.findOne(query, GoogleAuthenticatorAccount.class, this.collectionName);
        if (r != null) {
            return decode(r);
        }
    } catch (final NoResultException e) {
        LOGGER.debug("No record could be found for google authenticator id [{}]", username);
    }
    return null;
}
Also used : GoogleAuthenticatorAccount(org.apereo.cas.adaptors.gauth.repository.credentials.GoogleAuthenticatorAccount) Query(org.springframework.data.mongodb.core.query.Query) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)356 Query (javax.persistence.Query)205 EntityManager (javax.persistence.EntityManager)69 NonUniqueResultException (javax.persistence.NonUniqueResultException)33 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)25 TypedQuery (javax.persistence.TypedQuery)22 Transactional (org.springframework.transaction.annotation.Transactional)20 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19 Test (org.junit.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Session (org.hibernate.Session)13 UnitOfWork (com.google.inject.persist.UnitOfWork)12 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)11 PersistenceException (javax.persistence.PersistenceException)11 Date (java.util.Date)9 NotFoundException (org.opencastproject.util.NotFoundException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 List (java.util.List)8 NamedQuery (javax.persistence.NamedQuery)8