From e5eef609cd605264fe7a23f94d71a8dd836c7e80 Mon Sep 17 00:00:00 2001 From: masumcse1 Date: Tue, 18 Jul 2023 02:23:44 +0600 Subject: [PATCH] fix #739 --- .../meveo/api/CustomEntityTemplateApi.java | 5 ++- .../org/meveo/api/module/MeveoModuleApi.java | 5 +++ .../api/module/MeveoModuleItemInstaller.java | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/meveo-api/src/main/java/org/meveo/api/CustomEntityTemplateApi.java b/meveo-api/src/main/java/org/meveo/api/CustomEntityTemplateApi.java index 06f4df2bd..529db5f1f 100644 --- a/meveo-api/src/main/java/org/meveo/api/CustomEntityTemplateApi.java +++ b/meveo-api/src/main/java/org/meveo/api/CustomEntityTemplateApi.java @@ -643,9 +643,8 @@ private CustomEntityTemplate fromDTO(CustomEntityTemplateDto dto, CustomEntityTe if(dto.getCrudEventListenerScript() != null) { var crudListenerScript = scriptInstanceService.findByCode(dto.getCrudEventListenerScript()); - cet.setCrudEventListenerScript(crudListenerScript); - if(crudListenerScript == null) { - throw new IllegalArgumentException("Script " + dto.getCrudEventListenerScript() + " does not exists"); + if(crudListenerScript != null) { + cet.setCrudEventListenerScript(crudListenerScript); } } diff --git a/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleApi.java b/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleApi.java index c89422b15..a6eb79f2f 100644 --- a/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleApi.java +++ b/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleApi.java @@ -1761,6 +1761,11 @@ public void applyChanges(MeveoModule module, Set installItem meveoModuleItemInstaller.uninstallItem(options, null, item); } + // update CET + for (var itemDto : meveoModuleItemInstaller.getSortedModuleItems(installItems)) { + meveoModuleItemInstaller.updateCetforCrudEventListenerScript(itemDto); + } + moduleCtx.end(); meveoModuleService.update(module); diff --git a/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleItemInstaller.java b/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleItemInstaller.java index 260fa8f68..b69d9476a 100644 --- a/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleItemInstaller.java +++ b/meveo-api/src/main/java/org/meveo/api/module/MeveoModuleItemInstaller.java @@ -818,6 +818,37 @@ private void addCftToModuleItem(CustomRelationshipTemplateDto dto, MeveoModule m } } } + + public void updateCetforCrudEventListenerScript (MeveoModuleItemDto moduleItemDto) throws BusinessException { + + if (moduleItemDto.getDtoClassName().equals(CustomEntityTemplateDto.class.getName())) { + CustomEntityTemplateDto cetDto =null; + if(moduleItemDto.getDtoData() instanceof CustomEntityTemplateDto){ + cetDto = (CustomEntityTemplateDto) moduleItemDto.getDtoData(); + } else { + try { + Class dtoClass = (Class) Class.forName(moduleItemDto.getDtoClassName()); + cetDto = (CustomEntityTemplateDto) JacksonUtil.convert(moduleItemDto.getDtoData(), dtoClass); + } catch (ClassNotFoundException e) { + log.error("Cannot find dto class", e); + throw new BusinessException("cannot find crusdScript class "+moduleItemDto.getDtoClassName()); + } + } + if (cetDto.getCrudEventListenerScript() != null) { + CustomEntityTemplate cet = customEntityTemplateService.findByCode(cetDto.getCode()); + ScriptInstance si = scriptInstanceService.findByCode(cetDto.getCrudEventListenerScript()); + if (si != null) { + cet.setCrudEventListenerScript(si); + customEntityTemplateService.update(cet); + } else { + throw new BusinessException("cannot find crusdScript "+cetDto.getTransientCrudEventListenerScript()+" of entity "+cetDto.getCode()); + } + } + + } + +} + } \ No newline at end of file