Hello folk I am import ElementTemplates in BPMNreplace filePreformatted text
import {
pick,
assign,
filter,
forEach,
isArray,
isUndefined,
has
} from ‘min-dash’;
import { is } from ‘bpmn-js/lib/util/ModelUtil’;
import { isAny } from ‘bpmn-js/lib/features/modeling/util/ModelingUtil’;
import {
getBusinessObject
} from ‘bpmn-js/lib/util/ModelUtil’;
import {
isExpanded,
isEventSubProcess
} from ‘bpmn-js/lib/util/DiUtil’;
import { getPropertyNames } from ‘bpmn-js/lib/features/copy-paste/ModdleCopy’;
import * as _minDash from ‘min-dash’;
import * as _DiUtil from ‘bpmn-js/lib/util/DiUtil’;
import { getTemplate, getTemplateId, TEMPLATE_ATTR } from ‘bpmn-js-properties-panel/lib/provider/camunda/element-templates/Helper’;
import * as botdetails from ‘…/botdetails.js’;
import EntryFactory from “bpmn-js-properties-panel/lib/factory/EntryFactory”;
import ElementTemplates from “bpmn-js-properties-panel/lib/provider/camunda/element-templates/ElementTemplates”;
console.log(ElementTemplates)
console.log(‘elementTemplates’)
/*
*/
const test_url = “http://” + window.location.hostname + “:4200”;
function copyProperties(source, target, properties) {
if (!isArray(properties)) {
properties = [properties];
}
forEach(properties, function(property) {
if (!isUndefined(source[property])) {
target[property] = source[property];
}
});
}
var CUSTOM_PROPERTIES = [
'cancelActivity',
'instantiate',
'eventGatewayType',
'triggeredByEvent',
'isInterrupting'
];
function toggeling(element, target) {
var oldCollapsed = (
element && has(element, 'collapsed') ? element.collapsed : !isExpanded(element)
);
var targetCollapsed;
if (target && (has(target, 'collapsed') || has(target, 'isExpanded'))) {
// property is explicitly set so use it
targetCollapsed = (
has(target, 'collapsed') ? target.collapsed : !target.isExpanded
);
} else {
// keep old state
targetCollapsed = oldCollapsed;
}
if (oldCollapsed !== targetCollapsed) {
element.collapsed = oldCollapsed;
return true;
}
return false;
}
/*start custom code start */
function unknownTemplate(templateId, translate) {
return {
name: translate('[unknown template: {templateId}]', { templateId: templateId }),
value: templateId
};
}
function isDefaultTemplate(elementTemplate) {
return elementTemplate.isDefault;
}
function applyTemplate(element, newTemplateId, elementTemplates) {
// cleanup
// clear input output mappings
// undo changes to properties defined in template
// re-establish
// set input output mappings
// apply changes to properties as defined in new template
var oldTemplate = getTemplate(element, elementTemplates),
newTemplate = elementTemplates.get(newTemplateId);
console.log("newTemplate");
console.log(newTemplate)
localStorage.setItem("botName", newTemplate.name);
if (oldTemplate === newTemplate) {
return;
}
return {
cmd: 'propertiesPanel.camunda.changeTemplate',
context: {
element: element,
oldTemplate: oldTemplate,
newTemplate: newTemplate
}
};
}
function getoptions(emptyOption, elementTemplates, element, technologyCategory, technology, currentTemplateId) {
var allOptions = elementTemplates.getAll().reduce(function(templates, t) {
// alert("category " + t.category);
if (!isAny(element, t.appliesTo)) {
return templates;
}
if (t.technologyCategory == technologyCategory && t.technology == technology) {
return templates.concat({
name: t.name,
value: t.id,
isDefault: t.isDefault
});
}
return templates;
}, [emptyOption]);
var defaultOption = find(allOptions, function(option) {
return isDefaultTemplate(option);
});
var currentOption = find(allOptions, function(option) {
return option.value === currentTemplateId;
});
if (currentTemplateId && !currentOption) {
currentOption = unknownTemplate(currentTemplateId);
allOptions.push(currentOption);
}
if (!defaultOption) {
// return all options, including empty
// and optionally unknownTemplate option
return allOptions;
}
// special limited handling for
// default options
var options = [];
// current template not set
if (!currentTemplateId) {
options.push({
name: '',
value: ''
});
}
// current template not default
if (currentOption && currentOption !== defaultOption) {
options.push(currentOption);
}
options.push(defaultOption);
// [ (empty), (current), defaultOption ]
return options;
}
/*end custom code */
/**
- This module takes care of replacing BPMN elements
*/
export default function BpmnReplace(
bpmnFactory,
elementFactory,
moddleCopy,
modeling,
replace,
selection,
moddle,
) {
//Akhil changes for unit testing of bots starts here
function openPanel() {
console.log("requesting testing framework with technologyCategory :: " + localStorage.getItem("techCat") + " & technology :: " + localStorage.getItem("tech") + " bot name :: " + localStorage.getItem("botName"));
var url = test_url + "/BotTesting?technology=" + localStorage.getItem("tech") + "&botName=" + localStorage.getItem("botName");
// window.open(url,'popUpWindow','height=500,width=700,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');
parent.postMessage(localStorage.getItem("tech") + "&" + localStorage.getItem("botName") + "#@validateBot", "*");
}
//Akhil changes for unit testing of bots ends here
//Akhil changes for configure bots starts here
function callWizard() {
if (localStorage.getItem("technology") == 'undefined') {
alert("This feature is applicable only for bots")
} else {
console.log("requesting wizard to configure bot with technologyCategory :: " + localStorage.getItem("techCat") + " & technology :: " + localStorage.getItem("tech") + " bot name :: " + localStorage.getItem("botName") + " id ::" + localStorage.getItem("taskid"));
parent.postMessage(localStorage.getItem("taskid") + "#@configureEditor", "*");
}
}
function callUpgrade() {
if (localStorage.getItem("technology") == 'undefined') {
alert("This feature is applicable only for bots")
} else if (localStorage.getItem("technology").toLowerCase() != "java" && localStorage.getItem("technology").toLowerCase() != "python" && localStorage.getItem("technology").toLowerCase() != "dotnetcore" && localStorage.getItem("technology").toLowerCase() != "dotnetframework") {
alert("This feature is currently not supported for " + localStorage.getItem("technology"))
} else {
let obj = {};
obj['botName'] = localStorage.getItem("botName");
obj['technology'] = localStorage.getItem("technology");
obj['version'] = localStorage.getItem("version");
obj['taskid'] = localStorage.getItem("taskid");
obj['wfId'] = localStorage.getItem("wfId");
let objFinal = JSON.stringify(obj);
console.log("requesting wizard to view source with technologyCategory :: " + localStorage.getItem("techCat") + " & technology :: " + localStorage.getItem("tech") + " bot name :: " + localStorage.getItem("botName") + " id ::" + localStorage.getItem("taskid") + " botName :: " + localStorage.getItem("botName") + " technology :: " + localStorage.getItem("technology") + " version :: " + localStorage.getItem("version") + "workflow id :: " + localStorage.getItem("wfId"));
parent.postMessage(objFinal + "#@upgradeEditor", "*");
}
}
bpmnFactory.create = function(type, attrs, selection) {
//Akhil changes for unit testing of bots starts here
if (type == "bpmn:customTask") {
openPanel();
}
//Akhil changes for configure bots ends here
if (type == "bpmn:configureBot") {
callWizard();
}
if (type == "bpmn:upgradeBot") {
callUpgrade();
}
//Akhil changes for configure ends here
else {
var element = this._model.create(type, attrs || {});
this._ensureId(element);
return element;
}
};
//Akhil changes for configure bots ends here
/**
* Prepares a new business object for the replacement element
* and triggers the replace operation.
*
* @param {djs.model.Base} element
* @param {Object} target
* @param {Object} [hints]
*
* @return {djs.model.Base} the newly created element
*/
function replaceElement(element, target, hints) {
hints = hints || {};
var type = target.type,
oldBusinessObject = element.businessObject;
if (isSubProcess(oldBusinessObject)) {
if (type === 'bpmn:SubProcess') {
if (toggeling(element, target)) {
// expanding or collapsing process
modeling.toggleCollapse(element);
return element;
}
}
}
moddle.getType = function(descriptor) {
var cache = this.typeCache;
var name = (0, _minDash.isString)(descriptor) ? descriptor : descriptor.ns.name;
var type = cache[name];
//Akhil changes for unit testing of bots starts here
if (descriptor == "bpmn:customTask") {
type = "bpmn:customTask";
}
//Akhil changes for unit testing of bots ends here
//Akhil changes for configure bots starts here
if (descriptor == "bpmn:configureBot") {
type = "bpmn:configureBot";
}
if (descriptor == "bpmn:upgradeBot") {
type = "bpmn:upgradeBot";
}
//Akhil changes for configure bots ends here
if (!type) {
descriptor = this.registry.getEffectiveDescriptor(name);
type = cache[name] = this.factory.createType(descriptor);
}
return type;
};
var newBusinessObject = bpmnFactory.create(type);
var newElement = {
type: type,
businessObject: newBusinessObject
};
// console.log(newBusinessObject, 'newBusinessObject')
var elementProps = getPropertyNames(oldBusinessObject.$descriptor),
newElementProps = getPropertyNames(newBusinessObject.$descriptor, true),
copyProps = intersection(elementProps, newElementProps);
// initialize special properties defined in target definition
assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
var properties = filter(copyProps, function(propertyName) {
// copying event definitions, unless we replace
if (propertyName === 'eventDefinitions') {
return hasEventDefinition(element, target.eventDefinitionType);
}
// retain loop characteristics if the target element
// is not an event sub process
if (propertyName === 'loopCharacteristics') {
return !isEventSubProcess(newBusinessObject);
}
// so the applied properties from 'target' don't get lost
if (newBusinessObject.hasOwnProperty(propertyName)) {
return false;
}
if (propertyName === 'processRef' && target.isExpanded === false) {
return false;
}
if (propertyName === 'triggeredByEvent') {
return false;
}
return true;
});
newBusinessObject = moddleCopy.copyElement(
oldBusinessObject,
newBusinessObject,
properties
);
//Akhil changes for unit test of bots starts here
var custAttr = target.customAtttr;
if (custAttr) {
console.info("I am here");
if (!newBusinessObject.extensionElements) {
console.info("Not extensions found");
newBusinessObject.extensionElements = bpmnFactory.create('bpmn:ExtensionElements');
}
var taskextvalues = newBusinessObject.extensionElements.values;
if (!taskextvalues) {
taskextvalues = new Array();
newBusinessObject.extensionElements.values = taskextvalues
}
var taskproperties;
for (var j = 0; j < taskextvalues.length; j++) {
if (taskextvalues[j].$type === "camunda:Properties") {
taskproperties = taskextvalues[j];
break;
}
}
if (!taskproperties) {
taskproperties = bpmnFactory.create("camunda:Properties");
newBusinessObject.extensionElements.values.push(taskproperties);
taskproperties.values = new Array();
}
var i;
for (i = 0; i < custAttr.length; i++) {
if (custAttr[i].name == "UnitTest" && custAttr[i].value == "apicall") {
openPanel();
}
if (custAttr[i].name == "ConfigureBot" && custAttr[i].value == "apicall") {
callWizard();
}
if (custAttr[i].name == "UpgradeBot" && custAttr[i].value == "apicall") {
callUpgrade();
} else {
var custProperty = null;
for (var k = 0; k < taskproperties.values.length; k++) {
if (taskproperties.values[k].name == custAttr[i].name) {
custProperty = taskproperties.values[i];
break;
}
}
if (!custProperty) {
custProperty = bpmnFactory.create("camunda:Property");
custProperty.name = custAttr[i].name;
custProperty.value = "";
taskproperties.values.push(custProperty);
}
var attrvalue = custAttr[i].value;
custProperty.value = attrvalue;
if (target.color != undefined) {
var option = target.color[0];
var currentSelec = selection.get();
modeling.setColor(currentSelec, option);
}
}
}
}
//Akhil changes for unit test of bots end here
// initialize custom BPMN extensions
if (target.eventDefinitionType) {
// only initialize with new eventDefinition
// if we did not set an event definition yet,
// i.e. because we copied it
if (!hasEventDefinition(newBusinessObject, target.eventDefinitionType)) {
newElement.eventDefinitionType = target.eventDefinitionType;
newElement.eventDefinitionAttrs = target.eventDefinitionAttrs;
}
}
if (is(oldBusinessObject, 'bpmn:Activity')) {
if (isSubProcess(oldBusinessObject)) {
// no toggeling, so keep old state
newElement.isExpanded = isExpanded(oldBusinessObject);
}
// else if property is explicitly set, use it
else if (target && has(target, 'isExpanded')) {
newElement.isExpanded = target.isExpanded;
}
// TODO: need also to respect min/max Size
// copy size, from an expanded subprocess to an expanded alternative subprocess
// except bpmn:Task, because Task is always expanded
if ((isExpanded(oldBusinessObject) && !is(oldBusinessObject, 'bpmn:Task')) && newElement.isExpanded) {
newElement.width = element.width;
newElement.height = element.height;
}
}
// remove children if not expanding sub process
if (isSubProcess(oldBusinessObject) && !isSubProcess(newBusinessObject)) {
hints.moveChildren = false;
}
// transform collapsed/expanded pools
if (is(oldBusinessObject, 'bpmn:Participant')) {
// create expanded pool
if (target.isExpanded === true) {
newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
} else {
// remove children when transforming to collapsed pool
hints.moveChildren = false;
}
// apply same width and default height
newElement.width = element.width;
newElement.height = elementFactory._getDefaultSize(newBusinessObject).height;
}
newBusinessObject.name = oldBusinessObject.name;
// retain default flow's reference between inclusive <-> exclusive gateways and activities
if (
isAny(oldBusinessObject, [
'bpmn:ExclusiveGateway',
'bpmn:InclusiveGateway',
'bpmn:Activity'
]) &&
isAny(newBusinessObject, [
'bpmn:ExclusiveGateway',
'bpmn:InclusiveGateway',
'bpmn:Activity'
])
) {
newBusinessObject.default = oldBusinessObject.default;
}
//start properties code
var currentTemplateId = getTemplateId(element);
console.log(currentTemplateId, 'currentTemplateId')
var emptyOption = {
name: '',
value: ''
};
var technologyCategory = null;
var technology = null;
var botCategory = null;
var botName = null;
if (element.type === "bpmn:ServiceTask" || element.type === "bpmn:CallActivity") {
localStorage.setItem("taskid", element.id);
var props;
if (element.businessObject.extensionElements != null && element.businessObject.extensionElements.values != null) {
for (var j = 0; j < element.businessObject.extensionElements.values.length; j++) {
var extElements = element.businessObject.extensionElements.values[j];
if (extElements.$type === "camunda:Properties") {
props = extElements;
}
}
if (props) {
console.info("props");
console.log(props)
if (props != undefined && props.$parent != undefined && props.$parent.$parent != undefined) {
localStorage.setItem("taskid", props.$parent.$parent.id);
}
if (props != undefined && props.$type != undefined && props.$type == 'camunda:Properties' && props.values != undefined) {
props.values.forEach(item => {
if (item.name == 'botName') {
localStorage.setItem("botName", item.value);
} else if (item.name == 'technology') {
localStorage.setItem("technology", item.value);
} else if (item.name == 'version') {
localStorage.setItem("version", item.value);
}
});
}
var i = 0;
for (i = 0; i < props.values.length; i++) {
if (props.values[i].name === "technologyCategory") {
technologyCategory = props.values[i].value;
localStorage.setItem("techCat", technologyCategory);
} else if (props.values[i].name === "technology") {
technology = props.values[i].value;
localStorage.setItem("tech", technology);
} else if (props.values[i].name === "botCategory") {
botCategory = props.values[i].value;
} else if (props.values[i].name === "botName") {
botName = props.values[i].value;
localStorage.setItem("botName", botName);
}
}
}
} else {
localStorage.setItem("botName", undefined);
localStorage.setItem("technology", undefined);
localStorage.setItem("version", undefined);
localStorage.setItem("taskid", undefined);
}
}
var options = [];
// var group = []
console.log(technology, 'technology')
if (technology != null) {
var newbot = botdetails.botdetails
// ElementTemplates.set(newbot);
console.log(ElementTemplates)
console.log("inside fun")
var options = getoptions(emptyOption, ElementTemplates, element, technologyCategory, technology, currentTemplateId);
console.log(options, 'option menuu')
if (options.length === 1 && !options[0].isDefault) {
return;
}
console.log(group, 'camunda:modelerTemplate', EntryFactory)
group.entries.push(EntryFactory.selectBox({
id: 'elementTemplate-chooser',
label: translate('Bot Name'),
modelProperty: 'camunda:modelerTemplate',
selectOptions: options,
set: function(element, properties) {
return applyTemplate(element, properties[TEMPLATE_ATTR], ElementTemplates);
},
disabled: function() {
var template = getTemplate(element, ElementTemplates);
return template && isDefaultTemplate(template);
}
}));
}
//end properties code
if (
target.host &&
!is(oldBusinessObject, 'bpmn:BoundaryEvent') &&
is(newBusinessObject, 'bpmn:BoundaryEvent')
) {
newElement.host = target.host;
}
newElement.di = {};
// fill and stroke will be set to DI
copyProperties(oldBusinessObject.di, newElement.di, [
'fill',
'stroke'
]);
newElement = replace.replaceElement(element, newElement, hints);
if (hints.select !== false) {
selection.select(newElement);
}
return newElement;
}
this.replaceElement = replaceElement;
}
BpmnReplace.$inject = [
'bpmnFactory',
'elementFactory',
'moddleCopy',
'modeling',
'replace',
'selection',
'moddle',
];
function isSubProcess(bo) {
return is(bo, 'bpmn:SubProcess');
}
function hasEventDefinition(element, type) {
var bo = getBusinessObject(element);
return type && bo.get('eventDefinitions').some(function(definition) {
return is(definition, type);
});
}
/**
- Compute intersection between two arrays.
*/
function intersection(a1, a2) {
return a1.filter(function(el) {
return a2.indexOf(el) !== -1;
});
}
but when i print element tepmlates only
ƒ ElementTemplates() {
this._templates = {};
/**
* Sets the known element templates.
*
* @param {Array<TemplateDescriptor>} descriptors
*
* @return {ElementTemplates}…
getting this function not getting set and getall function is there any way to import elementTemplates and call function get and set and getAlltemplates
please help me hope u r understand my question