added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / agenda / models / test-schedule.js
diff --git a/otf-frontend/server/src/agenda/models/test-schedule.js b/otf-frontend/server/src/agenda/models/test-schedule.js
new file mode 100644 (file)
index 0000000..6494695
--- /dev/null
@@ -0,0 +1,154 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+const logger = require('../../lib/logger');\r
+const utils = require('../../lib/otf-util');\r
+const ObjectId = require('mongoose').Types.ObjectId;\r
+\r
+class TestSchedule {\r
+       constructor (testInstanceId, testInstanceStartDate, testInstanceExecFreqInSeconds, testInstanceEndDate,\r
+                    async, asyncTopic, asyncMode, executorId) {\r
+               this.testInstanceId = testInstanceId;\r
+               this.testInstanceStartDate = testInstanceStartDate;\r
+               this.testInstanceExecFreqInSeconds = testInstanceExecFreqInSeconds;\r
+               this.testInstanceEndDate = testInstanceEndDate;\r
+               this.async = async;\r
+               this.asyncTopic = asyncTopic;\r
+               this.asyncMode = asyncMode;\r
+               this.executorId = executorId;\r
+       }\r
+\r
+       get testInstanceId () {\r
+               return this._testInstanceId;\r
+       }\r
+\r
+       set testInstanceId (value) {\r
+               if (!value) {\r
+                       throw 'testInstanceId is required.';\r
+               }\r
+\r
+               if (!utils.isValidObjectId(value)) {\r
+                       throw 'testInstanceId must be a valid ObjectId';\r
+               }\r
+\r
+               this._testInstanceId = new ObjectId(value);\r
+       }\r
+\r
+       get testInstanceStartDate () {\r
+               return this._testInstanceStartDate;\r
+       }\r
+\r
+       set testInstanceStartDate (value) {\r
+               // Accepts type Date, and the "now" keyword recognized by human interval (integrated with Agenda)\r
+               if (value !== 'now') {\r
+                       let parsedDate = Date.parse(value);\r
+\r
+                       if (isNaN((parsedDate))) {\r
+                               throw 'testInstanceStartDate must be a valid date, or must be ' / 'now' / '.';\r
+                       }\r
+               }\r
+\r
+               this._testInstanceStartDate = value;\r
+       }\r
+\r
+       get testInstanceExecFreqInSeconds () {\r
+               return this._testInstanceExecFreqInSeconds;\r
+       }\r
+\r
+       set testInstanceExecFreqInSeconds (value) {\r
+               if (value) {\r
+                       if (typeof value !== 'number') {\r
+                               throw 'testInstanceExecFreqInSeconds must be a number.';\r
+                       }\r
+\r
+                       if (value < 30) {\r
+                               throw 'testInstanceExecFreqInSeconds must be greater than or equal to 30.';\r
+                       }\r
+               }\r
+\r
+               this._testInstanceExecFreqInSeconds = value;\r
+       }\r
+\r
+       get testInstanceEndDate () {\r
+               return this._testInstanceEndDate;\r
+       }\r
+\r
+       set testInstanceEndDate (value) {\r
+               // Allow a null end date\r
+               if (value) {\r
+                       let parsedDate = Date.parse(value);\r
+\r
+                       if (isNaN((parsedDate))) {\r
+                               throw 'testInstanceEndDate must be a valid date.';\r
+                       }\r
+               }\r
+\r
+               this._testInstanceEndDate = value;\r
+       }\r
+\r
+       get async () {\r
+               return this._async;\r
+       }\r
+\r
+       set async (value) {\r
+               this._async = value;\r
+       }\r
+\r
+       get asyncTopic () {\r
+               return this._asynTopic;\r
+       }\r
+\r
+       set asyncTopic (value) {\r
+               this._asynTopic = value;\r
+       }\r
+\r
+       get asyncMode () {\r
+               return this._asyncMode;\r
+       }\r
+\r
+       set asyncMode (value) {\r
+               this._asyncMode = value;\r
+       }\r
+\r
+       get executorId () {\r
+               return this._executorId;\r
+       }\r
+\r
+       set executorId (value) {\r
+               if (!value) {\r
+                       throw 'executorId is required.';\r
+               }\r
+\r
+               if (!utils.isValidObjectId(value)) {\r
+                       throw 'executorId must be a valid ObjectId.';\r
+               }\r
+\r
+               this._executorId = new ObjectId(value);\r
+       }\r
+\r
+       print () {\r
+               logger.debug(\r
+                       'testInstanceId: ' + this._testInstanceId + '\n' +\r
+                       'testInstanceStartDate: ' + this._testInstanceStartDate + '\n' +\r
+                       'testInstanceExecFreqInSeconds: ' + this._testInstanceExecFreqInSeconds + '\n' +\r
+                       'testInstanceStartDate: ' + this._testInstanceStartDate + '\n' +\r
+                       'async: ' + this._async + '\n' +\r
+                       'asnycTopic: ' + this._asyncTopic + '\n' +\r
+                       'executorId: ' + this._executorId);\r
+       }\r
+}\r
+\r
+module.exports = TestSchedule;\r