Liferay.Loader.define("portal-workflow-kaleo-designer-web@5.0.92/designer/js/definition-builder/source-builder/deserializeUtil",["module","exports","require","portal-workflow-kaleo-designer-web$react-flow-renderer","../constants","../util/utils","./constants","./utils","./xmlDefinition"],(function(e,t,i){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=DeserializeUtil;var a=i("portal-workflow-kaleo-designer-web$react-flow-renderer"),n=i("../constants"),r=i("../util/utils"),s=i("./constants"),o=i("./utils"),l=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(i("./xmlDefinition"));function DeserializeUtil(e){this.definition=new l.default({value:e})}DeserializeUtil.prototype={getElements(){const e=[],t=[],i=[];return this.definition.forEachField(((e,t)=>{t.results.forEach((e=>{i.push(e.name)}))})),this.definition.forEachField(((l,d)=>{d.results.forEach((d=>{var u,c,f,p;(null===(u=d.actions)||void 0===u?void 0:u.length)&&(d.notifications=d.actions.filter((e=>{if(e.template)return e})),d.actions=d.actions.filter((e=>{if(e.script||""===e.script)return e})));const g={};let m=l;d.initial&&(m="start");const h=d.metadata&&JSON.parse(d.metadata);((null==h?void 0:h.terminal)||"state"===m&&!d.transitions&&!h)&&(m="end"),g.x=(null==h?void 0:h.xy[0])||Math.floor(800*Math.random()),g.y=(null==h?void 0:h.xy[1])||Math.floor(500*Math.random());let v={};var w;Array.isArray(d.labels)?null===(w=d.labels)||void 0===w||w.map((e=>{Object.entries(e).map((([e,t])=>{v[e]=(0,r.replaceTabSpaces)((0,r.removeNewLine)(t))}))})):v={[n.defaultLanguageId]:d.name};const b={description:d.description,label:v,script:d.script};var y;("condition"===m&&(b.scriptLanguage=d.scriptLanguage||s.DEFAULT_LANGUAGE),"task"===m)&&(null===(y=d.assignments)||void 0===y||y.forEach((e=>{const t=e["role-type"];null==t||t.forEach(((e,i)=>{"depot"===e&&(t[i]="asset library")}))})),d.assignments&&(b.assignments=(0,o.parseAssignments)(d)),d.taskTimers&&(b.taskTimers=(0,o.parseTimers)(d)),b.scriptLanguage=d.scriptLanguage||s.DEFAULT_LANGUAGE);let E;if(b.actions=(null===(c=d.actions)||void 0===c?void 0:c.length)&&(0,o.parseActions)(d),b.notifications=(null===(f=d.notifications)||void 0===f?void 0:f.length)&&(0,o.parseNotifications)(d),null===(p=d.notifications)||void 0===p||p.forEach((e=>{const t=e["role-type"];null==t||t.forEach(((e,i)=>{"depot"===e&&(t[i]="asset library")}))})),d.id)E=d.id;else{if(!d.name)return;E=d.name}e.push({data:b,id:E,position:g,type:m}),d.transitions&&d.transitions.forEach((s=>{let o={};var l;Array.isArray(s.labels)?null===(l=s.labels)||void 0===l||l.map((e=>{Object.entries(e).map((([e,t])=>{o[e]=(0,r.replaceTabSpaces)((0,r.removeNewLine)(t))}))})):o={[n.defaultLanguageId]:s.name};let d;if(s.id)d=s.id;else{if(!s.name)return;d=s.name}t.includes(d)||i.includes(d)?d="".concat(E,"_").concat(d,"_").concat(s.target):t.push(d);const u=e.find((e=>(0,a.isEdge)(e)&&e.source===E&&e.data.defaultEdge));e.push({arrowHeadType:"arrowclosed",data:{defaultEdge:"true"===(null==s?void 0:s.default)||!u,label:o},id:d,source:E,target:s.target,type:"transition"})}))}))})),e},getMetadata(){return this.definition.getDefinitionMetadata()},updateXMLDefinition(e){this.definition=new l.default({value:e})}}}}));
//# sourceMappingURL=deserializeUtil.js.map