Added comments field for scheduled tasks. Fixes #1354
authorEriks Jenkevics <eriks@netxms.org>
Mon, 19 Dec 2016 15:24:04 +0000 (17:24 +0200)
committerEriks Jenkevics <eriks@netxms.org>
Wed, 28 Dec 2016 11:38:28 +0000 (13:38 +0200)
20 files changed:
include/netxmsdb.h
sql/schema.in
src/java/client/netxms-client/src/main/java/org/netxms/client/ScheduledTask.java
src/java/netxms-eclipse/Core/src/org/netxms/ui/eclipse/widgets/ScheduleSelector.java
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ScheduleMaintenance.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ScheduledTaskEditor.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ScheduledTaskView.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryComparator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryLabelProvider.java
src/server/core/ap_jobs.cpp
src/server/core/schedule.cpp
src/server/core/upload_job.cpp
src/server/include/nxcore_schedule.h
src/server/tools/nxdbmgr/upgrade.cpp
webui/webapp/Core/src/org/netxms/ui/eclipse/widgets/ScheduleSelector.java
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ScheduleMaintenance.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ScheduledTaskEditor.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/ScheduledTaskView.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryComparator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryLabelProvider.java

index 8a16081..cca45ad 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   424
+#define DB_FORMAT_VERSION   425
 
 #endif
index af4f062..8f312a9 100644 (file)
@@ -2445,6 +2445,7 @@ CREATE TABLE scheduled_tasks
   flags integer not null,
   owner integer not null,
   object_id integer not null,
+  comments varchar(255) null,
   PRIMARY KEY(id)
 ) TABLE_TYPE;
 
@@ -2458,6 +2459,7 @@ COMMENT_COLUMN(scheduled_tasks.last_execution_time, '')
 COMMENT_COLUMN(scheduled_tasks.flags, '')
 COMMENT_COLUMN(scheduled_tasks.owner, '')
 COMMENT_COLUMN(scheduled_tasks.object_id, '')
