use of org.nhindirect.config.store.DNSRecord 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.DNSRecord in project nhin-d by DirectProject.
the class ClientProxyDNSTest method addDNSRecord.
@Test
public void addDNSRecord() throws Exception {
cleanDNSRecords();
DNSRecord rec = DNSRecordUtils.createARecord("example.domain.com", 86400L, "127.0.0.1");
DnsRecord recToAdd = new DnsRecord();
recToAdd.setData(rec.getData());
recToAdd.setDclass(rec.getDclass());
recToAdd.setName(rec.getName());
recToAdd.setTtl(rec.getTtl());
recToAdd.setType(rec.getType());
proxy.addDNS(new DnsRecord[] { recToAdd });
assertEquals(1, proxy.getDNSCount());
DnsRecord[] recs = proxy.getDNSByNameAndType(recToAdd.getName(), recToAdd.getType());
assertNotNull(recs);
assertEquals(1, recs.length);
assertEquals(rec.getName(), recs[0].getName());
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class DNSDaoImpl method get.
/**
* {@inheritDoc}}
*/
@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Collection<DNSRecord> get(long[] recordIds) {
if (log.isDebugEnabled())
log.debug("get(long[]) Enter");
List<DNSRecord> result = Collections.emptyList();
if (recordIds != null && recordIds.length > 0) {
Query select = null;
StringBuffer idList = new StringBuffer("(");
for (long id : recordIds) {
if (idList.length() > 1) {
idList.append(", ");
}
idList.append(id);
}
idList.append(")");
String query = "SELECT d from DNSRecord d WHERE d.id IN " + idList.toString();
select = entityManager.createQuery(query);
@SuppressWarnings("rawtypes") List rs = select.getResultList();
if (rs != null && (rs.size() != 0) && (rs.get(0) instanceof DNSRecord)) {
result = (List<DNSRecord>) rs;
}
}
if (log.isDebugEnabled())
log.debug("get(long[]) Exit");
return result;
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class DNSDaoImpl method remove.
/**
* {@inheritDoc}}
*/
@Override
@Transactional(readOnly = false)
public void remove(Collection<DNSRecord> records) {
if (log.isDebugEnabled())
log.debug("remove(Collection<DNSRecord>) Enter");
if (records != null && records.size() > 0) {
Collection<DNSRecord> toDelete = new ArrayList<DNSRecord>();
// get the records out of the DAO
for (DNSRecord record : records) toDelete.addAll(get(record.getName(), record.getType()));
// delete all qualifying records
if (toDelete.size() > 0)
for (DNSRecord record : toDelete) entityManager.remove(record);
if (log.isDebugEnabled()) {
if (toDelete.size() == 0)
log.debug("No DNS records qualified for deletion.");
else
log.debug(toDelete.size() + " DNS records deleted");
}
entityManager.flush();
}
if (log.isDebugEnabled())
log.debug("remove(Collection<DNSRecord>) Exit");
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class DNSDaoImpl method get.
/**
* {@inheritDoc}}
*/
@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Collection<DNSRecord> get(int type) {
if (log.isDebugEnabled())
log.debug("get(int) Enter");
List<DNSRecord> result = Collections.emptyList();
Query select = null;
if (type != Type.ANY) {
select = entityManager.createQuery("SELECT d from DNSRecord d WHERE d.type = ?1");
select.setParameter(1, type);
} else
select = entityManager.createQuery("SELECT d from DNSRecord d");
@SuppressWarnings("rawtypes") List rs = select.getResultList();
if (rs != null && (rs.size() != 0) && (rs.get(0) instanceof DNSRecord)) {
result = (List<DNSRecord>) rs;
}
if (log.isDebugEnabled())
log.debug("get(int) Exit");
return result;
}
Aggregations