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("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() });
}
}
use of org.nhindirect.config.store.Address in project nhin-d by DirectProject.
the class AddressServiceTest method testUpdateAddress.
/**
* Test the updateAddress method.
*/
public void testUpdateAddress() {
final AddressDao addressDao = context.mock(AddressDao.class);
final Address address = new Address();
context.checking(new Expectations() {
{
// TODO
}
});
AddressServiceImpl service = new AddressServiceImpl();
service.setDao(addressDao);
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 AddressServiceTest method testAddAddress.
/**
* Test the addAddress method.
*/
public void testAddAddress() {
final AddressDao addressDao = context.mock(AddressDao.class);
final Collection<Address> addresses = Arrays.asList(new Address(new Domain("healthdomain.com"), "beau@healthdomain.com"), new Address(new Domain("healthdomain2.com"), "beau@healthdomain2.com"));
context.checking(new Expectations() {
{
// TODO
}
});
AddressServiceImpl service = new AddressServiceImpl();
service.setDao(addressDao);
try {
service.addAddress(addresses);
} catch (Exception e) {
fail("Exception thrown");
}
}
use of org.nhindirect.config.store.Address in project nhin-d by DirectProject.
the class ConfigurationServiceTest method testAddAddress.
/**
* Test the addAddress method.
*/
public void testAddAddress() throws Exception {
final AddressService addressService = context.mock(AddressService.class);
final Collection<Address> collection = Arrays.asList(new Address(new Domain("domain"), "address"));
context.checking(new Expectations() {
{
oneOf(addressService).addAddress(collection);
}
});
ConfigurationServiceImpl service = new ConfigurationServiceImpl();
service.setAddressSvc(addressService);
try {
service.addAddress(collection);
} catch (Exception e) {
fail("Exception thrown");
}
}
use of org.nhindirect.config.store.Address 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");
}
Aggregations