Search in sources :

Example 16 with ConfigurationStoreException

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

the class DNSDaoImpl method update.

/**
     * {@inheritDoc}}
     */
@Override
@Transactional(readOnly = false)
public void update(long id, DNSRecord record) {
    if (log.isDebugEnabled())
        log.debug("remove(long id, DNSRecord record) Enter");
    try {
        // get the record
        if (record.getType() == Type.ANY)
            throw new ConfigurationStoreException("Record type for update cannot be ANY");
        DNSRecord toUpdate = get(id);
        if (toUpdate == null)
            throw new ConfigurationStoreException("Record with id " + id + " does not exist.");
        toUpdate.setType(record.getType());
        toUpdate.setName(record.getName());
        toUpdate.setTtl(record.getTtl());
        toUpdate.setDclass(record.getDclass());
        toUpdate.setData(record.getData());
        entityManager.merge(toUpdate);
        entityManager.flush();
        if (log.isDebugEnabled())
            log.debug("1 DNS record updated.");
    } finally {
        if (log.isDebugEnabled())
            log.debug("remove(long id, DNSRecord record) Exit");
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with ConfigurationStoreException

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

the class DNSDaoImpl method add.

/**
     * {@inheritDoc}}
     */
@Override
@Transactional(readOnly = false)
public void add(Collection<DNSRecord> records) {
    if (log.isDebugEnabled())
        log.debug("add() Enter");
    try {
        if (records != null && records.size() > 0) {
            for (DNSRecord record : records) {
                if (record.getType() == Type.ANY)
                    throw new ConfigurationStoreException("Cannot add records with type ANY.");
                else {
                    Collection<DNSRecord> checkRecs = get(record.getName(), record.getType());
                    if (checkRecs.contains(record))
                        throw new ConfigurationStoreException("Record name " + record.getName() + " and type " + record.getType() + " already exists with same rdata.");
                }
                record.setCreateTime(Calendar.getInstance());
                if (log.isDebugEnabled())
                    log.debug("Persisting DNS record\r\n\tName: " + record.getName() + "\r\n\tType: " + record.getType());
                entityManager.persist(record);
            }
            if (log.isDebugEnabled())
                log.debug("Flushing " + records.size() + " added records.");
            entityManager.flush();
        }
    } finally {
        if (log.isDebugEnabled())
            log.debug("add() Exit");
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with ConfigurationStoreException

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

the class SettingDaoImpl method add.

/**
     * {@inheritDoc}
     */
@Transactional(readOnly = false)
public void add(String name, String value) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    if (name == null || name.isEmpty() || value == null)
        return;
    // make sure this setting doesn't already exist
    if (this.getByNames(Arrays.asList(name)).size() > 0)
        throw new ConfigurationStoreException("Setting " + name + " already exists.");
    Setting setting = new Setting();
    setting.setName(name);
    setting.setValue(value);
    setting.setCreateTime(Calendar.getInstance());
    setting.setUpdateTime(setting.getCreateTime());
    if (log.isDebugEnabled())
        log.debug("Calling JPA to persist the setting");
    entityManager.persist(setting);
    entityManager.flush();
    if (log.isDebugEnabled())
        log.debug("Returned from JPA: Setting ID=" + setting.getId());
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : Setting(org.nhindirect.config.store.Setting) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with ConfigurationStoreException

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

the class TrustBundleDaoImpl method disassociateTrustBundlesFromDomain.

/**
	 * {@inheritDoc}
	 */
@Override
@Transactional(readOnly = false)
public void disassociateTrustBundlesFromDomain(long domainId) 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");
    try {
        final Query delete = entityManager.createQuery("DELETE from TrustBundleDomainReltn tbd where tbd.domain  = ?1");
        delete.setParameter(1, domain);
        delete.executeUpdate();
        entityManager.flush();
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to dissaccociate trust bundle from domain id ." + domainId, e);
    }
}
Also used : Query(javax.persistence.Query) 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 20 with ConfigurationStoreException

use of org.nhindirect.config.store.ConfigurationStoreException 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)

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