Search in sources :

Example 41 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class DNSController method removeAnchors.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removesettings", method = RequestMethod.POST)
public ModelAndView removeAnchors(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, @ModelAttribute("AdnsForm") DNSEntryForm AdnsForm, @ModelAttribute("NSdnsForm") DNSEntryForm NSdnsForm, @ModelAttribute("AAdnsForm") DNSEntryForm AAdnsForm, @ModelAttribute("CdnsForm") DNSEntryForm CdnsForm, @ModelAttribute("CertdnsForm") DNSEntryForm CertdnsForm, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, @ModelAttribute("SoadnsForm") DNSEntryForm SoadnsForm, @ModelAttribute("MXdnsForm") DNSEntryForm MXdnsForm, HttpSession session, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter domain/removesettings");
    // A records
    try {
        Collection<DNSRecord> arecords = null;
        if (dnsService != null && AdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected As")) && AdnsForm.getRemove() != null) {
            int cnt = AdnsForm.getRemove().size();
            arecords = dnsService.getDNSRecord(DNSType.A.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = AdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = arecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // A4 records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && AAdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteA4DnsEntries") || actionPath.equalsIgnoreCase("Remove Selected A4s")) && AAdnsForm.getRemove() != null) {
            int cnt = AAdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.AAAA.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = AAdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // CNAME records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && CdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCNAMEDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CNAMEs")) && CdnsForm.getRemove() != null) {
            int cnt = AAdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.CNAME.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = CdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // MX records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && MXdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteMXDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected MXs")) && MXdnsForm.getRemove() != null) {
            int cnt = MXdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.MX.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = MXdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // CERT records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && CertdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteCERTDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected CERTs")) && CertdnsForm.getRemove() != null) {
            int cnt = CertdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.CERT.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = CertdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // SRV records
    try {
        Collection<DNSRecord> a4records = null;
        if (dnsService != null && SrvdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSRVDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SRVs")) && SrvdnsForm.getRemove() != null) {
            int cnt = SrvdnsForm.getRemove().size();
            a4records = dnsService.getDNSRecord(DNSType.SRV.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = SrvdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = a4records.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // SOA records
    try {
        Collection<DNSRecord> soarecords = null;
        if (dnsService != null && SoadnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteSOADnsEntries") || actionPath.equalsIgnoreCase("Remove Selected SOAs")) && SoadnsForm.getRemove() != null) {
            int cnt = SoadnsForm.getRemove().size();
            soarecords = dnsService.getDNSRecord(DNSType.SOA.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = SoadnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = soarecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // NS records
    try {
        Collection<DNSRecord> nsrecords = null;
        if (dnsService != null && NSdnsForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deleteNSDnsEntries") || actionPath.equalsIgnoreCase("Remove Selected NSs")) && NSdnsForm.getRemove() != null) {
            int cnt = NSdnsForm.getRemove().size();
            nsrecords = dnsService.getDNSRecord(DNSType.NS.getValue(), "");
            for (int x = 0; x < cnt; x++) {
                String removeid = NSdnsForm.getRemove().get(x);
                Long remid = Long.parseLong(removeid);
                for (Iterator<DNSRecord> iter = nsrecords.iterator(); iter.hasNext(); ) {
                    DNSRecord t = (DNSRecord) iter.next();
                    if (t.getId() == remid) {
                        dnsService.deleteDNSRecordsByIds(Arrays.asList(remid));
                    }
                }
            }
        }
    } catch (ServiceException e1) {
    }
    // additional post clean up to redisplay
    ModelAndView mav = new ModelAndView("dns");
    if (AdnsForm.getRemove() != null) {
        if (log.isDebugEnabled())
            log.debug("the list of checkboxes checked or not is: " + AdnsForm.getRemove().toString());
    }
    /*
		 * if (configSvc != null && simpleForm != null && actionPath != null &&
		 * actionPath.equalsIgnoreCase("delete") && simpleForm.getRemove() !=
		 * null) { int cnt = simpleForm.getRemove().size(); try{
		 * Collection<String> settingstoberemovedlist = simpleForm.getRemove();
		 * if (log.isDebugEnabled())
		 * log.debug(" Trying to remove settings from database");
		 * configSvc.deleteSetting(settingstoberemovedlist); if
		 * (log.isDebugEnabled())
		 * log.debug(" SUCCESS Trying to remove settings"); } catch
		 * (ConfigurationServiceException e) { if (log.isDebugEnabled())
		 * log.error(e); } }
		 */
    refreshModelFromService(model);
    model.addAttribute("dnsEntryForm", new DNSEntryForm());
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with ServiceException

use of org.nhindirect.common.rest.exceptions.ServiceException in project nhin-d by DirectProject.

the class DNSController method addSRVSetting.

@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addSRVDNSRecord", method = RequestMethod.POST)
public ModelAndView addSRVSetting(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute("SrvdnsForm") DNSEntryForm SrvdnsForm, Model model, @RequestParam(value = "submitType") String actionPath) {
    if (log.isDebugEnabled())
        log.debug("Enter");
    // A records
    if (SrvdnsForm != null && !SrvdnsForm.getName().equalsIgnoreCase("") && SrvdnsForm.getTtl() != 0L && !SrvdnsForm.getDest().equalsIgnoreCase("")) {
        final DNSRecord rec = DNSEntryForm.entityToModelRecord(DNSRecordUtils.createSRVRecord("_" + SrvdnsForm.getService() + "._" + SrvdnsForm.getProtocol() + "." + SrvdnsForm.getName(), SrvdnsForm.getDest(), SrvdnsForm.getTtl(), SrvdnsForm.getPort(), SrvdnsForm.getPriority(), SrvdnsForm.getWeight()));
        try {
            dnsService.addDNSRecord(rec);
        } catch (ServiceException e) {
            e.printStackTrace();
        }
    }
    model.addAttribute("AdnsForm", new DNSEntryForm());
    model.addAttribute("AAdnsForm", new DNSEntryForm());
    model.addAttribute("CdnsForm", new DNSEntryForm());
    model.addAttribute("MXdnsForm", new DNSEntryForm());
    model.addAttribute("CertdnsForm", new DNSEntryForm());
    model.addAttribute("SrvdnsForm", new DNSEntryForm());
    ModelAndView mav = new ModelAndView("dns");
    refreshModelFromService(model);
    mav.setViewName("dns");
    if (log.isDebugEnabled())
        log.debug("Exit");
    return mav;
}
Also used : DNSRecord(org.nhindirect.config.model.DNSRecord) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) ConfigurationServiceException(org.nhindirect.config.service.ConfigurationServiceException) ModelAndView(org.springframework.web.servlet.ModelAndView) DNSEntryForm(org.nhindirect.config.ui.form.DNSEntryForm) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)42 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)31 ModelAndView (org.springframework.web.servlet.ModelAndView)31 ConfigurationServiceException (org.nhindirect.config.service.ConfigurationServiceException)19 IOException (java.io.IOException)18 SearchDomainForm (org.nhindirect.config.ui.form.SearchDomainForm)15 X509Certificate (java.security.cert.X509Certificate)12 Certificate (org.nhindirect.config.model.Certificate)12 CertificateForm (org.nhindirect.config.ui.form.CertificateForm)12 ArrayList (java.util.ArrayList)11 Domain (org.nhindirect.config.model.Domain)10 TrustBundleAnchor (org.nhindirect.config.model.TrustBundleAnchor)9 AddressForm (org.nhindirect.config.ui.form.AddressForm)9 AnchorForm (org.nhindirect.config.ui.form.AnchorForm)9 Anchor (org.nhindirect.config.model.Anchor)8 DomainForm (org.nhindirect.config.ui.form.DomainForm)8 SimpleForm (org.nhindirect.config.ui.form.SimpleForm)8 DNSEntryForm (org.nhindirect.config.ui.form.DNSEntryForm)7 TrustBundle (org.nhindirect.config.model.TrustBundle)6