added svcapi ui and camunda code
[it/otf.git] / otf-frontend / server / src / feathers / models / test-instances.model.js
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 \r
18 module.exports = function (app) {\r
19         const mongooseClient = app.get('mongooseClient');\r
20         const { Schema } = mongooseClient;\r
21         const uniqueTIByTD = new Schema({\r
22                 testInstanceName: { type: String, required: true },\r
23                 testDefinitionId: { type: Schema.Types.ObjectId, ref: 'testDefinitions', required: true }\r
24         });\r
25         uniqueTIByTD.index({\r
26                 testInstanceName: 1,\r
27                 testDefinitionId: 1,\r
28         }, {\r
29                         unique: true,\r
30                 });\r
31 \r
32         const testInstances = new Schema({\r
33 \r
34                 testInstanceDescription: { type: String },\r
35                 testInstanceName: { type: String, required: true },\r
36                 testDefinitionId: { type: Schema.Types.ObjectId, ref: 'testDefinitions', required: true },\r
37                 useLatestTestDefinition: { type: Boolean, required: true },\r
38                 processDefinitionId: { type: String, default: '' },\r
39                 testData: { type: Object, default: {} },\r
40                 internalTestData: { type: Object, default: {} },\r
41                 simulationMode: { type: Boolean, default: false },\r
42                 simulationVthInput: { type: Object, default: {} },\r
43                 vthInput: { type: Object, default: {} },\r
44                 pfloInput: { type: Object, default: {} },\r
45                 disabled: { type: Boolean, default: false },\r
46                 maxExecutionTimeInMillis: { type: Number, default: 0 },\r
47 \r
48                 groupId: { type: Schema.Types.ObjectId, ref: 'groups', required: true },\r
49                 updatedBy: { type: Schema.Types.ObjectId, ref: 'users' },\r
50                 createdBy: { type: Schema.Types.ObjectId, ref: 'users' }\r
51         }, {\r
52                         timestamps: true,\r
53                         minimize: false\r
54                 });\r
55         testInstances.index({\r
56                 testInstanceName: 1,\r
57                 testDefinitionId: 1,\r
58         }, {\r
59                         unique: true,\r
60                 });\r
61 \r
62         testInstances.post('save', function (error, doc, next) {\r
63                 if (error.name === 'MongoError' && error.code === 11000) {\r
64                         next(new Error('Test Instance name must be unique per Test Definition'));\r
65                 } else {\r
66                         next();\r
67                 }\r
68         });\r
69 \r
70         return mongooseClient.model('testInstances', testInstances, 'testInstances');\r
71 };