From 11d40926aa43fc91752148d869c99f3f51356745 Mon Sep 17 00:00:00 2001 From: guozhiqi Date: Mon, 30 Jan 2023 09:01:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=EF=BC=8C=E4=BE=9D=E6=8D=AE=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=90=84=E4=B8=AA=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../replication/adjust/FormMetadataCloneAdjustStrategy.java | 4 ++++ .../adjust/WebCommandsMetadataCloneAdjustStrategy.java | 4 ++++ .../adjust/WebComponentMetadataCloneAdjustStrategy.java | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/FormMetadataCloneAdjustStrategy.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/FormMetadataCloneAdjustStrategy.java index c7ff6b1b..94453c5e 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/FormMetadataCloneAdjustStrategy.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/FormMetadataCloneAdjustStrategy.java @@ -1,5 +1,6 @@ package com.inspur.edp.web.formmetadata.replication.adjust; +import com.inspur.edp.formserver.viewmodel.GspViewModel; import com.inspur.edp.lcm.metadata.api.IMetadataContent; import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; import com.inspur.edp.web.common.utility.CommonUtility; @@ -13,6 +14,9 @@ import com.inspur.edp.web.formmetadata.metadata.formdom.FormDOM; class FormMetadataCloneAdjustStrategy implements GspMetadataCloneAdjustStrategy { @Override public void adjust(GspMetadata replicateMetadata, IMetadataContent targetMetadataContent) { + if (!(targetMetadataContent instanceof FormMetadataContent)) { + return; + } FormMetadataContent replicateFormMetadataContent = (FormMetadataContent) targetMetadataContent; replicateFormMetadataContent.setId(replicateMetadata.getHeader().getId()); diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebCommandsMetadataCloneAdjustStrategy.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebCommandsMetadataCloneAdjustStrategy.java index 7af60d37..9d87f197 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebCommandsMetadataCloneAdjustStrategy.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebCommandsMetadataCloneAdjustStrategy.java @@ -9,11 +9,15 @@ import java.util.regex.Pattern; /** * web 命令元数据拷贝 + * * @author guozhiqi */ class WebCommandsMetadataCloneAdjustStrategy implements GspMetadataCloneAdjustStrategy { @Override public void adjust(GspMetadata replicateMetadata, IMetadataContent replicateMetadataContent) { + if (!(replicateMetadataContent instanceof WebCommandsMetadata)) { + return; + } WebCommandsMetadata replicateWebCommandMetadataContent = (WebCommandsMetadata) replicateMetadataContent; replicateWebCommandMetadataContent.setId(replicateMetadata.getHeader().getId()); replicateWebCommandMetadataContent.setCode(replicateMetadata.getHeader().getCode()); diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebComponentMetadataCloneAdjustStrategy.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebComponentMetadataCloneAdjustStrategy.java index c2dd0f1c..d37083e9 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebComponentMetadataCloneAdjustStrategy.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/adjust/WebComponentMetadataCloneAdjustStrategy.java @@ -8,11 +8,15 @@ import java.util.regex.Pattern; /** * web 组件元数据 参数调整 + * * @author guozhiqi */ class WebComponentMetadataCloneAdjustStrategy implements GspMetadataCloneAdjustStrategy { @Override public void adjust(GspMetadata replicateMetadata, IMetadataContent replicateMetadataContent) { + if (!(replicateMetadataContent instanceof WebComponentMetadata)) { + return; + } WebComponentMetadata replicateWebComponentMetadataContent = (WebComponentMetadata) replicateMetadataContent; replicateWebComponentMetadataContent.setId(replicateMetadata.getHeader().getId()); replicateWebComponentMetadataContent.setCode(replicateMetadata.getHeader().getCode()); -- Gitee From 6a19132d9b031b764c0d0b17743d73977907a4c2 Mon Sep 17 00:00:00 2001 From: guozhiqi Date: Mon, 30 Jan 2023 13:52:10 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=EF=BC=8C=E4=BE=9D=E6=8D=AE=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=90=84=E4=B8=AA=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocalServerVersionManager.java | 2 +- .../manager/ScriptCacheVersionManager.java | 40 +++++++++---------- .../service/ScriptCacheServiceImpl.java | 20 +++++----- .../edp/web/common/utility/CommonUtility.java | 9 ----- .../replication/FormMetadataReplicator.java | 2 +- 5 files changed, 31 insertions(+), 42 deletions(-) diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/localserver/LocalServerVersionManager.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/localserver/LocalServerVersionManager.java index 657a7d8c..395e503f 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/localserver/LocalServerVersionManager.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/localserver/LocalServerVersionManager.java @@ -122,7 +122,7 @@ public class LocalServerVersionManager { localServerProjectVersion.setProjectName(formProjectCache.getProjectName()); localServerProjectVersion.setProjectRelativePath(formProjectCache.getProjectRelativePath()); // 设定版本为新的随机数值 - localServerProjectVersion.setVersion(this.scriptCacheVersionManagerInstance.generageRandomVersion()); + localServerProjectVersion.setVersion(this.scriptCacheVersionManagerInstance.generateRandomVersion()); needReSaveFile = true; } // 获取当前工程本地存储的工程版本 diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java index 0413da03..c228df44 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/manager/ScriptCacheVersionManager.java @@ -1,7 +1,7 @@ package com.inspur.edp.web.jitruntimebuild.scriptcache.manager; import com.inspur.edp.web.common.io.FileUtility; -import com.inspur.edp.web.common.utility.CommonUtility; +import com.inspur.edp.web.common.utility.RandomUtility; import com.inspur.edp.web.common.utility.StringUtility; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormProjectCache; import com.inspur.edp.web.jitruntimebuild.scriptcache.api.entity.FormScriptCache; @@ -50,8 +50,8 @@ public class ScriptCacheVersionManager { * * @return */ - public String generageRandomVersion() { - return CommonUtility.generateRandomId(); + public String generateRandomVersion() { + return RandomUtility.newGuid(); } @@ -63,7 +63,7 @@ public class ScriptCacheVersionManager { public void saveFormProjectCache(FormProjectCache formProjectCache) { if (StringUtility.isNullOrEmpty(formProjectCache.getId())) { - formProjectCache.setId(CommonUtility.generateRandomId()); + formProjectCache.setId(RandomUtility.newGuid()); } FormProjectCacheEntity projectCacheEntity = FormProjectCacheEntity.convertFrom(formProjectCache); this.formProjectCacheManager.save(projectCacheEntity); @@ -75,10 +75,9 @@ public class ScriptCacheVersionManager { * @param formProjectCache 工程脚本缓存 */ public void updateFormProjectCache(FormProjectCache formProjectCache) { - - if (StringUtility.isNullOrEmpty(formProjectCache.getId())) { - formProjectCache.setId(CommonUtility.generateRandomId()); - } + StringUtility.executeIfPresent(formProjectCache.getId(), StringUtility::isNullOrEmpty, (param) -> { + formProjectCache.setId(RandomUtility.newGuid()); + }); FormProjectCacheEntity projectCacheEntity = FormProjectCacheEntity.convertFrom(formProjectCache); this.formProjectCacheManager.save(projectCacheEntity); } @@ -89,10 +88,10 @@ public class ScriptCacheVersionManager { * @param formScriptCache 表单脚本缓存 */ public void saveFormScriptCache(FormScriptCache formScriptCache) { + StringUtility.executeIfPresent(formScriptCache.getId(), StringUtility::isNullOrEmpty, (item) -> { + formScriptCache.setId(RandomUtility.newGuid()); + }); - if (StringUtility.isNullOrEmpty(formScriptCache.getId())) { - formScriptCache.setId(CommonUtility.generateRandomId()); - } FormScriptCacheEntity scriptCacheEntity = FormScriptCacheEntity.convertFrom(formScriptCache); this.formScriptCacheManager.save(scriptCacheEntity); } @@ -103,10 +102,9 @@ public class ScriptCacheVersionManager { * @param formScriptCache 表单脚本缓存 */ public void updateFormScriptCache(FormScriptCache formScriptCache) { - - if (StringUtility.isNullOrEmpty(formScriptCache.getId())) { - formScriptCache.setId(CommonUtility.generateRandomId()); - } + StringUtility.executeIfPresent(formScriptCache.getId(), StringUtility::isNullOrEmpty, (item) -> { + formScriptCache.setId(RandomUtility.newGuid()); + }); FormScriptCacheEntity scriptCacheEntity = FormScriptCacheEntity.convertFrom(formScriptCache); this.formScriptCacheManager.update(scriptCacheEntity); } @@ -118,9 +116,9 @@ public class ScriptCacheVersionManager { * @param formScriptCacheContent 表单脚本缓存内容 */ public void saveFormScriptCacheContent(FormScriptCacheContent formScriptCacheContent) { - if (StringUtility.isNullOrEmpty(formScriptCacheContent.getId())) { - formScriptCacheContent.setId(CommonUtility.generateRandomId()); - } + StringUtility.executeIfPresent(formScriptCacheContent.getId(), StringUtility::isNullOrEmpty, (item) -> { + formScriptCacheContent.setId(RandomUtility.newGuid()); + }); FormScriptCacheContentEntity contentEntity = FormScriptCacheContentEntity.convertFrom(formScriptCacheContent); this.formScriptCacheContentManager.save(contentEntity); @@ -132,9 +130,9 @@ public class ScriptCacheVersionManager { * @param formScriptCacheContent 表单脚本缓存内容 */ public void updateFormScriptCacheContent(FormScriptCacheContent formScriptCacheContent) { - if (StringUtility.isNullOrEmpty(formScriptCacheContent.getId())) { - formScriptCacheContent.setId(CommonUtility.generateRandomId()); - } + StringUtility.executeIfPresent(formScriptCacheContent.getId(), StringUtility::isNullOrEmpty, (item) -> { + formScriptCacheContent.setId(RandomUtility.newGuid()); + }); FormScriptCacheContentEntity contentEntity = FormScriptCacheContentEntity.convertFrom(formScriptCacheContent); this.formScriptCacheContentManager.update(contentEntity); diff --git a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/service/ScriptCacheServiceImpl.java b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/service/ScriptCacheServiceImpl.java index 7a3d39f3..0dd72ac1 100644 --- a/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/service/ScriptCacheServiceImpl.java +++ b/runtime-scriptcache/src/main/java/com/inspur/edp/web/jitruntimebuild/scriptcache/service/ScriptCacheServiceImpl.java @@ -186,8 +186,8 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { // 构造对应的表单缓存脚本文件内容 FormScriptCacheContent scriptCacheContent = this.createFormScriptCacheContent(fileContent, formScriptVersion, formScriptContentId); if (isNewScriptCache) { - formScriptContentId = CommonUtility.generateRandomId(); - formScriptVersion = this.scriptCacheVersionManager.generageRandomVersion(); + formScriptContentId = RandomUtility.newGuid(); + formScriptVersion = this.scriptCacheVersionManager.generateRandomVersion(); formScriptCache = this.createFormScriptCache(file.getName(), request.getFormCode(), relativePath, metaDataId, formProjectCache, formScriptContentId, formScriptVersion); scriptCacheContent.setId(formScriptContentId); @@ -196,7 +196,7 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { this.scriptCacheVersionManager.saveFormScriptCache(formScriptCache); this.scriptCacheVersionManager.saveFormScriptCacheContent(scriptCacheContent); - formProjectCache.setVersion(this.scriptCacheVersionManager.generageRandomVersion()); + formProjectCache.setVersion(this.scriptCacheVersionManager.generateRandomVersion()); formProjectCache.setLastModifyTime(CommonUtility.getCurrentDate()); this.scriptCacheVersionManager.updateFormProjectCache(formProjectCache); } else { @@ -206,7 +206,7 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { // 从数据库表读取脚本文件内容项 FormScriptCacheContent formScriptCacheContent = this.scriptCacheVersionManager.getFormScriptCacheContentById(formScriptContentId); if (formScriptCacheContent == null) { - formScriptVersion = this.scriptCacheVersionManager.generageRandomVersion(); + formScriptVersion = this.scriptCacheVersionManager.generateRandomVersion(); scriptCacheContent.setId(formScriptContentId); formScriptCache.setVersion(formScriptVersion); @@ -216,13 +216,13 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { this.scriptCacheVersionManager.updateFormScriptCache(formScriptCache); this.scriptCacheVersionManager.saveFormScriptCacheContent(scriptCacheContent); - formProjectCache.setVersion(this.scriptCacheVersionManager.generageRandomVersion()); + formProjectCache.setVersion(this.scriptCacheVersionManager.generateRandomVersion()); formProjectCache.setLastModifyTime(CommonUtility.getCurrentDate()); this.scriptCacheVersionManager.updateFormProjectCache(formProjectCache); } else { boolean hasSameContent = EqualsUtility.getInstance().equalsWithoutOS(fileContent, formScriptCacheContent.getContent()); if (!hasSameContent) { - formScriptVersion = this.scriptCacheVersionManager.generageRandomVersion(); + formScriptVersion = this.scriptCacheVersionManager.generateRandomVersion(); scriptCacheContent.setId(formScriptCacheContent.getId()); scriptCacheContent.setLastModifyTime(CommonUtility.getCurrentDate()); scriptCacheContent.setContent(fileContent); @@ -235,7 +235,7 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { // 保存表单脚本缓存内容 this.scriptCacheVersionManager.updateFormScriptCacheContent(scriptCacheContent); - formProjectCache.setVersion(this.scriptCacheVersionManager.generageRandomVersion()); + formProjectCache.setVersion(this.scriptCacheVersionManager.generateRandomVersion()); formProjectCache.setLastModifyTime(CommonUtility.getCurrentDate()); this.scriptCacheVersionManager.updateFormProjectCache(formProjectCache); } @@ -261,11 +261,11 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { */ private FormProjectCache createFormProjectCache(String projectName, String projectCode, String projectRelativePath) { FormProjectCache formProjectCache = new FormProjectCache(); - formProjectCache.setId(CommonUtility.generateRandomId()); + formProjectCache.setId(RandomUtility.newGuid()); formProjectCache.setProjectName(projectName); formProjectCache.setProjectCode(projectCode); formProjectCache.setProjectRelativePath(projectRelativePath); - formProjectCache.setVersion(this.scriptCacheVersionManager.generageRandomVersion()); + formProjectCache.setVersion(this.scriptCacheVersionManager.generateRandomVersion()); formProjectCache.setCreateDate(CommonUtility.getCurrentDate()); formProjectCache.setLastModifyTime(CommonUtility.getCurrentDate()); return formProjectCache; @@ -300,7 +300,7 @@ public class ScriptCacheServiceImpl implements ScriptCacheService { private FormScriptCache createFormScriptCache(String scriptFileName, String scriptCode, String scriptRelativePath, String metaDataId, FormProjectCache formProjectCache, String formScriptCacheContentId, String formScriptVersion) { FormScriptCache formScriptCache = new FormScriptCache(); - formScriptCache.setId(CommonUtility.generateRandomId()); + formScriptCache.setId(RandomUtility.newGuid()); formScriptCache.setFormMetadataId(metaDataId); formScriptCache.setProjectVersionId(formProjectCache.getId()); diff --git a/web-common/src/main/java/com/inspur/edp/web/common/utility/CommonUtility.java b/web-common/src/main/java/com/inspur/edp/web/common/utility/CommonUtility.java index f295c32f..0f80a68b 100644 --- a/web-common/src/main/java/com/inspur/edp/web/common/utility/CommonUtility.java +++ b/web-common/src/main/java/com/inspur/edp/web/common/utility/CommonUtility.java @@ -37,15 +37,6 @@ public class CommonUtility { return sdf.format(getCurrentDate()); } - /** - * 生成随机化id - * - * @return - */ - public static String generateRandomId() { - return UUID.randomUUID().toString(); - } - /** * 获取程序启动时间 * diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java index 8a80b95a..e6ffd011 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java @@ -63,7 +63,7 @@ public class FormMetadataReplicator { * * @param metadataReplicationContext 元数据复制上下文参数 */ - private void executeReplicate(MetadataReplicationContext metadataReplicationContext) { + private void executeReplicate(final MetadataReplicationContext metadataReplicationContext) { GspMetadata sourceFormMetadata = metadataReplicationContext.getSourceMetadata(); MetadataDto targetMetadataDescription = metadataReplicationContext.getTargetMetadataDescription(); -- Gitee From 047559ccf63c5d19595fa3d2dd1935d8b6ab30d5 Mon Sep 17 00:00:00 2001 From: guozhiqi Date: Mon, 30 Jan 2023 14:09:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E9=80=82=E5=BA=94=E5=B9=B6=E5=8F=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspur/edp/web/common/utility/EqualsUtility.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web-common/src/main/java/com/inspur/edp/web/common/utility/EqualsUtility.java b/web-common/src/main/java/com/inspur/edp/web/common/utility/EqualsUtility.java index d617a69b..c91940df 100644 --- a/web-common/src/main/java/com/inspur/edp/web/common/utility/EqualsUtility.java +++ b/web-common/src/main/java/com/inspur/edp/web/common/utility/EqualsUtility.java @@ -22,15 +22,17 @@ public class EqualsUtility { /** * 增加volatile 避免由于指令重排序导致获取到的实例不完整 */ - private static volatile EqualsUtility instance; + private static volatile EqualsUtility _instance; public static EqualsUtility getInstance() { - if (instance == null) { + if (_instance == null) { synchronized (_lock) { - instance = new EqualsUtility(); + if (_instance == null) { + _instance = new EqualsUtility(); + } } } - return instance; + return _instance; } /** -- Gitee From cdeb2fbae500e1e62324e2d41e6b33a5653e1f82 Mon Sep 17 00:00:00 2001 From: guozhiqi Date: Mon, 30 Jan 2023 14:14:28 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0uuid=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edp/web/common/utility/RandomUtilityTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 web-common/src/test/java/com/inspur/edp/web/common/utility/RandomUtilityTest.java diff --git a/web-common/src/test/java/com/inspur/edp/web/common/utility/RandomUtilityTest.java b/web-common/src/test/java/com/inspur/edp/web/common/utility/RandomUtilityTest.java new file mode 100644 index 00000000..c860cc0d --- /dev/null +++ b/web-common/src/test/java/com/inspur/edp/web/common/utility/RandomUtilityTest.java @@ -0,0 +1,15 @@ +package com.inspur.edp.web.common.utility; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class RandomUtilityTest { + @Test + public void testUUID() { + String result = RandomUtility.newGuid(); + assertEquals(result.length(),36); + System.out.println(result); + System.out.println(result.length()); + } +} \ No newline at end of file -- Gitee From b969b47b1091e116e38419fa0a811eb00d7b11b5 Mon Sep 17 00:00:00 2001 From: guozhiqi Date: Mon, 30 Jan 2023 14:49:01 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=A1=A8=E5=8D=95=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=83=E6=95=B0=E6=8D=AE=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E5=A4=8D=E5=88=B6=E5=89=8Dvalidate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edp/web/common/entity/ResultCode.java | 16 ++++++++- .../web/common/metadata/MetadataUtility.java | 10 ++++++ .../manager/FormMetadataManager.java | 5 +-- .../replication/FormMetadataReplicator.java | 33 ++++++++++++------- .../MetaDataReplicateBeforeValidator.java | 30 +++++++++++++++++ .../service/FormMetataService.java | 5 +-- .../FormMetadataWebServiceImpl.java | 3 +- 7 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/MetaDataReplicateBeforeValidator.java diff --git a/web-common/src/main/java/com/inspur/edp/web/common/entity/ResultCode.java b/web-common/src/main/java/com/inspur/edp/web/common/entity/ResultCode.java index 96146aaf..ac3b9f99 100644 --- a/web-common/src/main/java/com/inspur/edp/web/common/entity/ResultCode.java +++ b/web-common/src/main/java/com/inspur/edp/web/common/entity/ResultCode.java @@ -12,6 +12,8 @@ public class ResultCode { private static final int SuccessCode = 1; private static final int FailureCode = 0; + private static final int InfoCode = 2; + /** * 获取成功编码 1 * 暴露此方法的目的是为了外部可以获取到对应的成功编码 @@ -34,13 +36,25 @@ public class ResultCode { /** * 不包含data参数 只有一个成功标识 - * @return + * * @param + * @return */ public static ResultMessage success() { return new ResultMessage<>(SuccessCode, ""); } + /** + * 不包含data参数 传递对应的info提示信息 + * + * @param message + * @param + * @return + */ + public static ResultMessage info(String message) { + return new ResultMessage<>(InfoCode, message); + } + public static ResultMessage success(T data) { return new ResultMessage<>(SuccessCode, "", data); } diff --git a/web-common/src/main/java/com/inspur/edp/web/common/metadata/MetadataUtility.java b/web-common/src/main/java/com/inspur/edp/web/common/metadata/MetadataUtility.java index fd14eebd..cf94d543 100644 --- a/web-common/src/main/java/com/inspur/edp/web/common/metadata/MetadataUtility.java +++ b/web-common/src/main/java/com/inspur/edp/web/common/metadata/MetadataUtility.java @@ -151,6 +151,16 @@ public final class MetadataUtility { return this.getMetadataService().isMetadataExistInProject(spacePath, metadataId); } + /** + * 判断指定工程路径下指定的元数据文件是否存在 + * @param metaDataPath 对应的元数据所在工程路径 + * @param fileName 对应的元数据文件名称 + * @return + */ + public boolean isMetaDataExistsWithMetadataPathAndFileName(String metaDataPath, String fileName) { + return this.getMetadataService().isMetadataExist(metaDataPath, fileName); + } + /** * 根据元数据id获取元数据信息 * diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/manager/FormMetadataManager.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/manager/FormMetadataManager.java index 6d903022..7c538218 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/manager/FormMetadataManager.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/manager/FormMetadataManager.java @@ -1,5 +1,6 @@ package com.inspur.edp.web.formmetadata.manager; +import com.inspur.edp.web.common.entity.ResultMessage; import com.inspur.edp.web.formmetadata.service.FormMetataService; import io.iec.edp.caf.i18n.framework.api.language.EcpLanguage; @@ -46,8 +47,8 @@ public class FormMetadataManager { return FormMetataService.getAllLanguageList(); } - public final void replicateForm(String sourceMetadataId, String sourceMetadataRelativePath, String targetMetadataCode, String targetMetadataName, String targetProjectName) { - FormMetataService.replicateForm(sourceMetadataId, sourceMetadataRelativePath, targetMetadataCode, targetMetadataName, targetProjectName); + public final ResultMessage replicateForm(String sourceMetadataId, String sourceMetadataRelativePath, String targetMetadataCode, String targetMetadataName, String targetProjectName) { + return FormMetataService.replicateForm(sourceMetadataId, sourceMetadataRelativePath, targetMetadataCode, targetMetadataName, targetProjectName); } diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java index e6ffd011..93c18ef9 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/FormMetadataReplicator.java @@ -9,6 +9,8 @@ import com.inspur.edp.lcm.metadata.api.service.MetadataService; import com.inspur.edp.web.command.component.metadata.CmpMethodRefering; import com.inspur.edp.web.command.component.metadata.WebCommandsMetadata; import com.inspur.edp.web.common.GSPException; +import com.inspur.edp.web.common.entity.ResultCode; +import com.inspur.edp.web.common.entity.ResultMessage; import com.inspur.edp.web.common.io.FileUtility; import com.inspur.edp.web.common.logger.WebLogger; import com.inspur.edp.web.common.metadata.MetadataUtility; @@ -44,8 +46,8 @@ public class FormMetadataReplicator { * @param targetMetadataName 目标元数据名称 * @param targetProjectName 目标元数据所在工程名称 */ - public final void replicate(GspMetadata sourceFormMetadata, String sourceProjectName, - String targetMetadataCode, String targetMetadataName, String targetProjectName) { + public final ResultMessage replicate(GspMetadata sourceFormMetadata, String sourceProjectName, + String targetMetadataCode, String targetMetadataName, String targetProjectName) { // 初始化元数据复制上下文 MetadataReplicationContext metadataReplicationContext = MetadataReplicationContextService.create(sourceProjectName, sourceFormMetadata, targetMetadataCode, targetMetadataName, targetProjectName); @@ -53,7 +55,7 @@ public class FormMetadataReplicator { MetadataReplicationContextService.updateMetadataReplicationContext(metadataReplicationContext); // 依据复制上下文 执行表单复制 - executeReplicate(metadataReplicationContext); + return executeReplicate(metadataReplicationContext); } @@ -61,15 +63,22 @@ public class FormMetadataReplicator { * 复制表单元数据及关联的元数据 * 目前仅支持同一个BO下复制(同一工程、不同工程) * - * @param metadataReplicationContext 元数据复制上下文参数 + * @param context 元数据复制上下文参数 */ - private void executeReplicate(final MetadataReplicationContext metadataReplicationContext) { - GspMetadata sourceFormMetadata = metadataReplicationContext.getSourceMetadata(); + private ResultMessage executeReplicate(final MetadataReplicationContext context) { + GspMetadata sourceFormMetadata = context.getSourceMetadata(); - MetadataDto targetMetadataDescription = metadataReplicationContext.getTargetMetadataDescription(); + MetadataDto targetMetadataDescription = context.getTargetMetadataDescription(); // 复制表单元数据 - GspMetadata replicateFormMetadata = MetadataCloneManager.cloneMetadata(metadataReplicationContext); + GspMetadata replicateFormMetadata = MetadataCloneManager.cloneMetadata(context); + + //执行复制前参数必要验证 + MetaDataReplicateBeforeValidator beforeValidator = new MetaDataReplicateBeforeValidator(); + ResultMessage validateResult = beforeValidator.validate(replicateFormMetadata); + if (!validateResult.isSuccess()) { + return validateResult; + } // 元数据创建前处理 // 如果待保存元数据所在文件夹不存在,则创建文件夹 @@ -86,19 +95,21 @@ public class FormMetadataReplicator { FormDOM replicateFormDOM = FormMetadataContentService.getInstance().getFormContent(replicateFormMetadataContent); // 1. 拷贝VO元数据及关联元数据 - FormMetadataVoManager.copyFormMetadataVo(metadataReplicationContext, sourceFormMetadata, targetMetadataDescription, replicateFormDOM, IsDebug); + FormMetadataVoManager.copyFormMetadataVo(context, sourceFormMetadata, targetMetadataDescription, replicateFormDOM, IsDebug); // 2. 表单关联状态机(从表单中获取stateMachineId) - FormMetadataSmManager.copyFormMetadataStateMachine(metadataReplicationContext, sourceFormMetadata, targetMetadataDescription, replicateFormDOM, IsDebug); + FormMetadataSmManager.copyFormMetadataStateMachine(context, sourceFormMetadata, targetMetadataDescription, replicateFormDOM, IsDebug); // 3. 表单关联命令构件及服务构件 - copyFormMetadataCmd(metadataReplicationContext, sourceFormMetadata, targetMetadataDescription, replicateFormDOM); + copyFormMetadataCmd(context, sourceFormMetadata, targetMetadataDescription, replicateFormDOM); // 更新 Form Content FormMetadataContentService.getInstance().setFormContent(replicateFormMetadataContent, replicateFormDOM); // 前置条件:保存前,对应的元数据文件已存在 MetadataUtility.getInstance().saveMetadata(replicateFormMetadata); + + return ResultCode.success(); } private void copyFormMetadataCmd(MetadataReplicationContext metadataReplicationContext, GspMetadata sourceFormMetadata, MetadataDto targetMetadataDescription, FormDOM replicateFormDOM) { diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/MetaDataReplicateBeforeValidator.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/MetaDataReplicateBeforeValidator.java new file mode 100644 index 00000000..21c1299e --- /dev/null +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/replication/MetaDataReplicateBeforeValidator.java @@ -0,0 +1,30 @@ +package com.inspur.edp.web.formmetadata.replication; + +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.web.common.entity.ResultCode; +import com.inspur.edp.web.common.entity.ResultMessage; +import com.inspur.edp.web.common.metadata.MetadataUtility; + +/** + * 元数据拷贝前参数及必要条件验证 + * + * @author guozhiqi + */ +class MetaDataReplicateBeforeValidator { + /** + * 针对待复制目标元数据的校验 + * + * @param targetMetaData 目标元数据 + * @return + */ + public ResultMessage validate(GspMetadata targetMetaData) { + ResultMessage resultMessage = null; + // 判断目标元数据是否存在 + boolean isExists = MetadataUtility.getInstance().isMetaDataExistsWithMetadataPathAndFileName(targetMetaData.getRelativePath(), targetMetaData.getHeader().getFileName()); + if (isExists) { + resultMessage = ResultCode.info("目标元数据存在,无法进行复制。对应目标元数据名称:" + targetMetaData.getHeader().getFileName() + ",所属工程路径:" + targetMetaData.getRelativePath()); + return resultMessage; + } + return ResultCode.success(); + } +} diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/service/FormMetataService.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/service/FormMetataService.java index aa9a5f17..eb072320 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/service/FormMetataService.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/service/FormMetataService.java @@ -10,6 +10,7 @@ import com.inspur.edp.lcm.metadata.api.entity.MetadataHeader; import com.inspur.edp.lcm.metadata.api.exception.MetadataNotFoundException; import com.inspur.edp.lcm.metadata.api.service.MetadataService; import com.inspur.edp.web.common.GSPException; +import com.inspur.edp.web.common.entity.ResultMessage; import com.inspur.edp.web.common.io.FileUtility; import com.inspur.edp.web.common.logger.WebLogger; import com.inspur.edp.web.common.metadata.MetadataUtility; @@ -263,7 +264,7 @@ public class FormMetataService { return languageService.getAllLanguages(); } - public static void replicateForm(String sourceMetadataId, String sourceMetadataRelativePath, String targetMetadataCode, String targetMetadataName, String targetProjectName) { + public static ResultMessage replicateForm(String sourceMetadataId, String sourceMetadataRelativePath, String targetMetadataCode, String targetMetadataName, String targetProjectName) { if (StringUtility.isNullOrEmpty(sourceMetadataId) || StringUtility.isNullOrEmpty(sourceMetadataRelativePath)) { WebLogger.Instance.error("待复制表单元数据ID或路径为空。请检查前端请求参数是否正常。", FormMetataService.class.getName()); throw new GSPException("Web_Replicate", "待复制表单元数据ID或路径为空。请检查前端请求参数是否正常。"); @@ -285,6 +286,6 @@ public class FormMetataService { } FormMetadataReplicator formMetadataReplicator = new FormMetadataReplicator(); - formMetadataReplicator.replicate(sourceFormMetadata, sourceProjectName, targetMetadataCode, targetMetadataName, targetProjectName); + return formMetadataReplicator.replicate(sourceFormMetadata, sourceProjectName, targetMetadataCode, targetMetadataName, targetProjectName); } } diff --git a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/webservice/FormMetadataWebServiceImpl.java b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/webservice/FormMetadataWebServiceImpl.java index 380c0b25..52385c88 100644 --- a/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/webservice/FormMetadataWebServiceImpl.java +++ b/web-form-metadata/src/main/java/com/inspur/edp/web/formmetadata/webservice/FormMetadataWebServiceImpl.java @@ -82,8 +82,7 @@ public class FormMetadataWebServiceImpl implements FormMetadataWebService { */ @Override public ResultMessage replicateForm(ReplicateFormRequestBody replicateFormRequestBody) { - ResultMessage resultMessage = ResultCode.success(); - FormMetadataManager.getNewInstance().replicateForm(replicateFormRequestBody.getSourceMetadataId(), + ResultMessage resultMessage = FormMetadataManager.getNewInstance().replicateForm(replicateFormRequestBody.getSourceMetadataId(), replicateFormRequestBody.getSourceMetadataRelativePath(), replicateFormRequestBody.getTargetMetadataCode(), replicateFormRequestBody.getTargetMetadataName(), -- Gitee