Search in sources :

Example 31 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class TrustBundleDaoImpl method updateTrustBundleAnchors.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void updateTrustBundleAnchors(long trustBundleId, Calendar attemptTime, Collection<TrustBundleAnchor> newAnchorSet, String bundleCheckSum) throws ConfigurationStoreException {
    validateState();
    try {
        final TrustBundle existingBundle = this.getTrustBundleById(trustBundleId);
        if (existingBundle == null)
            throw new ConfigurationStoreException("Trust bundle does not exist");
        // blow away all the existing bundles
        final Query delete = entityManager.createQuery("DELETE from TrustBundleAnchor tba where tba.trustBundle = ?1");
        delete.setParameter(1, existingBundle);
        delete.executeUpdate();
        // now update the bundle		
        existingBundle.setCheckSum(bundleCheckSum);
        existingBundle.setTrustBundleAnchors(newAnchorSet);
        existingBundle.setLastRefreshAttempt(attemptTime);
        existingBundle.setLastSuccessfulRefresh(Calendar.getInstance(Locale.getDefault()));
        entityManager.persist(existingBundle);
        entityManager.flush();
    } catch (ConfigurationStoreException cse) {
        throw cse;
    }///CLOVER:OFF
     catch (Exception e) {
        throw new ConfigurationStoreException("Failed to update anchors in trust bundle.", e);
    }
///CLOVER:ON
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method getPolicyByName.

@Override
@Transactional(readOnly = true)
public CertPolicy getPolicyByName(String policyName) throws ConfigurationStoreException {
    validateState();
    try {
        final Query select = entityManager.createQuery("SELECT cp from CertPolicy cp WHERE UPPER(cp.policyName) = ?1");
        select.setParameter(1, policyName.toUpperCase(Locale.getDefault()));
        final CertPolicy rs = (CertPolicy) select.getSingleResult();
        return rs;
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute certificate policy DAO query.", e);
    }
}
Also used : Query(javax.persistence.Query) CertPolicy(org.nhindirect.config.store.CertPolicy) 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 33 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method associatePolicyGroupToDomain.

@Override
@Transactional(readOnly = false)
public void associatePolicyGroupToDomain(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 CertPolicyGroupDomainReltn policyGroupDomainAssoc = new CertPolicyGroupDomainReltn();
        policyGroupDomainAssoc.setDomain(domain);
        policyGroupDomainAssoc.setCertPolicyGroup(policyGroup);
        entityManager.persist(policyGroupDomainAssoc);
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to associate policy group to domain.", e);
    }
}
Also used : CertPolicyGroupDomainReltn(org.nhindirect.config.store.CertPolicyGroupDomainReltn) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method getPolicyById.

@Override
@Transactional(readOnly = true)
public CertPolicy getPolicyById(long id) throws ConfigurationStoreException {
    validateState();
    try {
        final Query select = entityManager.createQuery("SELECT cp from CertPolicy cp WHERE cp.id = ?1");
        select.setParameter(1, id);
        final CertPolicy rs = (CertPolicy) select.getSingleResult();
        return rs;
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute certificate policy DAO query.", e);
    }
}
Also used : Query(javax.persistence.Query) CertPolicy(org.nhindirect.config.store.CertPolicy) 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 35 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException in project nhin-d by DirectProject.

the class CertPolicyDaoImpl method disassociatePolicyGroupFromDomains.

@Override
@Transactional(readOnly = false)
public void disassociatePolicyGroupFromDomains(long policyGroupId) throws ConfigurationStoreException {
    validateState();
    // make sure the policy group exists
    final CertPolicyGroup policyGroup = this.getPolicyGroupById(policyGroupId);
    if (policyGroup == null)
        throw new ConfigurationStoreException("Policy group with id " + policyGroupId + " does not exist");
    try {
        final Query delete = entityManager.createQuery("DELETE from CertPolicyGroupDomainReltn cpr where cpr.certPolicyGroup  = ?1");
        delete.setParameter(1, policyGroup);
        delete.executeUpdate();
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to dissaccociate domains from policy group id ." + policyGroupId, e);
    }
}
Also used : Query(javax.persistence.Query) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)45 Transactional (org.springframework.transaction.annotation.Transactional)39 NoResultException (javax.persistence.NoResultException)32 Query (javax.persistence.Query)21 TrustBundle (org.nhindirect.config.store.TrustBundle)15 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)10 Domain (org.nhindirect.config.store.Domain)10 CertPolicy (org.nhindirect.config.store.CertPolicy)8 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)6 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)5 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)4 File (java.io.File)3 CertPolicyGroupReltn (org.nhindirect.config.store.CertPolicyGroupReltn)3 DNSRecord (org.nhindirect.config.store.DNSRecord)2 ApplicationContext (org.springframework.context.ApplicationContext)2 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAKey (java.security.interfaces.RSAKey)1