use of org.nhindirect.config.ui.form.BundleForm in project nhin-d by DirectProject.
the class BundlesController method addBundle.
/*********************************
*
* Add Bundle Method
*
*********************************/
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addbundle", method = RequestMethod.POST)
public ModelAndView addBundle(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm bundleForm, Model model, @RequestParam(value = "submitType") String actionPath) {
final ModelAndView mav = new ModelAndView();
// Debug Statement
if (log.isDebugEnabled())
log.debug("Enter Add Trust Bundle");
if (actionPath.equalsIgnoreCase("cancel")) {
if (log.isDebugEnabled()) {
log.debug("trying to cancel from saveupdate");
}
// If cancel then clear form
final SearchDomainForm form2 = (SearchDomainForm) session.getAttribute("searchDomainForm");
model.addAttribute(form2 != null ? form2 : new SearchDomainForm());
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.setViewName("main");
mav.addObject("privKeyTypeList", PrivateKeyType.getPrivKeyTypeList());
mav.addObject("statusList", EntityStatus.getEntityStatusList());
return mav;
}
if (actionPath.equalsIgnoreCase("newbundle") || actionPath.equalsIgnoreCase("add bundle")) {
Boolean formValidated = true;
if (log.isDebugEnabled()) {
log.debug("Beginning to process signing certificate file");
}
model.addAttribute("signingCertError", false);
model.addAttribute("URLError", false);
final TrustBundle trustBundle = new TrustBundle();
String bundleName = bundleForm.getBundleName();
trustBundle.setBundleName(bundleName);
// Convert Hours to Seconds for backend
trustBundle.setRefreshInterval(bundleForm.getRefreshInterval() * 3600);
// Check if signing certificate is uploaded
if (!bundleForm.getFileData().isEmpty()) {
byte[] bytes = bundleForm.getFileData().getBytes();
final String fileType = bundleForm.getFileData().getContentType();
if (!fileType.matches("application/x-x509-ca-cert") && !fileType.matches("application/x-x509-user-cert") && !fileType.matches("application/pkix-cert")) {
model.addAttribute("signingCertError", true);
formValidated = false;
} else {
try {
trustBundle.setSigningCertificateData(bytes);
} catch (Exception ce) {
}
}
} else {
if (log.isDebugEnabled())
log.debug("DO NOT store the bundle into database BECAUSE THERE IS NO FILE");
}
// Check for empty bundle name
if (bundleName.isEmpty()) {
model.addAttribute("EmptyBundleError", true);
formValidated = false;
} else {
// Check if trust bundle name is already used
TrustBundle dupeBundle = null;
try {
dupeBundle = bundleService.getTrustBundle(bundleName);
} catch (ServiceException cse) {
log.error("Could not get bundle information from config service");
}
if (dupeBundle != null) {
model.addAttribute("DupeBundleError", true);
formValidated = false;
}
}
// Check for valid URL
final String trustURL = bundleForm.getTrustURL();
try {
new URL(trustURL);
} catch (MalformedURLException mu) {
model.addAttribute("URLError", true);
formValidated = false;
}
if (formValidated) {
trustBundle.setBundleURL(trustURL);
try {
trustBundle.setCheckSum("");
bundleService.addTrustBundle(trustBundle);
if (log.isDebugEnabled()) {
log.debug("Add Trust Bundle to Database");
}
} catch (Exception e) {
if (log.isDebugEnabled())
log.error(e);
e.printStackTrace();
}
final BundleForm bform = new BundleForm();
model.addAttribute("bundleForm", bform);
}
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
if (trustBundles != null) {
model.addAttribute("trustBundles", trustBundles);
}
} catch (ServiceException e1) {
}
model.addAttribute("bundlesSelected");
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
mav.setViewName("bundles");
}
return mav;
}
use of org.nhindirect.config.ui.form.BundleForm in project nhin-d by DirectProject.
the class BundlesController method removeCertificates.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/removebundle", method = RequestMethod.POST)
public ModelAndView removeCertificates(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
final ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/removebundle");
}
if (simpleForm.getBundlesSelected() != null) {
if (log.isDebugEnabled()) {
log.debug("Bundles marked for removal: " + simpleForm.getBundlesSelected().toString());
}
}
if (bundleService != null && simpleForm != null && simpleForm.getBundlesSelected() != null) {
final int bundleCount = simpleForm.getBundlesSelected().size();
if (log.isDebugEnabled()) {
log.debug("Removing Bundles");
}
for (int i = 0; i < bundleCount; i++) {
final String bundleName = simpleForm.getBundlesSelected().get(i);
log.error(bundleName);
// Delete Trust Bundle(s)
try {
bundleService.deleteTrustBundle(bundleName);
} catch (ServiceException cse) {
log.error("Problem removing bundles");
}
}
}
model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(requestedWith));
final BundleForm bform = new BundleForm();
bform.setId(0);
model.addAttribute("bundleForm", bform);
mav.setViewName("bundles");
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
if (trustBundles != null) {
model.addAttribute("trustBundles", trustBundles);
}
} catch (ServiceException e1) {
}
return mav;
}
use of org.nhindirect.config.ui.form.BundleForm in project nhin-d by DirectProject.
the class BundlesController method assignBundlesForm.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/assignBundlesForm", method = RequestMethod.GET)
public ModelAndView assignBundlesForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/assignBundles");
}
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = bundleService.getTrustBundles(false);
if (trustBundles != null) {
model.addAttribute("trustBundles", trustBundles);
}
} catch (ServiceException e1) {
}
BundleForm bform = new BundleForm();
bform.setId(0);
bform.setDomainName((String) session.getAttribute("currentDomainName"));
model.addAttribute("bundleForm", bform);
mav.setViewName("assignBundlesForm");
return mav;
}
use of org.nhindirect.config.ui.form.BundleForm in project nhin-d by DirectProject.
the class BundlesController method addMoreBundlesForm.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/addMoreBundlesForm", method = RequestMethod.GET)
public ModelAndView addMoreBundlesForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, @RequestParam(value = "domainName") String domainName, Model model) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/addMoreBundlesForm");
}
// Process data for Trust Bundle View
try {
// Get Trust Bundles
final Collection<TrustBundle> trustBundles = new ArrayList<TrustBundle>();
Collection<TrustBundle> newBundles = new ArrayList<TrustBundle>();
final Collection<TrustBundleDomainReltn> bundleRelationships = bundleService.getTrustBundlesByDomain(domainName, false);
final Collection<TrustBundle> allBundles = bundleService.getTrustBundles(false);
boolean bundleMatch = false;
if (bundleRelationships != null && !bundleRelationships.isEmpty()) {
for (TrustBundleDomainReltn relationship : bundleRelationships) {
trustBundles.add(relationship.getTrustBundle());
}
for (TrustBundle bundle : allBundles) {
bundleMatch = false;
for (TrustBundle subBundle : trustBundles) {
if (subBundle.getId() == bundle.getId()) {
bundleMatch = true;
}
}
if (!bundleMatch) {
newBundles.add(bundle);
}
}
} else {
newBundles = bundleService.getTrustBundles(false);
}
//if(trustBundles != null) {
model.addAttribute("trustBundles", newBundles);
//}
} catch (ServiceException e1) {
}
model.addAttribute("domainName", domainName);
BundleForm bform = new BundleForm();
bform.setId(0);
bform.setDomainName((String) session.getAttribute("currentDomainName"));
model.addAttribute("bundleForm", bform);
mav.setViewName("addMoreBundlesForm");
return mav;
}
use of org.nhindirect.config.ui.form.BundleForm in project nhin-d by DirectProject.
the class BundlesController method newBundleForm.
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/newBundleForm", method = RequestMethod.GET)
public ModelAndView newBundleForm(@RequestHeader(value = "X-Requested-With", required = false) String requestedWith, HttpSession session, @ModelAttribute BundleForm simpleForm, Model model) {
ModelAndView mav = new ModelAndView();
if (log.isDebugEnabled()) {
log.debug("Enter bundles/newBundles");
}
BundleForm bform = new BundleForm();
bform.setId(0);
model.addAttribute("bundleForm", bform);
mav.setViewName("newBundleForm");
return mav;
}
Aggregations