Search in sources :

Example 6 with DNSRecord

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");
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with DNSRecord

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");
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ConfigurationStoreException(org.nhindirect.config.store.ConfigurationStoreException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with DNSRecord

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) {
    }
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) DNSRecord(org.nhindirect.config.store.DNSRecord) NSRecord(org.xbill.DNS.NSRecord) TextParseException(org.xbill.DNS.TextParseException) CertificateEncodingException(javax.security.cert.CertificateEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException)

Example 9 with DNSRecord

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;
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm)

Example 10 with DNSRecord

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;
}
Also used : DNSRecord(org.nhindirect.config.store.DNSRecord) ArrayList(java.util.ArrayList) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm)

Aggregations

DNSRecord (org.nhindirect.config.store.DNSRecord)18 ArrayList (java.util.ArrayList)10 Transactional (org.springframework.transaction.annotation.Transactional)6 DNSDao (org.nhindirect.config.store.dao.DNSDao)5 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)4 List (java.util.List)3 Query (javax.persistence.Query)3 Expectations (org.jmock.Expectations)3 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)3 DNSServiceImpl (org.nhindirect.config.service.impl.DNSServiceImpl)3 Certificate (org.nhindirect.config.store.Certificate)3 TextParseException (org.xbill.DNS.TextParseException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateEncodingException (javax.security.cert.CertificateEncodingException)2 Address (org.nhindirect.config.store.Address)2 Anchor (org.nhindirect.config.store.Anchor)2 CertPolicy (org.nhindirect.config.store.CertPolicy)2 CertPolicyGroup (org.nhindirect.config.store.CertPolicyGroup)2 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)2 Domain (org.nhindirect.config.store.Domain)2