use of org.nhindirect.config.model.Address 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.model.Address in project nhin-d by DirectProject.
the class EntityModelConversion method toEntityDomain.
public static org.nhindirect.config.store.Domain toEntityDomain(Domain domain) {
final org.nhindirect.config.store.Domain retVal = new org.nhindirect.config.store.Domain();
final Collection<org.nhindirect.config.store.Address> addresses = new ArrayList<org.nhindirect.config.store.Address>();
if (domain.getAddresses() != null) {
for (Address address : domain.getAddresses()) {
addresses.add(toEntityAddress(address));
}
}
retVal.setAddresses(addresses);
retVal.setCreateTime(domain.getCreateTime());
retVal.setDomainName(domain.getDomainName());
retVal.setId(domain.getId());
if (domain.getPostmasterAddress() != null)
retVal.setPostMasterEmail(domain.getPostmasterAddress().getEmailAddress());
if (domain.getStatus() != null)
retVal.setStatus(org.nhindirect.config.store.EntityStatus.valueOf(domain.getStatus().toString()));
retVal.setUpdateTime(domain.getUpdateTime());
return retVal;
}
use of org.nhindirect.config.model.Address in project nhin-d by DirectProject.
the class EntityModelConversion method toModelDomain.
public static Domain toModelDomain(org.nhindirect.config.store.Domain domain) {
final Domain retVal = new Domain();
final Collection<Address> addresses = new ArrayList<Address>();
if (domain.getAddresses() != null) {
for (org.nhindirect.config.store.Address address : domain.getAddresses()) {
addresses.add(toModelAddress(address));
}
}
retVal.setAddresses(addresses);
retVal.setCreateTime(domain.getCreateTime());
retVal.setDomainName(domain.getDomainName());
retVal.setId(domain.getId());
// get the postmaster address
if (domain.getPostMasterEmail() != null && !domain.getPostMasterEmail().isEmpty()) {
System.out.println("Postmaster email address: " + domain.getPostMasterEmail());
if ((domain.getAddresses().size() > 0) && (domain.getPostmasterAddressId() != null) && (domain.getPostmasterAddressId() > 0)) {
for (org.nhindirect.config.store.Address address : domain.getAddresses()) {
if (address.getId().equals(domain.getPostmasterAddressId())) {
retVal.setPostmasterAddress(toModelAddress(address));
break;
}
}
}
}
if (domain.getStatus() != null)
retVal.setStatus(EntityStatus.valueOf(domain.getStatus().toString()));
retVal.setUpdateTime(domain.getUpdateTime());
return retVal;
}
use of org.nhindirect.config.model.Address in project nhin-d by DirectProject.
the class EntityModelConversion method toModelAddress.
public static Address toModelAddress(org.nhindirect.config.store.Address address) {
if (address == null)
return null;
final Address retVal = new Address();
retVal.setCreateTime(address.getCreateTime());
retVal.setDisplayName(address.getDisplayName());
retVal.setEmailAddress(address.getEmailAddress());
retVal.setEndpoint(address.getEndpoint());
retVal.setId(address.getId());
if (address.getStatus() != null)
retVal.setStatus(EntityStatus.valueOf(address.getStatus().toString()));
retVal.setType(address.getType());
retVal.setUpdateTime(address.getUpdateTime());
if (address.getDomain() != null)
retVal.setDomainName(address.getDomain().getDomainName());
return retVal;
}
use of org.nhindirect.config.model.Address 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