use of org.nhindirect.config.store.Setting in project nhin-d by DirectProject.
the class SettingDaoImpl method getByNames.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public Collection<Setting> getByNames(Collection<String> names) {
if (log.isDebugEnabled())
log.debug("Enter");
if (names == null || names.size() == 0)
return getAll();
List<Setting> result = Collections.emptyList();
Query select = null;
StringBuffer nameList = new StringBuffer("(");
for (String name : names) {
if (nameList.length() > 1) {
nameList.append(", ");
}
nameList.append("'").append(name.toUpperCase(Locale.getDefault())).append("'");
}
nameList.append(")");
String query = "SELECT s from Setting s WHERE UPPER(s.name) IN " + nameList.toString();
select = entityManager.createQuery(query);
@SuppressWarnings("rawtypes") List rs = select.getResultList();
if (rs != null && (rs.size() != 0) && (rs.get(0) instanceof Setting)) {
result = (List<Setting>) rs;
}
if (log.isDebugEnabled())
log.debug("Exit");
return result;
}
use of org.nhindirect.config.store.Setting 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;
}
Aggregations