Search in sources :

Example 41 with TrustBundle

use of org.nhindirect.config.store.TrustBundle 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 42 with TrustBundle

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

the class TrustBundleDaoImpl method deleteTrustBundles.

/**
	 * {@inheritDoc}
	 */
@Transactional(readOnly = false)
@Override
public void deleteTrustBundles(long[] trustBundleIds) throws ConfigurationStoreException {
    validateState();
    if (trustBundleIds == null || trustBundleIds.length == 0)
        return;
    for (long id : trustBundleIds) {
        try {
            final TrustBundle bundle = this.getTrustBundleById(id);
            this.disassociateTrustBundleFromDomains(id);
            entityManager.remove(bundle);
            entityManager.flush();
        } catch (ConfigurationStoreException e) {
            log.warn(e.getMessage(), e);
        }
    }
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with TrustBundle

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

the class TrustBundleDaoImpl method disassociateTrustBundleFromDomain.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundleFromDomain(long domainId, long trustBundleId) 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 trust bundle exists
    final TrustBundle trustBundle = this.getTrustBundleById(trustBundleId);
    if (trustBundle == null)
        throw new ConfigurationStoreException("Trust budnel with id " + trustBundle + " does not exist");
    try {
        final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain  = ?1 " + " and tbd.trustBundle = ?2 ");
        select.setParameter(1, domain);
        select.setParameter(2, trustBundle);
        final TrustBundleDomainReltn reltn = (TrustBundleDomainReltn) select.getSingleResult();
        entityManager.remove(reltn);
        entityManager.flush();
    } catch (NoResultException e) {
        throw new ConfigurationStoreException("Association between domain id " + domainId + " and trust bundle id" + trustBundleId + " does not exist", e);
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to delete trust bundle to domain relation.", e);
    }
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) 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) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with TrustBundle

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

the class TrustBundleDaoImpl method associateTrustBundleToDomain.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void associateTrustBundleToDomain(long domainId, long trustBundleId, boolean incoming, boolean outgoing) 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 trust bundle exists
    final TrustBundle trustBundle = this.getTrustBundleById(trustBundleId);
    if (trustBundle == null)
        throw new ConfigurationStoreException("Trust budnel with id " + trustBundle + " does not exist");
    try {
        final TrustBundleDomainReltn domainTrustBundleAssoc = new TrustBundleDomainReltn();
        domainTrustBundleAssoc.setDomain(domain);
        domainTrustBundleAssoc.setTrustBundle(trustBundle);
        domainTrustBundleAssoc.setIncoming(incoming);
        domainTrustBundleAssoc.setOutgoing(outgoing);
        entityManager.persist(domainTrustBundleAssoc);
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to associate trust bundle to domain.", e);
    }
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TrustBundle (org.nhindirect.config.store.TrustBundle)44 File (java.io.File)16 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)15 ApplicationContext (org.springframework.context.ApplicationContext)12 Transactional (org.springframework.transaction.annotation.Transactional)12 NoResultException (javax.persistence.NoResultException)11 TrustBundleAnchor (org.nhindirect.config.store.TrustBundleAnchor)10 Domain (org.nhindirect.config.store.Domain)9 Calendar (java.util.Calendar)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)7 X509Certificate (java.security.cert.X509Certificate)6 Query (javax.persistence.Query)6 TrustBundleDao (org.nhindirect.config.store.dao.TrustBundleDao)4 TrustBundleService (org.nhindirect.config.service.TrustBundleService)3 ArrayList (java.util.ArrayList)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 Certificate (org.nhindirect.config.store.Certificate)2