+COMMENT_COLUMN(scheduled_tasks.comments, '')
 
 /*
 ** ZMQ Subscriptions
index 679d14c..cf54b96 100644 (file)
@@ -10,6 +10,7 @@ public class ScheduledTask
    private String scheduledTaskId;
    private String schedule;
    private String parameters;
+   private String comments;
    private Date executionTime;
    private Date lastExecutionTime;
    private int flags;
@@ -33,6 +34,7 @@ public class ScheduledTask
       flags = 0;
       owner = 0;
       objectId = 0;
+      comments = "";
    }
    
    public ScheduledTask(final NXCPMessage msg, long base)
@@ -46,10 +48,11 @@ public class ScheduledTask
       flags = msg.getFieldAsInt32(base+6);
       owner = msg.getFieldAsInt64(base+7);
       objectId = msg.getFieldAsInt64(base+8);
+      comments = msg.getFieldAsString(base+9);
    }
    
    public ScheduledTask(String scheduledTaskId, String schedule, String parameters,
-         Date executionTime, int flags, long objectId)
+         String comments, Date executionTime, int flags, long objectId)
    {
       id = 0;
       this.scheduledTaskId = scheduledTaskId;
@@ -60,6 +63,7 @@ public class ScheduledTask
       this.flags = flags;
       owner = 0;
       this.objectId = objectId;
+      this.comments = comments;
    }
    
    public void fillMessage(NXCPMessage msg)
@@ -73,7 +77,8 @@ public class ScheduledTask
       msg.setField(NXCPCodes.VID_PARAMETER, parameters);
       msg.setField(NXCPCodes.VID_LAST_EXECUTION_TIME, lastExecutionTime);
       msg.setFieldInt32(NXCPCodes.VID_FLAGS, flags);
-      msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int)objectId);    
+      msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int)objectId);  
+      msg.setField(NXCPCodes.VID_COMMENTS, comments);
    }
 
    /**
@@ -231,6 +236,24 @@ public class ScheduledTask
       return "";
    }
    
+   /**
+    * Get scheduled task comments
+    * @return
+    */
+   public String getComments()
+   {
+      return comments;
+   }
+   
+   /**
+    * Set scheduled task comments
+    * @param comments
+    */
+   public void setComments(String comments)
+   {
+      this.comments = comments;
+   }
+   
    public boolean isDisbaled()
    {
       return (flags & DISABLED) > 0;
index 2d3b77d..4d5dc75 100644 (file)
@@ -146,7 +146,7 @@ public class ScheduleSelector extends Composite
 
    public ScheduledTask getSchedule()
    {
-      return new ScheduledTask("Upload.File", radioCronSchedule.getSelection() ? textSchedule.getText() : "","", execDateSelector.getValue(), 0, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+      return new ScheduledTask("Upload.File", radioCronSchedule.getSelection() ? textSchedule.getText() : "","", "", execDateSelector.getValue(), 0, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
 
    public void setSchedule(ScheduledTask scheduledTask)
index ef20158..83e35ca 100644 (file)
@@ -43,8 +43,8 @@ public class ScheduleMaintenance extends AbstractHandler
             {
                if (o instanceof AbstractObject)
                {
-                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                   session.addSchedule(taskStart);
                   session.addSchedule(taskEnd);                  
                }
index 1bb1c35..7a51812 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
 import org.netxms.client.ScheduledTask;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
@@ -42,6 +43,7 @@ public class ScheduledTaskEditor extends Dialog
    private ScheduledTask scheduledTask;
    private List<String> scheduleTypeList;
    private LabeledText textParameters;
+   private Text textComments;
    private Combo scheduleType;
    private ScheduleSelector scheduleSelector;
    private ObjectSelector selector;
@@ -121,6 +123,17 @@ public class ScheduledTaskEditor extends Dialog
       textParameters.setLayoutData(gd);
       textParameters.setText(scheduledTask.getParameters());
       
+      textComments = WidgetHelper.createLabeledText(dialogArea, SWT.MULTI | SWT.BORDER, SWT.DEFAULT, "Description",
+            scheduledTask.getComments(), WidgetHelper.DEFAULT_LAYOUT_DATA);
+      textComments.setTextLimit(255);
+      gd = new GridData();
+      gd.horizontalSpan = 2;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalAlignment = SWT.FILL;
+      gd.heightHint = 100;
+      gd.verticalAlignment = SWT.FILL;
+      textComments.setLayoutData(gd);
+      
       if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) != 0)
       {
          scheduleType.add(scheduledTask.getScheduledTaskId());
@@ -145,6 +158,7 @@ public class ScheduledTaskEditor extends Dialog
       ScheduledTask task = scheduleSelector.getSchedule();
       scheduledTask.setSchedule(task.getSchedule());
       scheduledTask.setExecutionTime(task.getExecutionTime());
+      scheduledTask.setComments(textComments.getText());
       
       if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) == 0)
       {
index 8bb284f..bd9e711 100644 (file)
@@ -78,6 +78,7 @@ public class ScheduledTaskView extends ViewPart
    public static final int LAST_EXECUTION_TIME = 5;
    public static final int STATUS = 6;   
    public static final int OWNER = 7;
+   public static final int COMMENTS = 8;
    
    private NXCSession session;
    private SessionListener listener;
@@ -106,8 +107,8 @@ public class ScheduledTaskView extends ViewPart
    @Override
    public void createPartControl(Composite parent)
    {      
-      final int[] widths = { 50, 100, 200, 400, 300, 300, 100, 100 };
-      final String[] names = { "Id", "Schedule Type", "Object", "Parameters", "Execution time", "Last execution time", "Status", "Owner" };
+      final int[] widths = { 50, 100, 200, 400, 150, 150, 100, 100, 200 };
+      final String[] names = { "Id", "Schedule Type", "Object", "Parameters", "Execution time", "Last execution time", "Status", "Owner", "Comments" };
       viewer = new SortableTableViewer(parent, names, widths, SCHEDULE_ID, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
       viewer.setContentProvider(new ArrayContentProvider());
       viewer.setLabelProvider(new ScheduleTableEntryLabelProvider());
index a51e1ff..68da25d 100644 (file)
@@ -83,6 +83,9 @@ public class ScheduleTableEntryComparator extends ViewerComparator
             
             result = user1.compareTo(user2);
             break;
+         case ScheduledTaskView.COMMENTS:
+            result = task1.getComments().compareToIgnoreCase(task2.getComments());
+            break;
          default:
             result = 0;
             break;
index c607eab..04572c7 100644 (file)
@@ -75,6 +75,8 @@ public class ScheduleTableEntryLabelProvider extends LabelProvider implements IT
                return "system";
             AbstractUserObject user = session.findUserDBObjectById(task.getOwner());
             return (user != null) ? user.getName() : ("[" + Long.toString(task.getOwner()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+         case ScheduledTaskView.COMMENTS:
+            return task.getComments();
       }
       return null;
    }
index 7b21ed6..11212e3 100644 (file)
@@ -162,7 +162,7 @@ const String PolicyInstallJob::serializeParameters()
  */
 void PolicyInstallJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Deploy"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getNodeId(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   AddOneTimeScheduledTask(_T("Policy.Deploy"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getNodeId(), SYSTEM_ACCESS_FULL, _T(""), SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
 }
 
 /**
@@ -302,5 +302,5 @@ const String PolicyUninstallJob::serializeParameters()
  */
 void PolicyUninstallJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getNodeId(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getNodeId(), SYSTEM_ACCESS_FULL, _T(""), SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
 }
index 271bf04..ae2356e 100644 (file)
@@ -40,12 +40,13 @@ ThreadPool *g_schedulerThreadPool = NULL;
 /**
  * Create recurrent task object
  */
-ScheduledTask::ScheduledTask(int id, const TCHAR *taskId, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags)
+ScheduledTask::ScheduledTask(int id, const TCHAR *taskId, const TCHAR *schedule, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags)
 {
    m_id = id;
    m_taskHandlerId = _tcsdup(CHECK_NULL_EX(taskId));
    m_schedule = _tcsdup(CHECK_NULL_EX(schedule));
    m_params = _tcsdup(CHECK_NULL_EX(params));
+   m_comments = _tcsdup(CHECK_NULL_EX(comments));
    m_executionTime = NEVER;
    m_lastExecution = NEVER;
    m_flags = flags;
@@ -56,12 +57,13 @@ ScheduledTask::ScheduledTask(int id, const TCHAR *taskId, const TCHAR *schedule,
 /**
  * Create one-time execution task object
  */
-ScheduledTask::ScheduledTask(int id, const TCHAR *taskId, time_t executionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags)
+ScheduledTask::ScheduledTask(int id, const TCHAR *taskId, time_t executionTime, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags)
 {
    m_id = id;
    m_taskHandlerId = _tcsdup(CHECK_NULL_EX(taskId));
    m_schedule = _tcsdup(_T(""));
    m_params = _tcsdup(CHECK_NULL_EX(params));
+   m_comments = _tcsdup(CHECK_NULL_EX(comments));
    m_executionTime = executionTime;
    m_lastExecution = NEVER;
    m_flags = flags;
@@ -83,6 +85,7 @@ ScheduledTask::ScheduledTask(DB_RESULT hResult, int row)
    m_flags = DBGetFieldULong(hResult, row, 6);
    m_owner = DBGetFieldULong(hResult, row, 7);
    m_objectId = DBGetFieldULong(hResult, row, 8);
+   m_comments = DBGetField(hResult, row, 9, NULL, 0);
 }
 
 /**
@@ -93,12 +96,13 @@ ScheduledTask::~ScheduledTask()
    safe_free(m_taskHandlerId);
    safe_free(m_schedule);
    safe_free(m_params);
+   safe_free(m_comments);
 }
 
 /**
  * Update task
  */
-void ScheduledTask::update(const TCHAR *taskHandlerId, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags)
+void ScheduledTask::update(const TCHAR *taskHandlerId, const TCHAR *schedule, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags)
 {
    safe_free(m_taskHandlerId);
    m_taskHandlerId = _tcsdup(CHECK_NULL_EX(taskHandlerId));
@@ -106,6 +110,8 @@ void ScheduledTask::update(const TCHAR *taskHandlerId, const TCHAR *schedule, co
    m_schedule = _tcsdup(CHECK_NULL_EX(schedule));
    safe_free(m_params);
    m_params = _tcsdup(CHECK_NULL_EX(params));
+   safe_free(m_comments);
+   m_comments = _tcsdup(CHECK_NULL_EX(comments));
    m_owner = owner;
    m_objectId = objectId;
    m_flags = flags;
@@ -114,7 +120,7 @@ void ScheduledTask::update(const TCHAR *taskHandlerId, const TCHAR *schedule, co
 /**
  * Update task
  */
-void ScheduledTask::update(const TCHAR *taskHandlerId, time_t nextExecution, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags)
+void ScheduledTask::update(const TCHAR *taskHandlerId, time_t nextExecution, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags)
 {
    free(m_taskHandlerId);
    m_taskHandlerId = _tcsdup(CHECK_NULL_EX(taskHandlerId));
@@ -122,6 +128,8 @@ void ScheduledTask::update(const TCHAR *taskHandlerId, time_t nextExecution, con
    m_schedule = _tcsdup(_T(""));
    free(m_params);
    m_params = _tcsdup(CHECK_NULL_EX(params));
+   free(m_comments);
+   m_comments = _tcsdup(CHECK_NULL_EX(comments));
    m_executionTime = nextExecution;
    m_owner  = owner;
    m_objectId = objectId;
@@ -140,13 +148,13 @@ void ScheduledTask::saveToDatabase(bool newObject)
    {
                hStmt = DBPrepare(db,
                     _T("INSERT INTO scheduled_tasks (taskId,schedule,params,execution_time,")
-                    _T("last_execution_time,flags,owner,object_id,id) VALUES (?,?,?,?,?,?,?,?,?)"));
+                    _T("last_execution_time,flags,owner,object_id,comments,id) VALUES (?,?,?,?,?,?,?,?,?,?)"));
    }
    else
    {
       hStmt = DBPrepare(db,
                     _T("UPDATE scheduled_tasks SET taskId=?,schedule=?,params=?,")
-                    _T("execution_time=?,last_execution_time=?,flags=?,owner=?,object_id=? ")
+                    _T("execution_time=?,last_execution_time=?,flags=?,owner=?,object_id=?,comments=? ")
                     _T("WHERE id=?"));
    }
 
@@ -158,7 +166,8 @@ void ScheduledTask::saveToDatabase(bool newObject)
        DBBind(hStmt, 6, DB_SQLTYPE_INTEGER, (LONG)m_flags);
        DBBind(hStmt, 7, DB_SQLTYPE_INTEGER, m_owner);
        DBBind(hStmt, 8, DB_SQLTYPE_INTEGER, m_objectId);
-       DBBind(hStmt, 9, DB_SQLTYPE_INTEGER, (LONG)m_id);
+   DBBind(hStmt, 9, DB_SQLTYPE_VARCHAR, m_comments, DB_BIND_STATIC);
+       DBBind(hStmt, 10, DB_SQLTYPE_INTEGER, (LONG)m_id);
 
        if (hStmt == NULL)
                return;
@@ -251,6 +260,7 @@ void ScheduledTask::fillMessage(NXCPMessage *msg)
    msg->setField(VID_FLAGS, (UINT32)m_flags);
    msg->setField(VID_OWNER, m_owner);
    msg->setField(VID_OBJECT_ID, m_objectId);
+   msg->setField(VID_COMMENTS, m_comments);
 }
 
 /**
@@ -267,6 +277,7 @@ void ScheduledTask::fillMessage(NXCPMessage *msg, UINT32 base)
    msg->setField(base + 6, m_flags);
    msg->setField(base + 7, m_owner);
    msg->setField(base + 8, m_objectId);
+   msg->setField(base + 9, m_comments);
 }
 
 /**
@@ -298,13 +309,13 @@ void RegisterSchedulerTaskHandler(const TCHAR *id, scheduled_action_executor exe
 /**
  * Scheduled task creation function
  */
-UINT32 AddScheduledTask(const TCHAR *task, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, UINT32 flags)
+UINT32 AddScheduledTask(const TCHAR *task, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, const TCHAR *comments, UINT32 flags)
 {
    if ((systemRights & (SYSTEM_ACCESS_ALL_SCHEDULED_TASKS | SYSTEM_ACCESS_USER_SCHEDULED_TASKS | SYSTEM_ACCESS_OWN_SCHEDULED_TASKS)) == 0)
       return RCC_ACCESS_DENIED;
    DbgPrintf(7, _T("AddSchedule: Add cron schedule %s, %s, %s"), task, schedule, params);
    s_cronScheduleLock.lock();
-   ScheduledTask *sh = new ScheduledTask(CreateUniqueId(IDG_SCHEDULED_TASK), task, schedule, params, owner, objectId, flags);
+   ScheduledTask *sh = new ScheduledTask(CreateUniqueId(IDG_SCHEDULED_TASK), task, schedule, params, comments, owner, objectId, flags);
    sh->saveToDatabase(true);
    s_cronSchedules.add(sh);
    s_cronScheduleLock.unlock();
@@ -314,13 +325,13 @@ UINT32 AddScheduledTask(const TCHAR *task, const TCHAR *schedule, const TCHAR *p
 /**
  * One time schedule creation function
  */
-UINT32 AddOneTimeScheduledTask(const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, UINT32 flags)
+UINT32 AddOneTimeScheduledTask(const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, const TCHAR *comments, UINT32 flags)
 {
    if ((systemRights & (SYSTEM_ACCESS_ALL_SCHEDULED_TASKS | SYSTEM_ACCESS_USER_SCHEDULED_TASKS | SYSTEM_ACCESS_OWN_SCHEDULED_TASKS)) == 0)
       return RCC_ACCESS_DENIED;
    DbgPrintf(7, _T("AddOneTimeAction: Add one time schedule %s, %d, %s"), task, nextExecutionTime, params);
    s_oneTimeScheduleLock.lock();
-   ScheduledTask *sh = new ScheduledTask(CreateUniqueId(IDG_SCHEDULED_TASK), task, nextExecutionTime, params, owner, objectId, flags);
+   ScheduledTask *sh = new ScheduledTask(CreateUniqueId(IDG_SCHEDULED_TASK), task, nextExecutionTime, params, comments, owner, objectId, flags);
    sh->saveToDatabase(true);
    s_oneTimeSchedules.add(sh);
    s_oneTimeSchedules.sort(ScheduledTaskComparator);
@@ -332,7 +343,7 @@ UINT32 AddOneTimeScheduledTask(const TCHAR *task, time_t nextExecutionTime, cons
 /**
  * Scheduled actionUpdate
  */
-UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags)
+UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags)
 {
    DbgPrintf(7, _T("UpdateSchedule: update cron schedule %d, %s, %s, %s"), id, task, schedule, params);
    s_cronScheduleLock.lock();
@@ -347,7 +358,7 @@ UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, con
             rcc = RCC_ACCESS_DENIED;
             break;
          }
-         s_cronSchedules.get(i)->update(task, schedule, params, owner, objectId, flags);
+         s_cronSchedules.get(i)->update(task, schedule, params, comments, owner, objectId, flags);
          s_cronSchedules.get(i)->saveToDatabase(false);
          found = true;
          break;
@@ -372,7 +383,7 @@ UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, con
             st = s_oneTimeSchedules.get(i);
             s_oneTimeSchedules.unlink(i);
             s_oneTimeSchedules.sort(ScheduledTaskComparator);
-            st->update(task, schedule, params, owner, objectId, flags);
+            st->update(task, schedule, params, comments, owner, objectId, flags);
             st->saveToDatabase(false);
             found = true;
             break;
@@ -393,7 +404,7 @@ UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, con
 /**
  * One time action update
  */
-UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags)
+UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags)
 {
    DbgPrintf(7, _T("UpdateOneTimeAction: update one time schedule %d, %s, %d, %s"), id, task, nextExecutionTime, params);
    bool found = false;
@@ -408,7 +419,7 @@ UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutio
             rcc = RCC_ACCESS_DENIED;
             break;
          }
-         s_oneTimeSchedules.get(i)->update(task, nextExecutionTime, params, owner, objectId, flags);
+         s_oneTimeSchedules.get(i)->update(task, nextExecutionTime, params, comments, owner, objectId, flags);
          s_oneTimeSchedules.get(i)->saveToDatabase(false);
          s_oneTimeSchedules.sort(ScheduledTaskComparator);
          found = true;
@@ -433,7 +444,7 @@ UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutio
             }
             st = s_cronSchedules.get(i);
             s_cronSchedules.unlink(i);
-            st->update(task, nextExecutionTime, params, owner, objectId, flags);
+            st->update(task, nextExecutionTime, params, comments, owner, objectId, flags);
             st->saveToDatabase(false);
             found = true;
             break;
@@ -593,18 +604,19 @@ UINT32 CreateScehduledTaskFromMsg(NXCPMessage *request, UINT32 owner, UINT64 sys
    TCHAR *schedule = NULL;
    time_t nextExecutionTime = 0;
    TCHAR *params = request->getFieldAsString(VID_PARAMETER);
+   TCHAR *comments = request->getFieldAsString(VID_COMMENTS);
    int flags = request->getFieldAsInt32(VID_FLAGS);
    int objectId = request->getFieldAsInt32(VID_OBJECT_ID);
    UINT32 result;
    if (request->isFieldExist(VID_SCHEDULE))
    {
       schedule = request->getFieldAsString(VID_SCHEDULE);
-      result = AddScheduledTask(taskId, schedule, params, owner, objectId, systemAccessRights, flags);
+      result = AddScheduledTask(taskId, schedule, params, owner, objectId, systemAccessRights, comments, flags);
    }
    else
    {
       nextExecutionTime = request->getFieldAsTime(VID_EXECUTION_TIME);
-      result = AddOneTimeScheduledTask(taskId, nextExecutionTime, params, owner, objectId, systemAccessRights, flags);
+      result = AddOneTimeScheduledTask(taskId, nextExecutionTime, params, owner, objectId, systemAccessRights, comments, flags);
    }
    free(taskId);
    free(schedule);
@@ -622,18 +634,19 @@ UINT32 UpdateScheduledTaskFromMsg(NXCPMessage *request,  UINT32 owner, UINT64 sy
    TCHAR *schedule = NULL;
    time_t nextExecutionTime = 0;
    TCHAR *params = request->getFieldAsString(VID_PARAMETER);
+   TCHAR *comments = request->getFieldAsString(VID_COMMENTS);
    UINT32 flags = request->getFieldAsInt32(VID_FLAGS);
    UINT32 objectId = request->getFieldAsInt32(VID_OBJECT_ID);
    UINT32 rcc;
    if(request->isFieldExist(VID_SCHEDULE))
    {
       schedule = request->getFieldAsString(VID_SCHEDULE);
-      rcc = UpdateScheduledTask(id, taskId, schedule, params, owner, objectId, systemAccessRights, flags);
+      rcc = UpdateScheduledTask(id, taskId, schedule, params, comments, owner, objectId, systemAccessRights, flags);
    }
    else
    {
       nextExecutionTime = request->getFieldAsTime(VID_EXECUTION_TIME);
-      rcc = UpdateOneTimeScheduledTask(id, taskId, nextExecutionTime, params, owner, objectId, systemAccessRights, flags);
+      rcc = UpdateOneTimeScheduledTask(id, taskId, nextExecutionTime, params, comments, owner, objectId, systemAccessRights, flags);
    }
    safe_free(taskId);
    safe_free(schedule);
@@ -807,7 +820,7 @@ void InitializeTaskScheduler()
    g_schedulerThreadPool = ThreadPoolCreate(1, 64, _T("SCHEDULER"));
    //read from DB configuration
    DB_HANDLE hdb = DBConnectionPoolAcquireConnection();
-   DB_RESULT hResult = DBSelect(hdb, _T("SELECT id,taskId,schedule,params,execution_time,last_execution_time,flags,owner,object_id FROM scheduled_tasks"));
+   DB_RESULT hResult = DBSelect(hdb, _T("SELECT id,taskId,schedule,params,execution_time,last_execution_time,flags,owner,object_id,comments FROM scheduled_tasks"));
    if (hResult != NULL)
    {
       int count = DBGetNumRows(hResult);
index 6c945fd..357481a 100644 (file)
@@ -246,5 +246,5 @@ const String FileUploadJob::serializeParameters()
  */
 void FileUploadJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getNodeId(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getNodeId(), SYSTEM_ACCESS_FULL, _T(""), SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
 }
index 4c225b6..f3e0a71 100644 (file)
@@ -74,6 +74,7 @@ private:
    TCHAR *m_taskHandlerId;
    TCHAR *m_schedule;
    TCHAR *m_params;
+   TCHAR *m_comments;
    time_t m_executionTime;
    time_t m_lastExecution;
    UINT32 m_flags;
@@ -81,8 +82,8 @@ private:
    UINT32 m_objectId;
 
 public:
-   ScheduledTask(int id, const TCHAR *taskHandlerId, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags = 0);
-   ScheduledTask(int id, const TCHAR *taskHandlerId, time_t executionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags = 0);
+   ScheduledTask(int id, const TCHAR *taskHandlerId, const TCHAR *schedule, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags = 0);
+   ScheduledTask(int id, const TCHAR *taskHandlerId, time_t executionTime, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags = 0);
    ScheduledTask(DB_RESULT hResult, int row);
    ~ScheduledTask();
 
@@ -99,8 +100,8 @@ public:
    void setFlag(UINT32 flag) { m_flags |= flag; }
    void removeFlag(UINT32 flag) { m_flags &= ~flag; }
 
-   void update(const TCHAR *taskHandlerId, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags);
-   void update(const TCHAR *taskHandlerId, time_t nextExecution, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT32 flags);
+   void update(const TCHAR *taskHandlerId, const TCHAR *schedule, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags);
+   void update(const TCHAR *taskHandlerId, time_t nextExecution, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT32 flags);
 
    void saveToDatabase(bool newObject);
    void run(SchedulerCallback *callback);
@@ -118,10 +119,10 @@ public:
 void InitializeTaskScheduler();
 void CloseTaskScheduler();
 void RegisterSchedulerTaskHandler(const TCHAR *id, scheduled_action_executor exec, UINT64 accessRight);
-UINT32 AddScheduledTask(const TCHAR *task, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, UINT32 flags = 0);
-UINT32 AddOneTimeScheduledTask(const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, UINT32 flags = 0);
-UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags);
-UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags);
+UINT32 AddScheduledTask(const TCHAR *task, const TCHAR *schedule, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, const TCHAR *comments = _T(""), UINT32 flags = 0);
+UINT32 AddOneTimeScheduledTask(const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, UINT32 owner, UINT32 objectId, UINT64 systemRights, const TCHAR *comments = _T(""), UINT32 flags = 0);
+UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags);
+UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutionTime, const TCHAR *params, const TCHAR *comments, UINT32 owner, UINT32 objectId, UINT64 systemAccessRights, UINT32 flags);
 UINT32 RemoveScheduledTask(UINT32 id, UINT32 user, UINT64 systemRights);
 void GetSchedulerTaskHandlers(NXCPMessage *msg, UINT64 accessRights);
 void GetScheduledTasks(NXCPMessage *msg, UINT32 userId, UINT64 systemRights);
index 75f842b..79bdb76 100644 (file)
@@ -722,6 +722,16 @@ static bool SetSchemaVersion(int version)
 }
 
 /**
+ *  Upgrade from V424 to V425
+ */
+static BOOL H_UpgradeFromV424(int currVersion, int newVersion)
+{
+   CHK_EXEC(SQLQuery(_T("ALTER TABLE scheduled_tasks ADD comments varchar(255)")));
+   CHK_EXEC(SetSchemaVersion(425));
+   return TRUE;
+}
+
+/**
  *  Upgrade from V423 to V424
  */
 static BOOL H_UpgradeFromV423(int currVersion, int newVersion)
@@ -753,7 +763,7 @@ static BOOL H_UpgradeFromV421(int currVersion, int newVersion)
 }
 
 /**
- * Upgrade from V420 to V421
+ *  Upgrade from V420 to V421
  */
 static BOOL H_UpgradeFromV420(int currVersion, int newVersion)
 {
@@ -10847,6 +10857,7 @@ static struct
    { 421, 422, H_UpgradeFromV421 },
    { 422, 423, H_UpgradeFromV422 },
    { 423, 424, H_UpgradeFromV423 },
+   { 424, 425, H_UpgradeFromV424 },
    { 0, 0, NULL }
 };
 
index 2d3b77d..4d5dc75 100644 (file)
@@ -146,7 +146,7 @@ public class ScheduleSelector extends Composite
 
    public ScheduledTask getSchedule()
    {
-      return new ScheduledTask("Upload.File", radioCronSchedule.getSelection() ? textSchedule.getText() : "","", execDateSelector.getValue(), 0, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+      return new ScheduledTask("Upload.File", radioCronSchedule.getSelection() ? textSchedule.getText() : "","", "", execDateSelector.getValue(), 0, 0); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
 
    public void setSchedule(ScheduledTask scheduledTask)
index ef20158..83e35ca 100644 (file)
@@ -43,8 +43,8 @@ public class ScheduleMaintenance extends AbstractHandler
             {
                if (o instanceof AbstractObject)
                {
-                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                   session.addSchedule(taskStart);
                   session.addSchedule(taskEnd);                  
                }
index 1bb1c35..7a51812 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
 import org.netxms.client.ScheduledTask;
 import org.netxms.client.objects.AbstractObject;
 import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
@@ -42,6 +43,7 @@ public class ScheduledTaskEditor extends Dialog
    private ScheduledTask scheduledTask;
    private List<String> scheduleTypeList;
    private LabeledText textParameters;
+   private Text textComments;
    private Combo scheduleType;
    private ScheduleSelector scheduleSelector;
    private ObjectSelector selector;
@@ -121,6 +123,17 @@ public class ScheduledTaskEditor extends Dialog
       textParameters.setLayoutData(gd);
       textParameters.setText(scheduledTask.getParameters());
       
+      textComments = WidgetHelper.createLabeledText(dialogArea, SWT.MULTI | SWT.BORDER, SWT.DEFAULT, "Description",
+            scheduledTask.getComments(), WidgetHelper.DEFAULT_LAYOUT_DATA);
+      textComments.setTextLimit(255);
+      gd = new GridData();
+      gd.horizontalSpan = 2;
+      gd.grabExcessHorizontalSpace = true;
+      gd.horizontalAlignment = SWT.FILL;
+      gd.heightHint = 100;
+      gd.verticalAlignment = SWT.FILL;
+      textComments.setLayoutData(gd);
+      
       if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) != 0)
       {
          scheduleType.add(scheduledTask.getScheduledTaskId());
@@ -145,6 +158,7 @@ public class ScheduledTaskEditor extends Dialog
       ScheduledTask task = scheduleSelector.getSchedule();
       scheduledTask.setSchedule(task.getSchedule());
       scheduledTask.setExecutionTime(task.getExecutionTime());
+      scheduledTask.setComments(textComments.getText());
       
       if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) == 0)
       {
index 8bb284f..bd9e711 100644 (file)
@@ -78,6 +78,7 @@ public class ScheduledTaskView extends ViewPart
    public static final int LAST_EXECUTION_TIME = 5;
    public static final int STATUS = 6;   
    public static final int OWNER = 7;
+   public static final int COMMENTS = 8;
    
    private NXCSession session;
    private SessionListener listener;
@@ -106,8 +107,8 @@ public class ScheduledTaskView extends ViewPart
    @Override
    public void createPartControl(Composite parent)
    {      
-      final int[] widths = { 50, 100, 200, 400, 300, 300, 100, 100 };
-      final String[] names = { "Id", "Schedule Type", "Object", "Parameters", "Execution time", "Last execution time", "Status", "Owner" };
+      final int[] widths = { 50, 100, 200, 400, 150, 150, 100, 100, 200 };
+      final String[] names = { "Id", "Schedule Type", "Object", "Parameters", "Execution time", "Last execution time", "Status", "Owner", "Comments" };
       viewer = new SortableTableViewer(parent, names, widths, SCHEDULE_ID, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
       viewer.setContentProvider(new ArrayContentProvider());
       viewer.setLabelProvider(new ScheduleTableEntryLabelProvider());
index a51e1ff..68da25d 100644 (file)
@@ -83,6 +83,9 @@ public class ScheduleTableEntryComparator extends ViewerComparator
             
             result = user1.compareTo(user2);
             break;
+         case ScheduledTaskView.COMMENTS:
+            result = task1.getComments().compareToIgnoreCase(task2.getComments());
+            break;
          default:
             result = 0;
             break;
index c607eab..04572c7 100644 (file)
@@ -75,6 +75,8 @@ public class ScheduleTableEntryLabelProvider extends LabelProvider implements IT
                return "system";
             AbstractUserObject user = session.findUserDBObjectById(task.getOwner());
             return (user != null) ? user.getName() : ("[" + Long.toString(task.getOwner()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
+         case ScheduledTaskView.COMMENTS:
+            return task.getComments();
       }
       return null;
    }