Search in sources :

Example 1 with Address

use of org.nhindirect.config.store.Address 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("addressDao");
    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("dnsDao");
    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)

Example 2 with Address

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

the class ConfigurationServiceTest method testUpdateAddress.

/**
     * Test the updateAddress method.
     */
public void testUpdateAddress() throws Exception {
    final AddressService addressService = context.mock(AddressService.class);
    final Address address = new Address(new Domain("domain"), "address");
    context.checking(new Expectations() {

        {
            oneOf(addressService).updateAddress(address);
        }
    });
    ConfigurationServiceImpl service = new ConfigurationServiceImpl();
    service.setAddressSvc(addressService);
    try {
        service.updateAddress(address);
    } catch (Exception e) {
        fail("Exception thrown");
    }
}
Also used : Expectations(org.jmock.Expectations) Address(org.nhindirect.config.store.Address) Domain(org.nhindirect.config.store.Domain) ConfigurationServiceImpl(org.nhindirect.config.service.impl.ConfigurationServiceImpl)

Example 3 with Address

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

the class AddressDaoImpl method getByDomain.

/* 
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.AddressDao#getByDomain(org.nhindirect.config.store.Domain, org.nhindirect.config.store.EntityStatus)
     */
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Address> getByDomain(Domain domain, EntityStatus status) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Address> result = null;
    Query select = null;
    if (domain != null) {
        String query = "SELECT a from Address a WHERE a.domain = ?1";
        if (status != null) {
            select = entityManager.createQuery(query + " AND a.status = ?2");
            select.setParameter(1, domain);
            select.setParameter(2, status);
        } else {
            select = entityManager.createQuery(query);
            select.setParameter(1, domain);
        }
    } else {
        if (status != null) {
            select = entityManager.createQuery("SELECT a from Address a WHERE a.status = ?1");
            select.setParameter(1, status);
        } else {
            select = entityManager.createQuery("SELECT a from Address a");
        }
    }
    @SuppressWarnings("rawtypes") List rs = select.getResultList();
    if ((rs.size() != 0) && (rs.get(0) instanceof Address)) {
        result = (List<Address>) rs;
    } else {
        result = new ArrayList<Address>();
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return result;
}
Also used : Address(org.nhindirect.config.store.Address) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Address

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

the class AddressDaoImpl method listAddresses.

/* 
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.AddressDao#listAddresses(java.util.List, org.nhindirect.config.store.EntityStatus)
     */
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<Address> listAddresses(List<String> names, EntityStatus status) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    List<Address> 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 a from Address a WHERE UPPER(a.emailAddress) IN " + nameList.toString();
        if (status != null) {
            select = entityManager.createQuery(query + " AND a.status = ?1");
            select.setParameter(1, status);
        } else {
            select = entityManager.createQuery(query);
        }
    } else {
        if (status != null) {
            select = entityManager.createQuery("SELECT a from Address a WHERE a.status = ?1");
            select.setParameter(1, status);
        } else {
            select = entityManager.createQuery("SELECT a from Address a");
        }
    }
    @SuppressWarnings("rawtypes") List rs = select.getResultList();
    if ((rs.size() != 0) && (rs.get(0) instanceof Address)) {
        result = (List<Address>) rs;
    } else {
        result = new ArrayList<Address>();
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
    return result;
}
Also used : Address(org.nhindirect.config.store.Address) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Address

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

the class DomainDaoImpl method update.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.config.store.dao.DomainDao#update(org.nhindirect.config.store.Domain)
     */
@Transactional(readOnly = false)
public void update(Domain item) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    if (item != null) {
        item.setUpdateTime(Calendar.getInstance());
        if ((item.getPostMasterEmail() != null) && (item.getPostMasterEmail().length() > 0)) {
            boolean found = false;
            Iterator<Address> addrs = item.getAddresses().iterator();
            while (addrs.hasNext()) {
                if (addrs.next().getEmailAddress().equals(item.getPostMasterEmail())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                if (log.isDebugEnabled())
                    log.debug("Adding new postmaster email address: " + item.getPostMasterEmail());
                item.getAddresses().add(new Address(item, item.getPostMasterEmail(), "Postmaster"));
            }
        }
        for (Address address : item.getAddresses()) {
            if ((address.getId() == null) || (address.getId().longValue() == 0)) {
                if (log.isDebugEnabled())
                    log.debug("Adding " + address.toString() + " to database");
                addressDao.add(address);
            }
        }
        // necessary.
        if ((item.getPostmasterAddressId() == null) || (item.getPostmasterAddressId().longValue() == 0L)) {
            Iterator<Address> addrs = item.getAddresses().iterator();
            while (addrs.hasNext()) {
                Address address = addrs.next();
                if (address.getDisplayName().equals("Postmaster")) {
                    if (log.isDebugEnabled())
                        log.debug("Linking domain's postmaster email address to " + address.toString());
                    item.setPostmasterAddressId(address.getId());
                    break;
                }
            }
        }
        if (log.isDebugEnabled())
            log.debug("Calling JPA to perform update...");
        entityManager.merge(item);
    }
    if (log.isDebugEnabled())
        log.debug("Exit");
}
Also used : Address(org.nhindirect.config.store.Address) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Address (org.nhindirect.config.store.Address)12 Transactional (org.springframework.transaction.annotation.Transactional)6 Domain (org.nhindirect.config.store.Domain)5 ArrayList (java.util.ArrayList)4 Expectations (org.jmock.Expectations)4 AddressDao (org.nhindirect.config.store.dao.AddressDao)4 Query (javax.persistence.Query)3 List (java.util.List)2 AddressServiceImpl (org.nhindirect.config.service.impl.AddressServiceImpl)2 ConfigurationServiceImpl (org.nhindirect.config.service.impl.ConfigurationServiceImpl)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 DNSRecord (org.nhindirect.config.store.DNSRecord)2 Setting (org.nhindirect.config.store.Setting)2 TrustBundle (org.nhindirect.config.store.TrustBundle)2 AnchorDao (org.nhindirect.config.store.dao.AnchorDao)2 CertPolicyDao (org.nhindirect.config.store.dao.CertPolicyDao)2 CertificateDao (org.nhindirect.config.store.dao.CertificateDao)2