Liferay.Loader.define("portal-workflow-kaleo-designer-web@5.0.115/designer/js/definition-builder/diagram-builder/util/populateAssignmentsData",["module","exports","require","../../util/fetchUtil","../components/sidebar/sections/assignments/utils"],(function(e,t,s){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=s("../../util/fetchUtil"),a=s("../components/sidebar/sections/assignments/utils");function ownKeys(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),s.push.apply(s,n)}return s}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(s),!0).forEach((function(t){_defineProperty(e,t,s[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):ownKeys(Object(s)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))}))}return e}function _defineProperty(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}const verifySectionsData=(e,t,s,n,a)=>{if(t.length){a.data.assignments.sectionsData=t;const s=e.findIndex((e=>e.id===a.id));e[s]=a,n([...e])}else delete a.data.assignments.sectionsData,a.data.assignments.emailAddress?(delete a.data.assignments.emailAddress,s((e=>_objectSpread(_objectSpread({},e),{},{errorMessage:Liferay.Language.get("please-enter-a-valid-email-address"),errorType:"assignment"})))):a.data.assignments.screenName?(delete a.data.assignments.screenName,s((e=>_objectSpread(_objectSpread({},e),{},{errorMessage:Liferay.Language.get("please-enter-a-valid-screen-name"),errorType:"assignment"})))):a.data.assignments.userId&&(delete a.data.assignments.userId,s((e=>_objectSpread(_objectSpread({},e),{},{errorMessage:Liferay.Language.get("please-enter-a-valid-user-id"),errorType:"assignment"}))))};var _default=(e,t,s,r)=>{const i=t.filter((e=>"task"===e.type));for(let o=0;o<i.length;o++){const d=i[o],l=(0,a.getAssignmentType)(d.data.assignments);if("roleId"===l)(0,n.retrieveRoleById)(d.data.assignments.roleId).then((e=>e.json())).then((e=>{d.data.assignments.sectionsData={id:e.id,name:e.name,roleType:e.roleType};const n=t.findIndex((e=>e.id===d.id));t[n]=d,s([...t])}));else if("roleType"===l)Promise.all([(0,n.retrieveRoles)(),(0,n.retrieveAccountRoles)(e)]).then((([e,n])=>Promise.all([e.json(),n.json()]).then((([e,n])=>{const a=e.items.concat(n.items);d.data.assignments.roleKey.forEach((e=>{const t=a.find((t=>t.externalReferenceCode===e||t.displayName===e));d.data.assignments.roleName||(d.data.assignments.roleName=[]),d.data.assignments.roleName.push(null==t?void 0:t.name)}));const r=t.findIndex((e=>e.id===d.id));t[r]=d,s([...t])}))));else if("user"===l){const e=[];let a=Object.keys(d.data.assignments)[1];const i=Object.values(d.data.assignments)[1];"screenName"===a?a="alternateName":"userId"===a&&(a=a.toLocaleLowerCase().replace("user","")),(0,n.retrieveUsersBy)(a,i).then((e=>e.json())).then((({items:t})=>{t.forEach(((t,s)=>{e.push({emailAddress:t.emailAddress,identifier:"".concat(Date.now(),"-").concat(s),name:t.name,screenName:t.alternateName,userId:t.id})}))})).then((()=>verifySectionsData(t,e,r,s,d)))}}};t.default=_default}}));
//# sourceMappingURL=populateAssignmentsData.js.map