X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=otf-frontend%2Fserver%2Fsrc%2Ffeathers%2Fmodels%2Ftest-instances.model.js;fp=otf-frontend%2Fserver%2Fsrc%2Ffeathers%2Fmodels%2Ftest-instances.model.js;h=1cb5f0e210ba1cbe42b5b4aa07b7ac616f5f6794;hb=14f6f95c84a4a1fa8774190db4a03fd0214ec55f;hp=0000000000000000000000000000000000000000;hpb=f49bd1efeaaddd4891c1f329b18d8cfb28b3e75b;p=it%2Fotf.git 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 index 0000000..1cb5f0e --- /dev/null +++ b/otf-frontend/server/src/feathers/models/test-instances.model.js @@ -0,0 +1,71 @@ +/* Copyright (c) 2019 AT&T Intellectual Property. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +##############################################################################*/ + + + +module.exports = function (app) { + const mongooseClient = app.get('mongooseClient'); + const { Schema } = mongooseClient; + const uniqueTIByTD = new Schema({ + testInstanceName: { type: String, required: true }, + testDefinitionId: { type: Schema.Types.ObjectId, ref: 'testDefinitions', required: true } + }); + uniqueTIByTD.index({ + testInstanceName: 1, + testDefinitionId: 1, + }, { + unique: true, + }); + + const testInstances = new Schema({ + + testInstanceDescription: { type: String }, + testInstanceName: { type: String, required: true }, + testDefinitionId: { type: Schema.Types.ObjectId, ref: 'testDefinitions', required: true }, + useLatestTestDefinition: { type: Boolean, required: true }, + processDefinitionId: { type: String, default: '' }, + testData: { type: Object, default: {} }, + internalTestData: { type: Object, default: {} }, + simulationMode: { type: Boolean, default: false }, + simulationVthInput: { type: Object, default: {} }, + vthInput: { type: Object, default: {} }, + pfloInput: { type: Object, default: {} }, + disabled: { type: Boolean, default: false }, + maxExecutionTimeInMillis: { type: Number, default: 0 }, + + groupId: { type: Schema.Types.ObjectId, ref: 'groups', required: true }, + updatedBy: { type: Schema.Types.ObjectId, ref: 'users' }, + createdBy: { type: Schema.Types.ObjectId, ref: 'users' } + }, { + timestamps: true, + minimize: false + }); + testInstances.index({ + testInstanceName: 1, + testDefinitionId: 1, + }, { + unique: true, + }); + + testInstances.post('save', function (error, doc, next) { + if (error.name === 'MongoError' && error.code === 11000) { + next(new Error('Test Instance name must be unique per Test Definition')); + } else { + next(); + } + }); + + return mongooseClient.model('testInstances', testInstances, 'testInstances'); +}; \ No newline at end of file