Search in sources :

Example 6 with Domain

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

the class TrustBundleDaoImpl method getTrustBundlesByDomain.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
@Transactional(readOnly = true)
public Collection<TrustBundleDomainReltn> getTrustBundlesByDomain(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");
    Collection<TrustBundleDomainReltn> retVal = null;
    try {
        final Query select = entityManager.createQuery("SELECT tbd from TrustBundleDomainReltn tbd where tbd.domain = ?1");
        select.setParameter(1, domain);
        retVal = (Collection<TrustBundleDomainReltn>) select.getResultList();
        if (retVal.size() == 0)
            return Collections.emptyList();
        for (TrustBundleDomainReltn reltn : retVal) {
            if (!reltn.getTrustBundle().getTrustBundleAnchors().isEmpty())
                for (TrustBundleAnchor anchor : reltn.getTrustBundle().getTrustBundleAnchors()) anchor.getData();
        }
    } catch (Exception e) {
        throw new ConfigurationStoreException("Failed to execute trust bundle relation DAO query.", e);
    }
    return retVal;
}
Also used : Query(javax.persistence.Query) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Domain(org.nhindirect.config.store.Domain) TrustBundleAnchor(org.nhindirect.config.store.TrustBundleAnchor) NoResultException(javax.persistence.NoResultException) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) TrustBundleDomainReltn(org.nhindirect.config.store.TrustBundleDomainReltn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Domain

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

the class DomainDaoImpl method getDomains.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#getDomains(java.lang.String, org.nhindirect.config.store.EntityStatus)
     * 
     * Convert the list of names into a String to be used in an IN clause (i.e.
     * {"One", "Two", "Three"} --> ('One', 'Two', 'Three'))
     */
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Domain> getDomains(List<String> names, EntityStatus status) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Domain> result = null;
    Query select = null;
    if (names != null) {
        StringBuffer nameList = new StringBuffer("(");
        for (String aName : names) {
            if (nameList.length() > 1) {
                nameList.append(", ");
            }
            nameList.append("'").append(aName.toUpperCase(Locale.getDefault())).append("'");
        }
        nameList.append(")");
        String query = "SELECT d from Domain d WHERE UPPER(d.domainName) IN " + nameList.toString();
        if (status != null) {
            select = entityManager.createQuery(query + " AND d.status = ?1");
            select.setParameter(1, status);
        } else {
            select = entityManager.createQuery(query);
        }
    } else {
        if (status != null) {
            select = entityManager.createQuery("SELECT d from Domain d WHERE d.status = ?1");
            select.setParameter(1, status);
        } else {
            select = entityManager.createQuery("SELECT d from Domain d");
        }
    }
    @SuppressWarnings("rawtypes") List rs = select.getResultList();
    if ((rs.size() != 0) && (rs.get(0) instanceof Domain)) {
        result = (List<Domain>) rs;
    } else {
        result = new ArrayList<Domain>();
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return result;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) Domain(org.nhindirect.config.store.Domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Domain

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

the class DomainDaoImpl method listDomains.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#listDomains(java.lang.String, int)
     */
// TODO I'm not sure if this is doing the right thing. I suspect that the
// real intent is to do some kind of db paging
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Domain> listDomains(String name, int count) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Domain> result = null;
    Query select = null;
    if (name != null) {
        select = entityManager.createQuery("SELECT d from Domain d WHERE UPPER(d.domainName) = ?1");
        select.setParameter(1, name.toUpperCase(Locale.getDefault()));
    } else {
        select = entityManager.createQuery("SELECT d from Domain d");
    }
    // assuming that a count of zero really means no limit
    if (count > 0) {
        select.setMaxResults(count);
    }
    @SuppressWarnings("rawtypes") List rs = select.getResultList();
    if ((rs.size() != 0) && (rs.get(0) instanceof Domain)) {
        result = (List<Domain>) rs;
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return result;
}
Also used : Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) Domain(org.nhindirect.config.store.Domain) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Domain

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

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

the class SpringBaseTest method cleanDataStore.

protected void cleanDataStore() throws Exception {
    final ApplicationContext ctx = ConfigServiceRunner.getSpringApplicationContext();
    final AddressDao addressDao = (AddressDao) ctx.getBean("addressDaoImpl");
    final TrustBundleDao trustDao = (TrustBundleDao) ctx.getBean("trustBundleDao");
    final DomainDao domainDao = (DomainDao) ctx.getBean("domainDao");
    final AnchorDao anchorDao = (AnchorDao) ctx.getBean("anchorDao");
    final CertificateDao certDao = (CertificateDao) ctx.getBean("certificateDao");
    final DNSDao dnsDao = (DNSDao) ctx.getBean("DNSDaoImpl");
    final SettingDao settingDao = (SettingDao) ctx.getBean("settingDao");
    final CertPolicyDao policyDao = (CertPolicyDao) ctx.getBean("certPolicyDao");
    // clean anchors
    final List<Anchor> anchors = anchorDao.listAll();
    if (!anchors.isEmpty()) {
        final List<Long> anchorIds = new ArrayList<Long>();
        for (Anchor anchor : anchors) anchorIds.add(anchor.getId());
        anchorDao.delete(anchorIds);
    }
    // clean domains and the trust bundle domain relationships
    final List<Domain> domains = domainDao.listDomains(null, domainDao.count());
    if (domains != null) {
        for (Domain domain : domains) {
            Collection<Address> addresses = addressDao.getByDomain(domain, null);
            if (addresses != null) {
                for (Address address : addresses) {
                    addressDao.delete(address.getEmailAddress());
                }
            }
            trustDao.disassociateTrustBundlesFromDomain(domain.getId());
            domainDao.delete(domain.getId());
        }
    }
    assertEquals(0, domainDao.count());
    //clean trust bundles
    Collection<TrustBundle> bundles = trustDao.getTrustBundles();
    for (TrustBundle bundle : bundles) trustDao.deleteTrustBundles(new long[] { bundle.getId() });
    bundles = trustDao.getTrustBundles();
    assertEquals(0, bundles.size());
    // clean certificates
    final List<Certificate> certs = certDao.list((String) null);
    if (!certs.isEmpty()) {
        for (Certificate cert : certs) {
            certDao.delete(cert.getOwner());
        }
    }
    // clean DNS records
    final Collection<DNSRecord> records = dnsDao.get(Type.ANY);
    if (!records.isEmpty()) {
        for (DNSRecord record : records) dnsDao.remove(record.getId());
    }
    // clean settings
    final Collection<Setting> settings = settingDao.getAll();
    if (!settings.isEmpty()) {
        for (Setting setting : settings) settingDao.delete(Arrays.asList(setting.getName()));
    }
    // clean policies
    final Collection<CertPolicy> policies = policyDao.getPolicies();
    if (!policies.isEmpty()) {
        for (CertPolicy policy : policies) policyDao.deletePolicies(new long[] { policy.getId() });
    }
    // clean policy groups
    final Collection<CertPolicyGroup> groups = policyDao.getPolicyGroups();
    if (!groups.isEmpty()) {
        for (CertPolicyGroup group : groups) policyDao.deletePolicyGroups(new long[] { group.getId() });
    }
}
Also used : CertificateDao(org.nhindirect.config.store.dao.CertificateDao) Address(org.nhindirect.config.store.Address) ArrayList(java.util.ArrayList) TrustBundleDao(org.nhindirect.config.store.dao.TrustBundleDao) AnchorDao(org.nhindirect.config.store.dao.AnchorDao) ApplicationContext(org.springframework.context.ApplicationContext) SettingDao(org.nhindirect.config.store.dao.SettingDao) DomainDao(org.nhindirect.config.store.dao.DomainDao) TrustBundle(org.nhindirect.config.store.TrustBundle) AddressDao(org.nhindirect.config.store.dao.AddressDao) CertPolicyDao(org.nhindirect.config.store.dao.CertPolicyDao) DNSRecord(org.nhindirect.config.store.DNSRecord) Setting(org.nhindirect.config.store.Setting) DNSDao(org.nhindirect.config.store.dao.DNSDao) Anchor(org.nhindirect.config.store.Anchor) CertPolicy(org.nhindirect.config.store.CertPolicy) CertPolicyGroup(org.nhindirect.config.store.CertPolicyGroup) Domain(org.nhindirect.config.store.Domain) Certificate(org.nhindirect.config.store.Certificate)

Aggregations

Domain (org.nhindirect.config.store.Domain)32 Transactional (org.springframework.transaction.annotation.Transactional)14 Query (javax.persistence.Query)10 Expectations (org.jmock.Expectations)10 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)10 TrustBundle (org.nhindirect.config.store.TrustBundle)9 NoResultException (javax.persistence.NoResultException)8 TrustBundleDomainReltn (org.nhindirect.config.store.TrustBundleDomainReltn)8 DomainDao (org.nhindirect.config.store.dao.DomainDao)7 ApplicationContext (org.springframework.context.ApplicationContext)7 File (java.io.File)5 DomainServiceImpl (org.nhindirect.config.service.impl.DomainServiceImpl)5 Address (org.nhindirect.config.store.Address)5 ArrayList (java.util.ArrayList)4 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)4 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)4 CertPolicyGroupDomainReltn (org.nhindirect.config.store.CertPolicyGroupDomainReltn)3 AddressDao (org.nhindirect.config.store.dao.AddressDao)3 List (java.util.List)2 Anchor (org.nhindirect.config.store.Anchor)2