Search in sources :

Example 1 with ScheduleTaskImpl

use of lucee.runtime.schedule.ScheduleTaskImpl in project Lucee by lucee.

the class Schedule method doList.

/**
 * @throws PageException
 */
private void doList() throws PageException {
    // if(tr ue) throw new PageRuntimeException("qqq");
    ScheduleTask[] tasks = scheduler.getAllScheduleTasks();
    final String v = "VARCHAR";
    String[] cols = new String[] { "task", "path", "file", "startdate", "starttime", "enddate", "endtime", "url", "port", "interval", "timeout", "username", "password", "proxyserver", "proxyport", "proxyuser", "proxypassword", "resolveurl", "publish", "valid", "paused", "autoDelete" };
    String[] types = new String[] { v, v, v, "DATE", "OTHER", "DATE", "OTHER", v, v, v, v, v, v, v, v, v, v, v, "BOOLEAN", v, "BOOLEAN", "BOOLEAN" };
    lucee.runtime.type.Query query = new QueryImpl(cols, types, tasks.length, "query");
    try {
        for (int i = 0; i < tasks.length; i++) {
            int row = i + 1;
            ScheduleTask task = tasks[i];
            query.setAt(KeyConstants._task, row, task.getTask());
            if (task.getResource() != null) {
                query.setAt(KeyConstants._path, row, task.getResource().getParent());
                query.setAt(KeyConstants._file, row, task.getResource().getName());
            }
            query.setAt("publish", row, Caster.toBoolean(task.isPublish()));
            query.setAt("startdate", row, task.getStartDate());
            query.setAt("starttime", row, task.getStartTime());
            query.setAt("enddate", row, task.getEndDate());
            query.setAt("endtime", row, task.getEndTime());
            query.setAt(KeyConstants._url, row, printUrl(task.getUrl()));
            query.setAt(KeyConstants._port, row, Caster.toString(HTTPUtil.getPort(task.getUrl())));
            query.setAt("interval", row, task.getStringInterval());
            query.setAt("timeout", row, Caster.toString(task.getTimeout() / 1000));
            query.setAt("valid", row, Caster.toString(task.isValid()));
            if (task.hasCredentials()) {
                query.setAt("username", row, task.getCredentials().getUsername());
                query.setAt("password", row, task.getCredentials().getPassword());
            }
            ProxyData pd = task.getProxyData();
            if (ProxyDataImpl.isValid(pd)) {
                query.setAt("proxyserver", row, pd.getServer());
                if (pd.getPort() > 0)
                    query.setAt("proxyport", row, Caster.toString(pd.getPort()));
                if (ProxyDataImpl.hasCredentials(pd)) {
                    query.setAt("proxyuser", row, pd.getUsername());
                    query.setAt("proxypassword", row, pd.getPassword());
                }
            }
            query.setAt("resolveurl", row, Caster.toString(task.isResolveURL()));
            query.setAt("paused", row, Caster.toBoolean(task.isPaused()));
            query.setAt("autoDelete", row, Caster.toBoolean(((ScheduleTaskImpl) task).isAutoDelete()));
        }
        pageContext.setVariable(result, query);
    } catch (DatabaseException e) {
    }
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) ProxyData(lucee.runtime.net.proxy.ProxyData) ScheduleTaskImpl(lucee.runtime.schedule.ScheduleTaskImpl) ScheduleTask(lucee.runtime.schedule.ScheduleTask) DatabaseException(lucee.runtime.exp.DatabaseException)

Example 2 with ScheduleTaskImpl

use of lucee.runtime.schedule.ScheduleTaskImpl in project Lucee by lucee.

the class Schedule method doUpdate.

/**
 * @throws PageException
 */
private void doUpdate() throws PageException {
    String message = "missing attribute for tag schedule with action update";
    String detail = "required attributes are [startDate, startTime, URL, interval, operation]";
    Resource file = null;
    // if(publish) {
    if (!StringUtil.isEmpty(strFile) && !StringUtil.isEmpty(strPath)) {
        file = ResourceUtil.toResourceNotExisting(pageContext, strPath);
        file = file.getRealResource(strFile);
    } else if (!StringUtil.isEmpty(strFile)) {
        file = ResourceUtil.toResourceNotExisting(pageContext, strFile);
    } else if (!StringUtil.isEmpty(strPath)) {
        file = ResourceUtil.toResourceNotExisting(pageContext, strPath);
    }
    if (file != null)
        pageContext.getConfig().getSecurityManager().checkFileLocation(pageContext.getConfig(), file, serverPassword);
    // missing attributes
    if (startdate == null || starttime == null || url == null || interval == null)
        throw new ApplicationException(message, detail);
    // timeout
    if (requesttimeout < 0)
        requesttimeout = pageContext.getRequestTimeout();
    // username/password
    Credentials cr = null;
    if (username != null)
        cr = CredentialsImpl.toCredentials(username, password);
    try {
        ScheduleTask st = new ScheduleTaskImpl(task, file, startdate, starttime, enddate, endtime, url, port, interval, requesttimeout, cr, ProxyDataImpl.getInstance(proxyserver, proxyport, proxyuser, proxypassword), resolveurl, publish, hidden, readonly, paused, autoDelete);
        scheduler.addScheduleTask(st, true);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
// 
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) ScheduleTaskImpl(lucee.runtime.schedule.ScheduleTaskImpl) Resource(lucee.commons.io.res.Resource) ScheduleTask(lucee.runtime.schedule.ScheduleTask) Credentials(lucee.commons.security.Credentials) DatabaseException(lucee.runtime.exp.DatabaseException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException)

Aggregations

DatabaseException (lucee.runtime.exp.DatabaseException)2 ScheduleTask (lucee.runtime.schedule.ScheduleTask)2 ScheduleTaskImpl (lucee.runtime.schedule.ScheduleTaskImpl)2 Resource (lucee.commons.io.res.Resource)1 Credentials (lucee.commons.security.Credentials)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 PageException (lucee.runtime.exp.PageException)1 ProxyData (lucee.runtime.net.proxy.ProxyData)1 QueryImpl (lucee.runtime.type.QueryImpl)1