added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / feathers / models / test-instances.model.js
diff --git a/otf-frontend/server/src/feathers/models/test-instances.model.js b/otf-frontend/server/src/feathers/models/test-instances.model.js
new file mode 100644 (file)
index 0000000..1cb5f0e
--- /dev/null
@@ -0,0 +1,71 @@
+/*  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
+\r
+module.exports = function (app) {\r
+       const mongooseClient = app.get('mongooseClient');\r
+       const { Schema } = mongooseClient;\r
+       const uniqueTIByTD = new Schema({\r
+               testInstanceName: { type: String, required: true },\r
+               testDefinitionId: { type: Schema.Types.ObjectId, ref: 'testDefinitions', required: true }\r
+       });\r
+       uniqueTIByTD.index({\r
+               testInstanceName: 1,\r
+               testDefinitionId: 1,\r
+       }, {\r
+                       unique: true,\r
+               });\r
+\r
+       const testInstances = new Schema({\r
+\r
+               testInstanceDescription: { type: String },\r
+               testInstanceName: { type: String, required: true },\r
+               testDefinitionId: { type: Schema.Types.ObjectId, ref: 'testDefinitions', required: true },\r
+               useLatestTestDefinition: { type: Boolean, required: true },\r
+               processDefinitionId: { type: String, default: '' },\r
+               testData: { type: Object, default: {} },\r
+               internalTestData: { type: Object, default: {} },\r
+               simulationMode: { type: Boolean, default: false },\r
+               simulationVthInput: { type: Object, default: {} },\r
+               vthInput: { type: Object, default: {} },\r
+               pfloInput: { type: Object, default: {} },\r
+               disabled: { type: Boolean, default: false },\r
+               maxExecutionTimeInMillis: { type: Number, default: 0 },\r
+\r
+               groupId: { type: Schema.Types.ObjectId, ref: 'groups', required: true },\r
+               updatedBy: { type: Schema.Types.ObjectId, ref: 'users' },\r
+               createdBy: { type: Schema.Types.ObjectId, ref: 'users' }\r
+       }, {\r
+                       timestamps: true,\r
+                       minimize: false\r
+               });\r
+       testInstances.index({\r
+               testInstanceName: 1,\r
+               testDefinitionId: 1,\r
+       }, {\r
+                       unique: true,\r
+               });\r
+\r
+       testInstances.post('save', function (error, doc, next) {\r
+               if (error.name === 'MongoError' && error.code === 11000) {\r
+                       next(new Error('Test Instance name must be unique per Test Definition'));\r
+               } else {\r
+                       next();\r
+               }\r
+       });\r
+\r
+       return mongooseClient.model('testInstances', testInstances, 'testInstances');\r
+};
\ No newline at end of file