use of org.directwebremoting.WebContext in project ma-modules-public by infiniteautomation.
the class ReportsDwr method saveReport.
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult saveReport(int id, String name, String xid, List<ReportPointVO> points, String template, int includeEvents, boolean includeUserComments, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, boolean schedule, int schedulePeriod, int runDelayMinutes, String scheduleCron, boolean email, boolean includeData, boolean zipData, List<RecipientListEntryBean> recipients) {
ProcessResult response = new ProcessResult();
// Basic validation
validateData(response, name, points, dateRangeType, relativeDateType, previousPeriodCount, pastPeriodCount);
// Validate XID
if (StringUtils.isBlank(xid))
response.addContextualMessage("xid", "validate.required");
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!ReportDao.instance.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");
if (schedule) {
if (schedulePeriod == ReportVO.SCHEDULE_CRON) {
// Check the cron pattern.
try {
new CronTimerTrigger(scheduleCron);
} catch (Exception e) {
response.addContextualMessage("scheduleCron", "reports.validate.cron", e.getMessage());
}
} else {
if (runDelayMinutes < 0)
response.addContextualMessage("runDelayMinutes", "reports.validate.lessThan0");
else if (runDelayMinutes > 59)
response.addContextualMessage("runDelayMinutes", "reports.validate.greaterThan59");
}
}
if (email && recipients.isEmpty())
response.addContextualMessage("recipients", "reports.validate.needRecip");
if (response.getHasMessages())
return response;
User user = Common.getUser();
ReportDao reportDao = ReportDao.instance;
ReportVO report;
if (id == Common.NEW_ID) {
report = new ReportVO();
report.setUserId(user.getId());
} else
report = reportDao.getReport(id);
ReportCommon.ensureReportPermission(user, report);
// Update the new values.
report.setXid(xid);
report.setName(name);
report.setPoints(points);
report.setTemplate(template);
report.setIncludeEvents(includeEvents);
report.setIncludeUserComments(includeUserComments);
report.setDateRangeType(dateRangeType);
report.setRelativeDateType(relativeDateType);
report.setPreviousPeriodCount(previousPeriodCount);
report.setPreviousPeriodType(previousPeriodType);
report.setPastPeriodCount(pastPeriodCount);
report.setPastPeriodType(pastPeriodType);
report.setFromNone(fromNone);
report.setFromYear(fromYear);
report.setFromMonth(fromMonth);
report.setFromDay(fromDay);
report.setFromHour(fromHour);
report.setFromMinute(fromMinute);
report.setToNone(toNone);
report.setToYear(toYear);
report.setToMonth(toMonth);
report.setToDay(toDay);
report.setToHour(toHour);
report.setToMinute(toMinute);
report.setSchedule(schedule);
report.setSchedulePeriod(schedulePeriod);
report.setRunDelayMinutes(runDelayMinutes);
report.setScheduleCron(scheduleCron);
report.setEmail(email);
report.setIncludeData(includeData);
report.setZipData(zipData);
report.setRecipients(recipients);
// Save the report
reportDao.saveReport(report);
// Conditionally schedule the report.
String host = "";
WebContext webContext = WebContextFactory.get();
int port;
if (webContext != null) {
HttpServletRequest req = webContext.getHttpServletRequest();
host = req.getServerName();
port = req.getLocalPort();
} else {
port = Common.envProps.getInt("web.port", 8080);
}
ReportJob.scheduleReportJob(host, port, report);
// Send back the report id in case this was new.
response.addData("reportId", report.getId());
response.addData("report", report);
return response;
}
use of org.directwebremoting.WebContext in project ma-core-public by infiniteautomation.
the class MiscDwr method setLocale.
@DwrPermission(anonymous = true)
public void setLocale(String locale) {
WebContext webContext = WebContextFactory.get();
LocaleResolver localeResolver = new SessionLocaleResolver();
LocaleEditor localeEditor = new LocaleEditor();
localeEditor.setAsText(locale);
localeResolver.setLocale(webContext.getHttpServletRequest(), webContext.getHttpServletResponse(), (Locale) localeEditor.getValue());
}
use of org.directwebremoting.WebContext in project ma-core-public by infiniteautomation.
the class StartupDwr method getStartupProgress.
@DwrPermission(anonymous = true)
public ProcessResult getStartupProgress(long since) {
ProcessResult result = new ProcessResult();
IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
float progress = lifecycle.getStartupProgress();
float shutdownProgress = lifecycle.getShutdownProgress();
List<String> messages = LoggingConsoleRT.instance.getMessagesSince(since);
StringBuilder builder = new StringBuilder();
for (String message : messages) {
builder.append(message);
builder.append("</br>");
}
result.addData("message", builder.toString());
result.addData("startupProgress", progress);
result.addData("shutdownProgress", shutdownProgress);
result.addData("state", getLifecycleStateMessage(lifecycle.getLifecycleState()));
if ((progress >= 100) && (shutdownProgress == 0)) {
WebContext ctx = WebContextFactory.get();
result.addData("startupUri", DefaultPagesDefinition.getLoginUri(ctx.getHttpServletRequest(), ctx.getHttpServletResponse()));
}
// Add the message to describe what process we are in
if ((progress < 100) && (shutdownProgress == 0)) {
result.addData("processMessage", this.translations.translate("startup.startingUp"));
} else if ((shutdownProgress > 0) && (lifecycle.isRestarting())) {
result.addData("processMessage", this.translations.translate("shutdown.restarting"));
} else if (shutdownProgress > 0) {
result.addData("processMessage", this.translations.translate("shutdown.shuttingDown"));
}
if ((progress == 100) && (shutdownProgress == 0)) {
result.addData("processMessage", this.translations.translate("startup.state.running"));
}
return result;
}
use of org.directwebremoting.WebContext in project ma-core-public by infiniteautomation.
the class StrutsCreator method getType.
/* (non-Javadoc)
* @see org.directwebremoting.Creator#getType()
*/
public Class getType() {
synchronized (this) {
if (moduleConfig == null) {
WebContext wc = WebContextFactory.get();
if (getInstanceMethod != null) {
try {
// ModuleUtils utils = ModuleUtils.getInstance();
Object utils = getInstanceMethod.invoke(null, new Object[0]);
// String moduleName = utils.getModuleName("/", wc.getServletContext());
String moduleName = (String) getModuleNameMethod.invoke(utils, new Object[] { "/", wc.getServletContext() });
// moduleConfig = utils.getModuleConfig(moduleName, wc.getServletContext());
moduleConfig = (ModuleConfig) getModuleConfigMethod.invoke(utils, new Object[] { moduleName, wc.getServletContext() });
} catch (Exception ex) {
throw new IllegalArgumentException(ex.getMessage());
}
} else {
HttpServletRequest request = wc.getHttpServletRequest();
if (request == null) {
log.warn("Using a FakeHttpServletRequest as part of setup");
request = new FakeHttpServletRequest();
}
moduleConfig = RequestUtils.getModuleConfig(request, wc.getServletContext());
}
}
}
try {
return LocalUtil.classForName(moduleConfig.findFormBeanConfig(formBean).getType());
} catch (ClassNotFoundException ex) {
throw new IllegalArgumentException(Messages.getString("Creator.ClassNotFound", moduleConfig.findFormBeanConfig(formBean).getType()));
}
}
use of org.directwebremoting.WebContext in project ma-core-public by infiniteautomation.
the class DefaultPageNormalizer method normalizePage.
/* (non-Javadoc)
* @see org.directwebremoting.extend.PageNormalizer#normalizePage(java.lang.String)
*/
public String normalizePage(String unnormalized) {
synchronized (initLock) {
if (welcomeFiles == null) {
if (servletContext != null) {
welcomeFiles = getWebXmlWelcomeFileList(servletContext);
} else {
WebContext webContext = WebContextFactory.get();
if (webContext == null) {
log.warn("Can't find ServletContext to check for <welcome-file-list> in web.xml. Assuming defaults.");
log.warn(" - To prevent this message from happening, either call the PageNormalizer from a DWR thread");
log.warn(" - Or seed the PageNormalizer with a ServletContext before access from outside a DWR thread");
} else {
ServletContext threadServletContext = webContext.getServletContext();
welcomeFiles = getWebXmlWelcomeFileList(threadServletContext);
}
}
}
if (welcomeFiles == null) {
log.debug("Using default welcome file list (index.[jsp|htm[l]])");
welcomeFiles = getDefaultWelcomeFileList();
}
}
if (unnormalized == null) {
return null;
}
String normalized = unnormalized;
if (!normalizeIncludesQueryString) {
int queryPos = normalized.indexOf('?');
if (queryPos != -1) {
normalized = normalized.substring(0, queryPos);
}
}
for (Iterator it = welcomeFiles.iterator(); it.hasNext(); ) {
String welcomeFile = (String) it.next();
if (normalized.endsWith(welcomeFile)) {
normalized = normalized.substring(0, normalized.length() - welcomeFile.length());
break;
}
}
return normalized;
}
Aggregations