Search in sources :

Example 26 with ConfigurationStoreException

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

the class DomainDaoImpl method add.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#add(org.nhindirect.config.store.Domain)
     */
@Transactional(readOnly = false)
public void add(Domain item) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    if (item.getDomainName() == null || item.getDomainName().isEmpty())
        throw new ConfigurationStoreException("Domain name cannot be empty or null");
    // to work.
    if (item != null) {
        String pm = item.getPostMasterEmail();
        Long pmId = item.getPostmasterAddressId();
        Collection<Address> addresses = item.getAddresses();
        if ((pmId != null) && (pmId.longValue() == 0)) {
            item.setPostmasterAddressId((Long) null);
        }
        item.setAddresses(null);
        item.setCreateTime(Calendar.getInstance());
        item.setUpdateTime(item.getCreateTime());
        if (log.isDebugEnabled())
            log.debug("Calling JPA to persist the Domain");
        entityManager.persist(item);
        entityManager.flush();
        if (log.isDebugEnabled())
            log.debug("Persisted the bare Domain");
        boolean needUpdate = false;
        if ((addresses != null) && (addresses.size() > 0)) {
            item.setAddresses(addresses);
            needUpdate = true;
        }
        if ((pm != null) && (pm.length() > 0)) {
            item.setPostMasterEmail(pm);
            needUpdate = true;
        }
        if (needUpdate) {
            if (log.isDebugEnabled())
                log.debug("Updating the domain with Address info");
            update(item);
        }
        if (log.isDebugEnabled())
            log.debug("Returned from JPA: Domain ID=" + item.getId());
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : Address(org.nhindirect.config.store.Address) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with ConfigurationStoreException

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

the class TrustBundleDaoImpl method getTrustBundleById.

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

Example 28 with ConfigurationStoreException

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

the class TrustBundleDaoImpl method updateTrustBundleSigningCertificate.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void updateTrustBundleSigningCertificate(long trustBundleId, X509Certificate signingCert) 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());
        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 29 with ConfigurationStoreException

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

the class TrustBundleDaoImpl method getTrustBundleByName.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = true)
public TrustBundle getTrustBundleByName(String bundleName) throws ConfigurationStoreException {
    validateState();
    try {
        Query select = entityManager.createQuery("SELECT tb from TrustBundle tb WHERE UPPER(tb.bundleName) = ?1");
        select.setParameter(1, bundleName.toUpperCase(Locale.getDefault()));
        TrustBundle rs = (TrustBundle) select.getSingleResult();
        // make sure the anchors are loaded
        if (!rs.getTrustBundleAnchors().isEmpty())
            for (TrustBundleAnchor anchor : rs.getTrustBundleAnchors()) anchor.getData();
        return rs;
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute trust bundle DAO query.", e);
    }
}
Also used : Query(javax.persistence.Query) TrustBundle(org.nhindirect.config.store.TrustBundle) NoResultException(javax.persistence.NoResultException) 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)

Example 30 with ConfigurationStoreException

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

the class TrustBundleDaoImpl method addTrustBundle.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void addTrustBundle(TrustBundle bundle) throws ConfigurationStoreException {
    validateState();
    try {
        final TrustBundle existingBundle = this.getTrustBundleByName(bundle.getBundleName());
        if (existingBundle != null)
            throw new ConfigurationStoreException("Trust bundle " + bundle.getBundleName() + " already exists");
        bundle.setCreateTime(Calendar.getInstance(Locale.getDefault()));
        entityManager.persist(bundle);
        entityManager.flush();
    } catch (ConfigurationStoreException cse) {
        throw cse;
    }///CLOVER:OFF
     catch (Exception e) {
        throw new ConfigurationStoreException("Failed to add trust bundle " + bundle.getBundleName(), 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)

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