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() });
}
}
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");
}
}
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;
}
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;
}
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");
}
Aggregations