use of org.nhindirect.config.model.Anchor in project nhin-d by DirectProject.
the class DomainController method removeDomain.
/** removeDomain
*
*
*
*
*/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/remove", method = RequestMethod.POST)
public ModelAndView removeDomain(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute SimpleForm simpleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled())
log.debug("Enter domain/remove");
if (log.isDebugEnabled())
log.debug("the list of checkboxes checked or not is: " + simpleForm.getRemove().toString());
if (domainService != null) {
int cnt = simpleForm.getRemove().size();
for (int x = 0; x < cnt; x++) {
try {
String strid = simpleForm.getRemove().get(x);
Domain dom = null;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
if (dom != null) {
String owner = dom.getDomainName();
if (log.isDebugEnabled())
log.debug("removing domain with name: " + strid);
domainService.deleteDomain(dom.getDomainName());
// now delete anchors
try {
// get list of certificates for this domain
final Collection<Anchor> certs = anchorService.getAnchorsForOwner(owner, false, false, "");
if (certs != null && !certs.isEmpty()) {
final ArrayList<Long> certtoberemovedlist = new ArrayList<Long>();
// appropriate ones
for (Iterator<Anchor> iter = certs.iterator(); iter.hasNext(); ) {
Anchor t = (Anchor) iter.next();
certtoberemovedlist.add(t.getId());
}
// from the configSvc
if (log.isDebugEnabled())
log.debug(" Trying to remove anchors from database");
anchorService.deleteAnchorsByIds(certtoberemovedlist);
if (log.isDebugEnabled())
log.debug(" SUCCESS Trying to remove anchors");
}
} catch (ServiceException e) {
if (log.isDebugEnabled())
log.error(e);
}
}
} catch (ServiceException e) {
if (log.isDebugEnabled())
log.error(e);
}
}
}
SearchDomainForm form2 = (SearchDomainForm) session.getAttribute("searchDomainForm");
model.addAttribute(form2 != null ? form2 : new SearchDomainForm());
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
// Get all domains managed by this HISP
String domain = "%";
List<Domain> results = null;
if (domainService != null) {
try {
List<Domain> domains = new ArrayList<Domain>();
Collection<Domain> enabledDomains = domainService.searchDomains(domain, EntityStatus.ENABLED);
Collection<Domain> disabledDomains = domainService.searchDomains(domain, EntityStatus.DISABLED);
Collection<Domain> newDomains = domainService.searchDomains(domain, EntityStatus.NEW);
if (!enabledDomains.isEmpty()) {
domains.addAll(enabledDomains);
}
if (!disabledDomains.isEmpty()) {
domains.addAll(disabledDomains);
}
if (newDomains != null) {
domains.addAll(newDomains);
}
results = domains;
} catch (ServiceException e) {
e.printStackTrace();
}
}
model.addAttribute("searchResults", results);
mav.setViewName("main");
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
mav.addObject("searchResults", results);
mav.addObject("statusList", EntityStatus.getEntityStatusList());
return mav;
}
use of org.nhindirect.config.model.Anchor in project nhin-d by DirectProject.
the class DomainController method addAnchor.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addanchor", method = RequestMethod.POST)
public ModelAndView addAnchor(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute AnchorForm anchorForm, Model model, @RequestParam(value = "submitType") String actionPath, @RequestParam(value = "id") String id) {
final String domAttr = (String) session.getAttribute("currentDomainName");
ModelAndView mav = new ModelAndView();
String strid = "";
//anchorForm.getId();
strid = "" + domAttr;
Domain dom = null;
try {
dom = domainService.getDomain(strid);
} catch (ServiceException e) {
e.printStackTrace();
}
if (log.isDebugEnabled())
log.debug("Enter domain/addanchor");
if (actionPath.equalsIgnoreCase("newanchor") || actionPath.equalsIgnoreCase("add anchor")) {
strid = "" + anchorForm.getId();
String owner = "";
if (dom != null) {
owner = dom.getDomainName();
}
// insert the new address into the Domain list of Addresses
if (log.isDebugEnabled())
log.debug("beginning to evaluate filedata");
try {
if (!anchorForm.getFileData().isEmpty()) {
final byte[] bytes = anchorForm.getFileData().getBytes();
String theUser = "";
if (bytes != null) {
// get the owner from the certificate information
// first transform into a certificate
CertContainer cont = toCertContainer(bytes);
if (cont != null && cont.getCert() != null) {
// now get the owner info from the cert
theUser = getTrustedEntityName(cont.getCert().getSubjectX500Principal());
anchorForm.setTrusteddomainoruser(theUser);
}
}
// store the bytes somewhere
final Anchor ank = new Anchor();
ank.setCertificateData(bytes);
if (log.isDebugEnabled())
log.debug("incoming is: " + anchorForm.isIncoming() + " and outgoing is: " + anchorForm.isOutgoing());
ank.setIncoming(anchorForm.isIncoming());
ank.setOutgoing(anchorForm.isOutgoing());
ank.setOwner(owner);
ank.setStatus(anchorForm.getStatus());
anchorService.addAnchor(ank);
if (log.isDebugEnabled())
log.debug("store the anchor certificate into database");
} else {
if (log.isDebugEnabled())
log.debug("DO NOT store the anchor certificate into database BECAUSE THERE IS NO FILE");
}
} catch (ConfigurationServiceException ed) {
if (log.isDebugEnabled())
log.error(ed);
} catch (Exception e) {
if (log.isDebugEnabled())
log.error(e.getMessage());
e.printStackTrace();
}
// certificate and anchor forms and results
try {
final Collection<Certificate> certs = certService.getCertificatesByOwner(owner);
model.addAttribute("certificatesResults", certs);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
final Collection<Anchor> anchors = anchorService.getAnchorsForOwner(owner, false, false, "");
final Collection<AnchorForm> convertedanchors = convertAnchors(anchors);
// now set anchorsResults
model.addAttribute("anchorsResults", convertedanchors);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
CertificateForm cform = new CertificateForm();
cform.setId(dom.getId());
model.addAttribute("certificateForm", cform);
} catch (Exception e1) {
e1.printStackTrace();
}
try {
AnchorForm aform = new AnchorForm();
aform.setId(dom.getId());
model.addAttribute("anchorForm", aform);
} catch (Exception e1) {
e1.printStackTrace();
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
SimpleForm simple = new SimpleForm();
simple.setId(dom.getId());
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));
model.addAttribute("addressForm", addressForm2);
return new ModelAndView("redirect:/config/domain?id=" + dom.getDomainName() + "#tab2");
//return mav;
}
Aggregations