diff --git a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js index df3e6659276fc8b78c97288612fb751a5366d73d..a408ef43f60f5f51dff7bdcccff261d65a8d4647 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js @@ -17,6 +17,7 @@ function Jeditor(props) { // console.log("In JEditor", props.schema); const editorRef = useRef(null); let pointingProps = useRef(null); + // let durationProps = useRef(null); let editor = null; /** @@ -113,6 +114,7 @@ function Jeditor(props) { props.defintionFormatter(schema); } pointingProps = []; + // durationProps = []; // Customize the pointing property to capture angle1 and angle2 to specified format for (const definitionKey in schema.definitions) { if (definitionKey === 'pointing') { @@ -133,6 +135,7 @@ function Jeditor(props) { } } } + // Customize datatype of certain properties like subbands, duration, etc., getCustomProperties(schema.properties); getCustomProperties(schema.definitions); @@ -193,7 +196,8 @@ function Jeditor(props) { } return errors; }); - schema.format = "grid" + schema.format = "grid"; + console.log(schema); const editorOptions = { form_name_root: "specification", schema: schema, @@ -307,6 +311,7 @@ function Jeditor(props) { newProperty.validationType = propertyKey === 'subbands'?'subband_list':'subband_list_optional'; properties[propertyKey] = newProperty; } else if (propertyKey.toLowerCase() === 'duration') { + // } else if (propertyValue['$id'] === '#duration') { let newProperty = { "type": "string", "format": "time", @@ -333,8 +338,8 @@ function Jeditor(props) { } } }; - properties[propertyKey] = newProperty; + // durationProps.push(propertyKey); } else if (propertyValue instanceof Object) { // by default previously, all field will have format as Grid, but this will fail for calendar, so added property called skipFormat if (propertyKey !== 'properties' && propertyKey !== 'default' && !propertyValue.skipFormat) { @@ -383,6 +388,7 @@ function Jeditor(props) { updateInput(inputValue); } } else if (inputKey.toLowerCase() === 'duration') { + // } else if (durationProps.indexOf(inputKey)) { editorInput[inputKey] = getTimeInput(inputValue); } } @@ -407,6 +413,7 @@ function Jeditor(props) { (outputKey === 'list' && typeof(outputValue) === 'string')) { editorOutput[outputKey] = getSubbandOutput(outputValue); } else if (outputKey.toLowerCase() === 'duration') { + // } else if (durationProps.indexOf(outputKey)) { const splitOutput = outputValue.split(':'); editorOutput[outputKey] = ((splitOutput[0] * 3600) + (splitOutput[1] * 60) + parseInt(splitOutput[2])); } diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.js index 7f552ba2d3c3bf60ebff7705b5f98edc3f38c999..f10d5e44b551c9d7e326c3f11e67ce9c38252d7a 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/create.js @@ -18,6 +18,7 @@ import ProjectService from '../../services/project.service'; import ScheduleService from '../../services/schedule.service'; import TaskService from '../../services/task.service'; import UIConstants from '../../utils/ui.constants'; +import ParserUtility from '../../utils/parser.utility'; import PageHeader from '../../layout/components/PageHeader'; import SchedulingConstraint from './Scheduling.Constraints'; import Stations from './Stations'; @@ -62,6 +63,7 @@ export class SchedulingUnitCreate extends Component { this.schedulingSets = []; // All scheduling sets to be filtered for project this.observStrategies = []; // All Observing strategy templates this.taskTemplates = []; // All task templates to be filtered based on tasks in selected strategy template + this.taskTemplateSchemas = {}; this.tooltipOptions = UIConstants.tooltipOptions; this.constraintTemplates = []; this.nameInput = React.createRef(); // Ref to Name field for auto focus @@ -135,74 +137,43 @@ export class SchedulingUnitCreate extends Component { * It generates the JSON schema for JSON editor and defult vales for the parameters to be captured * @param {number} strategyId */ - async changeStrategy (strategyId) { + async changeStrategy (strategyId) { const observStrategy = _.find(this.observStrategies, {'id': strategyId}); let station_group = []; - const tasks = observStrategy.template.tasks; + const tasks = observStrategy.template.tasks; + const parameters = observStrategy.template.parameters; let paramsOutput = {}; let schema = { type: 'object', additionalProperties: false, properties: {}, definitions:{} - }; - - // TODo: This schema reference resolving code has to be moved to common file and needs to rework - for (const taskName of _.keys(tasks)) { + }; + const $strategyRefs = await $RefParser.resolve(observStrategy.template); + // TODo: This schema reference resolving code has to be moved to common file and needs to rework + for (const param of parameters) { + let taskPaths = param.refs[0].split("/"); + const taskName = taskPaths[2]; + taskPaths = taskPaths.slice(4, taskPaths.length); const task = tasks[taskName]; - //Resolve task from the strategy template - const $taskRefs = await $RefParser.resolve(task); - - // Identify the task specification template of every task in the strategy template const taskTemplate = _.find(this.taskTemplates, {'name': task['specifications_template']}); - schema['$id'] = taskTemplate.schema['$id']; - schema['$schema'] = taskTemplate.schema['$schema']; if (taskTemplate.type_value==='observation' && task.specifications_doc.station_groups) { station_group = task.specifications_doc.station_groups; } - let index = 0; - for (const param of observStrategy.template.parameters) { - if (param.refs[0].indexOf(`/tasks/${taskName}`) > 0) { - // Resolve the identified template - const $templateRefs = await $RefParser.resolve(taskTemplate); - let property = { }; - let tempProperty = null; - const taskPaths = param.refs[0].split("/"); - // Get the property type from the template and create new property in the schema for the parameters - try { - const parameterRef = param.refs[0];//.replace(`#/tasks/${taskName}/specifications_doc`, '#/schema/properties'); - tempProperty = $templateRefs.get(parameterRef); - // property = _.cloneDeep(taskTemplate.schema.properties[taskPaths[4]]); - - } catch(error) { - tempProperty = _.cloneDeep(taskTemplate.schema.properties[taskPaths[4]]); - if (tempProperty['$ref']) { - tempProperty = await UtilService.resolveSchema(tempProperty); - if (tempProperty.definitions && tempProperty.definitions[taskPaths[4]]) { - schema.definitions = {...schema.definitions, ...tempProperty.definitions}; - tempProperty = tempProperty.definitions[taskPaths[4]]; - } else if (tempProperty.properties && tempProperty.properties[taskPaths[4]]) { - tempProperty = tempProperty.properties[taskPaths[4]]; - } - } - if (tempProperty.type === 'array' && taskPaths.length>6) { - tempProperty = tempProperty.items.properties[taskPaths[6]]; - } - property = tempProperty; - } - property.title = param.name; - property.default = $taskRefs.get(param.refs[0].replace(`#/tasks/${taskName}`, '#')); - paramsOutput[`param_${index}`] = property.default; - schema.properties[`param_${index}`] = property; - // Set property defintions taken from the task template in new schema - for (const definitionName in taskTemplate.schema.definitions) { - schema.definitions[definitionName] = taskTemplate.schema.definitions[definitionName]; - - } - } - index++; - + let taskTemplateSchema = this.taskTemplateSchemas[task['specifications_template']]; + if (!taskTemplateSchema) { + taskTemplateSchema = _.find(this.taskTemplates, {'name': task['specifications_template']}).schema; + taskTemplateSchema = await UtilService.resolveSchema(_.cloneDeep(taskTemplateSchema)); + this.taskTemplateSchemas[task['specifications_template']] = taskTemplateSchema; + } + schema.definitions = {...schema.definitions, ...taskTemplateSchema.definitions}; + taskPaths.reverse(); + const paramProp = await ParserUtility.getParamProperty($strategyRefs, taskPaths, taskTemplateSchema, param); + schema.properties[param.name] = _.cloneDeep(paramProp); + if (schema.properties[param.name]) { + schema.properties[param.name].title = param.name; + schema.properties[param.name].default = $strategyRefs.get(param.refs[0]); + paramsOutput[param.name] = schema.properties[param.name].default; } - } - this.setState({observStrategy: observStrategy, paramsSchema: schema, paramsOutput: paramsOutput, stationGroup: station_group, isDirty: true}); + this.setState({observStrategy: observStrategy, paramsSchema: _.cloneDeep(schema), paramsOutput: paramsOutput, stationGroup: station_group, isDirty: true}); publish('edit-dirty', true); // Function called to clear the JSON Editor fields and reload with new schema @@ -387,7 +358,7 @@ export class SchedulingUnitCreate extends Component { let observStrategy = _.cloneDeep(this.state.observStrategy); const $refs = await $RefParser.resolve(observStrategy.template); observStrategy.template.parameters.forEach(async(param, index) => { - $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput['param_' + index]); + $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput[param.name]); }); for (const taskName in observStrategy.template.tasks) { let task = observStrategy.template.tasks[taskName]; diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/edit.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/edit.js index d28fc907e584d5c443998210e87a01b5a55321a1..a5741a57125fb6fb4fa82e7c729f5ceb80bb7c57 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/edit.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/edit.js @@ -21,6 +21,7 @@ import ProjectService from '../../services/project.service'; import ScheduleService from '../../services/schedule.service'; import TaskService from '../../services/task.service'; import UIConstants from '../../utils/ui.constants'; +import ParserUtility from '../../utils/parser.utility'; import SchedulingConstraint from './Scheduling.Constraints'; import UtilService from '../../services/util.service'; @@ -54,6 +55,7 @@ export class EditSchedulingUnit extends Component { this.schedulingSets = []; // All scheduling sets to be filtered for project this.observStrategies = []; // All Observing strategy templates this.taskTemplates = []; // All task templates to be filtered based on tasks in selected strategy template + this.taskTemplateSchemas = {}; this.schedulingSets = []; this.observStrategies = []; this.taskTemplates = []; @@ -84,73 +86,50 @@ export class EditSchedulingUnit extends Component { * It generates the JSON schema for JSON editor and defult vales for the parameters to be captured * @param {number} strategyId */ - async changeStrategy (strategyId) { - let tasksToUpdate = {}; + async changeStrategy (strategyId) { const observStrategy = _.find(this.observStrategies, {'id': strategyId}); - const tasks = observStrategy.template.tasks; + let station_group = []; + let tasksToUpdate = {}; + const tasks = observStrategy.template.tasks; + const parameters = observStrategy.template.parameters; let paramsOutput = {}; let schema = { type: 'object', additionalProperties: false, properties: {}, definitions:{} - }; + }; + const $strategyRefs = await $RefParser.resolve(observStrategy.template); // TODo: This schema reference resolving code has to be moved to common file and needs to rework - for (const taskName in tasks) { + for (const param of parameters) { + let taskPaths = param.refs[0].split("/"); + const taskName = taskPaths[2]; + tasksToUpdate[taskName] = taskName; + taskPaths = taskPaths.slice(4, taskPaths.length); const task = tasks[taskName]; const taskDraft = this.state.taskDrafts.find(taskD => taskD.name === taskName); if (taskDraft) { task.specifications_doc = taskDraft.specifications_doc; } - //Resolve task from the strategy template - const $taskRefs = await $RefParser.resolve(task); - - // Identify the task specification template of every task in the strategy template const taskTemplate = _.find(this.taskTemplates, {'name': task['specifications_template']}); - schema['$id'] = taskTemplate.schema['$id']; - schema['$schema'] = taskTemplate.schema['$schema']; - let index = 0; - for (const param of observStrategy.template.parameters) { - if (param.refs[0].indexOf(`/tasks/${taskName}`) > 0) { - tasksToUpdate[taskName] = taskName; - // Resolve the identified template - const $templateRefs = await $RefParser.resolve(taskTemplate); - let property = { }; - let tempProperty = null; - const taskPaths = param.refs[0].split("/"); - // Get the property type from the template and create new property in the schema for the parameters - try { - const parameterRef = param.refs[0];//.replace(`#/tasks/${taskName}/specifications_doc`, '#/schema/properties'); - tempProperty = $templateRefs.get(parameterRef); - } catch(error) { - tempProperty = _.cloneDeep(taskTemplate.schema.properties[taskPaths[4]]); - if (tempProperty['$ref']) { - tempProperty = await UtilService.resolveSchema(tempProperty); - if (tempProperty.definitions && tempProperty.definitions[taskPaths[4]]) { - schema.definitions = {...schema.definitions, ...tempProperty.definitions}; - tempProperty = tempProperty.definitions[taskPaths[4]]; - } else if (tempProperty.properties && tempProperty.properties[taskPaths[4]]) { - tempProperty = tempProperty.properties[taskPaths[4]]; - } - } - if (tempProperty.type === 'array' && taskPaths.length>6) { - tempProperty = tempProperty.items.properties[taskPaths[6]]; - } - property = tempProperty; - } - property.title = param.name; - property.default = $taskRefs.get(param.refs[0].replace(`#/tasks/${taskName}`, '#')); - paramsOutput[`param_${index}`] = property.default; - schema.properties[`param_${index}`] = property; - // Set property defintions taken from the task template in new schema - for (const definitionName in taskTemplate.schema.definitions) { - schema.definitions[definitionName] = taskTemplate.schema.definitions[definitionName]; - } - } - index++; - } if (taskTemplate.type_value==='observation' && task.specifications_doc.station_groups) { - tasksToUpdate[taskName] = taskName; + station_group = task.specifications_doc.station_groups; + } + let taskTemplateSchema = this.taskTemplateSchemas[task['specifications_template']]; + if (!taskTemplateSchema) { + taskTemplateSchema = _.find(this.taskTemplates, {'name': task['specifications_template']}).schema; + taskTemplateSchema = await UtilService.resolveSchema(_.cloneDeep(taskTemplateSchema)); + this.taskTemplateSchemas[task['specifications_template']] = taskTemplateSchema; + } + schema.definitions = {...schema.definitions, ...taskTemplateSchema.definitions}; + taskPaths.reverse(); + const paramProp = await ParserUtility.getParamProperty($strategyRefs, taskPaths, taskTemplateSchema, param); + schema.properties[param.name] = _.cloneDeep(paramProp); + if (schema.properties[param.name]) { + schema.properties[param.name].title = param.name; + schema.properties[param.name].default = $strategyRefs.get(param.refs[0]); + paramsOutput[param.name] = schema.properties[param.name].default; } } this.setState({observStrategy: observStrategy, paramsSchema: schema, paramsOutput: paramsOutput, tasksToUpdate: tasksToUpdate}); + // this.setState({observStrategy: observStrategy, paramsSchema: _.cloneDeep(schema), paramsOutput: paramsOutput, stationGroup: station_group, isDirty: true}); // Function called to clear the JSON Editor fields and reload with new schema if (this.state.editorFunction) { @@ -354,7 +333,7 @@ export class EditSchedulingUnit extends Component { let observStrategy = _.cloneDeep(this.state.observStrategy); const $refs = await $RefParser.resolve(observStrategy.template); observStrategy.template.parameters.forEach(async(param, index) => { - $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput['param_' + index]); + $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput[param.name]); }); const schUnit = { ...this.state.schedulingUnit }; schUnit.scheduling_constraints_doc = constStrategy; diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js index ff028172ae69ebe0768d5451823edda91486d744..eb74629686387616f53433214eacda870b96f19f 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js @@ -34,6 +34,7 @@ import UtilService from '../../services/util.service'; import Validator from '../../utils/validator'; import UnitConverter from '../../utils/unit.converter' import UIConstants from '../../utils/ui.constants'; +import ParserUtility from '../../utils/parser.utility'; import moment from 'moment'; import _ from 'lodash'; @@ -155,6 +156,7 @@ export class SchedulingSetCreate extends Component { this.schedulingSets = []; // All scheduling sets to be filtered for project this.observStrategies = []; // All Observing strategy templates this.taskTemplates = []; // All task templates to be filtered based on tasks in selected strategy template + this.taskTemplateSchemas = []; this.constraintTemplates = []; this.agSUWithDefaultValue = {'id': 0, 'suname': '', 'sudesc': ''}; this.emptyAGSU = {}; @@ -483,6 +485,48 @@ export class SchedulingSetCreate extends Component { } async getTaskSchema(observStrategy) { + let station_group = []; + let tasksToUpdate = {}; + if(observStrategy) { + const tasks = observStrategy.template.tasks; + const parameters = observStrategy.template.parameters; + let paramsOutput = {}; + let schema = { type: 'object', additionalProperties: false, + properties: {}, definitions:{} + }; + const $strategyRefs = await $RefParser.resolve(observStrategy.template); + // TODo: This schema reference resolving code has to be moved to common file and needs to rework + for (const param of parameters) { + let taskPaths = param.refs[0].split("/"); + const taskName = taskPaths[2]; + tasksToUpdate[taskName] = taskName; + taskPaths = taskPaths.slice(4, taskPaths.length); + const task = tasks[taskName]; + const taskTemplate = _.find(this.taskTemplates, {'name': task['specifications_template']}); + if (taskTemplate.type_value==='observation' && task.specifications_doc.station_groups) { + station_group = task.specifications_doc.station_groups; + } + let taskTemplateSchema = this.taskTemplateSchemas[task['specifications_template']]; + if (!taskTemplateSchema) { + taskTemplateSchema = _.find(this.taskTemplates, {'name': task['specifications_template']}).schema; + taskTemplateSchema = await UtilService.resolveSchema(_.cloneDeep(taskTemplateSchema)); + this.taskTemplateSchemas[task['specifications_template']] = taskTemplateSchema; + } + schema.definitions = {...schema.definitions, ...taskTemplateSchema.definitions}; + taskPaths.reverse(); + const paramProp = await ParserUtility.getParamProperty($strategyRefs, taskPaths, taskTemplateSchema, param); + schema.properties[param.name] = _.cloneDeep(paramProp); + if (schema.properties[param.name]) { + schema.properties[param.name].title = param.name; + schema.properties[param.name].default = $strategyRefs.get(param.refs[0]); + paramsOutput[param.name] = schema.properties[param.name].default; + } + } + await this.setState({observStrategy: observStrategy, paramsSchema: schema, paramsOutput: paramsOutput,defaultStationGroups: station_group, tasksToUpdate: tasksToUpdate}); + } + } + + /*async getTaskSchema(observStrategy) { let station_group = []; let tasksToUpdate = {}; if(observStrategy) { @@ -526,7 +570,11 @@ export class SchedulingSetCreate extends Component { tempProperty = await UtilService.resolveSchema(tempProperty); if (tempProperty.definitions && tempProperty.definitions[taskPaths[4]]) { schema.definitions = {...schema.definitions, ...tempProperty.definitions}; - tempProperty = tempProperty.definitions[taskPaths[4]]; + if (taskPaths.length>6) { + tempProperty = _.cloneDeep(tempProperty.definitions[taskPaths[4]]); + } else { + tempProperty = {'$ref': `#/definitions/${taskPaths[4]}`}; + } } else if (tempProperty.properties && tempProperty.properties[taskPaths[4]]) { tempProperty = tempProperty.properties[taskPaths[4]]; } @@ -550,7 +598,7 @@ export class SchedulingSetCreate extends Component { } await this.setState({observStrategy: observStrategy, paramsSchema: schema, paramsOutput: paramsOutput,defaultStationGroups: station_group, tasksToUpdate: tasksToUpdate}); } - } + }*/ /** * Resolve JSON Schema @@ -1553,9 +1601,11 @@ export class SchedulingSetCreate extends Component { async prepareObservStrategyFromExcelValue(suRow) { let colKeys = Object.keys(suRow); let paramsOutput = {}; + let parameters = _.map(this.state.observStrategy.template.parameters, 'name'); for(const colKey of colKeys) { let prefix = colKey.split("~"); - if(colKey.startsWith('param_') && prefix.length > 1) { + // if(colKey.startsWith('param_') && prefix.length > 1) { + if(prefix.length > 1 && parameters.indexOf(prefix[0])>=0 ) { var res = Object.keys(suRow).filter(v => v.startsWith(prefix[0])); if(res && res.length > 1) { let res = paramsOutput[prefix[0]]; @@ -1591,7 +1641,8 @@ export class SchedulingSetCreate extends Component { let observStrategy = _.cloneDeep(this.state.observStrategy); const $refs = await $RefParser.resolve(observStrategy.template); observStrategy.template.parameters.forEach(async(param, index) => { - $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput['param_' + index]); + // $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput['param_' + index]); + $refs.set(observStrategy.template.parameters[index]['refs'][0], this.state.paramsOutput[param.name]); }); return observStrategy; } @@ -1806,9 +1857,9 @@ export class SchedulingSetCreate extends Component { } this.dialogContent = this.getSchedulingDialogContent; - this.onCancel = this.reset; + this.onCancel = null; this.onClose = this.reset; - this.callBackFunction = this.reset; + this.callBackFunction = null; this.setState({isDirty : false, showSpinner: false, confirmDialogVisible: true, /*dialog: dialog,*/ isAGLoading: true, copyHeader: false, rowData: []}); publish('edit-dirty', false); } else { @@ -1921,18 +1972,20 @@ export class SchedulingSetCreate extends Component { * Refresh the grid with updated data */ async reset() { - let schedulingUnitList = await ScheduleService.getSchedulingBySet(this.state.selectedSchedulingSetId); - schedulingUnitList = _.filter(schedulingUnitList,{'observation_strategy_template_id': this.state.observStrategy.id}) ; - this.setState({ - schedulingUnitList: schedulingUnitList, - confirmDialogVisible: false, - isDirty: false - }); - publish('edit-dirty', false); - this.isNewSet = false; - await this.prepareScheduleUnitListForGrid(); - this.state.gridApi.setRowData(this.state.rowData); - this.state.gridApi.redrawRows(); + if (this.state.confirmDialogVisible) { + let schedulingUnitList = await ScheduleService.getSchedulingBySet(this.state.selectedSchedulingSetId); + schedulingUnitList = _.filter(schedulingUnitList,{'observation_strategy_template_id': this.state.observStrategy.id}) ; + this.setState({ + schedulingUnitList: schedulingUnitList, + confirmDialogVisible: false, + isDirty: false + }); + publish('edit-dirty', false); + this.isNewSet = false; + await this.prepareScheduleUnitListForGrid(); + this.state.gridApi.setRowData(this.state.rowData); + this.state.gridApi.redrawRows(); + } } /** diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/parser.utility.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/parser.utility.js new file mode 100644 index 0000000000000000000000000000000000000000..a60078d385a0b718828e1d7377f94f92caadeb4f --- /dev/null +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/parser.utility.js @@ -0,0 +1,53 @@ +import _ from 'lodash'; +import $RefParser from "@apidevtools/json-schema-ref-parser"; + +const ParserUtility = { + /** + * Function to get the property of the parameter referred for the task. + * @param {*} $strategyRefs + * @param {Array} paramPaths - Property reference path. + * Example if the task parameter refers '#/tasks/Target Pointing 1/specifications_doc/SAPs/0/digital_pointing', + * then the parameter to be passed is [digital_pointing, 0, SAPs] + * @param {Object} taskTemplateSchema - JSON schema for the respective task template + * @returns + */ + getParamProperty: async($strategyRefs, paramPaths, taskTemplateSchema) => { + const $templateRefs = await $RefParser.resolve(taskTemplateSchema); + let pathIndex = 0; + let paramProp = {}; + for (const paramPath of paramPaths) { + let property = taskTemplateSchema.properties[paramPath]; + if (property) { + let rootPath = paramPaths.slice(0, pathIndex) + rootPath.reverse(); + paramProp = _.cloneDeep(property); + if (rootPath.length > 0) { + for (const path of rootPath) { + if (paramProp[path]) { + break; + } else { + if (paramProp['$ref']) { + paramProp = $templateRefs.get(paramProp['$ref']); + if (paramProp.properties && paramProp.properties[path]) { + paramProp = paramProp.properties[path]; + } + } else { + if (paramProp.type === "array") { + paramProp = paramProp.items.properties[path]; + } else if (paramProp.type === "object") { + paramProp = paramProp.properties[path]; + } else { + paramProp = paramProp[path]; + } + } + } + } + } + } + pathIndex++; + } + return paramProp; + } +} + +export default ParserUtility; \ No newline at end of file