use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method removeAddresses.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removeaddresses", method = RequestMethod.POST)
public ModelAndView removeAddresses(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final String domAttr = (String) session.getAttribute("currentDomainName");
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled())
log.debug("Enter domain/removeaddresses");
if (simpleForm.getRemove() != null) {
if (log.isDebugEnabled())
log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
}
Domain dom = null;
try {
dom = domainService.getDomain(domAttr);
} catch (ServiceException e) {
e.printStackTrace();
}
//+simpleForm.getId();
String strid = "" + dom.getDomainName();
String domname = "";
if (dom != null) {
domname = dom.getDomainName();
if (addressService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("delete") || actionPath.equalsIgnoreCase("remove selected Addresses")) && simpleForm.getRemove() != null) {
int cnt = simpleForm.getRemove().size();
if (log.isDebugEnabled())
log.debug("removing addresses for domain with name: " + domname);
try {
for (int x = 0; x < cnt; x++) {
String removeid = simpleForm.getRemove().get(x);
Collection<Address> t = dom.getAddresses();
for (Iterator<Address> iter = t.iterator(); iter.hasNext(); ) {
Address ts = (Address) iter.next();
if (ts.getId() == Long.parseLong(removeid)) {
dom.getAddresses().remove(ts);
if (addressService != null) {
addressService.deleteAddress(ts.getEmailAddress());
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
break;
}
}
}
}
if (log.isDebugEnabled())
log.debug(" Trying to update the domain with removed addresses");
domainService.updateDomain(dom);
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
if (log.isDebugEnabled())
log.debug(" SUCCESS Trying to update the domain with removed addresses");
final AddressForm addrform = new AddressForm();
addrform.setId(dom.getId());
addrform.setDomainName(dom.getDomainName());
model.addAttribute("addressForm", addrform);
// BEGIN: temporary code for mocking purposes
String owner = "";
model.addAttribute("addressesResults", dom.getAddresses());
Collection<Certificate> certlist = null;
try {
certlist = certService.getCertificatesByOwner(owner);
} catch (ServiceException e) {
e.printStackTrace();
}
Collection<Anchor> anchorlist = null;
try {
anchorlist = anchorService.getAnchorsForOwner(owner, false, false, "");
} catch (Exception e) {
}
model.addAttribute("certificatesResults", certlist);
// convert Anchor to AnchorForm
Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
// END: temporary code for mocking purposes
} catch (ServiceException e) {
if (log.isDebugEnabled())
log.error(e);
}
} else if (domainService != null && (actionPath.equalsIgnoreCase("newaddress") || actionPath.equalsIgnoreCase("add address"))) {
// insert the new address into the Domain list of Addresses
final String anEmail = simpleForm.getPostmasterEmail();
if (log.isDebugEnabled())
log.debug(" Trying to add address: " + anEmail);
final Address e = new Address();
e.setEmailAddress(anEmail);
dom.getAddresses().add(e);
simpleForm.setPostmasterEmail("");
try {
domainService.updateDomain(dom);
if (log.isDebugEnabled())
log.debug(" After attempt to insert new email address ");
} catch (ServiceException ed) {
if (log.isDebugEnabled())
log.error(ed);
}
}
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
final String action = "Update";
model.addAttribute("action", action);
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
form.populate(dom);
}
model.addAttribute("domainForm", form);
mav.setViewName("domain");
String owner = "";
// certificate and anchor forms and results
try {
if (owner != null && !owner.equalsIgnoreCase("")) {
final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
model.addAttribute("certificatesResults", certs);
final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
// convert Anchor to AnchorForm
final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
}
final CertificateForm cform = new CertificateForm();
model.addAttribute("certificateForm", cform);
final AnchorForm aform = new AnchorForm();
//aform.setId(dom.getId());
aform.setDomainName(dom.getDomainName());
model.addAttribute("anchorForm", aform);
} catch (ServiceException e1) {
e1.printStackTrace();
}
model.addAttribute("simpleForm", simpleForm);
//simpleForm.getId();
strid = "" + dom.getDomainName();
if (log.isDebugEnabled())
log.debug(" the value of id of simpleform is: " + strid);
return new ModelAndView("redirect:/config/domain?id=" + dom.getDomainName() + "#tab1");
//return mav;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class MainController method search.
/**
* Execute the search and return the results
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ModelAndView search(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
if (log.isDebugEnabled())
log.debug("Enter search");
String message = "Search complete";
ModelAndView mav = new ModelAndView();
// check to see if new domain requested
if (actionPath.equalsIgnoreCase("gotosettings")) {
if (log.isDebugEnabled())
log.debug("trying to go to the settings page");
String action = "add";
model.addAttribute("action", action);
mav.setViewName("settings");
mav.addObject("actionPath", actionPath);
SettingsForm form = (SettingsForm) session.getAttribute("settingsForm");
if (form == null) {
form = new SettingsForm();
}
model.addAttribute("settingsForm", form);
// retrieve list of settings for settingsResults
List<Setting> results = null;
if (configSvc != null) {
try {
Collection<Setting> settings = configSvc.getAllSettings();
if (settings != null)
results = new ArrayList<Setting>(settings);
else
results = new ArrayList<Setting>();
} catch (ConfigurationServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("simpleForm", new SimpleForm());
model.addAttribute("settingsResults", results);
} else if (actionPath.equalsIgnoreCase("gotocertificates")) {
if (log.isDebugEnabled())
log.debug("trying to go to the certificates page");
String action = "Update";
model.addAttribute("action", action);
mav.setViewName("certificates");
mav.addObject("actionPath", actionPath);
CertificateForm form = (CertificateForm) session.getAttribute("certificateForm");
if (form == null) {
form = new CertificateForm();
}
model.addAttribute("certificateForm", form);
// retrieve list of settings for settingsResults
List<Certificate> results = null;
if (configSvc != null) {
try {
Collection<Certificate> certs = configSvc.listCertificates(1, 10000, CertificateGetOptions.DEFAULT);
if (certs != null)
results = new ArrayList<Certificate>(certs);
else
results = new ArrayList<Certificate>();
} catch (ConfigurationServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("simpleForm", new SimpleForm());
model.addAttribute("certificatesResults", results);
} else if (actionPath.equalsIgnoreCase("newdomain")) {
if (log.isDebugEnabled())
log.debug("trying to go to the new domain page");
HashMap<String, String> msgs = new HashMap<String, String>();
mav.addObject("msgs", msgs);
model.addAttribute("simpleForm", new SimpleForm());
AddressForm addrform = new AddressForm();
addrform.setId(0L);
model.addAttribute("addressForm", addrform);
// TODO: once certificates and anchors are available change code accordingly
CertificateForm cform = new CertificateForm();
cform.setId(0L);
AnchorForm aform = new AnchorForm();
aform.setId(0L);
model.addAttribute("certificateForm", cform);
model.addAttribute("anchorForm", aform);
String action = "Add";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
mav.setViewName("domain");
mav.addObject("actionPath", actionPath);
mav.addObject("statusList", EntityStatus.getEntityStatusList());
} else if (actionPath.equalsIgnoreCase("gotodns")) {
if (log.isDebugEnabled())
log.debug("trying to go to the DNS page");
HashMap<String, String> msgs = new HashMap<String, String>();
mav.addObject("msgs", msgs);
String action = "Update";
model.addAttribute("action", action);
// get all DNSType.A.getValue() records
// GET A RECORDS
Collection<DNSRecord> arecords = null;
arecords = getDnsRecords(DNSType.A.getValue());
model.addAttribute("dnsARecordResults", arecords);
// GET A4 RECORDS
Collection<DNSRecord> a4records = null;
a4records = getDnsRecords(DNSType.AAAA.getValue());
model.addAttribute("dnsA4RecordResults", a4records);
// GET C RECORDS
Collection<DNSRecord> crecords = null;
crecords = getDnsRecords(DNSType.CNAME.getValue());
model.addAttribute("dnsCnameRecordResults", crecords);
// GET Cert RECORDS
Collection<DNSRecord> certrecords = null;
certrecords = getDnsRecords(DNSType.CERT.getValue());
model.addAttribute("dnsCertRecordResults", certrecords);
// GET MX RECORDS
Collection<DNSRecord> mxrecords = null;
mxrecords = getDnsRecords(DNSType.MX.getValue());
model.addAttribute("dnsMxRecordResults", mxrecords);
// GET SRV RECORDS
Collection<DNSRecord> srvrecords = null;
srvrecords = getDnsRecords(DNSType.SRV.getValue());
model.addAttribute("dnsSrvRecordResults", srvrecords);
mav.setViewName("dns");
mav.addObject("actionPath", actionPath);
model.addAttribute("AdnsForm", new DNSEntryForm());
model.addAttribute("AAdnsForm", new DNSEntryForm());
model.addAttribute("CdnsForm", new DNSEntryForm());
model.addAttribute("CertdnsForm", new DNSEntryForm());
model.addAttribute("MXdnsForm", new DNSEntryForm());
model.addAttribute("SrvdnsForm", new DNSEntryForm());
refreshModelFromService(model);
model.addAttribute("simpleForm", new SimpleForm());
} else {
SearchDomainForm form = (SearchDomainForm) session.getAttribute("searchDomainForm");
if (form == null) {
form = new SearchDomainForm();
}
model.addAttribute(form);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
String domain = form.getDomainName();
EntityStatus status = form.getStatus();
List<Domain> results = null;
if (configSvc != null) {
Collection<Domain> domains = configSvc.searchDomain(domain, status);
if (domains != null) {
results = new ArrayList<Domain>(domains);
} else {
results = new ArrayList<Domain>();
}
}
if (AjaxUtils.isAjaxRequest(requestedWith)) {
// prepare model for rendering success message in this request
model.addAttribute("message", new Message(MessageType.success, message));
model.addAttribute("ajaxRequest", true);
model.addAttribute("searchResults", results);
return null;
}
mav.setViewName("main");
mav.addObject("statusList", EntityStatus.getEntityStatusList());
mav.addObject("searchResults", results);
}
if (log.isDebugEnabled())
log.debug("Exit");
return mav;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method addCertificate.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addcertificate", method = RequestMethod.POST)
public ModelAndView addCertificate(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute CertificateForm certificateForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final ModelAndView mav = new ModelAndView();
String strid = "";
if (log.isDebugEnabled())
log.debug("Enter domain/addcertificate");
if (actionPath.equalsIgnoreCase("newcertificate") || actionPath.equalsIgnoreCase("add certificate")) {
strid = "" + certificateForm.getId();
Domain dom = null;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
String owner = "";
// insert the new address into the Domain list of Addresses
if (log.isDebugEnabled())
log.debug("beginning to evaluate filedata");
try {
if (!certificateForm.getFileData().isEmpty()) {
final byte[] bytes = certificateForm.getFileData().getBytes();
owner = certificateForm.getOwner();
final Certificate cert = new Certificate();
cert.setData(bytes);
cert.setOwner(owner);
cert.setStatus(certificateForm.getStatus());
certService.addCertificate(cert);
// store the bytes somewhere
if (log.isDebugEnabled())
log.debug("store the certificate into database");
} else {
if (log.isDebugEnabled())
log.debug("DO NOT store the certificate into database BECAUSE THERE IS NO FILE");
}
} catch (ServiceException ed) {
if (log.isDebugEnabled())
log.error(ed);
} catch (Exception e) {
if (log.isDebugEnabled())
log.error(e);
e.printStackTrace();
}
// certificate and anchor forms and results
try {
final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
model.addAttribute("certificatesResults", certs);
final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
final CertificateForm cform = new CertificateForm();
cform.setId(dom.getId());
model.addAttribute("certificateForm", cform);
final AnchorForm aform = new AnchorForm();
aform.setId(dom.getId());
model.addAttribute("anchorForm", aform);
} catch (ServiceException e1) {
e1.printStackTrace();
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
final SimpleForm simple = new SimpleForm();
simple.setId(Long.parseLong(strid));
model.addAttribute("simpleForm", simple);
model.addAttribute("addressesResults", dom.getAddresses());
mav.setViewName("domain");
// the Form's default button action
final String action = "Update";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
form.populate(dom);
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
}
final AddressForm addressForm2 = new AddressForm();
addressForm2.setDisplayName("");
addressForm2.setEndpoint("");
addressForm2.setEmailAddress("");
addressForm2.setType("");
addressForm2.setId(Long.parseLong(strid));
model.addAttribute("addressForm", addressForm2);
return mav;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method removeCertificates.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removecertifcates", method = RequestMethod.POST)
public ModelAndView removeCertificates(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute CertificateForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled())
log.debug("Enter domain/removecertificates");
if (simpleForm.getRemove() != null) {
if (log.isDebugEnabled())
log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
}
String strid = "" + simpleForm.getId();
Domain dom = null;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
String owner = "";
String domname = "";
if (certService != null && simpleForm != null && actionPath != null && (actionPath.equalsIgnoreCase("deletecertificate") || actionPath.equalsIgnoreCase("remove selected")) && simpleForm.getRemove() != null) {
int cnt = simpleForm.getRemove().size();
if (log.isDebugEnabled())
log.debug("removing certificates for domain with name: " + domname);
try {
// get list of certificates for this domain
final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
final ArrayList<Long> certtoberemovedlist = new ArrayList<Long>();
// now iterate over each one and remove the appropriate ones
for (int x = 0; x < cnt; x++) {
String removeid = simpleForm.getRemove().get(x);
for (Iterator<Certificate> iter = certs.iterator(); iter.hasNext(); ) {
Certificate t = (Certificate) iter.next();
//rest of the code block removed
if (t.getId() == Long.parseLong(removeid)) {
if (log.isDebugEnabled()) {
log.debug(" ");
log.debug("domain address id: " + t.getId());
log.debug(" ");
}
// create a collection of matching anchor ids
certtoberemovedlist.add(t.getId());
break;
}
}
}
// with the collection of anchor ids now remove them from the configSvc
if (log.isDebugEnabled())
log.debug(" Trying to remove certificates from database");
certService.deleteCertificatesByIds(certtoberemovedlist);
if (log.isDebugEnabled())
log.debug(" SUCCESS Trying to update the domain with removed certificates");
final AddressForm addrform = new AddressForm();
addrform.setId(dom.getId());
model.addAttribute("addressForm", addrform);
} catch (ServiceException e) {
if (log.isDebugEnabled())
log.error(e);
}
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
// BEGIN: temporary code for mocking purposes
final CertificateForm cform = new CertificateForm();
cform.setId(dom.getId());
model.addAttribute("certificateForm", cform);
final AnchorForm aform = new AnchorForm();
aform.setId(dom.getId());
model.addAttribute("anchorForm", aform);
model.addAttribute("addressesResults", dom.getAddresses());
mav.setViewName("domain");
// the Form's default button action
final String action = "Update";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
form.populate(dom);
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("action", action);
// SETTING THE ADDRESSES OBJECT
model.addAttribute("addressesResults", form.getAddresses());
Collection<Certificate> certlist = null;
try {
certlist = certService.getCertificatesByOwner(owner);
} catch (ServiceException e) {
e.printStackTrace();
}
Collection<Anchor> anchorlist = null;
try {
anchorlist = anchorService.getAnchorsForOwner(owner, false, false, "");
} catch (Exception e) {
e.printStackTrace();
}
model.addAttribute("certificatesResults", certlist);
// convert Anchor to AnchorForm
Collection<AnchorForm> convertedanchors = convertAnchors(anchorlist);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
// END: temporary code for mocking purposes
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
model.addAttribute("simpleForm", simpleForm);
strid = "" + simpleForm.getId();
if (log.isDebugEnabled())
log.debug(" the value of id of simpleform is: " + strid);
return mav;
}
use of org.nhindirect.config.ui.form.DomainForm in project nhin-d by DirectProject.
the class DomainController method addAddress.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addaddress", method = RequestMethod.POST)
public ModelAndView addAddress(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AddressForm addressForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final String domAttr = (String) session.getAttribute("currentDomainName");
ModelAndView mav = new ModelAndView();
String strid = "";
if (log.isDebugEnabled())
log.debug("Enter domain/addaddress");
Domain dom = null;
if (actionPath.equalsIgnoreCase("newaddress") || actionPath.equalsIgnoreCase("add address")) {
//addressForm.getId();
strid = "" + domAttr;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
String owner = dom.getDomainName();
// insert the new address into the Domain list of Addresses
final String anEmail = addressForm.getEmailAddress();
final String displayname = addressForm.getDisplayName();
final String endpoint = addressForm.getEndpoint();
final EntityStatus estatus = addressForm.getaStatus();
final String etype = addressForm.getType();
if (log.isDebugEnabled())
log.debug(" Trying to add address: " + anEmail);
final Address e = new Address();
e.setEmailAddress(anEmail);
e.setDisplayName(displayname);
e.setEndpoint(endpoint);
e.setStatus(estatus);
e.setType(etype);
final List<Address> modAddrs = new ArrayList<Address>(dom.getAddresses());
modAddrs.add(e);
dom.setAddresses(modAddrs);
try {
domainService.updateDomain(dom);
if (log.isDebugEnabled())
log.debug(" After attempt to insert new email address ");
} catch (ServiceException ed) {
if (log.isDebugEnabled())
log.error(ed);
}
// certificate and anchor forms and results
try {
final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
model.addAttribute("certificatesResults", certs);
} catch (ServiceException e1) {
}
try {
final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
// convert Anchor to AnchorForm
final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
} catch (Exception e1) {
}
try {
CertificateForm cform = new CertificateForm();
cform.setId(dom.getId());
model.addAttribute("certificateForm", cform);
AnchorForm aform = new AnchorForm();
aform.setId(dom.getId());
model.addAttribute("anchorForm", aform);
} catch (Exception e1x) {
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
SimpleForm simple = new SimpleForm();
//simple.setId(Long.parseLong(strid));
simple.setDomainName(dom.getDomainName());
model.addAttribute("simpleForm", simple);
model.addAttribute("addressesResults", dom.getAddresses());
mav.setViewName("domain");
// the Form's default button action
String action = "Update";
DomainForm form = (DomainForm) session.getAttribute("domainForm");
if (form == null) {
form = new DomainForm();
form.populate(dom);
}
model.addAttribute("domainForm", form);
model.addAttribute("action", action);
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
}
AddressForm addressForm2 = new AddressForm();
addressForm2.setDisplayName("");
addressForm2.setEndpoint("");
addressForm2.setEmailAddress("");
addressForm2.setType("");
//addressForm2.setId(Long.parseLong(strid));
addressForm2.setDomainName(strid);
model.addAttribute("addressForm", addressForm2);
//return new ModelAndView("redirect:/config/domain?id="+dom.getDomainName()+"#tab1");
return mav;
}
Aggregations