diff --git a/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts b/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts index e3214ec0ebfcbab24324908d9c3383d08dc1859b..a87aeee38c1253c008869b7febc1270f678a450f 100644 --- a/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts +++ b/src/app/p_services/admin/lifeCycleManagement/service-rule-design/service-rule-design.component.ts @@ -250,7 +250,7 @@ export class ServiceRuleDesignComponent implements OnInit { this.workspace.charsListSet = this.workspace.charsListSet.concat( this.charsListArray ); this.workspace.charsListBoolean = this.charsListBoolean; - + this.workspace.specService = this.specService; this.charvarsAllFunction(this.workspace); //calling this function here causes a preloading of the blocks in the model in a synchronous manner. Asynchronously it is recalled later in the blockly toolbar @@ -527,6 +527,8 @@ export class ServiceRuleDesignComponent implements OnInit { var xmlList = []; var chars: ServiceSpecRelationship[] = workspace.serviceSpecRel; + + if (Blockly.Blocks['getServiceRefName']) { for (var i = 0; i < chars.length; i++) { var blockText = '' + @@ -556,10 +558,112 @@ export class ServiceRuleDesignComponent implements OnInit { xmlList.push(block); + + + + // if (Blockly.Blocks['setServiceRefProps']) { + // for (var i = 0; i < chars.length; i++) { + + // var options = []; + // var serviceRefSpec; + // var servRef = chars[i]; + + // workspace.specService.retrieveServiceSpecification({id: servRef.id, servRef , xmlList }).subscribe( + // data => serviceRefSpec = data, + // error => console.error(error), + // () => { + + // var xmlx = xmlList; + // var serviceRefChars: ServiceSpecCharacteristic[] = serviceRefSpec.serviceSpecCharacteristic; + // for (var j = 0; j < serviceRefChars.length; j++) { + // options.push([ serviceRefChars[j].name, serviceRefChars[j].name ]); + // } + // console.log(servRef); + + // var sortedArray: string[] = options.sort((n1,n2) => { + // if (n1 > n2) { + // return 1; + // } + + // if (n1 < n2) { + // return -1; + // } + + // return 0; + // }); + + // Blockly.Blocks['setServiceRefProps'] = { + // init: function() { + // this.appendDummyInput() + // .appendField("Service") + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFNAME"); + // this.appendDummyInput() + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFUUID") + // .appendField(new Blockly.FieldLabelSerializable(""), "NAMELBL") + // .appendField(new Blockly.FieldDropdown( sortedArray ), "OPTIONEDVALUE"); + + + // this.appendValueInput("AVALUE") + // .setCheck("String") + // .setAlign(Blockly.ALIGN_RIGHT) + // .appendField("value"); + + + // this.setInputsInline( true ); + // this.setPreviousStatement(true, null); + // this.setNextStatement(true, null); + // this.setColour(160); + // this.setTooltip("Set values to characteristics of a refernced service."); + // this.setHelpUrl(""); + + // }, + + // }; + // } + // ) + + // var blockText = '' + + // ''+ servRef.name +'' + + // ''+ servRef.uuid +'' + + // ''; + // var block = Blockly.Xml.textToDom(blockText); + // xmlList.push(block); + + + // } + // } + + + + + if (Blockly.Blocks['setServiceRefCharacteristicValues']) { + for (var i = 0; i < chars.length; i++) { + + var blockText = '' + + '' + chars[i].name + '' + + '' + chars[i].uuid + '' + + ''; + var block = Blockly.Xml.textToDom(blockText); + xmlList.push(block); + + } + } + + + if (Blockly.Blocks['serviceRefCharacteristic']) { + var blockText = '' + + '' + + '' + + ''; + var block = Blockly.Xml.textToDom(blockText); + xmlList.push(block); + } + return xmlList; }; + /** @@ -567,7 +671,7 @@ export class ServiceRuleDesignComponent implements OnInit { * @param {!Blockly.Workspace} workspace The workspace this flyout is for. * @return {!Array.} Array of XML block elements. */ - resourceSpecRelsFunction = function(workspace: any) { + resourceSpecRelsFunction = function(workspace: any) { var xmlList = []; var chars: ResourceSpecificationRef[] = workspace.resourceserviceSpecRef; @@ -581,7 +685,7 @@ export class ServiceRuleDesignComponent implements OnInit { } } - blockText = ''; + blockText = ''; block = Blockly.Xml.textToDom(blockText); xmlList.push(block); @@ -618,11 +722,9 @@ export class ServiceRuleDesignComponent implements OnInit { var objects = Blockly.Java.valueToCode(block, 'VARIABLES', Blockly.Java.ORDER_NONE) || null; - objects = objects.replace('[', ' ,'); - objects = objects.replace(']', ' '); - + objects = objects.substring(1, objects.length-1 ); //remove first and last brackets - var code = 'String.format(' + atext + objects + ')'; + var code = 'String.format(' + atext + ', ' + objects + ')'; return [code, Blockly.Java.ORDER_ATOMIC]; }; @@ -1366,12 +1468,66 @@ export class ServiceRuleDesignComponent implements OnInit { var avalue = Blockly.Java.valueToCode(block, 'CONDITION', Blockly.Java.ORDER_ASSIGNMENT) || 'true'; - - var code = 'createServiceRefIf(' + serviceName +', '+ avalue +');\n'; - + + var charvalsVarName = 'charvals'; + //put it in braces so to ensure the scope of the hashmap variable + var code = '{\n'; + + var charvalsVarName = 'charvals'; + code += 'java.util.HashMap ' + charvalsVarName + ' = new java.util.HashMap<>();\n'; + + var varray = '['; + var cvs = Blockly.Java.valueToCode(block, 'CHARVALUES', Blockly.Java.ORDER_NONE) || null ; + console.log( cvs ); + var objects = JSON.parse( cvs ); + console.log( objects ); + if (objects){ + objects.forEach(element => { + var charname = element.charname; + var avalue = element.charvalue; + code += charvalsVarName + '.put(' + charname + ',' +avalue + ');\n'; + }); + } + varray += ']'; + + code += 'createServiceRefIf(' + serviceName +', '+ avalue +', '+ charvalsVarName +');\n'; + code += '}\n'; return code; }; + Blockly.Java['createResourceRefIf'] = function(block: any) { + var resourceName = Blockly.Java.valueToCode(block, 'RESOURCE_NAME', + Blockly.Java.ORDER_NONE) || '""'; + + + var avalue = Blockly.Java.valueToCode(block, 'CONDITION', + Blockly.Java.ORDER_ASSIGNMENT) || 'true'; + + var charvalsVarName = 'charvals'; + //put it in braces so to ensure the scope of the hashmap variable + var code = '{\n'; + + var charvalsVarName = 'charvals'; + code += 'java.util.HashMap ' + charvalsVarName + ' = new java.util.HashMap<>();\n'; + + var varray = '['; + var cvs = Blockly.Java.valueToCode(block, 'CHARVALUES', Blockly.Java.ORDER_NONE) || null ; + console.log( cvs ); + var objects = JSON.parse( cvs ); + console.log( objects ); + if (objects){ + objects.forEach(element => { + var charname = element.charname; + var avalue = element.charvalue; + code += charvalsVarName + '.put(' + charname + ',' +avalue + ');\n'; + }); + } + varray += ']'; + + code += 'createResourceRefIf(' + resourceName +', '+ avalue +', '+ charvalsVarName +');\n'; + code += '}\n'; + return code; + }; Blockly.Java['getServiceRefName'] = function(block: any) { @@ -1416,6 +1572,107 @@ export class ServiceRuleDesignComponent implements OnInit { }; + + // Blockly.Java['setServiceRefProps'] = function(block: any) { + // // Variable getter. + // console.log('setServiceRefProps'); + + + // //var acharname='""'; + // var servicename = block.getFieldValue('ASERVICEREFNAME'); + // servicename = Blockly.Java.quote_( servicename ); + // var servicerefuuid = block.getFieldValue('ASERVICEREFUUID'); + // servicerefuuid = Blockly.Java.quote_( servicerefuuid ); + + // console.log( servicename ); + + + // // var acharname = Blockly.Java.valueToCode(block, 'characteristicName', + // // Blockly.Java.ORDER_ASSIGNMENT) || '""'; + // var acharname = block.getFieldValue('OPTIONEDVALUE'); + // console.log( acharname ); + + + // var aVALUE = Blockly.Java.valueToCode(block, 'AVALUE', + // Blockly.Java.ORDER_ASSIGNMENT) || '""'; + + // console.log( aVALUE ); + + // var code = 'setServiceRefPropValue(' + servicename +', '+acharname +', '+aVALUE +');\n'; + + + // return code; + // }; + + + + Blockly.Java['serviceRefCharacteristic'] = function(block: any) { + // Variable getter. + console.log('serviceRefCharacteristic'); + + var acharname = Blockly.Java.valueToCode(block, 'ACHARACTERISTICNAME', + Blockly.Java.ORDER_ASSIGNMENT) || '""'; + console.log( acharname ); + + var aVALUE = Blockly.Java.valueToCode(block, 'AVALUE', + Blockly.Java.ORDER_ASSIGNMENT) || '""'; + + console.log( aVALUE ); + + var code: any = { "charname" : acharname, "charvalue" : aVALUE }; + + code = JSON.stringify( code, null ); + return [code, Blockly.Java.ORDER_ATOMIC]; + }; + + Blockly.Java['setServiceRefCharacteristicValues'] = function(block: any) { + // Variable getter. + console.log('setServiceRefCharacteristicValues'); + + + //var acharname='""'; + var servicename = block.getFieldValue('ASERVICEREFNAME'); + servicename = Blockly.Java.quote_( servicename ); + var servicerefuuid = block.getFieldValue('ASERVICEREFUUID'); + servicerefuuid = Blockly.Java.quote_( servicerefuuid ); + + console.log( servicename ); + + + var acharname = Blockly.Java.valueToCode(block, 'characteristicName', + Blockly.Java.ORDER_ASSIGNMENT) || '""'; + + console.log( acharname ); + + + var cvs = Blockly.Java.valueToCode(block, 'CHARVALUES', Blockly.Java.ORDER_NONE) || null ; + console.log( cvs ); + var objects = JSON.parse( cvs ); + console.log( objects ); + + //var charvalsVarName = 'charvals_'+ Math.floor(Math.random() * 1000) + 1; + var charvalsVarName = 'charvals'; + //put it in braces so to ensure the scope of the hashmap variable + var code = '{\n'; + code += 'java.util.HashMap ' + charvalsVarName + ' = new java.util.HashMap<>();\n'; + + var varray = '['; + + if (objects){ + objects.forEach(element => { + var charname = element.charname; + var avalue = element.charvalue; + code += charvalsVarName + '.put(' + charname + ',' +avalue + ');\n'; + }); + } + varray += ']'; + + code += 'setServiceRefCharacteristicsValues(' + servicename +', ' + charvalsVarName + ');\n'; + code += '}\n'; + + return code; + }; + } diff --git a/src/assets/blockly/custom_blocks.js b/src/assets/blockly/custom_blocks.js index 51d44d03862e662826f4ead578e8937d2795a5f3..a3a0cb5cf420a8059b3e4b352d4ded3a927aff94 100644 --- a/src/assets/blockly/custom_blocks.js +++ b/src/assets/blockly/custom_blocks.js @@ -1214,8 +1214,16 @@ Blockly.Blocks['example_variable_typed'] = { .appendField("Create Ref Service"); this.appendValueInput("CONDITION") .setCheck("Boolean") + .setAlign(Blockly.ALIGN_RIGHT) .appendField("if"); - this.setInputsInline(true); + + this.appendValueInput("CHARVALUES") + .setCheck("Array") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("Characteristics"); + + + this.setInputsInline(false); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(230); @@ -1224,6 +1232,27 @@ Blockly.Blocks['example_variable_typed'] = { } }; + Blockly.Blocks['createResourceRefIf'] = { + init: function() { + this.appendValueInput("RESOURCE_NAME") + .setCheck("String") + .appendField("Create Ref Resource"); + this.appendValueInput("CONDITION") + .setCheck("Boolean") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("if"); + this.appendValueInput("CHARVALUES") + .setCheck("Array") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("Characteristics"); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(230); + this.setTooltip("Create a resource when a condition validates to true during the creation process."); + this.setHelpUrl(""); + } + }; @@ -1356,4 +1385,94 @@ Blockly.Blocks['example_variable_typed'] = { this.updateShape(); } }; + + + + + // Blockly.Blocks['setServiceRefProps'] = { + // init: function() { + // this.appendDummyInput() + // .appendField("Service") + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFNAME"); + // this.appendDummyInput() + // .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFUUID") + // .appendField(new Blockly.FieldLabelSerializable(""), "NAMELBL") + // .appendField(new Blockly.FieldLabelSerializable(""), "OPTIONEDVALUE"); + + + + // this.appendValueInput("AVALUE") + // .setCheck("String") + // .setAlign(Blockly.ALIGN_RIGHT) + // .appendField("value"); + + + // this.setInputsInline( true ); + // this.setPreviousStatement(true, null); + // this.setNextStatement(true, null); + // this.setColour(colourtexts); + // this.setTooltip("Set values to characteristics of a refernced service."); + // this.setHelpUrl(""); + + // }, + + // }; + + + + Blockly.Blocks['serviceRefCharacteristic'] = { + init: function() { + + this.appendValueInput("ACHARACTERISTICNAME") + .setCheck("String") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("Name"); + + + this.appendValueInput("AVALUE") + .setCheck("String") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("value"); + + + this.setInputsInline( true ); + this.setOutput(true, 'String'); + this.setColour(colourtexts); + this.setTooltip("Set values to characteristics of a referenced service."); + this.setHelpUrl(""); + + }, + + }; + + + Blockly.Blocks['setServiceRefCharacteristicValues'] = { + init: function() { + this.appendDummyInput() + .appendField("Service") + .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFNAME"); + this.appendDummyInput() + .appendField(new Blockly.FieldLabelSerializable(""), "ASERVICEREFUUID"); + + + + this.appendValueInput("CHARVALUES") + .setCheck("Array") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("Characteristics"); + + + this.setInputsInline( false ); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour(colourtexts); + this.setTooltip("Set values to characteristics of a refernced service."); + this.setHelpUrl(""); + + }, + + + + + }; \ No newline at end of file