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