use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class DNSDaoImpl method update.
/**
* {@inheritDoc}}
*/
@Override
@Transactional(readOnly = false)
public void update(long id, DNSRecord record) {
if (log.isDebugEnabled())
log.debug("remove(long id, DNSRecord record) Enter");
try {
// get the record
if (record.getType() == Type.ANY)
throw new ConfigurationStoreException("Record type for update cannot be ANY");
DNSRecord toUpdate = get(id);
if (toUpdate == null)
throw new ConfigurationStoreException("Record with id " + id + " does not exist.");
toUpdate.setType(record.getType());
toUpdate.setName(record.getName());
toUpdate.setTtl(record.getTtl());
toUpdate.setDclass(record.getDclass());
toUpdate.setData(record.getData());
entityManager.merge(toUpdate);
entityManager.flush();
if (log.isDebugEnabled())
log.debug("1 DNS record updated.");
} finally {
if (log.isDebugEnabled())
log.debug("remove(long id, DNSRecord record) Exit");
}
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class DNSDaoImpl method add.
/**
* {@inheritDoc}}
*/
@Override
@Transactional(readOnly = false)
public void add(Collection<DNSRecord> records) {
if (log.isDebugEnabled())
log.debug("add() Enter");
try {
if (records != null && records.size() > 0) {
for (DNSRecord record : records) {
if (record.getType() == Type.ANY)
throw new ConfigurationStoreException("Cannot add records with type ANY.");
else {
Collection<DNSRecord> checkRecs = get(record.getName(), record.getType());
if (checkRecs.contains(record))
throw new ConfigurationStoreException("Record name " + record.getName() + " and type " + record.getType() + " already exists with same rdata.");
}
record.setCreateTime(Calendar.getInstance());
if (log.isDebugEnabled())
log.debug("Persisting DNS record\r\n\tName: " + record.getName() + "\r\n\tType: " + record.getType());
entityManager.persist(record);
}
if (log.isDebugEnabled())
log.debug("Flushing " + records.size() + " added records.");
entityManager.flush();
}
} finally {
if (log.isDebugEnabled())
log.debug("add() Exit");
}
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class ServiceTest method testNS.
// @Test
public void testNS() {
DNSEntryForm nsForm = new DNSEntryForm();
nsForm.setTtl(8455L);
nsForm.setName("name3");
nsForm.setDest("192.3.4.5");
try {
Collection<DNSRecord> arecords = configSvc.getDNSByType(DNSType.NS.getValue());
for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
DNSRecord arec = iter.next();
NSRecord newrec = (NSRecord) Record.newRecord(Name.fromString(arec.getName()), arec.getType(), arec.getDclass(), arec.getTtl(), arec.getData());
System.out.println("target : " + newrec.getTarget());
System.out.println("name: " + newrec.getName());
}
} catch (Exception e) {
}
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class DNSController method convertDNSRecords.
private Collection<DNSEntryForm> convertDNSRecords(Collection<DNSRecord> entries) {
if (log.isDebugEnabled())
log.debug("Enter");
Collection<DNSEntryForm> forms = new ArrayList<DNSEntryForm>();
if (entries != null) {
for (Iterator<DNSRecord> iter = entries.iterator(); iter.hasNext(); ) {
DNSEntryForm form = new DNSEntryForm(iter.next());
forms.add(form);
}
}
if (log.isDebugEnabled())
log.debug("Exit");
return forms;
}
use of org.nhindirect.config.store.DNSRecord in project nhin-d by DirectProject.
the class MainController method convertDNSRecords.
private Collection<DNSEntryForm> convertDNSRecords(Collection<DNSRecord> entries) {
if (log.isDebugEnabled())
log.debug("Enter");
Collection<DNSEntryForm> forms = new ArrayList<DNSEntryForm>();
if (entries != null) {
for (Iterator<DNSRecord> iter = entries.iterator(); iter.hasNext(); ) {
DNSEntryForm form = new DNSEntryForm(iter.next());
forms.add(form);
}
}
if (log.isDebugEnabled())
log.debug("Exit");
return forms;
}
Aggregations