Search in sources :

Example 6 with TrustBundle

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

the class DefaultBundleRefreshProcessorImpl_refreshBundleTest method testRefreshBundle_errorOnUpdate.

@SuppressWarnings("unchecked")
public void testRefreshBundle_errorOnUpdate() throws Exception {
    DefaultBundleRefreshProcessorImpl processor = new DefaultBundleRefreshProcessorImpl();
    processor.setDao(dao);
    final TrustBundle bundle = new TrustBundle();
    bundle.setBundleName("Junit Bundle");
    File fl = new File("src/test/resources/bundles/signedbundle.p7b");
    bundle.setBundleURL(filePrefix + fl.getAbsolutePath());
    doThrow(new ConfigurationStoreException("Just Passing Through")).when(dao).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
    processor.refreshBundle(bundle);
    verify(dao, times(1)).updateTrustBundleAnchors(eq(bundle.getId()), (Calendar) any(), (Collection<TrustBundleAnchor>) any(), (String) any());
}
Also used : TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) File(java.io.File) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor)

Example 7 with TrustBundle

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

the class TrustBundleDaoImpl method updateLastUpdateError.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void updateLastUpdateError(long trustBundleId, Calendar attemptTime, BundleRefreshError error) throws ConfigurationStoreException {
    validateState();
    try {
        final TrustBundle existingBundle = this.getTrustBundleById(trustBundleId);
        if (existingBundle == null)
            throw new ConfigurationStoreException("Trust bundle does not exist");
        existingBundle.setLastRefreshAttempt(attemptTime);
        existingBundle.setLastRefreshError(error);
        entityManager.persist(existingBundle);
        entityManager.flush();
    } catch (ConfigurationStoreException cse) {
        throw cse;
    }///CLOVER:OFF
     catch (Exception e) {
        throw new ConfigurationStoreException("Failed to update bundle last refresh error.", e);
    }
///CLOVER:ON
}
Also used : 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 8 with TrustBundle

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

the class TrustBundleDaoImpl method disassociateTrustBundleFromDomains.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundleFromDomains(long trustBundleId) throws ConfigurationStoreException {
    validateState();
    // 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 delete = entityManager.createQuery("DELETE from TrustBundleDomainReltn tbd where tbd.trustBundle  = ?1");
        delete.setParameter(1, trustBundle);
        delete.executeUpdate();
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to dissaccociate domains from trust bundle id ." + trustBundleId, e);
    }
}
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 9 with TrustBundle

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

the class TrustBundleDaoImpl method updateTrustBundleAttributes.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void updateTrustBundleAttributes(long trustBundleId, String bundleName, String bundleUrl, X509Certificate signingCert, int refreshInterval) throws ConfigurationStoreException {
    validateState();
    try {
        final TrustBundle existingBundle = this.getTrustBundleById(trustBundleId);
        if (existingBundle == null)
            throw new ConfigurationStoreException("Trust bundle does not exist");
        if (signingCert == null)
            existingBundle.setSigningCertificateData(null);
        else
            existingBundle.setSigningCertificateData(signingCert.getEncoded());
        existingBundle.setRefreshInterval(refreshInterval);
        if (bundleName != null && !bundleName.isEmpty())
            existingBundle.setBundleName(bundleName);
        if (bundleUrl != null && !bundleUrl.isEmpty())
            existingBundle.setBundleURL(bundleUrl);
        entityManager.persist(existingBundle);
        entityManager.flush();
    } catch (ConfigurationStoreException cse) {
        throw cse;
    }///CLOVER:OFF
     catch (Exception e) {
        throw new ConfigurationStoreException("Failed to update bundle last refresh error.", e);
    }
///CLOVER:ON
}
Also used : 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 10 with TrustBundle

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

the class TrustBundleDaoImpl method getTrustBundles.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<TrustBundle> getTrustBundles() throws ConfigurationStoreException {
    validateState();
    Collection<TrustBundle> rs;
    try {
        Query select = entityManager.createQuery("SELECT tb from TrustBundle tb");
        rs = select.getResultList();
        if (rs.size() == 0)
            return Collections.emptyList();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute trust bundle DAO query.", e);
    }
    // make sure the anchors are loaded
    for (TrustBundle bundle : rs) {
        if (!bundle.getTrustBundleAnchors().isEmpty())
            for (TrustBundleAnchor anchor : bundle.getTrustBundleAnchors()) anchor.getData();
    }
    return rs;
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) 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