From 7a703e69d7566e0b9214e3e23da48cefe7423bc0 Mon Sep 17 00:00:00 2001 From: Q-Lee Date: Sat, 8 May 2021 17:45:59 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9Alcm-metadata-fra?= =?UTF-8?q?mework=E5=B7=A5=E7=A8=8B=E4=BB=A3=E7=A0=81=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../initializer/ExternalApiInitializer.java | 4 +- .../provider/ExternalApiMetadataBuilder.java | 18 +- model/externalapi/runtime-core/pom.xml | 6 + model/framework/common/pom.xml | 66 +- .../lcm/file/system/FileSystemServiceImp.java | 73 ++ .../system/monitor/FileAltMonitorFactory.java | 24 + .../system/monitor/FileAltMonitorImpl.java | 147 ++++ .../entity/AdvancedFunctionConfiguration.java | 24 + .../metadata/api/entity/DbConnectionInfo.java | 112 +++ .../metadata/api/entity/DebugEnvironment.java | 73 ++ .../api/entity/DeploymentContext.java | 38 + .../metadata/api/entity/ExtractContext.java | 9 + .../metadata/api/entity/MetadataRTFilter.java | 42 ++ .../api/entity/WorkspaceDataLocation.java | 32 + .../compiler/MetadataCompilerConfigData.java | 38 + .../MetadataCompilerConfiguration.java | 47 ++ .../api/entity/deployer/DeployConfigData.java | 38 + .../api/entity/deployer/DeploymentType.java | 46 ++ .../IndexServerConfiguration.java | 38 + .../metadata/api/service/FileAltMonitor.java | 24 + .../api/service/FileSystemService.java | 35 + .../api/service/MavenUtilsService.java | 42 ++ .../api/service/MetadataRTService.java | 99 +++ .../api/service/PackageGenerateService.java | 37 + .../api/service/ProjectExtendService.java | 62 ++ .../metadata/cache/MetadataCacheManager.java | 0 .../cache/MetadataDevCacheManager.java | 0 .../cache/MetadataDistCacheManager.java | 0 .../metadata/cache/MetadataRtDistCache.java | 0 .../lcm/metadata/cache/RtCacheHandler.java | 0 .../metadata/common/MetadataDtoConverter.java | 6 +- .../MetadataCompilerConfigLoader.java | 59 ++ .../compiler/MetadataCompilerHelper.java | 53 ++ .../common/config/LcmComConfiguration.java | 38 + .../common/context/RuntimeContext.java | 51 ++ .../common/deployer/DeploymentHelper.java | 57 ++ .../deployer/DeploymentTypeConfigLoader.java | 87 +++ .../common/extractor/ExtractConfigLoader.java | 67 ++ .../common/extractor/ExtractHelper.java | 53 ++ .../common/logging/MvnStreamConsumer.java | 57 ++ .../lcm/metadata/common/util/CommandUtil.java | 642 ++++++++++++++++ .../edp/lcm/metadata/common/util/DbUtil.java | 49 ++ .../lcm/metadata/common/util/EncryptUtil.java | 69 ++ .../lcm/metadata/common/util/Kernel32.java | 25 + .../edp/lcm/metadata/spi/ExtractAction.java | 27 + .../metadata/spi/IProjectCreateManager.java | 22 + .../lcm/metadata/spi/JitRuntimeAction.java | 20 + .../metadata/spi/MdExtendRuleSerializer.java | 29 + .../metadata/spi/MetadataCompileAction.java | 27 + .../metadata/spi/MetadataExtRuleService.java | 24 + .../lcm/metadata/spi/MetadataI18nService.java | 33 + model/framework/devtime-api/pom.xml | 15 +- .../api/exception/MetadataExceptionCode.java | 20 + model/framework/devtime-core/pom.xml | 71 +- .../core/PackageGenerateCoreService.java | 304 ++++++++ .../core/PackageGenerateServiceImp.java | 40 + .../core/ProjectExtendCoreService.java | 273 +++++++ .../core/ProjectExtendServiceImp.java | 55 ++ .../core/config/CoreServiceConfiguration.java | 55 ++ .../core/config/JitRuntimeConfigLoader.java | 66 ++ .../core/config/JitRuntimeHelper.java | 58 ++ .../core/config/ServiceConfiguration.java | 73 ++ .../metadata/core/thread/ProcessRunnable.java | 36 + .../extend/action/DeployActionImpl.java | 44 ++ .../extend/action/ExtractActionImpl.java | 110 +++ .../action/MetadataCompileActionImpl.java | 29 + .../edp/lcm/metadata/ref/MavenUtilsImp.java | 45 ++ .../edp/lcm/metadata/ref/MdpkgServiceImp.java | 181 +++++ .../metadata/ref/config/RefConfiguration.java | 44 ++ model/framework/devtime-webapi/pom.xml | 37 + .../main/java/webapi/FileSystemWebApi.java | 42 ++ .../java/webapi/GspProjectServiceWebApi.java | 78 ++ .../src/main/java/webapi/MdServiceWebApi.java | 378 ++++++++++ .../webapi/MetadataConfigServiceWebApi.java | 62 ++ .../webapi/MetadataPackageServiceWebApi.java | 77 ++ .../webapi/MetadataProjectServiceWebApi.java | 192 +++++ .../java/webapi/MetadataServiceWebApi.java | 508 +++++++++++++ .../webapi/ProjectDeployServiceWebApi.java | 54 ++ .../main/java/webapi/ProjectExtendWebApi.java | 67 ++ .../src/main/java/webapi/RepoRefWebApi.java | 246 +++++++ .../webapi/config/WebApiConfiguration.java | 115 +++ model/framework/entity/pom.xml | 27 + .../metadata/api/ConfigData/BaseConfig.java | 0 .../gspproject/ProjectCommonConfigData.java | 0 .../gspproject/ProjectConfiguration.java | 0 .../gspproject/ProjectCreateConfigData.java | 0 .../lcm/metadata/api/entity/GspProject.java | 0 .../lcm/metadata/api/entity/Metadata4Ref.java | 0 .../metadata/api/entity/Metadata4RefDto.java | 0 .../lcm/metadata/api/entity/MetadataDto.java | 0 .../metadata/api/entity/MetadataFilter.java | 0 .../api/entity/MetadataIndexItemDto.java | 0 .../metadata/api/entity/MetadataPackage.java | 0 .../api/entity/MetadataPackageHeader.java | 0 .../api/entity/MetadataPackageReference.java | 0 .../api/entity/MetadataPackageVersion.java | 0 .../metadata/api/entity/MetadataProject.java | 2 +- .../lcm/metadata/api/entity/MetadataType.java | 0 .../lcm/metadata/api/entity/ProcessMode.java | 0 .../metadata/api/entity/ProjectHeader.java | 0 .../metadata/api/entity/ServiceUnitInfo.java | 0 .../MetadataIndexRepoItemDto.java | 0 .../api/mvnEntity/MavenComponent.java | 0 .../api/mvnEntity/MavenComponents.java | 0 .../api/mvnEntity/MavenPackageRefs.java | 0 .../metadata/api/mvnEntity/MetadataRepo.java | 0 .../api/mvnEntity/PackageSourceDto.java | 0 model/framework/generator-api/pom.xml | 10 + .../edp/jittojava/context/JitContext.java | 14 +- model/framework/pom.xml | 122 ++- model/framework/runtime-api/pom.xml | 11 + .../serverapi/MetadataRTServerService.java | 161 ++++ model/framework/runtime-core/pom.xml | 29 + .../rtservice/MetadataRTServiceImp.java | 164 +++++ .../metadata/rtservice/MetadataRtUtils.java | 83 +++ .../MetadataRTServerServiceImpl.java | 693 ++++++++++++++++++ .../configuration/RestConfiguarion.java | 47 ++ .../event/MdPkgChangedEventBroker.java | 66 ++ .../event/MdPkgChangedEventManager.java | 76 ++ .../monitor/MdpkgAlterationMonitor.java | 105 +++ .../monitor/MdpkgListenerAdapter.java | 197 +++++ .../monitor/MonitorInitializer.java | 42 ++ .../persistent/MetadataPackageRepository.java | 107 +++ .../MetadataPackageRepositoryImp.java | 196 +++++ .../persistent/RepositoryFactory.java | 46 ++ .../util/MetadataServerManagerUitls.java | 77 ++ .../servermanager/util/MetadataUtils.java | 35 + model/framework/runtime-spi/pom.xml | 2 - .../metadata/spi/event/MdPkgChangedArgs.java | 8 + 129 files changed, 8281 insertions(+), 83 deletions(-) create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/FileSystemServiceImp.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorFactory.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorImpl.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/AdvancedFunctionConfiguration.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DbConnectionInfo.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DebugEnvironment.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DeploymentContext.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataRTFilter.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/WorkspaceDataLocation.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfigData.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfiguration.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeployConfigData.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeploymentType.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileAltMonitor.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileSystemService.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MavenUtilsService.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MetadataRTService.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/PackageGenerateService.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/ProjectExtendService.java rename model/framework/{devtime-core => common}/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java (100%) rename model/framework/{devtime-core => common}/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDevCacheManager.java (100%) rename model/framework/{devtime-core => common}/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDistCacheManager.java (100%) rename model/framework/{devtime-core => common}/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataRtDistCache.java (100%) rename model/framework/{devtime-core => common}/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java (100%) create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerConfigLoader.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerHelper.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/config/LcmComConfiguration.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/context/RuntimeContext.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentHelper.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentTypeConfigLoader.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractConfigLoader.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractHelper.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/DbUtil.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/Kernel32.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/ExtractAction.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/IProjectCreateManager.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/JitRuntimeAction.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MdExtendRuleSerializer.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataCompileAction.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataExtRuleService.java create mode 100644 model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataI18nService.java create mode 100644 model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateCoreService.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateServiceImp.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendServiceImp.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/CoreServiceConfiguration.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/ServiceConfiguration.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/thread/ProcessRunnable.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/DeployActionImpl.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/MetadataCompileActionImpl.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MavenUtilsImp.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java create mode 100644 model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/config/RefConfiguration.java create mode 100644 model/framework/devtime-webapi/pom.xml create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/FileSystemWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/GspProjectServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/MdServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/MetadataConfigServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/MetadataPackageServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/MetadataProjectServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/MetadataServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/ProjectDeployServiceWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/ProjectExtendWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/RepoRefWebApi.java create mode 100644 model/framework/devtime-webapi/src/main/java/webapi/config/WebApiConfiguration.java create mode 100644 model/framework/entity/pom.xml rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/BaseConfig.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCommonConfigData.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectConfiguration.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCreateConfigData.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/GspProject.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4Ref.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4RefDto.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataDto.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataFilter.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataIndexItemDto.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackage.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageHeader.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageReference.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageVersion.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataType.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProcessMode.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProjectHeader.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ServiceUnitInfo.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/MetadataIndexRepoItemDto.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponent.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponents.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenPackageRefs.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MetadataRepo.java (100%) rename model/framework/{common => entity}/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/PackageSourceDto.java (100%) create mode 100644 model/framework/runtime-api/src/main/java/com/inspur/edp/lcm/metadata/serverapi/MetadataRTServerService.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRtUtils.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/configuration/RestConfiguarion.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventBroker.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgAlterationMonitor.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MonitorInitializer.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepository.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/RepositoryFactory.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataServerManagerUitls.java create mode 100644 model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataUtils.java diff --git a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java index bd2c3d4..e2fac1e 100644 --- a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java +++ b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java @@ -15,8 +15,8 @@ */ package org.openatom.ubml.model.externalapi.devtime.core.initializer; -import java.util.UUID; import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import java.util.UUID; import org.openatom.ubml.model.externalapi.definition.entity.ExternalApi; import org.openatom.ubml.model.externalapi.definition.temp.lcm.MetadataContentManager; @@ -38,7 +38,7 @@ public class ExternalApiInitializer implements MetadataContentManager { eapi.setName(metadata.getHeader().getName()); eapi.setVersion("1.0"); eapi.getService().setId(UUID.randomUUID().toString()); - eapi.setBusinessObject(metadata.getHeader().getBizObjectId()); + eapi.setBusinessObject(metadata.getHeader().getBizobjectID()); //TODO:后续添加SU/APP/RouteURL信息 metadata.setContent(eapi); } diff --git a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java index 8e62abc..25a18a6 100644 --- a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java +++ b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java @@ -69,7 +69,7 @@ public class ExternalApiMetadataBuilder { if (metadataList != null && metadataList.size() > 0) { String metadataCode = eApi.getHeader().getCode(); boolean exist = metadataList.stream() - .anyMatch(x -> metadataCode.equalsIgnoreCase(x.getHeader().getCode())); + .anyMatch(x -> metadataCode.equalsIgnoreCase(x.getHeader().getCode())); if (exist) { metadataService.deleteMetadata(relativePath, eApi.getHeader().getCode() + EAPI_SUFFIX_NAME); } @@ -99,7 +99,7 @@ public class ExternalApiMetadataBuilder { eApi.setId(eapiMetadata.getHeader().getId()); eApi.setCode(eapiMetadata.getHeader().getCode()); eApi.setName(eapiMetadata.getHeader().getName()); - eApi.setBusinessObject(eapiMetadata.getHeader().getBizObjectId()); + eApi.setBusinessObject(eapiMetadata.getHeader().getBizobjectID()); //TODO:set app&su eApi.setApplication(null); eApi.setMicroServiceUnit(null); @@ -133,9 +133,9 @@ public class ExternalApiMetadataBuilder { models.add(model); } else { long count = - eapiContent.getModels().stream() - .filter(x -> x.getId().equalsIgnoreCase(model.getId())) - .count(); + eapiContent.getModels().stream() + .filter(x -> x.getId().equalsIgnoreCase(model.getId())) + .count(); if (count <= 0) { models.add(model); } @@ -156,7 +156,7 @@ public class ExternalApiMetadataBuilder { service.setId(UUID.randomUUID().toString()); service.setResourceId(vo.getHeader().getId()); service.setResourceType(getResourceType(resourceType)); - service.setResourceCode(((GspViewModel)vo.getContent()).getGeneratedConfigID()); + service.setResourceCode(((GspViewModel) vo.getContent()).getGeneratedConfigID()); service.setResourceName(vo.getHeader().getName()); service.setOperations(new ArrayList<>()); switch (resourceType) { @@ -179,11 +179,11 @@ public class ExternalApiMetadataBuilder { metadata.getHeader().setCode(vo.getHeader().getCode()); metadata.getHeader().setName(vo.getHeader().getName()); metadata.getHeader().setExtendable(vo.getHeader().isExtendable()); - if (StringUtils.isBlank(vo.getHeader().getBizObjectId())) { + if (StringUtils.isBlank(vo.getHeader().getBizobjectID())) { throw new RuntimeException( - String.format("VO元数据【%s(ID:%s)】的业务对象不能为空", vo.getHeader().getCode(), vo.getHeader().getId())); + String.format("VO元数据【%s(ID:%s)】的业务对象不能为空", vo.getHeader().getCode(), vo.getHeader().getId())); } - metadata.getHeader().setBizObjectId(vo.getHeader().getBizObjectId()); + metadata.getHeader().setBizobjectID(vo.getHeader().getBizobjectID()); metadata.getHeader().setType(Constants.EXTERNAL_API_METADATA_TYPE); metadata.getHeader().setFileName(vo.getHeader().getCode() + EAPI_SUFFIX_NAME); metadata.setRelativePath(getEapiRelativePath(path)); diff --git a/model/externalapi/runtime-core/pom.xml b/model/externalapi/runtime-core/pom.xml index b6844d1..a2df916 100644 --- a/model/externalapi/runtime-core/pom.xml +++ b/model/externalapi/runtime-core/pom.xml @@ -50,6 +50,12 @@ ubml-model-framework-common 0.9.0-SNAPSHOT compile + + + lcm-metadata-api + com.inspur.edp + + diff --git a/model/framework/common/pom.xml b/model/framework/common/pom.xml index 9b9df9a..bad6930 100644 --- a/model/framework/common/pom.xml +++ b/model/framework/common/pom.xml @@ -8,9 +8,7 @@ 0.9.0-SNAPSHOT 4.0.0 - ubml-model-framework-common ${project.version} - ubml-model-framework-common @@ -20,42 +18,68 @@ - org.openatom.ubml - ubml-model-common-definition - 0.9.0-SNAPSHOT - compile + com.alibaba + fastjson + - org.apache.maven - maven-model - 3.6.1 - compile + io.iec.edp + caf-boot-commons-environment io.iec.edp - caf-boot-commons-environment - 0.3.7-SNAPSHOT + caf-boot-commons-layeringcache + + + io.iec.edp + caf-boot-starter-context + com.inspur.edp - lcm-metadata-spi - 0.1.25 - compile + lcm-logging-service + + + com.inspur.edp + lcm-project-deployer-spi org.apache.maven maven-settings + + + com.inspur.edp + workspace-api + + + + org.openatom.ubml + ubml-model-common-definition + ${project.version} + + + org.openatom.ubml + ubml-model-framework-devtime-api + ${project.version} + + + + org.apache.maven + maven-model 3.6.1 + compile - io.iec.edp - caf-boot-commons-layeringcache - 0.3.2 + org.apache.maven.shared + maven-invoker + 3.0.1 + compile - com.inspur.edp - workspace-api - 0.1.1 + net.java.dev.jna + jna + 4.1.0 + compile diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/FileSystemServiceImp.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/FileSystemServiceImp.java new file mode 100644 index 0000000..d9efae9 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/FileSystemServiceImp.java @@ -0,0 +1,73 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.file.system; + +import com.inspur.edp.lcm.file.system.monitor.FileAltMonitorImpl; +import com.inspur.edp.lcm.metadata.api.entity.FileType; +import com.inspur.edp.lcm.metadata.api.service.FileAltMonitor; +import com.inspur.edp.lcm.metadata.api.service.FileSystemService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import io.iec.edp.caf.boot.context.CAFContext; +import io.iec.edp.caf.core.session.WebSession; +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; + +public class FileSystemServiceImp implements FileSystemService { + FileServiceImp fileServiceImp = new FileServiceImp(); + + @Override + public void showInExplorer(String path) throws IOException { + WebSession webSession = (WebSession) CAFContext.current.getCurrentSession(); + if (!webSession.getRemoteAddress().equals("127.0.0.1") && !webSession.getRemoteAddress().equals("0:0:0:0:0:0:0:1")) { + throw new RuntimeException("不支持访问远程路径。"); + } + String absolutePath = ManagerUtils.getAbsolutePath(path); + absolutePath = fileServiceImp.isFileExist(absolutePath) ? fileServiceImp.getDirectoryName(absolutePath) : absolutePath; + if (!fileServiceImp.isDirectoryExist(absolutePath)) { + throw new RuntimeException("路径不存在:" + path + "。"); + } + + File file = new File(absolutePath); + try { + System.setProperty("java.awt.headless", "false"); + Desktop.getDesktop().open(file); + } catch (Exception e) { + openDirectoryByShell(absolutePath); + } + } + + @Override + public FileAltMonitor createFileMonitor(String path, FileType type, FileAlterationListenerAdaptor adaptor) { + return new FileAltMonitorImpl(path, type, adaptor); + } + + private void openDirectoryByShell(String path) throws IOException { + if (System.getProperty("os.name").toLowerCase().contains("win")) { + String[] cmd = new String[5]; + cmd[0] = "cmd"; + cmd[1] = "/c"; + cmd[2] = "start"; + cmd[3] = " "; + cmd[4] = new File(path).getAbsolutePath(); + Runtime.getRuntime().exec(cmd); + } else { + throw new RuntimeException("仅支持windows系统"); + } + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorFactory.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorFactory.java new file mode 100644 index 0000000..e5f53fb --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorFactory.java @@ -0,0 +1,24 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.file.system.monitor; + +import org.apache.commons.io.monitor.FileAlterationMonitor; + +class FileAltMonitorFactory { + static FileAlterationMonitor create(Long interval) { + return new FileAlterationMonitor(interval); + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorImpl.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorImpl.java new file mode 100644 index 0000000..d271a63 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/file/system/monitor/FileAltMonitorImpl.java @@ -0,0 +1,147 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.file.system.monitor; + +import com.inspur.edp.lcm.metadata.api.entity.FileType; +import com.inspur.edp.lcm.metadata.api.service.FileAltMonitor; +import org.apache.commons.io.filefilter.FileFilterUtils; +import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; +import org.apache.commons.io.monitor.FileAlterationMonitor; +import org.apache.commons.io.monitor.FileAlterationObserver; + +public class FileAltMonitorImpl implements FileAltMonitor { + private String path; // 文件夹目录 + + private String fileSuffix; // 需要监听的文件名后缀 + + private long interval; // 监听间隔 + + private FileAlterationMonitor monitor; // 监视器 + + private static final long DEFAULT_INTERVAL = 5 * 1000; // 默认监听间隔10s + + private boolean running = false; + + private FileAlterationListenerAdaptor listener; // 事件处理类对象 + + public FileAltMonitorImpl(String path, String fileSuffix, FileAlterationListenerAdaptor listenerAdaptor) { + this(path, fileSuffix, DEFAULT_INTERVAL, listenerAdaptor); + } + + public FileAltMonitorImpl(String path, FileAlterationListenerAdaptor listenerAdaptor) { + this(path, DEFAULT_INTERVAL, listenerAdaptor); + } + + public FileAltMonitorImpl(String path, long interval, FileAlterationListenerAdaptor listenerAdaptor) { + this(path, "", interval, listenerAdaptor); + } + + public FileAltMonitorImpl(String path, String fileSuffix, long interval, + FileAlterationListenerAdaptor listenerAdaptor) { + this.path = path; + this.fileSuffix = fileSuffix; + this.interval = interval; + this.listener = listenerAdaptor; + init(); + } + + public FileAltMonitorImpl(String path, FileType fileType, FileAlterationListenerAdaptor listenerAdaptor) { + this(path, fileType, DEFAULT_INTERVAL, listenerAdaptor); + } + + public FileAltMonitorImpl(String path, FileType fileType, long interval, + FileAlterationListenerAdaptor listenerAdaptor) { + this(path, parseToString(fileType), interval, listenerAdaptor); + } + + private static String parseToString(FileType fileType) { + switch (fileType) { + case MDPKG: + return ".mdpkg"; + case JAR: + return ".jar"; + default: + return null; + } + } + + private void init() { + if (path == null || "".equals(path)) { + throw new IllegalStateException("Listen path must not be null"); + } + if (listener == null) { + throw new IllegalStateException("Listener must not be null"); + } + + // 设定观察者,监听文件 + FileAlterationObserver observer; + if (fileSuffix == null || "".equals(fileSuffix)) { + observer = new FileAlterationObserver(path); + } else { + observer = new FileAlterationObserver(path, + FileFilterUtils.suffixFileFilter(fileSuffix)); + } + + // 给观察者添加监听事件 + observer.addListener(listener); + + // FileAlterationMonitor本身实现了 Runnable,是单独的一个线程,按照设定的时间间隔运行,默认间隔是 10s + monitor = FileAltMonitorFactory.create(interval); + + monitor.addObserver(observer); + } + + /*** + * 开启监听 + */ + public void start() { + try { + monitor.start(); + running = true; + } catch (Exception e) { + throw new RuntimeException("monitor start error", e); + } + } + + public void stop() { + try { + monitor.stop(); + running = false; + } catch (Exception e) { + throw new RuntimeException("monitor stop error", e); + } + } + + public void checkAndNotify() { + if (running) { + for (FileAlterationObserver observer : this.monitor.getObservers()) { + observer.checkAndNotify(); + } + } + } + + public void setPath(String path) { + this.path = path; + } + + public void setFileSuffix(String fileSuffix) { + this.fileSuffix = fileSuffix; + } + + public void setAdaptor(FileAlterationListenerAdaptor listenerAdaptor) { + this.listener = listenerAdaptor; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/AdvancedFunctionConfiguration.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/AdvancedFunctionConfiguration.java new file mode 100644 index 0000000..bcc578a --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/AdvancedFunctionConfiguration.java @@ -0,0 +1,24 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity; + +import lombok.Data; + +@Data +public class AdvancedFunctionConfiguration { + private boolean maven; + private boolean menu; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DbConnectionInfo.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DbConnectionInfo.java new file mode 100644 index 0000000..01e52f0 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DbConnectionInfo.java @@ -0,0 +1,112 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity; + +import io.iec.edp.caf.commons.dataaccess.DbType; + +public class DbConnectionInfo { + private String dbServerIP; + private String dbPort; + private String dbName; + private String dbUserName; + private String dbPassword; + private DbType dbType; + + public String getDbServerIP() { + return dbServerIP; + } + + public void setDbServerIP(String dbServerIP) { + this.dbServerIP = dbServerIP; + } + + public String getDbPort() { + return dbPort; + } + + public void setDbPort(String dbPort) { + this.dbPort = dbPort; + } + + public String getDbName() { + return dbName; + } + + public void setDbName(String dbName) { + this.dbName = dbName; + } + + public String getDbUserName() { + return dbUserName; + } + + public void setDbUserName(String dbUserName) { + this.dbUserName = dbUserName; + } + + public String getDbPassword() { + return dbPassword; + } + + public void setDbPassword(String dbPassword) { + this.dbPassword = dbPassword; + } + + public DbType getDbType() { + return dbType; + } + + public void setDbType(DbType dbType) { + this.dbType = dbType; + } + + private String url; + + public String getUrl() { + if (url == null || url.length() <= 0) { + switch (dbType) { + case DM: + url = "jdbc:dm://" + getDbServerIP() + ":" + dbPort + "/DMSERVER?schema=" + dbName; + break; + case PgSQL: + url = "jdbc:postgresql://" + getDbServerIP() + ":" + dbPort + "/" + dbName; + break; + case Oracle: + url = "jdbc:oracle:thin:@//" + getDbServerIP() + ":" + dbPort + "/" + dbName; + break; + case SQLServer: + url = "jdbc:sqlserver://" + getDbServerIP() + "\\" + dbName + ":" + dbPort + ";database=" + dbName; + break; + case HighGo: + url = "jdbc:highgo://" + getDbServerIP() + ":" + dbPort + "/" + dbName; + break; + case MySQL: + url = "jdbc:mysql://" + getDbServerIP() + ":" + dbPort + "/" + dbName + "?characterEncoding=utf8&serverTimezone=UTC&useSSL=false"; + break; + case Oscar: + url = "jdbc:oscar://" + getDbServerIP() + ":" + dbPort + "/" + dbName; + break; + default: + throw new RuntimeException("数据库类型不正确"); + } + } + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DebugEnvironment.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DebugEnvironment.java new file mode 100644 index 0000000..c44e54b --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DebugEnvironment.java @@ -0,0 +1,73 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity; + +public class DebugEnvironment { + private String serverPath; + private String language; + private String deployPath; + private String deployConfigPath; + private DbConnectionInfo dbConnectionInfo; + private DbConnectionInfo centralDbConnectionInfo; + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getServerPath() { + return serverPath; + } + + public void setServerPath(String serverPath) { + this.serverPath = serverPath; + } + + public String getDeployPath() { + return deployPath; + } + + public void setDeployPath(String deployPath) { + this.deployPath = deployPath; + } + + public String getDeployConfigPath() { + return deployConfigPath; + } + + public void setDeployConfigPath(String deployConfigPath) { + this.deployConfigPath = deployConfigPath; + } + + public DbConnectionInfo getDbConnectionInfo() { + return dbConnectionInfo; + } + + public void setDbConnectionInfo(DbConnectionInfo dbConnectionInfo) { + this.dbConnectionInfo = dbConnectionInfo; + } + + public DbConnectionInfo getCentralDbConnectionInfo() { + return centralDbConnectionInfo; + } + + public void setCentralDbConnectionInfo(DbConnectionInfo centralDbConnectionInfo) { + this.centralDbConnectionInfo = centralDbConnectionInfo; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DeploymentContext.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DeploymentContext.java new file mode 100644 index 0000000..8f9ac17 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/DeploymentContext.java @@ -0,0 +1,38 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity; + +public class DeploymentContext { + private DebugEnvironment debugEnvironment; + + public DebugEnvironment getDebugEnvironment() { + return debugEnvironment; + } + + public void setDebugEnvironment(DebugEnvironment debugEnvironment) { + this.debugEnvironment = debugEnvironment; + } + + public String getPublishPath() { + return publishPath; + } + + public void setPublishPath(String publishPath) { + this.publishPath = publishPath; + } + + private String publishPath; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ExtractContext.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ExtractContext.java index e3826d1..b96eff3 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ExtractContext.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ExtractContext.java @@ -21,6 +21,15 @@ public class ExtractContext { private String deployPath; private String deployConfigPath; private String webModulePath; + private String deployType; + + public String getDeployType() { + return deployType; + } + + public void setDeployType(String deployType) { + this.deployType = deployType; + } public String getProjectPath() { return projectPath; diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataRTFilter.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataRTFilter.java new file mode 100644 index 0000000..109fb2b --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataRTFilter.java @@ -0,0 +1,42 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity; + +import java.util.List; +import lombok.Data; + +/** + * Classname MetadataRTFilter Description 过滤条件实体类 Date 2019/11/18 15:21 + * + * @author zhongchq + * @version 1.0 + */ +@Data +public class MetadataRTFilter { + + //关键应用编号 + public String appCode; + //服务单元编号 + public String serviceUnitCode; + //业务对象ID + public List bizobjectId; + + public String type; + + public String code; + + public String nameSpace; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/WorkspaceDataLocation.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/WorkspaceDataLocation.java new file mode 100644 index 0000000..aca8a1f --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/WorkspaceDataLocation.java @@ -0,0 +1,32 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity; + +import lombok.Data; + +/** + * @Classname WorkspaceDataLocation + * @Description TODO + * @Date 2019/7/20 15:08 + * @Created by zhongchq + * @Version 1.0 + */ + +@Data +public class WorkspaceDataLocation { + + public String workspaceDataLocation; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfigData.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfigData.java new file mode 100644 index 0000000..9be1eb4 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfigData.java @@ -0,0 +1,38 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity.compiler; + +public class MetadataCompilerConfigData { + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + private String name; + + public String getAssembly() { + return assembly; + } + + public void setAssembly(String assembly) { + this.assembly = assembly; + } + + private String assembly; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfiguration.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfiguration.java new file mode 100644 index 0000000..1116f87 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/compiler/MetadataCompilerConfiguration.java @@ -0,0 +1,47 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity.compiler; + +public class MetadataCompilerConfiguration { + private String typeCode; + private boolean enable; + + public String getTypeCode() { + return typeCode; + } + + public void setTypeCode(String typeCode) { + this.typeCode = typeCode; + } + + public boolean getEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + + public MetadataCompilerConfigData getMetadataCompiler() { + return metadataCompiler; + } + + public void setMetadataCompiler(MetadataCompilerConfigData metadataCompiler) { + this.metadataCompiler = metadataCompiler; + } + + private MetadataCompilerConfigData metadataCompiler; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeployConfigData.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeployConfigData.java new file mode 100644 index 0000000..11692b2 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeployConfigData.java @@ -0,0 +1,38 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity.deployer; + +public class DeployConfigData { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAssembly() { + return assembly; + } + + public void setAssembly(String assembly) { + this.assembly = assembly; + } + + private String assembly; +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeploymentType.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeploymentType.java new file mode 100644 index 0000000..843b521 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/deployer/DeploymentType.java @@ -0,0 +1,46 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity.deployer; + +public class DeploymentType { + public DeployConfigData getDeployer() { + return deployer; + } + + public void setDeployer(DeployConfigData deployer) { + this.deployer = deployer; + } + + public boolean getEnable() { + return enable; + } + + public void setEnable(boolean enable) { + this.enable = enable; + } + + private String typeCode; + private DeployConfigData deployer; + private boolean enable; + + public String getTypeCode() { + return typeCode; + } + + public void setTypeCode(String typeCode) { + this.typeCode = typeCode; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java new file mode 100644 index 0000000..1ab08dd --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.entity.metadataindex; + +public class IndexServerConfiguration { + private String IP; + + private String port; + + public String getIP() { + return IP; + } + + public void setIP(String IP) { + this.IP = IP; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileAltMonitor.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileAltMonitor.java new file mode 100644 index 0000000..aa0a55a --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileAltMonitor.java @@ -0,0 +1,24 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.service; + +public interface FileAltMonitor { + void stop(); + + void start(); + + void checkAndNotify(); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileSystemService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileSystemService.java new file mode 100644 index 0000000..9a5012f --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/FileSystemService.java @@ -0,0 +1,35 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.service; + +import com.inspur.edp.lcm.metadata.api.entity.FileType; +import java.io.IOException; +import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; + +/** + * @author zhaoleitr + */ +public interface FileSystemService { + /** + * 展示到浏览器 + * + * @param path 路径 + * @throws IOException + */ + void showInExplorer(String path) throws IOException; + + FileAltMonitor createFileMonitor(String path, FileType type, FileAlterationListenerAdaptor adaptor); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MavenUtilsService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MavenUtilsService.java new file mode 100644 index 0000000..e069a34 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MavenUtilsService.java @@ -0,0 +1,42 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.service; + +/** + * Classname MavenUtilsService Description Maven操作工具类 Date 2020/1/9 14:55 + * + * @author zhongchq + * @version 1.0 + */ +public interface MavenUtilsService { + + /** + * 获取本地仓库地址 + * + * @return 本地仓库地址 + */ + String getLocalRepository(); + + /** + * 执行maven命令 + * + * @param mePath java代码路径 + * @param comd 命令 + * @return 命令是否执行成功 + */ + boolean exeMavenCommand(String mePath, String comd); + +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MetadataRTService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MetadataRTService.java new file mode 100644 index 0000000..a41c4cb --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/MetadataRTService.java @@ -0,0 +1,99 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.service; + +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4Ref; +import com.inspur.edp.lcm.metadata.api.entity.MetadataCustomizationFilter; +import com.inspur.edp.lcm.metadata.api.entity.MetadataRTFilter; +import com.inspur.edp.lcm.metadata.api.entity.ServiceUnitInfo; +import java.util.List; + +/** + * 元数据运行时服务接口 + * + * @author zhaoleitr + */ +public interface MetadataRTService { + /** + * 运行时获取元数据(不带国际化信息) + * + * @param id 元数据id + * @return 元数据内容实体 + */ + GspMetadata getMetadataRTByID(String id); + + /** + * 运行时获取元数据(带国际化信息) + * + * @param id 元数据id + * @return 元数据内容实体 + */ + GspMetadata getMetadata(String id); + + /** + * 根据过滤条件获取元数据 + * + * @param metadataCustomizationFilter 元数据过滤器 + * @return 元数据实体 + */ + GspMetadata getMetadata(MetadataCustomizationFilter metadataCustomizationFilter); + + /** + * 加载服务端所有的元数据 + */ + void loadAllMetadata(); + + /** + * 根据元数据类型获取元数据信息列表 + * + * @param metadataTypes 元数据类型列表,通过","分隔 + * @return 元数据信息列表 + */ + List getMetadataRefList(String metadataTypes); + + /** + * 获取所有的元数据列表 + * + * @return 元数据信息列表 + */ + List getMetadataRefList(); + + /** + * @param filter 过滤条件 + * @return 元数据信息列表 + * @author zhongchq + */ + List getMetadataListByFilter(MetadataRTFilter filter); + + /** + * 根据业务主键获取元数据 + * + * @param metadataNamespace 元数据命名空间 + * @param metadataCode 元数据编号 + * @param metadataTypeCode 元数据类型编号 + * @return 元数据内容实体 + */ + GspMetadata getMetadataBySemanticID(String metadataNamespace, String metadataCode, String metadataTypeCode); + + /** + * 根据元数据ID获取SU信息 + * + * @param metadataId 元数据id + * @return 服务单元信息 + */ + ServiceUnitInfo getServiceUnitInfo(String metadataId); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/PackageGenerateService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/PackageGenerateService.java new file mode 100644 index 0000000..cec4e5a --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/PackageGenerateService.java @@ -0,0 +1,37 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.service; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import java.util.List; + +/** + * 打包服务 + * + * @author zhaoleitr + */ +public interface PackageGenerateService { + + /** + * 打包 + * + * @param projectPath 工程路径 + */ + void generatePackage(String projectPath); + + List getLocalPackages(String path); +} + diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/ProjectExtendService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/ProjectExtendService.java new file mode 100644 index 0000000..f32f304 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/service/ProjectExtendService.java @@ -0,0 +1,62 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.service; + +import com.inspur.edp.lcm.metadata.api.entity.DbConnectionInfo; +import java.io.IOException; +import java.util.List; + +/** + * @author zhaoleitr + */ +public interface ProjectExtendService { + /** + * 提取 + * + * @param path + */ + void extract(String path); + + /** + * 部署 + * + * @param dBConnectionInfo 数据库信息 + * @param serverPath + * @param projPath 工程路径 + * @param restart 是否重启 + * @return + */ + void deploy(DbConnectionInfo dBConnectionInfo, String serverPath, String projPath, String restart); + + /** + * 文件迁移 + * + * @param path 工程路径 + */ + void migration(String path); + + /** + * 获取部署状态 + * + * @param sign 加密的文件路径 + * @return 部署状态 + * @throws IOException + */ + String getDeployStatus(String sign) throws IOException; + + List batchCompile(String path, String exts, String disabledExts); +} + diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java similarity index 100% rename from model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java rename to model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDevCacheManager.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDevCacheManager.java similarity index 100% rename from model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDevCacheManager.java rename to model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDevCacheManager.java diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDistCacheManager.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDistCacheManager.java similarity index 100% rename from model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDistCacheManager.java rename to model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataDistCacheManager.java diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataRtDistCache.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataRtDistCache.java similarity index 100% rename from model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataRtDistCache.java rename to model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataRtDistCache.java diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java similarity index 100% rename from model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java rename to model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java index 3afbc00..c089ef6 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java @@ -49,7 +49,7 @@ public class MetadataDtoConverter { return null; } MetadataDto metadataDto = new MetadataDto(); - metadataDto.setBizobjectID(metadata.getHeader().getBizObjectId()); + metadataDto.setBizobjectID(metadata.getHeader().getBizobjectID()); metadataDto.setType(metadata.getHeader().getType()); metadataDto.setId(metadata.getHeader().getId()); metadataDto.setCode(metadata.getHeader().getCode()); @@ -59,7 +59,7 @@ public class MetadataDtoConverter { metadataDto.setLanguage(metadata.getHeader().getLanguage()); metadataDto.setRelativePath(metadata.getRelativePath()); //GspMetadata没有此属性 - metadataDto.setTranslating(metadata.getHeader().getTranslating()); + metadataDto.setIsTranslating(metadata.getHeader().isTranslating()); metadataDto.setExtendProperty(metadata.getExtendProperty()); metadataDto.setExtendable(metadata.getHeader().isExtendable()); metadataDto.setExtented(metadata.isExtended()); @@ -125,7 +125,7 @@ public class MetadataDtoConverter { GspMetadata metadata = new GspMetadata(); metadata.setHeader(new MetadataHeader()); metadata.getHeader().setId(metadataDto.getId()); - metadata.getHeader().setBizObjectId(metadataDto.getBizobjectID()); + metadata.getHeader().setBizobjectID(metadataDto.getBizobjectID()); metadata.getHeader().setNameSpace(metadataDto.getNameSpace()); metadata.getHeader().setType(metadataDto.getType()); metadata.getHeader().setFileName(metadataDto.getFileName()); diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerConfigLoader.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerConfigLoader.java new file mode 100644 index 0000000..2527cae --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerConfigLoader.java @@ -0,0 +1,59 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.compiler; + +import com.inspur.edp.lcm.metadata.api.entity.compiler.MetadataCompilerConfiguration; +import com.inspur.edp.lcm.metadata.common.configuration.MetadataServiceHelper; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.List; + +public class MetadataCompilerConfigLoader { + private String fileName = "config/platform/common/lcm_gspprojectextend.json"; + private String sectionName = "MetadataCompilerConfigration"; + private List compileConfigrations; + + protected List loadCompileConfigration() { + MetadataServiceHelper metadataServiceHelper = new MetadataServiceHelper(); + try { + if (compileConfigrations == null || compileConfigrations.size() <= 0) { + fileName = Paths.get(EnvironmentUtil.getServerRTPath()).resolve(fileName).toString(); + compileConfigrations = metadataServiceHelper.getCompileConfigrationList(fileName, sectionName); + return compileConfigrations; + } else { + return compileConfigrations; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + protected MetadataCompilerConfiguration getCompileConfigurationData(String typeName) { + loadCompileConfigration(); + if (compileConfigrations != null && compileConfigrations.size() > 0) { + for (MetadataCompilerConfiguration data : compileConfigrations) { + if (data.getTypeCode().equalsIgnoreCase(typeName)) { + return data; + } + } + } else { + return null; + } + return null; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerHelper.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerHelper.java new file mode 100644 index 0000000..a1e7c72 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/compiler/MetadataCompilerHelper.java @@ -0,0 +1,53 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.compiler; + +import com.inspur.edp.lcm.metadata.api.entity.compiler.MetadataCompilerConfiguration; +import com.inspur.edp.lcm.metadata.spi.MetadataCompileAction; +import java.util.List; + +public class MetadataCompilerHelper extends MetadataCompilerConfigLoader { + private static MetadataCompilerHelper singleton = null; + + public static MetadataCompilerHelper getInstance() { + if (singleton == null) { + singleton = new MetadataCompilerHelper(); + } + return singleton; + } + + public List getCompileConfigrationList() { + return loadCompileConfigration(); + } + + public MetadataCompileAction getManager(String typeCode) { + MetadataCompileAction manager = null; + MetadataCompilerConfiguration compileConfigurationData = getCompileConfigurationData(typeCode); + if (compileConfigurationData != null) { + Class cls; + try { + if (compileConfigurationData.getMetadataCompiler() != null) { + cls = Class.forName(compileConfigurationData.getMetadataCompiler().getName()); + manager = (MetadataCompileAction) cls.newInstance(); + } + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + return manager; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/config/LcmComConfiguration.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/config/LcmComConfiguration.java new file mode 100644 index 0000000..83e0c2e --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/config/LcmComConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.config; + +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Classname LcmComConfiguration Description LcmComConfiguration Date 2020/1/9 14:58 + * + * @author zhongchq + * @version 1.0 + */ +//todo +//@Configuration(proxyBeanMethods = false) +@Configuration() +public class LcmComConfiguration { + + @Bean + public FileService createFileService() { + return new FileServiceImp(); + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/context/RuntimeContext.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/context/RuntimeContext.java new file mode 100644 index 0000000..9635086 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/context/RuntimeContext.java @@ -0,0 +1,51 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.context; + +import io.iec.edp.caf.boot.context.CAFContext; +import lombok.Setter; + +/** + * Classname RuntimeContext Description TODO Date 2019/8/20 14:11 + * + * @author zhongchq + * @version 1.0 + */ +public class RuntimeContext { + + @Setter + public static String tenantID; + + public static String getTenantID() { + + if (tenantID == null) { + tenantID = "9999"; + } + return tenantID; + } + + @Setter + private static String language; + + public static String getLanguage() { + try { + language = CAFContext.current.getLanguage(); + } catch (Exception e) { + language = "zh-CHS"; + } + return language; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentHelper.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentHelper.java new file mode 100644 index 0000000..80089e5 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentHelper.java @@ -0,0 +1,57 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.deployer; + +import com.inspur.edp.lcm.metadata.api.entity.deployer.DeploymentType; +import com.inspur.edp.lcm.project.deployer.spi.DeployAction; +import java.util.List; + +public class DeploymentHelper extends DeploymentTypeConfigLoader { + + private static DeploymentHelper singleton = null; + + public DeploymentHelper() { + } + + public static DeploymentHelper getInstance() { + if (singleton == null) { + singleton = new DeploymentHelper(); + } + return singleton; + } + + public List getDeploymentType() { + return loadDeploymentTypeConfiguration(); + } + + public DeployAction getManager(String typeCode) { + DeployAction manager = null; + DeploymentType deploymentType = getDeploymentType(typeCode); + if (deploymentType != null) { + Class cls; + try { + if (deploymentType.getDeployer() != null) { + cls = Class.forName(deploymentType.getDeployer().getName()); + manager = (DeployAction) cls.newInstance(); + } + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + return manager; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentTypeConfigLoader.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentTypeConfigLoader.java new file mode 100644 index 0000000..df9f4a3 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/deployer/DeploymentTypeConfigLoader.java @@ -0,0 +1,87 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.deployer; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.lcm.metadata.api.entity.deployer.DeploymentType; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.List; + +public class DeploymentTypeConfigLoader { + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + private String serverPath; + protected String fileName = "tools/deploy/project_java/config/platform/common/lcm_deploymenttype.json"; + private String sectionName = "DeploymentType"; + + private List deploymentTypeConfiguration; + + public DeploymentTypeConfigLoader() { + serverPath = Paths.get(Utils.getStartupPath()).resolve("../..").toString().replace("\\", "/"); + } + + protected List loadDeploymentTypeConfiguration() { + if (deploymentTypeConfiguration != null) { + return deploymentTypeConfiguration; + } + try { + fileName = Paths.get(serverPath).resolve(fileName).toString(); + deploymentTypeConfiguration = getDeploymentTypeConfiguration(fileName, sectionName); + return deploymentTypeConfiguration; + } catch (IOException ioException) { + ioException.printStackTrace(); + } finally { + fileName = "tools/deploy/project_java/config/platform/common/lcm_deploymenttype.json"; + } + return null; + } + + protected DeploymentType getDeploymentType(String typeCode) { + List deploymentTypes = loadDeploymentTypeConfiguration(); + DeploymentType deploymentType = deploymentTypes.stream().filter(type -> type.getTypeCode().equals(typeCode)).findFirst().orElse(null); + return deploymentType; + } + + private List getDeploymentTypeConfiguration(String path, String sectionName) throws IOException { + FileServiceImp fileService = new FileServiceImp(); + String fileContents = fileService.fileRead(path); + ObjectMapper objectMapper = Utils.getMapper(); + JsonNode jsonNode = objectMapper.readTree(fileContents); + String deploymentType = jsonNode.findValue(sectionName).toString(); + return objectMapper.readValue(deploymentType, new TypeReference>() { + }); + } + + public String getServerPath() { + return serverPath; + } + + public void setServerPath(String serverPath) { + this.serverPath = serverPath; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractConfigLoader.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractConfigLoader.java new file mode 100644 index 0000000..ba2f64c --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractConfigLoader.java @@ -0,0 +1,67 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.extractor; + +import com.inspur.edp.lcm.metadata.api.entity.extract.ExtractConfigration; +import com.inspur.edp.lcm.metadata.common.configuration.MetadataServiceHelper; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.List; + +public class ExtractConfigLoader { + private String fileName = "config/platform/common/lcm_gspprojectextend.json"; + private String sectionName = "ExtractConfigration"; + private List extractConfigrations; + + /** + * @param + * @return java.util.List + * @throws + * @author zhongchq + * @description 获取配置文件数据 + * @date 15:40 2019/7/23 + **/ + protected List loadExtractConfigration() { + MetadataServiceHelper metadataServiceHelper = new MetadataServiceHelper(); + try { + if (extractConfigrations == null || extractConfigrations.size() <= 0) { + fileName = Paths.get(EnvironmentUtil.getServerRTPath()).resolve(fileName).toString(); + extractConfigrations = metadataServiceHelper.getExtractConfigrationList(fileName, sectionName); + return extractConfigrations; + } else { + return extractConfigrations; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + protected ExtractConfigration getExtractConfigurationData(String typeName) { + loadExtractConfigration(); + if (extractConfigrations != null && extractConfigrations.size() > 0) { + for (ExtractConfigration data : extractConfigrations) { + if (data.getTypeCode().equalsIgnoreCase(typeName)) { + return data; + } + } + } else { + return null; + } + return null; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractHelper.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractHelper.java new file mode 100644 index 0000000..bb3d999 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/extractor/ExtractHelper.java @@ -0,0 +1,53 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.extractor; + +import com.inspur.edp.lcm.metadata.api.entity.extract.ExtractConfigration; +import com.inspur.edp.lcm.metadata.spi.ExtractAction; +import java.util.List; + +public class ExtractHelper extends ExtractConfigLoader { + private static ExtractHelper singleton = null; + + public static ExtractHelper getInstance() { + if (singleton == null) { + singleton = new ExtractHelper(); + } + return singleton; + } + + public List getExtractConfigrationList() { + return loadExtractConfigration(); + } + + public ExtractAction getManager(String typeCode) { + ExtractAction manager = null; + ExtractConfigration extractConfigurationData = getExtractConfigurationData(typeCode); + if (extractConfigurationData != null) { + Class cls; + try { + if (extractConfigurationData.getExtract() != null) { + cls = Class.forName(extractConfigurationData.getExtract().getName()); + manager = (ExtractAction) cls.newInstance(); + } + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + return manager; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java new file mode 100644 index 0000000..476f7fb --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java @@ -0,0 +1,57 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.logging; + +import com.inspur.lcm.metadata.logging.LoggerDisruptorQueue; +import io.iec.edp.caf.boot.context.CAFContext; +import lombok.extern.slf4j.Slf4j; +import org.apache.maven.shared.invoker.InvocationOutputHandler; + +/** + * Classname MvnStreamConsumer Description 获取日志 Date 2020/3/4 11:32 + * + * @author zhongchq + * @version 1.0 + */ +@Slf4j +public class MvnStreamConsumer implements InvocationOutputHandler { + + private String exceptionString; + + @Override + public void consumeLine(String line) { + if (line.contains("[INFO]")) { +// System.out.println("mvn userId :"+CAFContext.current.getUserId()); + LoggerDisruptorQueue.publishEvent(line, CAFContext.current.getUserId()); + log.info(line); + } else if (line.contains("[WARNING]")) { + LoggerDisruptorQueue.publishEvent(line, CAFContext.current.getUserId()); + log.warn(line); + } else if (line.contains("[ERROR]")) { + this.exceptionString += line + "\r\n"; + LoggerDisruptorQueue.publishEvent(line, CAFContext.current.getUserId()); + log.error(line); + } + } + + public String getExceptionString() { + return exceptionString; + } + + public void setExceptionString(String exceptionString) { + this.exceptionString = exceptionString; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java new file mode 100644 index 0000000..086b1fb --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java @@ -0,0 +1,642 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.util; + +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.net.Socket; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class CommandUtil { + public static void newProcess(String directory, String command) { + ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command); + builder.directory(new File(directory)); + builder.redirectOutput(ProcessBuilder.Redirect.INHERIT); + builder.redirectError(ProcessBuilder.Redirect.INHERIT); + builder.redirectInput(ProcessBuilder.Redirect.INHERIT); + builder.redirectErrorStream(true); + + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + + Process p; + try { + p = builder.start(); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + String line; + while (true) { + line = br.readLine(); + if (line == null) { + break; + } + System.out.println(line); + } + + p.waitFor(); + int exit = p.exitValue(); + if (exit != 0) { + throw new RuntimeException("程序调用异常"); + } + } catch (IOException | InterruptedException e) { + throw new RuntimeException("程序调用异常", e); + } finally { + try { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public static void start(String serverPath) { + Runtime runtime = Runtime.getRuntime(); + try { + runtime.exec("cmd /k start " + serverPath); + } catch (IOException e) { + e.printStackTrace(); + } + } + +// public static int getPid(Process process) { +// int pid = 0; +// try { +// Field field = process.getClass().getDeclaredField("handle"); +// field.setAccessible(true); +// Long pidL = Kernel32.INSTANCE.GetProcessId((Long) field.get(process)); +// pid = pidL.intValue(); +// } catch (Exception ex) { +// ex.printStackTrace(); +// } +// return pid; +// } + + // 通过获取当前运行主机的pidName,截取获得他的pid + public static int getCurrentPid() { + RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); + String pidName = runtime.getName();// 5296@dell-PC + int pid = Integer.parseInt(pidName.substring(0, pidName.indexOf("@"))); + return pid; + } + + // 通过Pid获取PidName + public static String getPidNameByPid(int pid) throws Exception { + String pidName = null; + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + String[] array; + try { + Process p = Runtime.getRuntime().exec("cmd /c TASKLIST /NH /FO CSV /FI \"PID EQ " + pid + "\""); + is = p.getInputStream(); // "javaw.exe","3856","Console","1","72,292 + // K"从这个进程中获取对应的PidName + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + if (line.indexOf(String.valueOf(pid)) != -1) { + array = line.split(","); + line = array[0].replaceAll("\"", ""); + line = line.replaceAll(".exe", "");// 考虑pidName后缀为exe或者EXE + line = line.replaceAll(".exe".toUpperCase(), ""); + pidName = line; + } + } + } catch (IOException localIOException) { + throw new Exception("获取进程名称出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + return pidName; + } + + // 根据Pid获取当前进程的CPU + public static String getCPUByPID(int pid) throws Exception { + if (pid == 0) { + return null; + } + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + String[] array; + try { + Process p = Runtime.getRuntime().exec("cmd /c TASKLIST /NH /FO CSV /FI \"PID EQ " + pid + "\""); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + if (!"".equals(line)) { + array = line.split("\",\""); + line = array[3].replaceAll("\"", ""); + return line; + } + } + } catch (Exception localException) { + throw new Exception("获取进程CPU信息出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + return null; + } + + // 根据Pid获取当前进程的memory + public static String getMemByPID(int pid) throws Exception { + if (pid == 0) { + return null; + } + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + String[] array; + try { + Process p = Runtime.getRuntime().exec("cmd /c TASKLIST /NH /FO CSV /FI \"PID EQ " + pid + "\""); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + if (!"".equals(line)) { + array = line.split("\",\""); + if (array.length < 5) { + continue; + } + line = array[4].replaceAll("\"", ""); + return line; + } + } + } catch (IOException localIOException) { + throw new Exception("获取进程内存信息出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + return null; + } + + // 根据Pid将进程干掉 + public static void killProcessByPid(int pid) throws Exception { + Runtime.getRuntime().exec("taskkill /F /PID " + pid); + } + + // 根据PidName将进程干掉 + public static void killProcessByPidName(String pidName) throws Exception { + Runtime.getRuntime().exec("taskkill /F /IM " + pidName); + } + + // 根据PidName获取当前的Pid的list集合 + public static List getPidsByPidName(String pidName) throws Exception { + List pidList = new ArrayList<>(); + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + String[] array; + try { + String imageName = pidName; + Process p = Runtime.getRuntime().exec("cmd /c TASKLIST /NH /FO CSV /FI \"IMAGENAME EQ " + imageName + "\""); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + if (line.indexOf(imageName) != -1) { + array = line.split(","); + line = array[1].replaceAll("\"", ""); + pidList.add(Integer.parseInt(line)); + } + } + } catch (IOException localIOException) { + throw new Exception("获取进程ID出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + return pidList; + } + + // 获取所有的pid + public static List getPidsByFilter(String filter) throws Exception { + List pids = new ArrayList<>(); + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + String[] array; + try { + Process p = Runtime.getRuntime().exec("cmd /c TASKLIST /NH /FO CSV | findstr " + filter); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + array = line.split(","); + int pid = Integer.parseInt(array[1].replace("\"", "")); + if (pid != 0) { + pids.add(pid); + } + } + } catch (IOException localIOException) { + throw new Exception("获取系统所有进程名出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + return pids; + } + + // 获取当前系统的所有的PidName + public static Set getCurrOsAllPidNameSet() throws Exception { + Set pidNameSet = new HashSet<>(); + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + String[] array; + try { + Process p = Runtime.getRuntime().exec("cmd /c TASKLIST /NH /FO CSV"); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + array = line.split(","); + line = array[0].replaceAll("\"", ""); + line = line.replaceAll(".exe", ""); + line = line.replaceAll(".exe".toUpperCase(), ""); + if (line != "") { + pidNameSet.add(line); + } + } + } catch (IOException localIOException) { + throw new Exception("获取系统所有进程名出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + return pidNameSet; + } + + // 判断当前pid是否退出,判断根据pid查询的内存是否为空来决定 + public static boolean isPidExist(int pid) throws Exception { + return getMemByPID(pid) != null; + } + + // 对启动路径和运行参数的拼接 + public static String getCommandFormatStr(String proPath) {// 这样的思路就可以控制俩种参数的输入 + return getCommandFormatStr(proPath, null); + } + + public static String getCommandFormatStr(String proPath, String runArgs) { + StringBuffer command = new StringBuffer(); + command.append("\""); + command.append(proPath); + command.append("\""); + if (runArgs != "") { + command.append(" ").append(runArgs); + } + return command.toString(); + } + + // 执行完相应的命令行就退出cmd + private static String getCommandByCmd(String cmdStr) { + StringBuffer command = new StringBuffer(); + command.append("cmd /C "); + command.append(cmdStr); + return command.toString(); + } + + // 通过cmd打开对应的文件 + public static void openDir(String fileDir) throws Exception {// 打开cmd,执行explorer + Runtime.getRuntime().exec("cmd /c start explorer " + fileDir);// explorer.exe是Windows的程序管理器或者文件资源管理器 + } + + // 根据当前的Pid获取当前进程的端口 + public static int getPortByPID(int pid) { + if (pid == 0) { + return 0; + } + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line = ""; + String LISTENING_STATE_TYPE = "LISTENING";// 状态值 + String[] array; + try { + Process p = Runtime.getRuntime().exec("cmd /c netstat /ano | findstr [ | findstr " + pid + " | findstr " + LISTENING_STATE_TYPE); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + do { + if (line.indexOf(String.valueOf(pid)) != -1) { + line = line.replaceFirst("\\s+", ""); + array = line.split("\\s+"); + int port = Integer.parseInt(array[1].split(":")[3].trim()); + return port; + } + if ((line = br.readLine()) == null) { + break; + } + } + while (pid != 0); + } catch (IOException localIOException) { + throw new RuntimeException("获取进程端口信息出错!"); + } finally { + try { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return 0; + } + + // 根据当前的Pid获取当前进程的端口 + public static Map> getPortsByPID(int pid) throws Exception { + if (pid == 0) { + return null; + } + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line = null; + String TCP_TYPE = "TCP"; + String UDP_TYPE = "UDP"; + String LISTENING_STATE_TYPE = "LISTENING";// 状态值 + Map> portMap = new HashMap<>(); + List tcpPortList = new ArrayList<>(); + List udpPortList = new ArrayList<>(); + portMap.put(TCP_TYPE, tcpPortList); + portMap.put(UDP_TYPE, udpPortList); + String[] array; + try { + Process p = Runtime.getRuntime().exec("netstat /ano"); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + do { + if (line.indexOf(pid) != -1) { + line = line.replaceFirst("\\s+", ""); + if (line.indexOf(TCP_TYPE) != -1) { + if (line.indexOf(LISTENING_STATE_TYPE) != -1) { + array = line.split("\\s+"); + String port = array[1].split(":")[1]; + tcpPortList.add(port); + } + } else { + array = line.split("\\s+"); + String port = array[1].split(":")[1]; + udpPortList.add(port); + } + } + if ((line = br.readLine()) == null) { + break; + } + } + while (pid != 0); + } catch (IOException localIOException) { + throw new Exception("获取进程端口信息出错!"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + return portMap; + } + + public static List getPidsByServerPath(String serverPath) { + List pids = new ArrayList<>(); + ArrayList inputs; + String cmd = "wmic process where caption=\"java.exe\" get caption,executablepath,processid"; + try { + inputs = getInputs(cmd); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("获取进程信息失败:" + cmd, e); + } + List processInfos = inputs.stream().filter(input -> input.contains(serverPath)).collect(Collectors.toList()); + if (processInfos != null) { + processInfos.forEach(processInfo -> { + String[] splits = processInfo.split("\\s+"); + int pid = Integer.parseInt(splits[2].trim()); + pids.add(pid); + }); + } + return pids; + } + + // 根据当前的Pid获取当前进程的端口 + public static ArrayList getInputs(String cmd) throws Exception { + ArrayList inputs = new ArrayList<>(); + InputStream is = null; + InputStreamReader ir = null; + BufferedReader br = null; + String line; + try { + Process p = Runtime.getRuntime().exec(cmd); + is = p.getInputStream(); + ir = new InputStreamReader(is); + br = new BufferedReader(ir); + while ((line = br.readLine()) != null) { + inputs.add(line); + } + + p.waitFor(); + int exit = p.exitValue(); + if (exit != 0) { + throw new RuntimeException("程序调用异常"); + } + } catch (IOException localIOException) { + throw new Exception("执行命令:" + cmd + "出错。"); + } finally { + if (br != null) { + br.close(); + } + if (ir != null) { + ir.close(); + } + if (is != null) { + is.close(); + } + } + return inputs; + } + + public static List getPidsByPort(int port) { + ArrayList pids = new ArrayList<>(); + try { + Runtime rt = Runtime.getRuntime(); + Process proc = rt.exec("cmd /c netstat -ano | findstr " + port); + + BufferedReader stdInput = new BufferedReader(new + InputStreamReader(proc.getInputStream())); + String s = null; + if ((s = stdInput.readLine()) != null) { + int index = s.lastIndexOf(" "); + String sc = s.substring(index); + pids.add(Integer.parseInt(sc.trim())); + //rt.exec("cmd /c Taskkill /PID" +sc+" /T /F"); + } + return pids; + } catch (Exception e) { + throw new RuntimeException("获取pid失败"); + } + } + + public static boolean isPortAvailable(int port) { + try (Socket ignored = new Socket("localhost", port)) { + return false; + } catch (IOException ignored) { + return true; + } + } + + public static boolean isWindows() { + String OS = System.getProperty("os.name").toLowerCase(); + boolean isWindows = OS.startsWith("windows"); + return isWindows; + } + + // 获取当前环境的Java_Home + public static String getJavaHome(boolean isDeployTool) { + String javaHomeInServer = getJavaHomeInServer(isDeployTool); + if (new File(javaHomeInServer).exists()) { + return javaHomeInServer; + } + + String javaHome = System.getenv("JAVA_HOME"); + javaHome = javaHome == null ? System.getProperty("java.home") : javaHome; + + if (Utils.isNullOrEmpty(javaHome)) { + throw new RuntimeException("请配置系统变量JAVA_HOME"); + } + + return ""; + } + + public static String getJavaHomeInServer(boolean isDeployTool) { + String javaDir = isWindows() ? "amd64-win" : "x86_64-linux"; + String javaHome = FileServiceImp.combinePath(Utils.getBasePath(isDeployTool), EnvironmentUtil.getServerRuntimePathName(), "runtime/java", javaDir, "bin"); + return javaHome; + } + + // 对于这个方法在产品阶段用于判断是否具有JAVA_HOME + public static boolean existJavaHome() throws Exception { + ArrayList inputs = getInputs("cmd /c echo %JAVA_HOME%"); + if (Utils.isNullOrEmpty(inputs)) { + return false; + } + boolean existFlag = inputs.stream().anyMatch(input -> input.contains("%JAVA_HOME%")); + return existFlag; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/DbUtil.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/DbUtil.java new file mode 100644 index 0000000..d2b125b --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/DbUtil.java @@ -0,0 +1,49 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.util; + +import com.inspur.edp.lcm.metadata.api.entity.DbConnectionInfo; +import io.iec.edp.caf.commons.dataaccess.DbConfigDataConvertor; +import io.iec.edp.caf.commons.dataaccess.DbType; +import io.iec.edp.caf.commons.dataaccess.GSPDbConfigData; +import io.iec.edp.caf.commons.dataaccess.JDBCConnectionInfo; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class DbUtil { + public static void testDBConnection(DbConnectionInfo dbConnectionInfo) { + JDBCConnectionInfo dbConfigData = getDbConfigData(dbConnectionInfo); + try { + DriverManager.getConnection(dbConfigData.getDatabaseURL(), dbConfigData.getUserName(), dbConfigData.getPassword()); + } catch (SQLException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + private static JDBCConnectionInfo getDbConfigData(DbConnectionInfo dbConnectionInfo) { + String source = dbConnectionInfo.getDbServerIP() + ":" + dbConnectionInfo.getDbPort(); + source = dbConnectionInfo.getDbType().equals(DbType.Oracle) ? source + "/" + dbConnectionInfo.getDbName() : source; + GSPDbConfigData gspDbConfigData = new GSPDbConfigData(); + gspDbConfigData.setDbType(dbConnectionInfo.getDbType()); + gspDbConfigData.setSource(source); + gspDbConfigData.setCatalog(dbConnectionInfo.getDbName()); + gspDbConfigData.setUserId(dbConnectionInfo.getDbUserName()); + gspDbConfigData.setPassword(dbConnectionInfo.getDbPassword()); + JDBCConnectionInfo dbConfigData = DbConfigDataConvertor.Convert(gspDbConfigData); + return dbConfigData; + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java new file mode 100644 index 0000000..73adf48 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java @@ -0,0 +1,69 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.util; + +import com.inspur.edp.lcm.metadata.common.Utils; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import sun.misc.BASE64Decoder; +import sun.misc.BASE64Encoder; + +public class EncryptUtil { + final static BASE64Decoder decoder = new BASE64Decoder(); + final static BASE64Encoder encoder = new BASE64Encoder(); + + public static String decryptInBASE64(String decryptString) { + try { + return new String(decoder.decodeBuffer(decryptString), StandardCharsets.UTF_8); + } catch (Exception e) { + throw new RuntimeException("配置解密失败, 请重新配置或者联系系统管理员。", e); + } + } + + public static String encryptInBASE64(String encodeString) { + if (Utils.isNullOrEmpty(encodeString)) { + return ""; + } + try { + return encoder.encode(encodeString.getBytes(StandardCharsets.UTF_8.name())); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return ""; + } + + public static String encryptInAscii(String text, int offset) { + if (Utils.isNullOrEmpty(text)) { + return ""; + } + char[] chars = text.toCharArray(); + for (int i = 0; i < chars.length; i++) { + chars[i] = (char) (chars[i] + offset); + } + return new String(chars); + } + + public static String decryptInAscii(String text, int offset) { + if (Utils.isNullOrEmpty(text)) { + return ""; + } + char[] chars = text.toCharArray(); + for (int i = 0; i < chars.length; i++) { + chars[i] = (char) (chars[i] - offset); + } + return new String(chars); + } +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/Kernel32.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/Kernel32.java new file mode 100644 index 0000000..3e83358 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/Kernel32.java @@ -0,0 +1,25 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.common.util; + +import com.sun.jna.Library; +import com.sun.jna.Native; + +public interface Kernel32 extends Library { + public static Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class); + + public long GetProcessId(Long hProcess); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/ExtractAction.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/ExtractAction.java new file mode 100644 index 0000000..2a6acd3 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/ExtractAction.java @@ -0,0 +1,27 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +import com.inspur.edp.lcm.metadata.api.entity.ExtractContext; + +public interface ExtractAction { + /** + * 提取扩展动作 + * + * @param context 提取上下文 + */ + void extract(ExtractContext context); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/IProjectCreateManager.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/IProjectCreateManager.java new file mode 100644 index 0000000..2b82448 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/IProjectCreateManager.java @@ -0,0 +1,22 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +import java.util.Map; + +public interface IProjectCreateManager { + void onCreatedProject(String projectPathWithFileName, Map items); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/JitRuntimeAction.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/JitRuntimeAction.java new file mode 100644 index 0000000..c34939b --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/JitRuntimeAction.java @@ -0,0 +1,20 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +public interface JitRuntimeAction { + void generateRuntime(String projPath); +} \ No newline at end of file diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MdExtendRuleSerializer.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MdExtendRuleSerializer.java new file mode 100644 index 0000000..e0c35fa --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MdExtendRuleSerializer.java @@ -0,0 +1,29 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +import com.fasterxml.jackson.databind.JsonNode; +import com.inspur.edp.lcm.metadata.api.IMdExtRuleContent; + +/** + * @author zhaoleitr 元数据扩展规则序列化 + */ +public interface MdExtendRuleSerializer { + + JsonNode serialize(IMdExtRuleContent extendRule); + + IMdExtRuleContent deSerialize(JsonNode contentJObject); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataCompileAction.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataCompileAction.java new file mode 100644 index 0000000..8186c24 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataCompileAction.java @@ -0,0 +1,27 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataCompilerContext; + +public interface MetadataCompileAction { + /** + * 编译扩展动作 + * + * @param context 扩展上下文 + */ + void metadataCompile(MetadataCompilerContext context); +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataExtRuleService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataExtRuleService.java new file mode 100644 index 0000000..7e2ab44 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataExtRuleService.java @@ -0,0 +1,24 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +import com.inspur.edp.lcm.metadata.api.IMetadataContent; + +public interface MetadataExtRuleService { + + public IMetadataContent getDefaultExtRule(String type); + +} diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataI18nService.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataI18nService.java new file mode 100644 index 0000000..24b9942 --- /dev/null +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/spi/MetadataI18nService.java @@ -0,0 +1,33 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.spi; + +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.I18nResource; +import java.util.List; + +public interface MetadataI18nService { + /// 合并(用于加载翻译后的元数据) + /// 基础元数据 + /// 多语资源 + GspMetadata merge(GspMetadata metadata, List resource); + + /// 此方法在运行时 获取元数据时,用不到。 + /// 此方法用于在设计时抽取资源元数据内容。 + /// 从基础元数据抽取资源元数据内容 + /// 基础元数据 + I18nResource getResourceItem(GspMetadata metadata); +} diff --git a/model/framework/devtime-api/pom.xml b/model/framework/devtime-api/pom.xml index 453e1a3..44be71b 100644 --- a/model/framework/devtime-api/pom.xml +++ b/model/framework/devtime-api/pom.xml @@ -8,24 +8,15 @@ 0.9.0-SNAPSHOT 4.0.0 - ubml-model-framework-devtime-api ${project.version} - ubml-model-framework-devtime-api + org.openatom.ubml - ubml-model-common-definition - 0.9.0-SNAPSHOT - compile - - - org.openatom.ubml - ubml-model-framework-common - 0.9.0-SNAPSHOT - compile + ubml-model-framework-entity + ${project.version} - \ No newline at end of file diff --git a/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java b/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java new file mode 100644 index 0000000..f0766d0 --- /dev/null +++ b/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java @@ -0,0 +1,20 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.api.exception; + +public class MetadataExceptionCode { + public final String Unknown = "GSP_LCM_Meta_0000"; +} diff --git a/model/framework/devtime-core/pom.xml b/model/framework/devtime-core/pom.xml index 9483ce1..6082276 100644 --- a/model/framework/devtime-core/pom.xml +++ b/model/framework/devtime-core/pom.xml @@ -12,42 +12,77 @@ ubml-model-framework-devtime-core - - org.openatom.ubml - ubml-model-framework-devtime-api - 0.9.0-SNAPSHOT - compile - io.iec.edp caf-business-object-api - 0.1.4 - com.inspur.edp - lcm-logging-service - 0.1.4 + io.iec.edp + caf-boot-starter-context com.inspur.edp - ide-setting-core - 0.1.4 + i18n-resource-api + + + lcm-metadata-api + com.inspur.edp + + io.iec.edp - caf-boot-starter-context - 0.3.2 + caf-sumgr-core + com.inspur.edp - i18n-resource-api - 0.1.2 + lcm-logging-service + + + com.inspur.edp + ide-setting-core + + + lcm-metadata-devcommon + com.inspur.edp + + com.inspur.edp metadata-to-java-context - 0.1.3 + + + lcm-metadata-api + com.inspur.edp + + + lcm-metadata-manager + com.inspur.edp + + + lcm-metadata-core + com.inspur.edp + + - + + org.openatom.ubml + ubml-model-framework-common + ${project.version} + + + lcm-metadata-api + com.inspur.edp + + + + + org.openatom.ubml + ubml-model-framework-runtime-spi + ${project.version} + + \ No newline at end of file diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateCoreService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateCoreService.java new file mode 100644 index 0000000..12eacb6 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateCoreService.java @@ -0,0 +1,304 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.GspProject; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageHeader; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageReference; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageVersion; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; +import com.inspur.edp.lcm.metadata.api.entity.ServiceUnitInfo; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static com.inspur.edp.lcm.metadata.common.Utils.handlePath; + +/** + * @author zhaoleitr + */ +public class PackageGenerateCoreService { + private final MetadataProjectCoreService projectService = new MetadataProjectCoreService(); + + private String packageName = ""; + private String projectPath = ""; + private String packagePath = ""; + private String projectFileName = ""; + private MetadataPackageHeader metadataPackageHeader; + private List metadataList; + private Map metadataAndDirPathList; + private MetadataPackageVersion packageVersion = new MetadataPackageVersion(); + private final FileServiceImp fileService = new FileServiceImp(); + + public void generatePackage(String path) { + projectPath = handlePath(path); + //1、初始化参数 + initialize(projectPath); + //2、组织manifest文件 + getManifest(); + //3、打包 + publishPackage(); + } + + private void initialize(String path) { + MetadataProject project = projectService.getMetadataProjInfo(path); + projectFileName = project.getName() + Utils.getMetadataProjSuffix(); + packageName = project.getMetadataPackageInfo().getName(); + packageVersion = project.getMetadataPackageInfo().getVersion(); + metadataPackageHeader = project.getMetadataPackageInfo(); + + String tempPath = fileService.getCombinePath(projectPath, "bin"); + packagePath = fileService.getCombinePath(tempPath, UUID.randomUUID().toString()); + metadataAndDirPathList = new LinkedHashMap<>(); + metadataList = new ArrayList<>(); + } + + private void getManifest() { + //1、获取头结点 + MetadataPackageHeader mpHeader = metadataPackageHeader; + //2、获取SU信息 + ServiceUnitInfo suInfo = getServiceUnitInfo(); + //3、获取依赖关系 + List mpRefs = getMpReference(); + //4、查找元数据前处理 + handleMetadataBeforePackage(metadataAndDirPathList, projectPath, packagePath); + //5、查找元数据后处理 + handleMetadataAfterFinding(mpHeader, suInfo, mpRefs); + } + + private void publishPackage() { + Utils.compress(packagePath, fileService.getDirectoryName(packagePath), this.packageName); + //将新建的文件夹删除,只保留生成的元数据包文件 + handleMetadataAfterPackage(packagePath); + } + + private MetadataPackageHeader getMpHeader() { + MetadataPackageHeader mpHeader = new MetadataPackageHeader(); + mpHeader.setName(packageName); + mpHeader.setVersion(packageVersion); + + return mpHeader; + } + + private ServiceUnitInfo getServiceUnitInfo() { + // 获取工程信息 + GspProject gspProject = new GspProjectCoreService().getGspProjectInfo(projectPath); + // 从工程信息中获取服务单元信息 + ServiceUnitInfo suInfo = new ServiceUnitInfo(); + suInfo.setAppCode(gspProject.getAppCode()); + suInfo.setServiceUnitCode(gspProject.getServiceUnitCode()); + + return suInfo; + } + + private List getMpReference() { + String projectFilePath = fileService.getCombinePath(projectPath, projectFileName); + if (!fileService.isFileExist(projectFilePath)) { + return null; + } + List mpReferences = new ArrayList<>(); + FileService service = new FileServiceImp(); + String projStr = null; + try { + projStr = service.fileRead(projectFilePath); + } catch (IOException e) { + e.printStackTrace(); + } + ObjectMapper objectMapper = Utils.getMapper(); + MetadataProject project; + try { + project = objectMapper.readValue(projStr, MetadataProject.class); + } catch (Exception e) { + throw new RuntimeException(e); + } + if (project.getMetadataPackageRefs() == null) { + return null; + } + for (MetadataPackageHeader item : project.getMetadataPackageRefs()) { + MetadataPackageReference mpRefs = new MetadataPackageReference(); + mpRefs.setDepententPackage(new MetadataPackageHeader()); + mpRefs.getDepententPackage().setName(item.getName()); + if (item.getVersion().getVersionString().contains("-")) { + mpRefs.getDepententPackage().setVersion(new MetadataPackageVersion(item.getVersion().getVersionString().substring(0, item.getVersion().getVersionString().indexOf("-")))); + } else { + mpRefs.getDepententPackage().setVersion(new MetadataPackageVersion(item.getVersion())); + } + mpReferences.add(mpRefs); + } + + return mpReferences; + } + + private void handleMetadataBeforePackage(Map hashMap, String projectPath, String packagePath) { + //找到工程下所有的元数据及文件夹列表 + findMdAndDirPathWithinProject(hashMap, projectPath); + //创建临时文件夹 + if (!fileService.isDirectoryExist(packagePath)) { + fileService.createDirectory(packagePath); + } + //拷贝元数据文件到临时路径下 + copyMdFiles(hashMap, projectPath, packagePath); + if (hashMap != null && hashMap.size() > 0) { + for (String item : hashMap.keySet()) { + String relativePath; + if ("File".equals(hashMap.get(item))) { + GspMetadata metadata = new MetadataCoreManager().getMetadataWithoutContent(item); + relativePath = item.replace(projectPath, ""); + metadata.setRelativePath(Utils.handlePath(relativePath)); + if (!metadataList.contains(metadata)) { + metadataList.add(metadata); + } + } + } + } + } + + private void handleMetadataAfterFinding(MetadataPackageHeader mpHeader, ServiceUnitInfo suInfo, + List mpReference) { + MetadataPackage metadataPackage = new MetadataPackage(); + metadataPackage.setHeader(mpHeader); + metadataPackage.setServiceUnitInfo(suInfo); + metadataPackage.setReference(mpReference); + metadataPackage.setMetadataList(new ArrayList<>()); + if (metadataList != null && metadataList.size() > 0) { + metadataList.forEach(item -> metadataPackage.getMetadataList().add(item)); + } + ObjectMapper objectMapper = new ObjectMapper(); + String metadataPackageStr; + try { + metadataPackageStr = objectMapper.writeValueAsString(metadataPackage); + } catch (Exception e) { + throw new RuntimeException(e); + } + String manifestPath = fileService.getCombinePath(packagePath, Utils.getManifestFileName()); + if (!fileService.isFileExist(manifestPath)) { + try { + fileService.createFile(packagePath, Utils.getManifestFileName()); + fileService.fileUpdate(manifestPath, metadataPackageStr); + } catch (Exception e) { + throw new RuntimeException(e); + } + } else { + fileService.fileUpdate(manifestPath, metadataPackageStr); + } + } + + private void findMdAndDirPathWithinProject(Map hashMap, String projectPath) { + + List dirs = fileService.getDirectorys(projectPath); + if (dirs.size() > 0) { + for (File dir : dirs) { + String dirName = fileService.getFileName(handlePath(dir.getPath())); + String temPath = projectPath + File.separator + dirName; + if (!hashMap.containsKey(temPath) && !".git".equals(dirName) && !".vs".equals(dirName) && !"bin".equals(dirName) && !"publish".equals(dirName) && !"obj".equals(dirName) && !"src".equals(dirName)) { + hashMap.put(handlePath(temPath), "Directory"); + findMdAndDirPathWithinProject(hashMap, temPath); + } + } + } + + List paths = fileService.getAllFiles(projectPath); + if (paths.size() > 0) { + boolean isMetadataExisting = false; + for (File path : paths) { + String extension = fileService.getExtension(handlePath(path.getPath())).toLowerCase(); + //TODO 这里需要从配置文件读取元数据后缀类型 + List metadataAllTypes = Utils.getMetadataPostfixTypes(); + boolean flag = false; + for (String item : metadataAllTypes) { + if (item.toLowerCase().equals(extension)) { + flag = true; + break; + } + } + if (flag) { + hashMap.put(handlePath(path.getPath()), "File"); + isMetadataExisting = true; + } + } + if (!isMetadataExisting) { + hashMap.remove(handlePath(projectPath)); + } + } else { + hashMap.remove(handlePath(projectPath)); + } + } + + private void copyMdFiles(Map hashMap, String projectPath, String packagePath) { + //将工程下的元数据文件都拷贝到新建的以程序集名称的文件夹下 + String absolutePath; + String relativePath; + if (hashMap == null || metadataAndDirPathList.size() == 0) { + return; + } + for (String path : metadataAndDirPathList.keySet()) { + relativePath = path.replace(projectPath, "").substring(1); + absolutePath = fileService.getCombinePath(packagePath, relativePath); + if ("Directory".equals(hashMap.get(path))) { + if (!fileService.isDirectoryExist(absolutePath)) { + fileService.createDirectory(absolutePath); + } + } else { + if (fileService.isFileExist(absolutePath)) { + try { + fileService.fileDelete(absolutePath); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + copyMdFiles(path, absolutePath); + } + } + } + + private void copyMdFiles(String sourcePath, String destinationPath) { + try { + fileService.fileCopy(sourcePath, destinationPath); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private void handleMetadataAfterPackage(String path) { + try { + fileService.deleteAllFilesUnderDirectory(path); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public List getLocalPackages(String absolutePath) { + List metadataPackages = new ArrayList<>(); + File[] files = new File(absolutePath).listFiles(pathname -> pathname.getName().endsWith(Utils.getMetadataProjSuffix())); + if (files != null && files.length > 0) { + MetadataCoreManager metadataCoreManager = new MetadataCoreManager(); + for (File file : files) { + metadataPackages.add(metadataCoreManager.getMetadataPackageInfo(file.getName(), file.getParent())); + } + } + return metadataPackages; + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateServiceImp.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateServiceImp.java new file mode 100644 index 0000000..ad633d0 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageGenerateServiceImp.java @@ -0,0 +1,40 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.api.service.PackageGenerateService; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import java.util.List; + +/** + * @author zhaoleitr + */ +public class PackageGenerateServiceImp implements PackageGenerateService { + private PackageGenerateCoreService packageGenerateCoreService = new PackageGenerateCoreService(); + + @Override + public void generatePackage(String path) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + packageGenerateCoreService.generatePackage(absolutePath); + } + + @Override + public List getLocalPackages(String path) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + return packageGenerateCoreService.getLocalPackages(absolutePath); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java new file mode 100644 index 0000000..8b405c4 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java @@ -0,0 +1,273 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core; + +import com.inspur.edp.lcm.metadata.api.entity.DbConnectionInfo; +import com.inspur.edp.lcm.metadata.api.entity.DebugEnvironment; +import com.inspur.edp.lcm.metadata.api.entity.DeploymentContext; +import com.inspur.edp.lcm.metadata.api.entity.ExtractContext; +import com.inspur.edp.lcm.metadata.api.entity.GspProject; +import com.inspur.edp.lcm.metadata.api.entity.MetadataCompilerContext; +import com.inspur.edp.lcm.metadata.api.entity.compiler.MetadataCompilerConfiguration; +import com.inspur.edp.lcm.metadata.api.entity.extract.ExtractConfigration; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.common.compiler.MetadataCompilerHelper; +import com.inspur.edp.lcm.metadata.common.deployer.DeploymentHelper; +import com.inspur.edp.lcm.metadata.common.extractor.ExtractHelper; +import com.inspur.edp.lcm.metadata.common.util.CommandUtil; +import com.inspur.edp.lcm.metadata.core.thread.ProcessRunnable; +import com.inspur.edp.lcm.metadata.spi.ExtractAction; +import com.inspur.edp.lcm.metadata.spi.MetadataCompileAction; +import com.inspur.edp.lcm.project.deployer.spi.DeployAction; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import io.iec.edp.caf.sumgr.core.ServiceUnitFactory; +import java.io.File; +import java.io.IOException; +import java.net.URLDecoder; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.stream.Collectors; +import sun.misc.BASE64Decoder; + +/** + * @author zhaoleitr + */ +public class ProjectExtendCoreService { + private final FileServiceImp fileService = new FileServiceImp(); + private final MetadataProjectCoreService metadataProjectCoreService = new MetadataProjectCoreService(); + private final GspProjectCoreService gspProjectCoreService = new GspProjectCoreService(); + + public String getDeployStatus(String sign) throws IOException { + BASE64Decoder decoder = new BASE64Decoder(); + byte[] bytes = decoder.decodeBuffer(sign); + String urlEncodeSign = new String(bytes); + String fileName = URLDecoder.decode(urlEncodeSign, "utf8"); + String status = ""; + if (fileService.isFileExist(fileName)) { + status = fileService.fileRead(fileName); + switch (status) { + case "success": + case "fail": + fileService.fileDelete(fileName); + break; + default: + break; + } + } + return status; + } + + public void extract(String absolutePath) { + List projPaths = new ArrayList<>(); + if (absolutePath.endsWith(Utils.getMetadataProjPath())) { + absolutePath = new File(absolutePath).getParent(); + } + metadataProjectCoreService.getProjPathsInPath(absolutePath, projPaths); + for (String projPath : projPaths) { + GspProject gspProjectInfo = gspProjectCoreService.getGspProjectInfo(projPath); + ExtractContext extractContext = new ExtractContext(); + extractContext.setProjectPath(projPath); + extractContext.setDeployPath(gspProjectInfo.getSuDeploymentPath()); + doExtract(extractContext); + } + } + + private void doExtract(ExtractContext extractContext) { + // 文件清理 + clearPublishDir(extractContext); + // 组织上下文 + buildExtractContext(extractContext); + // 各类型提取扩展 + List extractConfigrationList = ExtractHelper.getInstance().getExtractConfigrationList(); + extractConfigrationList.forEach(item -> { + if (item.isEnable()) { + if (extractContext.getDeployType() != null && ("WEB").equals(item.getTypeCode()) && !"all".equals(extractContext.getDeployType()) && !extractContext.getDeployType().contains("web")) { + return; + } + ExtractAction extractAction = ExtractHelper.getInstance().getManager(item.getTypeCode()); + if (extractAction == null) { + throw new RuntimeException("未能获取到" + item.getTypeCode() + "的提取器,请确认配置是否正确"); + } + extractAction.extract(extractContext); + } + }); + } + + private void buildExtractContext(ExtractContext context) { + String publishPath = Paths.get(context.getProjectPath()).resolve(Utils.getPublishPath()).toString(); + String deployPath = Paths.get(publishPath).resolve(Utils.getJstackPath()).resolve(context.getDeployPath().toLowerCase()).toString(); + context.setDeployPath(deployPath); + } + + private void clearPublishDir(ExtractContext extractContext) { + String publishPath = Paths.get(extractContext.getProjectPath()).resolve(Utils.getPublishPath()).toString(); + File file = new File(publishPath); + if (!file.exists()) { + file.mkdir(); + } + try { + fileService.cleanDirectory(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void deploy(DbConnectionInfo dBConnectionInfo, String serverPath, String projPath, String restart) { + serverPath = serverPath == null || serverPath.isEmpty() ? Utils.getBasePath() : serverPath; + + beforeDeploy(serverPath, projPath); + + String args = handleArgs(dBConnectionInfo, serverPath, projPath, restart); + String currentServerPath = Paths.get(Utils.getBasePath()).resolve("tools/deploy/project_java/runtime").toString(); + String javaHome = CommandUtil.getJavaHome(false); + String javaCmd = javaHome == "" ? "java" : javaHome + "/java"; + String serverRuntimePathName = EnvironmentUtil.getServerRuntimePathName(); + String command = javaCmd + " -server \"-Dloader.path=libs,3rd\" \"-Dserver.runtime.path.name=" + serverRuntimePathName + "\" \"-Dspring.config.location=../config/application.yaml\" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n -jar lcm-project-deploy-tool.jar" + args; + if ("0".equals(restart)) { + newProcessRunnable(currentServerPath, command); + } else { + CommandUtil.newProcess(currentServerPath, command); + } + } + + private void beforeDeploy(String serverPath, String projPath) { + if (!suFileExists(serverPath, projPath)) { + generateSuFile(serverPath, projPath); + } + } + + private boolean suFileExists(String serverPath, String projPath) { + GspProject gspProjectInfo = gspProjectCoreService.getGspProjectInfo(projPath); + String serverLink = new File(FileServiceImp.combinePath(serverPath, "jstack")).exists() ? "jstack" : "server"; + String destDir = FileServiceImp.combinePath(serverPath, serverLink, "apps", gspProjectInfo.getAppCode().toLowerCase(), gspProjectInfo.getServiceUnitCode().toLowerCase()); + File file = new File(destDir); + file.mkdirs(); + Boolean existsFlag = ServiceUnitFactory.createGenerator().exists(file); + return existsFlag; + } + + private void generateSuFile(String serverPath, String projPath) { + GspProject gspProjectInfo = gspProjectCoreService.getGspProjectInfo(projPath); + io.iec.edp.caf.sumgr.api.entity.ServiceUnitInfo serviceUnitInfo = new io.iec.edp.caf.sumgr.api.entity.ServiceUnitInfo(); + serviceUnitInfo.setApplicationName(gspProjectInfo.getAppCode()); + serviceUnitInfo.setName(gspProjectInfo.getServiceUnitCode()); + String serverLink = new File(FileServiceImp.combinePath(serverPath, "jstack")).exists() ? "jstack" : "server"; + String destDir = FileServiceImp.combinePath(serverPath, serverLink, "apps", gspProjectInfo.getAppCode().toLowerCase(), gspProjectInfo.getServiceUnitCode().toLowerCase()); + File file = new File(destDir); + ServiceUnitFactory.createGenerator().generate(serviceUnitInfo, file); + } + + private void newProcessRunnable(String serverPath, String command) { + ProcessRunnable processRunnable = new ProcessRunnable(); + processRunnable.setServerPath(serverPath); + processRunnable.setCommand(command); + ExecutorService executor = Executors.newCachedThreadPool(); + executor.submit(processRunnable::run); + } + + private String handleArgs(DbConnectionInfo dbConnectionInfo, String serverPath, String projPath, String restart) { + StringBuilder stringBuilder = new StringBuilder(); + String publishPath = Paths.get(metadataProjectCoreService.getProjPath(projPath)).resolve(Utils.getPublishPath()).toString(); + appendArg(stringBuilder, publishPath); + appendArg(stringBuilder, serverPath); + appendArg(stringBuilder, dbConnectionInfo.getDbServerIP()); + appendArg(stringBuilder, dbConnectionInfo.getDbPort()); + appendArg(stringBuilder, dbConnectionInfo.getDbName()); + appendArg(stringBuilder, dbConnectionInfo.getDbUserName()); + appendArg(stringBuilder, dbConnectionInfo.getDbPassword()); + appendArg(stringBuilder, String.valueOf(dbConnectionInfo.getDbType().ordinal())); + appendArg(stringBuilder, restart); + + if (restart.equals("0")) { + int currentPid = CommandUtil.getCurrentPid(); + appendArg(stringBuilder, String.valueOf(currentPid)); + } + + return stringBuilder.toString(); + } + + private void appendArg(StringBuilder stringBuilder, String arg) { + stringBuilder.append(" \""); + stringBuilder.append(arg); + stringBuilder.append("\""); + } + + public void migration(String absolutePath) { + DeploymentContext context = new DeploymentContext(); + String publishPath = Paths.get(metadataProjectCoreService.getProjPath(absolutePath)).resolve(Utils.getPublishPath()).toString(); + context.setPublishPath(publishPath); + DebugEnvironment debugEnvironment = new DebugEnvironment(); + debugEnvironment.setServerPath(Utils.getBasePath()); + context.setDebugEnvironment(debugEnvironment); + DeployAction baseMigration = DeploymentHelper.getInstance().getManager("BaseMigration"); + if (baseMigration == null) { + throw new RuntimeException("未能获取到BaseMigration的部署器,请确认配置是否正确"); + } + baseMigration.deploy(context); + } + + public List batchCompile(String absolutePath, String exts, String disabledExts, String packagePath) { + List projPaths = new ArrayList<>(); + if (absolutePath.contains(",")) { + projPaths = Arrays.asList(absolutePath.split(",")); + } else { + if (absolutePath.endsWith(Utils.getMetadataProjPath())) { + absolutePath = new File(absolutePath).getParent(); + } + metadataProjectCoreService.getProjPathsInPath(absolutePath, projPaths); + } + + List extsList = exts.isEmpty() ? new ArrayList<>() : Arrays.asList(exts.split(",")); + List disabledExtsList = disabledExts.isEmpty() ? new ArrayList<>() : Arrays.asList(disabledExts.split(",")); + + for (String projPath : projPaths) { + System.out.println("正在编译:" + projPath); + String projectMetadataPath = Paths.get(projPath).resolve(Utils.getMetadataProjPath()).toString(); + MetadataCompilerContext metadataCompilerContext = new MetadataCompilerContext(); + metadataCompilerContext.setProjectPath(projectMetadataPath); + compile(metadataCompilerContext, extsList, disabledExtsList); + System.out.println("编译完成:" + projPath); + } + + return null; + } + + private void compile(MetadataCompilerContext metadataCompilerContext, List extsList, + List disabledExtsList) { + List compileConfigrationList = MetadataCompilerHelper.getInstance().getCompileConfigrationList(); + if (extsList != null && extsList.size() > 0) { + compileConfigrationList = compileConfigrationList.stream().filter(config -> extsList.contains(config.getTypeCode())).collect(Collectors.toList()); + } + if (disabledExtsList != null && disabledExtsList.size() > 0) { + compileConfigrationList = compileConfigrationList.stream().filter(config -> !disabledExtsList.contains(config.getTypeCode())).collect(Collectors.toList()); + } + for (MetadataCompilerConfiguration item : compileConfigrationList) { + if (item.getEnable()) { + MetadataCompileAction manager = MetadataCompilerHelper.getInstance().getManager(item.getTypeCode()); + if (manager != null) { + manager.metadataCompile(metadataCompilerContext); + } else { + System.out.println(item.getTypeCode() + "无法获取类"); + } + } + } + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendServiceImp.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendServiceImp.java new file mode 100644 index 0000000..acae329 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendServiceImp.java @@ -0,0 +1,55 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core; + +import com.inspur.edp.lcm.metadata.api.entity.DbConnectionInfo; +import com.inspur.edp.lcm.metadata.api.service.ProjectExtendService; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import java.util.List; + +public class ProjectExtendServiceImp implements ProjectExtendService { + private final ProjectExtendCoreService projectExtendCoreService = new ProjectExtendCoreService(); + + @Override + public void deploy(DbConnectionInfo dBConnectionInfo, String serverPath, String projPath, String restart) { + String absolutePath = ManagerUtils.getAbsolutePath(projPath); + projectExtendCoreService.deploy(dBConnectionInfo, serverPath, absolutePath, restart); + } + + @Override + public void extract(String path) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + projectExtendCoreService.extract(absolutePath); + } + + @Override + public void migration(String path) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + projectExtendCoreService.migration(absolutePath); + } + + @Override + public String getDeployStatus(String sign) { + return null; + } + + @Override + public List batchCompile(String path, String exts, String disabledExts) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String packagePath = ManagerUtils.getMetadataPackageLocation(); + return projectExtendCoreService.batchCompile(absolutePath, exts, disabledExts, packagePath); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/CoreServiceConfiguration.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/CoreServiceConfiguration.java new file mode 100644 index 0000000..ec7e9dd --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/CoreServiceConfiguration.java @@ -0,0 +1,55 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core.config; + +import com.inspur.edp.lcm.metadata.core.event.DirEventBroker; +import com.inspur.edp.lcm.metadata.core.event.MetadataCreateEventBroker; +import com.inspur.edp.lcm.metadata.core.event.MetadataEventBroker; +import io.iec.edp.caf.commons.event.config.EventListenerSettings; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Classname ServiceConfiguration Description TODO Date 2019/11/9 15:40 + * + * @author zhongchq + * @version 1.0 + */ +//todo +//@Configuration(proxyBeanMethods = false) +@Configuration() +public class CoreServiceConfiguration { + private EventListenerSettings settings; + + public CoreServiceConfiguration(EventListenerSettings settings) { + this.settings = settings; + } + + @Bean + public MetadataEventBroker metadataEventBroker() { + return new MetadataEventBroker(settings); + } + + @Bean + public MetadataCreateEventBroker metadataCreateEventBroker() { + return new MetadataCreateEventBroker(settings); + } + + @Bean + public DirEventBroker dirEventBroker() { + return new DirEventBroker(settings); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java new file mode 100644 index 0000000..fde9144 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java @@ -0,0 +1,66 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core.config; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.inspur.edp.lcm.metadata.api.mvnEntity.JitRuntimeConfigration; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import java.io.IOException; +import java.nio.file.Paths; +import lombok.Getter; +import lombok.Setter; + +public class JitRuntimeConfigLoader { + + private static final String sectionName = "JitRuntimeConfigration"; + @Getter + @Setter + static JitRuntimeConfigration jitRuntimeConfigration; + private static String fileName = "config/platform/common/lcm_gspprojectextend.json"; + + public JitRuntimeConfigLoader() { + } + + protected JitRuntimeConfigration getJitRuntimeConfigration() { + + fileName = Paths.get(EnvironmentUtil.getServerRTPath()).resolve(fileName).toString(); + + try { + if (jitRuntimeConfigration == null) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + FileServiceImp fileService = new FileServiceImp(); + String fileContents = fileService.fileRead(fileName); + JsonNode jsonNode = objectMapper.readTree(fileContents); + String jitRuntimeConfigrationJson = jsonNode.findValue(sectionName).toString(); + jitRuntimeConfigration = objectMapper.readValue(jitRuntimeConfigrationJson, new TypeReference() { + }); + return jitRuntimeConfigration; + } else { + return jitRuntimeConfigration; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java new file mode 100644 index 0000000..16aec0f --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java @@ -0,0 +1,58 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core.config; + +import com.inspur.edp.lcm.metadata.api.mvnEntity.JitRuntimeConfigration; +import com.inspur.edp.lcm.metadata.spi.JitRuntimeAction; + +/** + * @Classname JitCompilerHelper + * @Description TODO + * @Date 2019/7/29 16:06 + * @Created by zhongchq + * @Version 1.0 + */ +public class JitRuntimeHelper extends JitRuntimeConfigLoader { + + private static JitRuntimeHelper singleton = null; + + public JitRuntimeHelper() { + } + + public static JitRuntimeHelper getInstance() { + if (singleton == null) { + singleton = new JitRuntimeHelper(); + } + return singleton; + } + + public JitRuntimeAction getManager() { + JitRuntimeAction manager = null; + JitRuntimeConfigration data = getJitRuntimeConfigration(); + if (data != null && data.getEnable() == true) { + Class cls = null; + if (data.getAction() != null) { + try { + cls = Class.forName(data.getAction().getName()); + manager = (JitRuntimeAction) cls.newInstance(); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + return manager; + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/ServiceConfiguration.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/ServiceConfiguration.java new file mode 100644 index 0000000..29524ce --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/ServiceConfiguration.java @@ -0,0 +1,73 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core.config; + +import com.inspur.edp.lcm.metadata.api.service.GspProjectService; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.api.service.MetadataService; +import com.inspur.edp.lcm.metadata.api.service.PackageGenerateService; +import com.inspur.edp.lcm.metadata.api.service.ProjectExtendService; +import com.inspur.edp.lcm.metadata.api.service.RefCommonService; +import com.inspur.edp.lcm.metadata.core.GspProjectServiceImp; +import com.inspur.edp.lcm.metadata.core.MetadataProjectServiceImp; +import com.inspur.edp.lcm.metadata.core.MetadataServiceImp; +import com.inspur.edp.lcm.metadata.core.PackageGenerateServiceImp; +import com.inspur.edp.lcm.metadata.core.ProjectExtendServiceImp; +import com.inspur.edp.lcm.metadata.core.RefCommonServiceImp; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Classname ServiceConfiguration + * @Description 配置类 + * @Date 2019/7/26 14:55 + * @Created by liu_bintr + * @Version 1.0 + */ +//todo +//@Configuration(proxyBeanMethods = false) +@Configuration() +public class ServiceConfiguration { + @Bean + public MetadataService createMetadataService() { + return new MetadataServiceImp(); + } + + @Bean + public GspProjectService createGspProjectService() { + return new GspProjectServiceImp(); + } + + @Bean + public MetadataProjectService createMetadataProjectService() { + return new MetadataProjectServiceImp(); + } + + @Bean + public RefCommonService createRefService() { + return new RefCommonServiceImp(); + } + + @Bean + public PackageGenerateService createPackageGenerateService() { + return new PackageGenerateServiceImp(); + } + + @Bean + public ProjectExtendService createProjectExtendService() { + return new ProjectExtendServiceImp(); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/thread/ProcessRunnable.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/thread/ProcessRunnable.java new file mode 100644 index 0000000..c509827 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/thread/ProcessRunnable.java @@ -0,0 +1,36 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.core.thread; + +import com.inspur.edp.lcm.metadata.common.util.CommandUtil; + +public class ProcessRunnable implements Runnable { + private String serverPath; + private String command; + + public void setServerPath(String serverPath) { + this.serverPath = serverPath; + } + + public void setCommand(String command) { + this.command = command; + } + + @Override + public void run() { + CommandUtil.newProcess(serverPath, command); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/DeployActionImpl.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/DeployActionImpl.java new file mode 100644 index 0000000..e5e706a --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/DeployActionImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.extend.action; + +import com.inspur.edp.lcm.metadata.api.entity.DeploymentContext; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.project.deployer.spi.DeployAction; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.File; +import java.nio.file.Paths; + +public class DeployActionImpl implements DeployAction { + @Override + public void deploy(DeploymentContext context) { + File publishFile = new File(context.getPublishPath()); + FileService fileService = SpringBeanUtils.getBean(FileService.class); + File[] files = publishFile.listFiles(); + for (File file : files) { + if (file.getName().equals("jstack")) { + String serverRtPath = Paths.get(context.getDebugEnvironment().getServerPath(), "server").toString(); + if (fileService.isDirectoryExist(serverRtPath)) { + fileService.folderCopy(file.getPath(), serverRtPath); + } else { + fileService.folderCopy(file.getPath(), Paths.get(context.getDebugEnvironment().getServerPath(), file.getName()).toString()); + } + } else { + fileService.folderCopy(file.getPath(), Paths.get(context.getDebugEnvironment().getServerPath(), file.getName()).toString()); + } + } + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java new file mode 100644 index 0000000..d5af8be --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java @@ -0,0 +1,110 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.extend.action; + +import com.inspur.edp.lcm.metadata.api.entity.ExtractContext; +import com.inspur.edp.lcm.metadata.api.entity.ProcessMode; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.spi.ExtractAction; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + +public class ExtractActionImpl implements ExtractAction { + @Override + public void extract(ExtractContext context) { + // 提取元数据包 + extractMdpkg(context); + + if (context.getDeployType() != null && !"all".equals(context.getDeployType()) && !context.getDeployType().contains("jar")) { + return; + } + + // 提取java交付物 + extractJavaProduct(context); + } + + private void extractJavaProduct(ExtractContext context) { + + String javaCodePath = Paths.get(context.getProjectPath()).resolve(Utils.getJavaProjectPath()).resolve(Utils.getCodePath()).toString(); + String deployPath = Paths.get(context.getDeployPath()).resolve(Utils.getLibsPath()).toString(); + + MetadataProjectService metadataProjectService = SpringBeanUtils.getBean(MetadataProjectService.class); + ProcessMode processMode = metadataProjectService.getProcessMode(context.getProjectPath()); + if (ProcessMode.GENERATION.equals(processMode)) { + copyJar(javaCodePath, "api", deployPath); + copyJar(javaCodePath, "core", deployPath); + } + + copyJar(javaCodePath, "comp", deployPath); + } + + private void copyJar(String javaCodePath, String module, String deployPath) { + FileService fileService = SpringBeanUtils.getBean(FileService.class); + String moduleJarPath = getJarPath(javaCodePath, module); + if (moduleJarPath.isEmpty()) { + return; + } + String destPath = Paths.get(deployPath).resolve(new File(moduleJarPath).getName()).toString(); + fileService.createDirectory(deployPath); + try { + fileService.fileCopy(moduleJarPath, destPath); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private String getJarPath(String javaCodePath, String module) { + String targetPath = Paths.get(javaCodePath).resolve(module).resolve(Utils.getTargetPath()).toString(); + File file = new File(targetPath); + if (file.exists()) { + File[] files = file.listFiles((dir, name) -> name.endsWith(Utils.getJarSuffix())); + if (files.length > 0) { + return files[0].getPath(); + } + } + System.out.println("无" + module + "jar包。"); + return ""; + } + + private void extractMdpkg(ExtractContext context) { + String binPath = Paths.get(context.getProjectPath()).resolve(Utils.getMetadataProjPath()).resolve(Utils.getMetadataBinPath()).toString(); + File binFile = new File(binPath); + String sourcePath = ""; + if (binFile.exists()) { + File[] files = binFile.listFiles((dir, name) -> name.endsWith(Utils.getMetadataPackageExtension())); + if (files.length > 0) { + sourcePath = files[0].getPath(); + } + } + if (sourcePath.isEmpty()) { + throw new RuntimeException("元数据包不存在,请先生成元数据包:" + context.getProjectPath()); + } + String targetDir = FileServiceImp.combinePath(context.getDeployPath().replace("publish\\jstack\\apps", "publish\\metadata\\apps").replace("publish/jstack/apps", "publish/metadata/apps"), "metadata"); + String targetPath = FileServiceImp.combinePath(targetDir, new File(sourcePath).getName()); + FileService fileService = SpringBeanUtils.getBean(FileService.class); + fileService.createDirectory(targetDir); + try { + fileService.fileCopy(sourcePath, targetPath); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/MetadataCompileActionImpl.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/MetadataCompileActionImpl.java new file mode 100644 index 0000000..c0d5f13 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/MetadataCompileActionImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.extend.action; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataCompilerContext; +import com.inspur.edp.lcm.metadata.api.service.PackageGenerateService; +import com.inspur.edp.lcm.metadata.spi.MetadataCompileAction; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; + +public class MetadataCompileActionImpl implements MetadataCompileAction { + @Override + public void metadataCompile(MetadataCompilerContext context) { + PackageGenerateService packageGenerateService = SpringBeanUtils.getBean(PackageGenerateService.class); + packageGenerateService.generatePackage(context.getProjectPath()); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MavenUtilsImp.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MavenUtilsImp.java new file mode 100644 index 0000000..78fb424 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MavenUtilsImp.java @@ -0,0 +1,45 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.ref; + +import com.inspur.edp.lcm.metadata.api.service.MavenUtilsService; +import com.inspur.edp.lcm.metadata.core.MavenUtilsCore; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import lombok.extern.slf4j.Slf4j; + +/** + * Classname MavenUtils Description mvn操作工具类 Date 2019/12/9 9:49 + * + * @author zhongchq + * @version 1.0 + */ +@Slf4j +public class MavenUtilsImp implements MavenUtilsService { + + @Override + public boolean exeMavenCommand(String javaCodePath, String goal) { + + String mavenPath = ManagerUtils.getMavenStoragePath(); + MavenUtilsCore mavenUtilsCore = new MavenUtilsCore(); + return mavenUtilsCore.exeMavenCommand(javaCodePath, mavenPath, goal); + } + + @Override + public String getLocalRepository() { + MavenUtilsCore mavenUtilsCore = new MavenUtilsCore(); + return mavenUtilsCore.getLocalRepository(); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java new file mode 100644 index 0000000..f31dc01 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java @@ -0,0 +1,181 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.ref; + +import com.inspur.edp.lcm.metadata.api.entity.ProcessMode; +import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenComponents; +import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenPackageRefs; +import com.inspur.edp.lcm.metadata.api.mvnEntity.MetadataRepo; +import com.inspur.edp.lcm.metadata.api.service.MdpkgService; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.core.PackageCoreService; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.IOException; +import java.util.List; +import lombok.extern.slf4j.Slf4j; + +/** + * 元数据服务 + */ +@Slf4j +public class MdpkgServiceImp implements MdpkgService { + + private MetadataProjectService metadataProjectService; + + private MetadataProjectService getMetadataProjectService() { + if (metadataProjectService == null) { + metadataProjectService = SpringBeanUtils.getBean(MetadataProjectService.class); + } + return metadataProjectService; + } + + private PackageCoreService packageCoreService = new PackageCoreService(); + + /** + * @param path 路径 + * @param modules 模块 + */ + @Override + public void compile(String path, String modules) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + packageCoreService.compile(absolutePath, modules, mavenPath); + } + + @Override + public void compileAll(String path) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + packageCoreService.compile(absolutePath, "all", mavenPath); + } + + @Override + public void restore(String path, Boolean force) { + if (Utils.isNullOrEmpty(path)) { + throw new IllegalArgumentException("工程路径不能为空"); + } + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + String packagePath = ManagerUtils.getMetadataPackageLocation(); + packageCoreService.restore(absolutePath, force, mavenPath, packagePath); + } + + @Override + public void addDepedencyAndRestore(String path, List metadataPackages) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + String packagePath = ManagerUtils.getMetadataPackageLocation(); + packageCoreService.addDependencyAndRestore(absolutePath, metadataPackages, mavenPath, packagePath); + } + + @Override + public void deployReleaseMdVersion(String path, String version, String repoId, boolean revert, + String dependenciesVersion) throws IOException { + Utils.checkEmpty(path, "工程路径不能为空"); + Utils.checkEmpty(path, "version不能为空"); + String absolutePath = ManagerUtils.getAbsolutePath(path); + String projPath = getMetadataProjectService().getProjPath(absolutePath); + String mavenPath = ManagerUtils.getMavenStoragePath(); + final ProcessMode processMode = getMetadataProjectService().getProcessMode(projPath); + switch (processMode.toString()) { + case "interpretation": + packageCoreService.deployMdpkgForInterpretation(projPath, repoId, version, dependenciesVersion, mavenPath); + break; + default: + packageCoreService.deployReleaseMdVersion(projPath, version, repoId, revert, dependenciesVersion, mavenPath); + } + } + + @Override + public void deploySnapshotMdVersion(String path, String repoId, String version, boolean revert) { + Utils.checkEmpty(path, "工程路径不能为空"); + Utils.checkEmpty(path, "version不能为空"); + String absolutePath = ManagerUtils.getAbsolutePath(path); + String projPath = getMetadataProjectService().getProjPath(absolutePath); + String mavenPath = ManagerUtils.getMavenStoragePath(); + + final ProcessMode processMode = getMetadataProjectService().getProcessMode(projPath); + switch (processMode.toString()) { + case "interpretation": + packageCoreService.deployMdpkgForInterpretation(projPath, repoId, version, null, mavenPath); + break; + default: + packageCoreService.deploySnapshotMdVersion(projPath, repoId, version, revert, mavenPath); + } + } + + @Override + public void installMdpkg(String groupId, String artifactId, String version, String proPath, + Boolean forceUpdateFlag) throws IOException { + // 创建pom文件,对应的mdproj添加依赖信息 + String absolutePath = ManagerUtils.getAbsolutePath(proPath); + String mavenPath = ManagerUtils.getMavenStoragePath(); + String packagePath = ManagerUtils.getMetadataPackageLocation(); + packageCoreService.installMdpkg(groupId, artifactId, version, absolutePath, forceUpdateFlag, mavenPath, packagePath); + } + + @Override + public void uninstallMdpkg(String projPath, String packName) { + String absolutePath = ManagerUtils.getAbsolutePath(projPath); + String mavenPath = ManagerUtils.getMavenStoragePath(); + packageCoreService.uninstallMdpkg(absolutePath, packName, mavenPath); + } + + @Override + public void addProjectDependency(String pomp_ath, String groupId, String artifactId, String version) { + packageCoreService.addProjectDependency(pomp_ath, groupId, artifactId, version); + } + + @Override + public void deployMdpkg(String proPath, String repoId, String dependencyVersion) { + proPath = getMetadataProjectService().getProjPath(proPath); + String mavenPath = ManagerUtils.getMavenStoragePath(); + packageCoreService.deployMdpkg(proPath, repoId, dependencyVersion, mavenPath); + } + + @Override + public MetadataRepo getRepoList() { + return packageCoreService.getHostedRepoList(); + } + + @Override + public String getMavenPackageLatestVersion(String groupId, String artifactId) { + return packageCoreService.getMavenPackageLatestVersion(groupId, artifactId); + } + + @Override + public MavenPackageRefs getGAByMdpkgName(String mdpkgName) { + return packageCoreService.getGAByMdpkgName(mdpkgName); + } + + @Override + public MavenComponents getVersionsOfSinglePackage(String sourceId, String packName) { + MetadataRepo metadataRepo = getRepoList(); + return metadataRepo.getRepoList().stream().filter(repo -> repo.getId().equals(sourceId)) + .findFirst() + .map(repo -> packageCoreService.getVersionsOfSinglePackage(repo.getSourceUrl(), packName)) + .orElse(null); + } + + @Override + public void batchOperate(String path, List operations) { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + packageCoreService.batchOperation(absolutePath, mavenPath, operations); + } +} diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/config/RefConfiguration.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/config/RefConfiguration.java new file mode 100644 index 0000000..50ffd26 --- /dev/null +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/config/RefConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.ref.config; + +import com.inspur.edp.lcm.metadata.api.service.MavenUtilsService; +import com.inspur.edp.lcm.metadata.api.service.MdpkgService; +import com.inspur.edp.lcm.metadata.ref.MavenUtilsImp; +import com.inspur.edp.lcm.metadata.ref.MdpkgServiceImp; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Classname RefConfiguration Description ref配置类 Date 2019/11/28 10:34 + * + * @author zhongchq + * @version 1.0 + */ +//todo +//@Configuration(proxyBeanMethods = false) +@Configuration() +public class RefConfiguration { + @Bean + public MdpkgService createMdpkgService() { + return new MdpkgServiceImp(); + } + + @Bean + public MavenUtilsService createMavenUtilsService() { + return new MavenUtilsImp(); + } +} diff --git a/model/framework/devtime-webapi/pom.xml b/model/framework/devtime-webapi/pom.xml new file mode 100644 index 0000000..0aaf73f --- /dev/null +++ b/model/framework/devtime-webapi/pom.xml @@ -0,0 +1,37 @@ + + + + ubml-model-framework + org.openatom.ubml + 0.9.0-SNAPSHOT + + 4.0.0 + ubml-model-framework-devtime-webapi ${project.version} + ubml-model-framework-devtime-webappi + + + + io.iec.edp + caf-boot-starter-rest-server + + + + org.openatom.ubml + ubml-model-framework-common + ${project.version} + + + lcm-metadata-api + com.inspur.edp + + + + + + + 8 + 8 + + \ No newline at end of file diff --git a/model/framework/devtime-webapi/src/main/java/webapi/FileSystemWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/FileSystemWebApi.java new file mode 100644 index 0000000..da2a8a1 --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/FileSystemWebApi.java @@ -0,0 +1,42 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.file.system.FileSystemServiceImp; +import com.inspur.edp.lcm.metadata.api.service.FileSystemService; +import java.io.IOException; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +/** + * @author zhaoleitr + */ +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class FileSystemWebApi { + + FileSystemService fileSystemService = new FileSystemServiceImp(); + + @GET + public void showInExplorer(@QueryParam(value = "path") String path) throws IOException { + fileSystemService.showInExplorer(path); + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/GspProjectServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/GspProjectServiceWebApi.java new file mode 100644 index 0000000..e8af26d --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/GspProjectServiceWebApi.java @@ -0,0 +1,78 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.ConfigData.gspproject.ProjectConfiguration; +import com.inspur.edp.lcm.metadata.api.entity.GspProject; +import com.inspur.edp.lcm.metadata.api.service.GspProjectService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.IOException; +import java.util.List; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +public class GspProjectServiceWebApi { + private GspProjectService gspProjectService; + + private GspProjectService getGspProjectService() { + if (gspProjectService == null) { + gspProjectService = SpringBeanUtils.getBean(GspProjectService.class); + } + return gspProjectService; + } + + /** + * 获取工程信息(GSPProject.json的信息) + * + * @param path 工程路径 + * @return 工程路径 + * @throws IOException + */ + @GET + public GspProject getGspProjectInfo(@QueryParam(value = "path") String path) throws IOException { + return getGspProjectService().getGspProjectInfo(path); + } + + /** + * 获取工程类型 + * + * @return + */ + @GET + @Path("/type") + public List getGspProjectTypeInfo() { + return getGspProjectService().getGspProjectTypeInfo(); + } + + /** + * 更新工程基础技术栈 + * + * @param path 工程路径 + * @param codeLanguage 技术栈 + * @Description 暂时不用 + */ + @PUT + public void updateGspProject(@QueryParam(value = "path") String path, + @QueryParam(value = "codeLanguage") String codeLanguage) { + return; + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/MdServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/MdServiceWebApi.java new file mode 100644 index 0000000..5de73be --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/MdServiceWebApi.java @@ -0,0 +1,378 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.lcm.metadata.api.IMdExtRuleContent; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataIndexItemDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; +import com.inspur.edp.lcm.metadata.api.entity.MetadataType; +import com.inspur.edp.lcm.metadata.api.entity.Page; +import com.inspur.edp.lcm.metadata.api.entity.ProcessMode; +import com.inspur.edp.lcm.metadata.api.entity.metadataindex.MetadataIndexDto; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.api.service.MetadataService; +import com.inspur.edp.lcm.metadata.api.service.PackageGenerateService; +import com.inspur.edp.lcm.metadata.api.service.RefCommonService; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.common.configuration.MdExtRuleSerializerHelper; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import com.inspur.edp.lcm.metadata.spi.MdExtendRuleSerializer; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +public class MdServiceWebApi { + private MetadataService metadataService; + + private MetadataService getMetadataService() { + if (metadataService == null) { + metadataService = SpringBeanUtils.getBean(MetadataService.class); + } + return metadataService; + } + + private MetadataProjectService metadataProjectService; + + private MetadataProjectService getMetadataProjectService() { + if (metadataProjectService == null) { + metadataProjectService = SpringBeanUtils.getBean(MetadataProjectService.class); + } + return metadataProjectService; + } + + private RefCommonService refCommonService; + + private RefCommonService getRefCommonService() { + if (refCommonService == null) { + refCommonService = SpringBeanUtils.getBean(RefCommonService.class); + } + return refCommonService; + } + + PackageGenerateService packService; + + private PackageGenerateService getPackService() { + if (packService == null) { + packService = SpringBeanUtils.getBean(PackageGenerateService.class); + } + return packService; + } + + /** + * @param spacePath 元数据路径 + * @param metadataTypeList 元数据类型 + * @return java.util.List + * @author zhongchq + **/ + @GET + public List getMetadataList(@QueryParam(value = "path") String spacePath, + @QueryParam(value = "metadataTypeList") String metadataTypeList) { + List result = getMetadataService().getMetadataList(spacePath, handleMetadataTypeList(metadataTypeList)); + + String projPath = getMetadataProjectService().getProjPath(spacePath); + ProcessMode processMode = ProcessMode.GENERATION; + if (projPath != null && !projPath.isEmpty()) { + processMode = getMetadataProjectService().getProcessMode(projPath); + } + List metadataDtos = asMdDtos(result, processMode); + metadataDtos.forEach(dto -> dto.setRelativePath(ManagerUtils.getRalativePath(dto.getRelativePath()))); + return metadataDtos; + } + + /** + * 根据当前工程路径获取bo下的元数据列表(会根据processMode过滤) + * + * @param path + * @param metadataTypeList + * @return List + */ + @GET + @Path(value = "/metadataListInBo") + public List getMetadataListInBo(@QueryParam(value = "path") String path, + @QueryParam(value = "metadataTypeList") String metadataTypeList) { + List result = getMetadataService().getMetadataListInBo(path, handleMetadataTypeList(metadataTypeList)); + result.forEach(dto -> dto.setRelativePath(ManagerUtils.getRalativePath(dto.getRelativePath()))); + return result; + } + + /*** + * @author zhongchq + * @param metadataPath + * 元数据所在路径信息,当前工程下的某个路径,相对路径 + * @param metadataID + *元数据唯一标识 + * @return com.inspur.edp.lcm.metadata.api.entity.MetadataDto + **/ + @GET + @Path(value = "/relied") + public MetadataDto getRefMetadata(@QueryParam(value = "metadataPath") String metadataPath, + @QueryParam(value = "metadataID") String metadataID) { + Utils.setMetadataPath(metadataPath); + return MetadataDtoConverter.asDto(getRefCommonService().getRefMetadata(metadataID)); + } + + /** + * 获取各元数据配置的元数据类型信息及后缀信息 + * + * @return java.util.List + * @author zhongchq + **/ + @GET + @Path(value = "/typeList") + public List getMetadataTypeList() { + return getMetadataService().getMetadataTypeList(); + } + + /** + * @param projectPath 获取工程信息 + * @return com.inspur.edp.lcm.metadata.api.entity.MetadataProject + * @author zhongchq + **/ + @GET + @Path(value = "/projectInfo") + public MetadataProject getMetadataProjInfo(@QueryParam(value = "projectPath") String projectPath) { + if (projectPath == null || projectPath.isEmpty()) { + throw new IllegalArgumentException("projectPath参数不能为空"); + } + return getMetadataService().getMetadataProjInfo(projectPath); + } + + /** + * @param scopeType 查找范围0.默认 1.本地 2.已安装 3.已引用 4.仓库中 + * @param text 查询内容 + * @param path 相对于开发根路径的路径信息 + * @param metadataTypeList 可以传递想要获取的元数据类型,类型用逗号隔开,如metadataTypeList=.be,.cmp,.api 该参数可以不赋值,默认获取所有类型 + * @param conflictAvoid 冲突避免 + * @param selectedPackageSource 包源 + * @param page 是否分页 + * @param pageSize 每页大小 + * @param pageIndex 第几页 + * @return com.inspur.edp.lcm.metadata.api.entity.metadataindex.MetadataIndexDto + * @author zhongchq + **/ + @GET + @Path(value = "/mdlist") + public MetadataIndexDto getMetadataIndexList(@QueryParam(value = "scopeType") int scopeType, + @DefaultValue("") @QueryParam(value = "text") String text, + @QueryParam(value = "path") String path, + @QueryParam(value = "metadataTypeList") String metadataTypeList, + @DefaultValue("") @QueryParam(value = "selectedPackageSource") String selectedPackageSource, + @DefaultValue("true") @QueryParam(value = "page") boolean page, + @DefaultValue("10") @QueryParam(value = "pageSize") int pageSize, + @DefaultValue("0") @QueryParam(value = "pageIndex") int pageIndex, + @DefaultValue("false") @QueryParam(value = "conflictAvoid") boolean conflictAvoid) { + if (metadataTypeList != null) { + metadataTypeList = metadataTypeList.toLowerCase(); + } + MetadataIndexDto dto = new MetadataIndexDto(); + List list; + switch (scopeType) { + // 离线 + case 1: + list = getLocalMetadataList(text, path, metadataTypeList, page, pageSize, pageIndex); + break; + // 远程 + case 2: + list = getRemoteMetadataIndexList(text, path, selectedPackageSource, metadataTypeList, page, pageSize, pageIndex, false, conflictAvoid); + break; + // 引用 + case 3: + list = getRemoteMetadataIndexList(text, path, selectedPackageSource, metadataTypeList, page, pageSize, pageIndex, true, conflictAvoid); + break; + default: + throw new IllegalArgumentException("Param scope is invalid."); + } + if (list.size() > 0) { + dto.setMetadataIndexItems(list); + Page page1 = new Page(); + page1.setPageIndex(pageIndex); + page1.setPageSize(list.size()); + dto.setPage(page1); + } else { + Page page2 = new Page(); + page2.setPageIndex(pageIndex); + page2.setPageSize(0); + dto.setPage(page2); + } + return dto; + } + + /** + * @param scopeType 查找范围0.默认 1.本地 2.已安装 3.已引用 4.仓库中 + * @param currentPath 当前路径 + * @param metadataIndexDto MetadataIndexItemDto实体 + * @param isNeedMdDto 是否需要??? + * @return com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto + * @author zhongchq + **/ + @POST + @Path(value = "pickmd") + public Metadata4RefDto pickMetadataIndex(@QueryParam(value = "scopeType") int scopeType, + @QueryParam(value = "currentPath") String currentPath, + MetadataIndexItemDto metadataIndexDto, + @DefaultValue("true") @QueryParam(value = "isNeedMdDto") boolean isNeedMdDto) { + return getMetadataService().pickMetadataIndex(scopeType, currentPath, metadataIndexDto, isNeedMdDto); + } + + @GET + @Path(value = "/metadata") + public MetadataDto loadMetadataByMetadataId(String metadataId, String path) { + final GspMetadata metadata = getMetadataService().loadMetadataByMetadataId(metadataId, path); + Utils.checkNPE(metadata, "工程" + path + "中找不到元数据:" + metadataId); + return MetadataDtoConverter.asDto(metadata); + } + + @GET + @Path(value = "/indexServerStatus") + public String getIndexServerStatus(@QueryParam(value = "ip") String ip, @QueryParam(value = "port") String port) { + return getMetadataService().getIndexServerStatus(ip, port); + } + + @GET + @Path(value = "/extendrule") + public String getMdExtRule(@QueryParam(value = "metadataId") String metadataId, + @QueryParam(value = "path") String path) { + IMdExtRuleContent extendRule = getMetadataService().getMdExtRule(metadataId, path); + String result = null; + if (extendRule == null) { + return null; + } + List metadataList = getMetadataService().getMetadataList(path); + Optional optMetadata = metadataList.stream().filter(item -> item.getHeader().getId() == metadataId).findAny(); + if (!optMetadata.isPresent()) { + throw new RuntimeException("不存在ID为" + metadataId + ",路径为" + path + "的元数据"); + } + MdExtendRuleSerializer mdExtRulemanager = MdExtRuleSerializerHelper.getInstance().getManager(optMetadata.get().getHeader().getType()); + if (mdExtRulemanager != null) { + JsonNode extRuleNode = mdExtRulemanager.serialize(extendRule); + ObjectMapper objectMapper = Utils.getMapper(); + try { + result = objectMapper.writeValueAsString(extRuleNode); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + return result; + } + + @PUT + @Path(value = "/extendrule") + public void saveMdExtRule(@QueryParam(value = "metadataId") String metadataId, + @QueryParam(value = "path") String path, String extendRuleStr) { + List metadataList = getMetadataService().getMetadataList(path); + Optional optMetadata = metadataList.stream().filter(item -> item.getHeader().getId() == metadataId).findAny(); + if (!optMetadata.isPresent()) { + throw new RuntimeException("不存在ID为" + metadataId + ",路径为" + path + "的元数据"); + } + MdExtendRuleSerializer mdExtRulemanager = MdExtRuleSerializerHelper.getInstance().getManager(optMetadata.get().getHeader().getType()); + IMdExtRuleContent extendRule = null; + if (mdExtRulemanager != null) { + ObjectMapper objectMapper = Utils.getMapper(); + try { + JsonNode extRuleNode = objectMapper.readTree(extendRuleStr); + extendRule = mdExtRulemanager.deSerialize(extRuleNode); + } catch (IOException e) { + e.printStackTrace(); + } + } + getMetadataService().saveMdExtRule(metadataId, path, extendRule); + } + + @GET + @Path(value = "/processMode") + public String getProcessMode(@QueryParam(value = "path") String path) { + return getMetadataProjectService().getProcessMode(path).toString(); + } + + @GET + @Path(value = "/projinpath") + public List getProjPathsInPath(@QueryParam(value = "path") String path) { + return getMetadataProjectService().getProjPathsInPath(path); + } + + @GET + @Path(value = "/isMetadataRefed") + public boolean isMetadataRefed(@QueryParam(value = "path") String path) { + return getMetadataService().isMetadataRefed(path); + } + + @GET + @Path(value = "/mdpkgNameExist") + public String getMdpkgNameExistInBo(@QueryParam(value = "path") String path, + @QueryParam(value = "mdpkgName") String mdpkgName) { + return getMetadataProjectService().getMdpkgNameExistInBo(path, mdpkgName); + } + + @POST + @Path(value = "/changeProcessMode") + public void changeProcessMode(@QueryParam(value = "path") String path, + @QueryParam(value = "processMode") String processMode) { + getMetadataProjectService().changeProcessMode(path, ProcessMode.valueOf(processMode)); + } + + private List getRemoteMetadataIndexList(String text, String path, + String selectedPackageSource, + String metadataTypeList, boolean page, int pageSize, + int pageIndex, boolean isFilterByRefs, boolean conflictAvoidFlag) { + List typeList = handleMetadataTypeList(metadataTypeList); + return getMetadataService().getRemoteMetadataIndexList(text, path, selectedPackageSource, typeList, page, + pageSize, pageIndex, isFilterByRefs, conflictAvoidFlag); + } + + private List getLocalMetadataList(String text, String path, String metadataTypeList, + boolean page, int pageSize, int pageIndex) { + List typeList = handleMetadataTypeList(metadataTypeList); + return getMetadataService().getLocalMetadataList(text, path, typeList, page, pageSize, pageIndex); + } + + private List asMdDtos(List mds, ProcessMode processMode) { + if (mds == null) { + return null; + } + List list = new ArrayList<>(); + mds.forEach(md -> { + MetadataDto metadataDto = MetadataDtoConverter.asDto(md); + metadataDto.setProcessMode(processMode.toString()); + list.add(metadataDto); + }); + return list; + } + + private List handleMetadataTypeList(String metadataTypes) { + List typeList = null; + if (!(metadataTypes == null || metadataTypes.isEmpty())) { + String[] types = metadataTypes.split(","); + typeList = new ArrayList<>(Arrays.asList(types)); + } + return typeList; + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/MetadataConfigServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/MetadataConfigServiceWebApi.java new file mode 100644 index 0000000..a8d1607 --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/MetadataConfigServiceWebApi.java @@ -0,0 +1,62 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataType; +import com.inspur.edp.lcm.metadata.api.service.MetadataService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class MetadataConfigServiceWebApi { + private MetadataService metadataService; + + private MetadataService getMetadataService() { + if (metadataService == null) { + metadataService = SpringBeanUtils.getBean(MetadataService.class); + } + return metadataService; + } + + /** + * 获取各元数据配置的元数据类型信息及后缀信息 + * + * @return + */ + @GET + public List getMetadataTypeList() { + return getMetadataService().getMetadataTypeList(); + } + + /** + * 更新元数据缓存路径 + * + * @param path 工程路径 + */ + @PUT + public void setMetadataUri(@QueryParam(value = "path") String path) { + getMetadataService().setMetadataUri(path); + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/MetadataPackageServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/MetadataPackageServiceWebApi.java new file mode 100644 index 0000000..aa0c65e --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/MetadataPackageServiceWebApi.java @@ -0,0 +1,77 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageDto; +import com.inspur.edp.lcm.metadata.api.service.MetadataService; +import com.inspur.edp.lcm.metadata.api.service.PackageGenerateService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.File; +import java.util.List; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +public class MetadataPackageServiceWebApi { + PackageGenerateService metadataPackageService; + + private PackageGenerateService getMetadataPackageService() { + if (metadataPackageService == null) { + metadataPackageService = SpringBeanUtils.getBean(PackageGenerateService.class); + } + return metadataPackageService; + } + + private MetadataService metadataService; + + private MetadataService getMetadataService() { + if (metadataService == null) { + metadataService = SpringBeanUtils.getBean(MetadataService.class); + } + return metadataService; + } + + /** + * 生成元数据包 + * + * @param metadataPackageDto 实体中的ProjectPath必填,其他值不需要 + */ + @POST + public void generatePackage(MetadataPackageDto metadataPackageDto) { + getMetadataPackageService().generatePackage(metadataPackageDto.getProjectPath()); + } + + /** + * 获取元数据包的基本信息 + * + * @param packagePath 元数据包路径+元数据包名称,要带后缀.mdpkg,需要Encode,这里暂时定的是全路径,因为元数据包也是固定存放在开发服务器一个目录下,但是不是开发根路径 + * @return + */ + @GET + @Path("/packagePath") + public MetadataPackage getMetadataPackageInfo(@QueryParam(value = "packagePath") String packagePath) { + File file = new File(packagePath); + return getMetadataService().getMetadataPackageInfo(file.getName(), file.getParent()); + } + + @GET + @Path("local") + public List getLocalPackages(@QueryParam(value = "path") String path) { + return getMetadataPackageService().getLocalPackages(path); + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/MetadataProjectServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/MetadataProjectServiceWebApi.java new file mode 100644 index 0000000..090e0ee --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/MetadataProjectServiceWebApi.java @@ -0,0 +1,192 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageHeader; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageVersion; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProjectDto; +import com.inspur.edp.lcm.metadata.api.entity.bo.BOInfo; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.api.service.MetadataService; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class MetadataProjectServiceWebApi { + private MetadataProjectService metadataProjectService; + + private MetadataProjectService getMetadataProjectService() { + if (metadataProjectService == null) { + metadataProjectService = SpringBeanUtils.getBean(MetadataProjectService.class); + } + return metadataProjectService; + } + + private MetadataService metadataService; + + private MetadataService getMetadataService() { + if (metadataService == null) { + metadataService = SpringBeanUtils.getBean(MetadataService.class); + } + return metadataService; + } + + /** + * 获取元数据工程信息 + * + * @param path 元数据工程所在的路径或者下级路径 + * @return + */ + @GET + public MetadataProject getMetadataProjInfo(@QueryParam(value = "path") String path) { + MetadataProject metadataProjInfo = getMetadataProjectService().getMetadataProjInfo(path); + metadataProjInfo.setProjectPath(ManagerUtils.getRalativePath(metadataProjInfo.getProjectPath())); + return metadataProjInfo; + } + + @GET + @Path("bo") + public List getBOInfo(@QueryParam("boids") String boids) { + String[] boidArray = boids.split(","); + return getMetadataProjectService().getBOInfo(boidArray); + } + + /** + * 根据工程或者下级路径,获取工程路径 + * + * @param path 工程或者下级路径 + * @return + */ + @GET + @Path("/path") + public String getProjPath(@QueryParam(value = "path") String path) { + String projPath = getMetadataProjectService().getProjPath(path); + String ralativePath = ManagerUtils.getRalativePath(projPath); + return ralativePath; + } + + /** + * 元数据工程更新引用信息 + * + * @param metadataProjectDto 需要传递ProjectPath、DepPackageName、DepPackageVersion、DepPackageLocation等信息 + */ + @PUT + public void updateReference(MetadataProjectDto metadataProjectDto) { + MetadataPackageHeader metadataPackageHeader = new MetadataPackageHeader(); + metadataPackageHeader.setName(metadataProjectDto.getDepPackageName()); + metadataPackageHeader.setVersion(new MetadataPackageVersion(metadataProjectDto.getDepPackageVersion())); + metadataPackageHeader.setLocation(metadataProjectDto.getDepPackageLocation()); + getMetadataProjectService().updateRefs(metadataProjectDto.getProjectPath(), metadataPackageHeader); + } + + /** + * 元数据工程文件是否存在,用在前端判断是否可以执行打包操作 + * + * @param path 路径信息,相对路径 + * @return + */ + @GET + @Path("/validationrecursively") + public boolean isExistProjFileRecursively(@QueryParam(value = "path") String path) { + return getMetadataProjectService().isExistProjFileRecursively(path); + } + + /** + * 获取bo路径 + * + * @param path 工程路径 + * @return + */ + @GET + @Path("/bopath") + public String getBoPath(@QueryParam(value = "path") String path) { + return getMetadataProjectService().getBoPath(path); + } + + /** + * 获取是否解析型 + * + * @param path 工程路径 + * @return + */ + @GET + @Path("/isInterpretation") + public boolean isInterpretation(@QueryParam(value = "path") String path) { + return getMetadataProjectService().isInterpretation(path); + } + + /** + * 当前目录是否存在,已废弃,使用getProjPath代替 + * + * @param path + * @return + */ + @Deprecated + @GET + @Path("/validation") + public boolean isExistProjectFile(@QueryParam(value = "path") String path) { + return getMetadataProjectService().isExistProjFile(path); + } + + /** + * 获取技术栈,已废弃,仅保留java技术栈 + * + * @param path 工程路径 + * @return + */ + @Deprecated + @GET + @Path("/codelanguage") + public String getCodeLanguage(@QueryParam(value = "path") String path) { + return "java"; + } + + /** + * 是否使用maven,都使用maven,所以废弃 + * + * @param path 工程路径 + * @return + */ + @Deprecated + @GET + @Path("/isMaven") + public boolean getMavenStatus(@QueryParam(value = "path") String path) { + return true; + } + + /** + * 更新元数据缓存路径 + * + * @param path 工程路径 + */ + @Deprecated + @PUT + @Path("/metadataPath") + public void setMetadataPath(@QueryParam(value = "path") String path) { + getMetadataService().setMetadataUri(path); + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/MetadataServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/MetadataServiceWebApi.java new file mode 100644 index 0000000..2953724 --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/MetadataServiceWebApi.java @@ -0,0 +1,508 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.lcm.metadata.api.IMdExtRuleContent; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataFilter; +import com.inspur.edp.lcm.metadata.api.entity.MetadataHeader; +import com.inspur.edp.lcm.metadata.api.entity.MetadataIndexItemDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; +import com.inspur.edp.lcm.metadata.api.entity.MetadataType; +import com.inspur.edp.lcm.metadata.api.entity.Page; +import com.inspur.edp.lcm.metadata.api.entity.ProcessMode; +import com.inspur.edp.lcm.metadata.api.entity.metadataindex.MetadataIndexDto; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.api.service.MetadataService; +import com.inspur.edp.lcm.metadata.api.service.PackageGenerateService; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.common.configuration.MdExtRuleSerializerHelper; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import com.inspur.edp.lcm.metadata.spi.MdExtendRuleSerializer; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class MetadataServiceWebApi { + private MetadataService metadataService; + + private MetadataService getMetadataService() { + if (metadataService == null) { + metadataService = SpringBeanUtils.getBean(MetadataService.class); + } + return metadataService; + } + + private MetadataProjectService metadataProjectService; + + private MetadataProjectService getMetadataProjectService() { + if (metadataProjectService == null) { + metadataProjectService = SpringBeanUtils.getBean(MetadataProjectService.class); + } + return metadataProjectService; + } + + PackageGenerateService packService; + + private PackageGenerateService getPackService() { + if (packService == null) { + packService = SpringBeanUtils.getBean(PackageGenerateService.class); + } + return packService; + } + +/******************************************************************************************/ + + /** + * 用于新建元数据之前初始化元数据实体 + * + * @param nameSpace 元数据命名空间 + * @param code 元数据编号 + * @param name 元数据名称 + * @param type 元数据类型 + * @param bizObjectID 业务对象主键 + * @param metadataPath 元数据创建路径,相对于开发根路径的路径信息 + * @param extendProperty 扩展属性,默认为空,可以不赋值 + * @return + */ + @GET + @Path("initialized") + public MetadataDto initializeMetadataEntity(@QueryParam(value = "nameSpace") String nameSpace, + @QueryParam(value = "code") String code, + @QueryParam(value = "name") String name, + @QueryParam(value = "type") String type, + @QueryParam(value = "bizObjectID") String bizObjectID, + @QueryParam(value = "metadataPath") String metadataPath, + @DefaultValue("") @QueryParam(value = "extendProperty") String extendProperty) { + GspMetadata metadata = new GspMetadata(); + metadata.setHeader(new MetadataHeader()); + metadata.getHeader().setName(name); + metadata.getHeader().setCode(code); + metadata.getHeader().setNameSpace(nameSpace); + metadata.getHeader().setType(type); + metadata.getHeader().setBizObjectId(bizObjectID); + metadata.setRelativePath(metadataPath); + metadata.setExtendProperty(extendProperty); + getMetadataService().initializeMetadataEntity(metadata); + return MetadataDtoConverter.asDto(metadata); + } + + /** + * 新建元数据,元数据设计器打开之前文件被创建 + * + * @param metadataDto 新建元数据需要的参数,新建元数据之前需要调用初始化元数据实体,因此该参数即为InitializeMetadataEntity返回的实体 + */ + @POST + public void createMetadata(MetadataDto metadataDto) { + String path = metadataDto.relativePath; + getMetadataService().createMetadata(path, MetadataDtoConverter.asMetadata(metadataDto)); + } + + @DELETE + @Path("/delete") + public void deleteUri(@QueryParam(value = "fullPath") String fullPath) { + fullPath = ManagerUtils.getAbsolutePath(fullPath); + File file = new File(fullPath); + if (file.isDirectory()) { + getMetadataService().deleteFolder(fullPath); + } else { + getMetadataService().deleteMetadata(file.getParent(), file.getName()); + } + } + + @PUT + public void saveMetadata(MetadataDto metadataDto) { + final GspMetadata metadata = MetadataDtoConverter.asMetadata(metadataDto); + String fullPath = metadataDto.getRelativePath() + File.separator + metadataDto.getFileName(); + getMetadataService().saveMetadata(metadata, fullPath); + } + + @GET + @Path("/load") + public MetadataDto loadMetadata(@QueryParam(value = "metadataFullPath") String metadataFullPath) { + File file = new File(metadataFullPath); + GspMetadata metadata = getMetadataService().loadMetadata(file.getName(), file.getParent()); + return MetadataDtoConverter.asDto(metadata); + } + + @GET + @Path("/metadataInBo") + public MetadataDto loadMetadata(@QueryParam(value = "metadataFullPath") String metadataFullPath, + @QueryParam(value = "currentProjPath") String currentProjPath) { + GspMetadata metadata = getMetadataService().loadMetadataInBo(metadataFullPath, currentProjPath); + return MetadataDtoConverter.asDto(metadata); + } + + /** + * @param spacePath 元数据路径 + * @param metadataTypeList 元数据类型 + * @return java.util.List + * @author zhongchq + **/ + @GET + public List getMetadataList(@QueryParam(value = "path") String spacePath, + @QueryParam(value = "metadataTypeList") String metadataTypeList) { + List result = getMetadataService().getMetadataList(spacePath, handleMetadataTypeList(metadataTypeList)); + + String projPath = getMetadataProjectService().getProjPath(spacePath); + ProcessMode processMode = ProcessMode.GENERATION; + if (projPath != null && !projPath.isEmpty()) { + processMode = getMetadataProjectService().getProcessMode(projPath); + } + List metadataDtos = asMdDtos(result, processMode); + metadataDtos.forEach(dto -> dto.setRelativePath(ManagerUtils.getRalativePath(dto.getRelativePath()))); + return metadataDtos; + } + + /** + * 根据当前工程路径获取bo下的元数据列表(会根据processMode过滤) + * + * @param path + * @param metadataTypeList + * @return List + */ + @GET + @Path(value = "/metadataListInBo") + public List getMetadataListInBo(@QueryParam(value = "path") String path, + @QueryParam(value = "metadataTypeList") String metadataTypeList) { + List result = getMetadataService().getMetadataListInBo(path, handleMetadataTypeList(metadataTypeList)); + result.forEach(dto -> dto.setRelativePath(ManagerUtils.getRalativePath(dto.getRelativePath()))); + return result; + } + + /** + * 根据过滤条件获取元数据列表,如构件可细分为多种子构件,可根据filter精确过滤具体类型的元数据 + * + * @param path 工程路径 + * @param typeCode 需要精确获取元数据类型的元数据编号 + * @param filter 过滤条件 + * @param postfix 要获取的元数据后缀,不传则默认获取工程下所有的元数据 + * @return + */ + @GET + @Path(value = "/filter") + public List getMetadataByFilter(@QueryParam(value = "path") String path, + @QueryParam(value = "typeCode") String typeCode, @QueryParam(value = "filter") String filter, + @QueryParam(value = "postfix") String postfix) { + MetadataFilter metadataFilter = new MetadataFilter(); + metadataFilter.setFilter(filter); + metadataFilter.setTypeCode(typeCode); + metadataFilter.setMetadataPostfix(postfix); + List metadataByFilter = getMetadataService().getMetadataByFilter(path, metadataFilter); + List dtoList = new ArrayList<>(); + if (metadataByFilter != null) { + metadataByFilter.forEach(metadata -> { + dtoList.add(MetadataDtoConverter.asDto(metadata)); + }); + } + return dtoList; + } + + /*** + * @author zhongchq + * @param metadataPath + * 元数据所在路径信息,当前工程下的某个路径,相对路径 + * @param metadataID + *元数据唯一标识 + * @return com.inspur.edp.lcm.metadata.api.entity.MetadataDto + **/ + @GET + @Path(value = "/relied") + public MetadataDto getRefMetadata(@QueryParam(value = "metadataPath") String metadataPath, + @QueryParam(value = "metadataID") String metadataID) { + return MetadataDtoConverter.asDto(getMetadataService().getRefMetadata(metadataPath, metadataID)); + } + + /** + * 判断元数据新建的路径下是否有相同名称的文件存在 + * + * @param path 元数据新建的路径 + * @param fileName 元数据文件名 + * @return + */ + @GET + @Path("/validation") + public boolean validateRepeatName(@QueryParam(value = "path") String path, + @QueryParam(value = "fileName") String fileName) { + boolean canCreateFlag = getMetadataService().validateRepeatName(path, fileName); + return canCreateFlag; + } + + /*** + * 获取各元数据配置的元数据类型信息及后缀信息 + * @author zhongchq + * @return java.util.List + **/ + @GET + @Path(value = "/typeList") + public List getMetadataTypeList() { + return getMetadataService().getMetadataTypeList(); + } + + @POST + @Path(value = "/packages") + public void GeneratePackage(@QueryParam(value = "projPath") String projPath) { + getPackService().generatePackage(projPath); + } + + /*** + * @author zhongchq + * @param projectPath + * 获取工程信息 + * @return com.inspur.edp.lcm.metadata.api.entity.MetadataProject + **/ + @GET + @Path(value = "/projectInfo") + public MetadataProject getMetadataProjInfo(@QueryParam(value = "projectPath") String projectPath) { + if (projectPath == null || projectPath.isEmpty()) { + throw new IllegalArgumentException("projectPath参数不能为空"); + } + return getMetadataService().getMetadataProjInfo(projectPath); + } + + /*** + * @author zhongchq + * @param scopeType 查找范围0.默认 1.本地 2.已安装 3.已引用 4.仓库中 + * @param text 查询内容 + * @param path 相对于开发根路径的路径信息 + * @param metadataTypeList 可以传递想要获取的元数据类型,类型用逗号隔开,如metadataTypeList=.be,.cmp,.api 该参数可以不赋值,默认获取所有类型 + * @param conflictAvoid 冲突避免 + * @param selectedPackageSource 包源 + * @param page 是否分页 + * @param pageSize 每页大小 + * @param pageIndex 第几页 + * @return com.inspur.edp.lcm.metadata.api.entity.metadataindex.MetadataIndexDto + **/ + @GET + @Path(value = "/mdlist") + public MetadataIndexDto getMetadataIndexList(@QueryParam(value = "scopeType") int scopeType, + @DefaultValue("") @QueryParam(value = "text") String text, + @QueryParam(value = "path") String path, + @QueryParam(value = "metadataTypeList") String metadataTypeList, + @DefaultValue("") @QueryParam(value = "selectedPackageSource") String selectedPackageSource, + @DefaultValue("true") @QueryParam(value = "page") boolean page, + @DefaultValue("10") @QueryParam(value = "pageSize") int pageSize, + @DefaultValue("0") @QueryParam(value = "pageIndex") int pageIndex, + @DefaultValue("false") @QueryParam(value = "conflictAvoid") boolean conflictAvoid) { + if (metadataTypeList != null) { + metadataTypeList = metadataTypeList.toLowerCase(); + } + MetadataIndexDto dto = new MetadataIndexDto(); + List list; + switch (scopeType) { + // 离线 + case 1: + list = getLocalMetadataList(text, path, metadataTypeList, page, pageSize, pageIndex); + break; + // 远程 + case 2: + list = getRemoteMetadataIndexList(text, path, selectedPackageSource, metadataTypeList, page, pageSize, pageIndex, false, conflictAvoid); + break; + // 引用 + case 3: + list = getRemoteMetadataIndexList(text, path, selectedPackageSource, metadataTypeList, page, pageSize, pageIndex, true, conflictAvoid); + break; + default: + throw new IllegalArgumentException("Param scope is invalid."); + } + if (list.size() > 0) { + dto.setMetadataIndexItems(list); + Page page1 = new Page(); + page1.setPageIndex(pageIndex); + page1.setPageSize(list.size()); + dto.setPage(page1); + } else { + Page page2 = new Page(); + page2.setPageIndex(pageIndex); + page2.setPageSize(0); + dto.setPage(page2); + } + return dto; + } + + /** + * @param scopeType 查找范围0.默认 1.本地 2.已安装 3.已引用 4.仓库中 + * @param currentPath 当前路径 + * @param metadataIndexDto MetadataIndexItemDto实体 + * @param isNeedMdDto 是否需要??? + * @return com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto + * @author zhongchq + **/ + @POST + @Path(value = "pickmd") + public Metadata4RefDto pickMetadataIndex(@QueryParam(value = "scopeType") int scopeType, + @QueryParam(value = "currentPath") String currentPath, + MetadataIndexItemDto metadataIndexDto, + @DefaultValue("true") @QueryParam(value = "isNeedMdDto") boolean isNeedMdDto) { + return getMetadataService().pickMetadataIndex(scopeType, currentPath, metadataIndexDto, isNeedMdDto); + } + + @GET + @Path(value = "/metadata") + public MetadataDto loadMetadataByMetadataId(@QueryParam(value = "metadataId") String metadataId, + @QueryParam(value = "path") String path) { + final GspMetadata metadata = getMetadataService().loadMetadataByMetadataId(metadataId, path); + Utils.checkNPE(metadata, "工程" + path + "中找不到元数据:" + metadataId); + return MetadataDtoConverter.asDto(metadata); + } + + @GET + @Path(value = "/indexServerStatus") + public String getIndexServerStatus(@QueryParam(value = "ip") String ip, @QueryParam(value = "port") String port) { + return getMetadataService().getIndexServerStatus(ip, port); + } + + @GET + @Path(value = "/extendrule") + public String getMdExtRule(@QueryParam(value = "metadataId") String metadataId, + @QueryParam(value = "path") String path) { + IMdExtRuleContent extendRule = getMetadataService().getMdExtRule(metadataId, path); + String result = null; + if (extendRule == null) { + return null; + } + List metadataList = getMetadataService().getMetadataList(path); + Optional optMetadata = metadataList.stream().filter(item -> item.getHeader().getId() == metadataId).findAny(); + if (!optMetadata.isPresent()) { + throw new RuntimeException("不存在ID为" + metadataId + ",路径为" + path + "的元数据"); + } + MdExtendRuleSerializer mdExtRulemanager = MdExtRuleSerializerHelper.getInstance().getManager(optMetadata.get().getHeader().getType()); + if (mdExtRulemanager != null) { + JsonNode extRuleNode = mdExtRulemanager.serialize(extendRule); + ObjectMapper objectMapper = Utils.getMapper(); + try { + result = objectMapper.writeValueAsString(extRuleNode); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + return result; + } + + @PUT + @Path(value = "/extendrule") + public void saveMdExtRule(@QueryParam(value = "metadataId") String metadataId, + @QueryParam(value = "path") String path, String extendRuleStr) { + List metadataList = getMetadataService().getMetadataList(path); + Optional optMetadata = metadataList.stream().filter(item -> item.getHeader().getId() == metadataId).findAny(); + if (!optMetadata.isPresent()) { + throw new RuntimeException("不存在ID为" + metadataId + ",路径为" + path + "的元数据"); + } + MdExtendRuleSerializer mdExtRulemanager = MdExtRuleSerializerHelper.getInstance().getManager(optMetadata.get().getHeader().getType()); + IMdExtRuleContent extendRule = null; + if (mdExtRulemanager != null) { + ObjectMapper objectMapper = Utils.getMapper(); + try { + JsonNode extRuleNode = objectMapper.readTree(extendRuleStr); + extendRule = mdExtRulemanager.deSerialize(extRuleNode); + } catch (IOException e) { + e.printStackTrace(); + } + } + getMetadataService().saveMdExtRule(metadataId, path, extendRule); + } + + @GET + @Path(value = "/processMode") + public String getProcessMode(@QueryParam(value = "path") String path) { + return getMetadataProjectService().getProcessMode(path).toString(); + } + + @GET + @Path(value = "/mavensetting") + public boolean getMavenSetting() { + return true; + } + + @GET + @Path(value = "/projinpath") + public List getProjPathsInPath(@QueryParam(value = "path") String path) { + return getMetadataProjectService().getProjPathsInPath(path); + } + + @GET + @Path(value = "/isMetadataRefed") + public boolean isMetadataRefed(@QueryParam(value = "path") String path) { + return getMetadataService().isMetadataRefed(path); + } + + @GET + @Path(value = "/mdpkgNameExist") + public String getMdpkgNameExistInBo(@QueryParam(value = "path") String path, + @QueryParam(value = "mdpkgName") String mdpkgName) { + return getMetadataProjectService().getMdpkgNameExistInBo(path, mdpkgName); + } + + private List getRemoteMetadataIndexList(String text, String path, + String selectedPackageSource, + String metadataTypeList, boolean page, int pageSize, + int pageIndex, boolean isFilterByRefs, boolean conflictAvoidFlag) { + List typeList = handleMetadataTypeList(metadataTypeList); + return getMetadataService().getRemoteMetadataIndexList(text, path, selectedPackageSource, typeList, page, + pageSize, pageIndex, isFilterByRefs, conflictAvoidFlag); + } + + private List getLocalMetadataList(String text, String path, String metadataTypeList, + boolean page, int pageSize, int pageIndex) { + List typeList = handleMetadataTypeList(metadataTypeList); + return getMetadataService().getLocalMetadataList(text, path, typeList, page, pageSize, pageIndex); + } + + private List asMdDtos(List mds, ProcessMode processMode) { + if (mds == null) { + return null; + } + List list = new ArrayList<>(); + mds.forEach(md -> { + MetadataDto metadataDto = MetadataDtoConverter.asDto(md); + metadataDto.setProcessMode(processMode.toString()); + list.add(metadataDto); + }); + return list; + } + + private List handleMetadataTypeList(String metadataTypes) { + List typeList = null; + if (!(metadataTypes == null || metadataTypes.isEmpty())) { + String[] types = metadataTypes.split(","); + typeList = new ArrayList<>(Arrays.asList(types)); + } + return typeList; + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/ProjectDeployServiceWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/ProjectDeployServiceWebApi.java new file mode 100644 index 0000000..38f3e27 --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/ProjectDeployServiceWebApi.java @@ -0,0 +1,54 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.entity.DbConnectionInfo; +import com.inspur.edp.lcm.metadata.api.service.ProjectExtendService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.IOException; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class ProjectDeployServiceWebApi { + private ProjectExtendService projectExtendService; + + private ProjectExtendService getProjectExtendService() { + if (projectExtendService == null) { + projectExtendService = SpringBeanUtils.getBean(ProjectExtendService.class); + } + return projectExtendService; + } + + @POST + public void deploy(DbConnectionInfo dbConnectionInfo, @QueryParam("path") String path, + @QueryParam("restart") String restart) { + getProjectExtendService().deploy(dbConnectionInfo, "", path, restart); + } + + @GET + public String getDeployStatus(@QueryParam("sign") String sign) throws IOException { + return getProjectExtendService().getDeployStatus(sign); + } + +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/ProjectExtendWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/ProjectExtendWebApi.java new file mode 100644 index 0000000..12a9959 --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/ProjectExtendWebApi.java @@ -0,0 +1,67 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.entity.ExtractContext; +import com.inspur.edp.lcm.metadata.api.service.ProjectExtendService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class ProjectExtendWebApi { + private ProjectExtendService projectExtendService; + + private ProjectExtendService getProjectExtendService() { + if (projectExtendService == null) { + projectExtendService = SpringBeanUtils.getBean(ProjectExtendService.class); + } + return projectExtendService; + } + + /** + * 批量编译当前目录下的所有工程 + * + * @param path 路径 + * @param exts 扩展 + * @param disabledExts 禁用的扩展 + * @return + */ + @POST + public List BatchCompile(@QueryParam("path") String path, @QueryParam("exts") String exts, + @QueryParam("disabledExts") String disabledExts) { + return getProjectExtendService().batchCompile(path, exts, disabledExts); + } + + @PUT + public void batchExtract(@QueryParam("path") String path) { + getProjectExtendService().extract(path); + } + + @PUT + @Path("single") + public void extract(ExtractContext context) { + getProjectExtendService().extract(context.getProjectPath()); + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/RepoRefWebApi.java b/model/framework/devtime-webapi/src/main/java/webapi/RepoRefWebApi.java new file mode 100644 index 0000000..34bc0f8 --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/RepoRefWebApi.java @@ -0,0 +1,246 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi; + +import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenComponents; +import com.inspur.edp.lcm.metadata.api.mvnEntity.MetadataRepo; +import com.inspur.edp.lcm.metadata.api.mvnEntity.ModuleDependencies; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.api.service.MdpkgService; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * Description Maven引用设计时接口实现 + * + * @version 1.0 + */ +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class RepoRefWebApi { + + private MdpkgService mdpkgService; + + private MdpkgService getMdpkgService() { + if (mdpkgService == null) { + mdpkgService = SpringBeanUtils.getBean(MdpkgService.class); + } + return mdpkgService; + } + + private FileService fileService; + + private FileService getFileService() { + if (fileService == null) { + fileService = SpringBeanUtils.getBean(FileService.class); + } + return fileService; + } + + private MetadataProjectService metadataProjectService; + + private MetadataProjectService getMetadataProjectService() { + if (metadataProjectService == null) { + metadataProjectService = SpringBeanUtils.getBean(MetadataProjectService.class); + } + return metadataProjectService; + } + + /** + * 部署jar到nexus私服中。 step1:将元数据包打包中jar中。 step2:推送 + * + * @param proPath 元数据工程路径 + * @param proPath 推送的仓库地址 + * @param version 工程的版本号 + * @param revert 版本号是否回退 + * @return void + **/ + @POST + public void deployMdpkg(@QueryParam(value = "proPath") String proPath, + @QueryParam(value = "repoId") String repoId, + @QueryParam(value = "version") String version, + @DefaultValue("false") @QueryParam(value = "revert") boolean revert) throws IOException { + getMdpkgService().deploySnapshotMdVersion(proPath, repoId, version, revert); + } + + /** + * @param path gsp工程路径 + * @param version 工程版本号 + * @param repoId 仓库唯一id + * @param revert 默认为true,即推送完release版,版本号revert回原版本 + */ + @POST + @Path(value = "/release") + public void deployReleaseMdVersion(@QueryParam(value = "path") String path, + @QueryParam(value = "version") String version, + @QueryParam(value = "repoId") String repoId, + @DefaultValue("false") @QueryParam(value = "revert") boolean revert, + @QueryParam(value = "depversion") String dependenciesVersion) throws IOException { + getMdpkgService().deployReleaseMdVersion(path, version, repoId, revert, dependenciesVersion); + } + + /*** + * 获取仓库列表 + * + * @return com.inspur.edp.lcm.metadata.api.mvnEntity.MetadataRepo + **/ + @GET + @Path(value = "/repolist") + public MetadataRepo getRepoList() { + return getMdpkgService().getRepoList(); + } + + /** + * 实现maven install + * + * @param path gsp工程路径 + **/ + @POST + @Path(value = "/compile") + public void compile(@QueryParam(value = "path") String path, @QueryParam(value = "modules") String modules) { + String projPath = getMetadataProjectService().getProjPath(path); + getMdpkgService().compile(projPath, modules); + } + + /** + * @param path + * @param operations + */ + @POST + @Path(value = "/batchOperate") + public void batchOperate(@QueryParam(value = "path") String path, + @QueryParam(value = "operations") String operations) { + List operationList = Arrays.asList(operations.split(",")); + getMdpkgService().batchOperate(path, operationList); + } + + /** + * 实现maven install + * + * @param path gsp工程路径 + */ + @POST + @Path(value = "/compileAll") + public void compileAll(@QueryParam(value = "path") String path) { + String projPath = getMetadataProjectService().getProjPath(path); + getMdpkgService().compileAll(projPath); + } + + /** + * @param path 工程路径 + */ + @POST + @Path(value = "/restore") + public void restore(@QueryParam(value = "path") String path, @QueryParam(value = "force") Boolean force) { + getMdpkgService().restore(path, force); + } + + /** + * 给工程添加依赖并拉取 + * + * @param path 工程路径 + * @param metadataPackages 新添加的依赖的额元数据包 + */ + @PUT + @Path(value = "/adddepedency") + public void addDepedencyAndRestore(@QueryParam(value = "path") String path, + @QueryParam(value = "metadataPackages") String metadataPackages) { + String[] packages = metadataPackages.split(","); + List packageList = new ArrayList<>(Arrays.asList(packages)); + getMdpkgService().addDepedencyAndRestore(path, packageList); + } + + @GET + @Path(value = "/projversion") + public ModuleDependencies getDependenciesVersion(@QueryParam(value = "path") String path) throws IOException { + String absolutePath = ManagerUtils.getAbsolutePath(path); + + if (getFileService().getApiModulePath(absolutePath) == null) { + throw new RuntimeException("代码未生成,请生成java代码"); + } + String apiPath = getFileService().getApiModulePath(absolutePath) + "/pom.xml"; + List list; + try (FileInputStream fis = new FileInputStream(apiPath)) { + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(fis); + list = model.getDependencies(); + ModuleDependencies dependencies = new ModuleDependencies(); + if (model.getVersion() != null) { + dependencies.setProjVersion(model.getVersion()); + } else { + dependencies.setProjVersion(model.getParent().getVersion()); + } + for (Dependency dependency : list) { + if (dependency.getVersion().endsWith("SNAPSHOT")) { + dependencies.setNeedChange(true); + } + } + return dependencies; + } catch (IOException | XmlPullParserException e) { + e.printStackTrace(); + } + return new ModuleDependencies(); + } + + @GET + @Path(value = "/buildorder") + public List getBuildOrder(@QueryParam(value = "projPath") String projPath) { + return getMetadataProjectService().getBuildOrder(projPath); + } + + @GET + @Path(value = "/single") + public MavenComponents getVersionsOfSinglePackage(@QueryParam(value = "sourceId") String sourceId, + @QueryParam(value = "packName") String packName) { + return getMdpkgService().getVersionsOfSinglePackage(sourceId, packName); + } + + @PUT + @Path(value = "/install") + public void installMdpkg(@QueryParam(value = "groupId") String groupId, + @QueryParam(value = "artifactId") String artifactId, @QueryParam(value = "version") String version, + @QueryParam(value = "path") String path) throws IOException { + Boolean forceUpdateFlag = version.contains("-") ? true : false; + getMdpkgService().installMdpkg(groupId, artifactId, version, path, forceUpdateFlag); + } + + @POST + @Path(value = "/uninstall") + public void uninstallMdpkg(@QueryParam(value = "projPath") String projPath, + @QueryParam(value = "packName") String packName) { + getMdpkgService().uninstallMdpkg(projPath, packName); + } +} diff --git a/model/framework/devtime-webapi/src/main/java/webapi/config/WebApiConfiguration.java b/model/framework/devtime-webapi/src/main/java/webapi/config/WebApiConfiguration.java new file mode 100644 index 0000000..6faf4ca --- /dev/null +++ b/model/framework/devtime-webapi/src/main/java/webapi/config/WebApiConfiguration.java @@ -0,0 +1,115 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package webapi.config; + +import io.iec.edp.caf.rest.RESTEndpoint; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import webapi.FileSystemWebApi; +import webapi.GspProjectServiceWebApi; +import webapi.MdServiceWebApi; +import webapi.MetadataConfigServiceWebApi; +import webapi.MetadataPackageServiceWebApi; +import webapi.MetadataProjectServiceWebApi; +import webapi.MetadataServiceWebApi; +import webapi.ProjectDeployServiceWebApi; +import webapi.ProjectExtendWebApi; +import webapi.RepoRefWebApi; + +//todo +//@Configuration(proxyBeanMethods = false) +@Configuration() +public class WebApiConfiguration { + @Bean + public RESTEndpoint gspFSEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/file-system", + new FileSystemWebApi() + ); + } + + @Bean + public RESTEndpoint gspProjectEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/gsp-projects", + new GspProjectServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspMdEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/mdservice", + new MdServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspConfigEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/metadata-configs", + new MetadataConfigServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspMdPkgEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/metadata-packages", + new MetadataPackageServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspMdProjectEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/metadata-projects", + new MetadataProjectServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspMetadataEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/metadatas", + new MetadataServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspDeployEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/deploy-projects", + new ProjectDeployServiceWebApi() + ); + } + + @Bean + public RESTEndpoint gspExtendEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/extend-projects", + new ProjectExtendWebApi() + ); + } + + @Bean + public RESTEndpoint gspRepoEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/repo-packages", + new RepoRefWebApi() + ); + } +} diff --git a/model/framework/entity/pom.xml b/model/framework/entity/pom.xml new file mode 100644 index 0000000..333aea2 --- /dev/null +++ b/model/framework/entity/pom.xml @@ -0,0 +1,27 @@ + + + + ubml-model-framework + org.openatom.ubml + 0.9.0-SNAPSHOT + + 4.0.0 + ubml-model-framework-entity ${project.version} + ubml-model-framework-entity + + + 8 + 8 + + + + + org.openatom.ubml + ubml-model-common-definition + ${project.version} + + + + \ No newline at end of file diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/BaseConfig.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/BaseConfig.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/BaseConfig.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/BaseConfig.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCommonConfigData.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCommonConfigData.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCommonConfigData.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCommonConfigData.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectConfiguration.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectConfiguration.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectConfiguration.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectConfiguration.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCreateConfigData.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCreateConfigData.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCreateConfigData.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/gspproject/ProjectCreateConfigData.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/GspProject.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/GspProject.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/GspProject.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/GspProject.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4Ref.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4Ref.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4Ref.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4Ref.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4RefDto.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4RefDto.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4RefDto.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/Metadata4RefDto.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataDto.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataDto.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataDto.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataDto.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataFilter.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataFilter.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataFilter.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataFilter.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataIndexItemDto.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataIndexItemDto.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataIndexItemDto.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataIndexItemDto.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackage.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackage.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackage.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackage.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageHeader.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageHeader.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageHeader.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageHeader.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageReference.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageReference.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageReference.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageReference.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageVersion.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageVersion.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageVersion.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataPackageVersion.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java index 5a2c846..d198d08 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java +++ b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataProject.java @@ -16,8 +16,8 @@ package com.inspur.edp.lcm.metadata.api.entity; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenPackageRefs; +import java.util.List; /** * 元数据工程实体,对应.mdproj文件 diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataType.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataType.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataType.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/MetadataType.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProcessMode.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProcessMode.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProcessMode.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProcessMode.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProjectHeader.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProjectHeader.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProjectHeader.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ProjectHeader.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ServiceUnitInfo.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ServiceUnitInfo.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ServiceUnitInfo.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/ServiceUnitInfo.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/MetadataIndexRepoItemDto.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/MetadataIndexRepoItemDto.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/MetadataIndexRepoItemDto.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/MetadataIndexRepoItemDto.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponent.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponent.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponent.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponent.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponents.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponents.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponents.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenComponents.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenPackageRefs.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenPackageRefs.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenPackageRefs.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MavenPackageRefs.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MetadataRepo.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MetadataRepo.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MetadataRepo.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/MetadataRepo.java diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/PackageSourceDto.java b/model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/PackageSourceDto.java similarity index 100% rename from model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/PackageSourceDto.java rename to model/framework/entity/src/main/java/com/inspur/edp/lcm/metadata/api/mvnEntity/PackageSourceDto.java diff --git a/model/framework/generator-api/pom.xml b/model/framework/generator-api/pom.xml index a5480a9..6526661 100644 --- a/model/framework/generator-api/pom.xml +++ b/model/framework/generator-api/pom.xml @@ -19,6 +19,16 @@ 0.9.0-SNAPSHOT compile + + org.openatom.ubml + ubml-model-framework-devtime-core + 0.9.0-SNAPSHOT + compile + + + org.springframework.boot + spring-boot-starter-test + diff --git a/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java b/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java index 3687bd3..345f062 100644 --- a/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java +++ b/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java @@ -15,16 +15,16 @@ */ package com.inspur.edp.jittojava.context; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.inspur.edp.jittojava.context.temp.ModuleGenerateInfo; +import com.inspur.edp.jittojava.context.temp.ModuleGenerator; import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; -import com.inspur.edp.lcm.metadata.api.service.RefCommonService; import com.inspur.edp.lcm.metadata.api.entity.GspProject; import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; -import com.inspur.edp.jittojava.context.temp.ModuleGenerateInfo; -import com.inspur.edp.jittojava.context.temp.ModuleGenerator; -import com.inspur.edp.jittojava.context.temp.RefCommonServiceImp; +import com.inspur.edp.lcm.metadata.api.service.RefCommonService; +import com.inspur.edp.lcm.metadata.core.RefCommonServiceImp; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class JitContext { RefCommonService refCommonService; diff --git a/model/framework/pom.xml b/model/framework/pom.xml index 584b636..cce6c08 100644 --- a/model/framework/pom.xml +++ b/model/framework/pom.xml @@ -14,8 +14,10 @@ ubml-model-framework pom + entity devtime-api devtime-core + devtime-webapi runtime-spi runtime-api runtime-core @@ -27,15 +29,119 @@ 2.2.0.RELEASE + 1.2.62 + + 0.3.7-SNAPSHOT + 0.3.2 + 0.3.3 + 0.1.4 + 0.1.2 + 0.3.2 + 0.3.8 + 0.3.2 + + 0.1.4 + 0.1.25 + 0.1.0 + 3.6.1 + 0.1.4 + 0.1.3 + 0.1.0 - - - org.springframework.boot - spring-boot-starter-test - ${spring-boot.version} - test - - + + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + + + com.alibaba + fastjson + ${fastjson.version} + + + + io.iec.edp + caf-boot-commons-environment + ${caf-boot-commons-environment.version} + + + io.iec.edp + caf-boot-commons-layeringcache + ${caf-boot-commons-layeringcache.version} + + + io.iec.edp + caf-boot-starter-context + ${caf-boot-starter-context.version} + compile + + + io.iec.edp + caf-business-object-api + ${caf-business-object-api.version} + + + com.inspur.edp + i18n-resource-api + ${i18n-resource-api.version} + + + io.iec.edp + caf-boot-starter-rest-server + ${caf-boot-starter-rest-server.version} + + + io.iec.edp + caf-sumgr-core + ${caf-sumgr-core.version} + + + io.iec.edp + caf-rpc-api + ${caf-rpc-api.version} + + + + com.inspur.edp + lcm-logging-service + ${lcm-logging-service.version} + + + com.inspur.edp + lcm-metadata-spi + ${lcm-metadata-spi.version} + compile + + + com.inspur.edp + lcm-project-deployer-spi + ${lcm-project-deployer-spi.version} + compile + + + org.apache.maven + maven-settings + ${maven-settings.version} + + + com.inspur.edp + ide-setting-core + ${ide-setting-core.version} + + + com.inspur.edp + metadata-to-java-context + ${metadata-to-java-context.version} + + + com.inspur.edp + workspace-api + ${workspace-api.version} + + + \ No newline at end of file diff --git a/model/framework/runtime-api/pom.xml b/model/framework/runtime-api/pom.xml index b66e305..bda1332 100644 --- a/model/framework/runtime-api/pom.xml +++ b/model/framework/runtime-api/pom.xml @@ -11,6 +11,17 @@ ubml-model-framework-runtime-api ${project.version} + + + io.iec.edp + caf-rpc-api + + + org.openatom.ubml + ubml-model-framework-common + ${project.version} + + ubml-model-framework-runtime-api diff --git a/model/framework/runtime-api/src/main/java/com/inspur/edp/lcm/metadata/serverapi/MetadataRTServerService.java b/model/framework/runtime-api/src/main/java/com/inspur/edp/lcm/metadata/serverapi/MetadataRTServerService.java new file mode 100644 index 0000000..e3d6358 --- /dev/null +++ b/model/framework/runtime-api/src/main/java/com/inspur/edp/lcm/metadata/serverapi/MetadataRTServerService.java @@ -0,0 +1,161 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.serverapi; + +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4Ref; +import com.inspur.edp.lcm.metadata.api.entity.MetadataCustomizationFilter; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.api.entity.MetadataRTFilter; +import com.inspur.edp.lcm.metadata.api.entity.ServiceUnitInfo; +import io.iec.edp.caf.rpc.api.annotation.GspServiceBundle; +import io.iec.edp.caf.rpc.api.annotation.RpcParam; +import java.util.List; +import java.util.Map; + +@GspServiceBundle(applicationName = "runtime", serviceUnitName = "Lcm", serviceName = "metadata-rt") +public interface MetadataRTServerService { + + /** + * 根据元数据id获取运行时元数据 + * + * @param id 元数据id + * @return 元数据内容实体 + */ + MetadataDto getMetadataDtoRTByID(@RpcParam(paramName = "id") String id); + + /** + * 根据元数据ID获取元数据 + * + * @param id 元数据id + * @return 元数据内容实体 + */ + MetadataDto getMetadataDto(@RpcParam(paramName = "id") String id); + + /** + * 根据元数据id获取元数据 + * + * @param id 元数据ID + * @return 元数据内容实体 + */ + GspMetadata getMetadata(String id); + + /** + * @Author Robin + * @Description 加载服务端所有的元数据 + * @Date 10:02 2019/8/20 + * @Param [] + **/ + void loadAllMetadata(); + + /** + * 根据元数据类型获取元数据 + * + * @param metadataTypes 元数据类型类别,以逗号拼接 + * @return 序列化的元数据信息列表 + */ + String getMetadataRefDtoListWithTypes(String metadataTypes); + + /** + * @return 元数据信息列表 + */ + String getMetadataRefDtoList(); + + /** + * 获取所有元数据信息列表 + * + * @return 元数据信息列表 + */ + List getMetadataRefList(); + + /** + * 根据类型获取元数据信息列表 + * + * @param metadataTypes + * @return + */ + List getMetadataRefListWithTypes(@RpcParam(paramName = "metadataTypes") String metadataTypes); + + /** + * 根据过滤条件获取元数据信息列表 + * + * @param filter 过滤条件 + * @return 元数据信息列表 + */ + String getMetadataDtoListByFilter(@RpcParam(paramName = "filter") String filter); + + /** + * 根据逻辑ID获取元数据 + * + * @param metadataNamespace 命名空间 + * @param metadataCode 元数据编号 + * @param metadataTypeCode 元数据类型 + * @return 元数据实体 + */ + MetadataDto getMetadataDtoBySemanticID(@RpcParam(paramName = "metadataNamespace") String metadataNamespace, + @RpcParam(paramName = "metadataCode") String metadataCode, + @RpcParam(paramName = "metadataTypeCode") String metadataTypeCode); + + /** + * 根据过滤条件虎丘元数据信息列表 + * + * @param filter 过滤条件 + * @return 元数据信息列表 + */ + List getMetadataListByFilter(MetadataRTFilter filter); + + /** + * 根据元数据ID获取SU信息 + * + * @param metadataId 元数据ID + * @return 元数据所属SU信息 + */ + ServiceUnitInfo getServiceUnitInfo(@RpcParam(paramName = "metadataId") String metadataId); + + /** + * 获取元数据 + * + * @param metadataCustomizationFilter 运行时定制元数据过滤器 + * @return 元数据内容实体 + */ + String getMetadataString( + @RpcParam(paramName = "metadataCustomizationFilter") MetadataCustomizationFilter metadataCustomizationFilter); + + /** + * 根据路径递归获取路径下元数据包中元数据列表 + * + * @param path 路径 + * @return 元数据列表 + */ + List getMetadataListRecursivly(String path); + + /** + * 获取路径下元数据包列表 + * + * @param path 路径 + * @return 元数据包列表 + */ + Map getMetadataPackagesRecursivly(String path); + + /** + * 根据元数据包路径及元数据包信息获取元数据列表 + * + * @param packagePath 元数据包路径 + * @return 元数据列表 + */ + List getMetadataListFromPackage(String packagePath); +} diff --git a/model/framework/runtime-core/pom.xml b/model/framework/runtime-core/pom.xml index ce61f0d..961705a 100644 --- a/model/framework/runtime-core/pom.xml +++ b/model/framework/runtime-core/pom.xml @@ -12,7 +12,36 @@ ubml-model-framework-runtime-core ubml-model-framework-runtime-core ${project.version} + + + com.inspur.edp + i18n-resource-api + + + lcm-metadata-api + com.inspur.edp + + + + + org.openatom.ubml + ubml-model-framework-common + ${project.version} + + + org.openatom.ubml + ubml-model-framework-runtime-spi + 0.9.0-SNAPSHOT + compile + + + org.openatom.ubml + ubml-model-framework-runtime-api + 0.9.0-SNAPSHOT + compile + + \ No newline at end of file diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java new file mode 100644 index 0000000..f74189d --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java @@ -0,0 +1,164 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.rtservice; + +import com.inspur.edp.i18n.resource.api.II18nResourceRTManager; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.I18nResource; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4Ref; +import com.inspur.edp.lcm.metadata.api.entity.MetadataCustomizationFilter; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataRTFilter; +import com.inspur.edp.lcm.metadata.api.entity.ServiceUnitInfo; +import com.inspur.edp.lcm.metadata.api.service.MetadataRTService; +import com.inspur.edp.lcm.metadata.cache.MetadataDistCacheManager; +import com.inspur.edp.lcm.metadata.cache.RtCacheHandler; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import com.inspur.edp.lcm.metadata.common.MetadataSerializer; +import com.inspur.edp.lcm.metadata.common.configuration.I18nManagerHelper; +import com.inspur.edp.lcm.metadata.common.context.RuntimeContext; +import com.inspur.edp.lcm.metadata.spi.MetadataI18nService; +import io.iec.edp.caf.commons.layeringcache.cache.Cache; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import io.iec.edp.caf.rpc.api.service.RpcClient; +import java.util.LinkedHashMap; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import lombok.var; + +@Slf4j +public class MetadataRTServiceImp implements MetadataRTService { + MetadataRtUtils utils = new MetadataRtUtils(); + + private Cache cacheManager; + + @Override + public GspMetadata getMetadataRTByID(String id) { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("id", id); + MetadataDto response = client.invoke(MetadataDto.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataDtoRTByID", "Lcm", params, null); + return MetadataDtoConverter.asMetadata(response); + } + + @Override + public GspMetadata getMetadata(String id) { + String language = RuntimeContext.getLanguage(); + String metadataKey = RtCacheHandler.getMetadataCacheKey(id, language); + Cache cacheManager = MetadataDistCacheManager.getMetadataCache(); + GspMetadata metadata = cacheManager.get(metadataKey, GspMetadata.class); + if (metadata != null) { + return metadata; + } + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("id", id); + MetadataDto response = client.invoke(MetadataDto.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataDto", "Lcm", params, null); + metadata = MetadataDtoConverter.asMetadata(response); + if (metadata != null) { + cacheManager.put(metadataKey, metadata); + } + return metadata; + } + + @Override + public GspMetadata getMetadata(MetadataCustomizationFilter metadataCustomizationFilter) { + String language = metadataCustomizationFilter.isI18n() ? RuntimeContext.getLanguage() : ""; + String metadataKey = RtCacheHandler.getMetadataCacheKey(metadataCustomizationFilter.getMetadataId(), language); + cacheManager = MetadataDistCacheManager.getMetadataCache(); + GspMetadata metadata = cacheManager.get(metadataKey, GspMetadata.class); + if (metadata != null) { + return metadata; + } + + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("metadataCustomizationFilter", metadataCustomizationFilter); + String response = client.invoke(String.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataString", "Lcm", params, null); + metadata = new MetadataSerializer().deserialize(response, GspMetadata.class); + + if (metadataCustomizationFilter.isI18n()) { + try { + List resources = SpringBeanUtils.getBean(II18nResourceRTManager.class).getI18nResource(metadata, language); + MetadataI18nService service = I18nManagerHelper.getInstance().getI18nManager(metadata.getHeader().getType()); + if (service != null && resources != null && resources.size() > 0) { + var result = service.merge(metadata, resources); + RtCacheHandler.updateMetadataCache(metadataKey, result); + return result; + } + } catch (Exception e) { + //TODO 表单强制获取资源项,获取不到时会报错,异常太多,暂时catch住 + } + } + + if (metadata != null) { + cacheManager.put(metadataKey, metadata); + } + return metadata; + } + + @Override + public void loadAllMetadata() { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + client.invoke(String.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.loadAllMetadata", "Lcm", params, null); + } + + @Override + public List getMetadataRefList(String metadataTypes) { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("metadataTypes", metadataTypes); + String response = client.invoke(String.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataRefDtoListWithTypes", "Lcm", params, null); + return utils.buildMetadata4RefList(response); + } + + @Override + public List getMetadataRefList() { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + String response = client.invoke(String.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataRefDtoList", "Lcm", params, null); + return utils.buildMetadata4RefList(response); + } + + @Override + public List getMetadataListByFilter(MetadataRTFilter filter) { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("filter", utils.serializerMetadataRtFilter(filter)); + String response = client.invoke(String.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataDtoListByFilter", "Lcm", params, null); + return utils.buildMetadata4RefList(response); + } + + @Override + public GspMetadata getMetadataBySemanticID(String metadataNamespace, String metadataCode, String metadataTypeCode) { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("metadataNamespace", metadataNamespace); + params.put("metadataCode", metadataCode); + params.put("metadataTypeCode", metadataTypeCode); + MetadataDto response = client.invoke(MetadataDto.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getMetadataDtoBySemanticID", "Lcm", params, null); + return MetadataDtoConverter.asMetadata(response); + } + + @Override + public ServiceUnitInfo getServiceUnitInfo(String metadataId) { + RpcClient client = SpringBeanUtils.getBean(RpcClient.class); + LinkedHashMap params = new LinkedHashMap<>(); + params.put("metadataId", metadataId); + return client.invoke(ServiceUnitInfo.class, "com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService.getServiceUnitInfo", "Lcm", params, null); + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRtUtils.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRtUtils.java new file mode 100644 index 0000000..21f6af7 --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRtUtils.java @@ -0,0 +1,83 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.rtservice; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4Ref; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataRTFilter; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.springframework.util.StringUtils; + +/** + * @author zhaoleitr + */ +public class MetadataRtUtils { + public List buildMetadata4RefList(String dtosStr) { + if (StringUtils.isEmpty(dtosStr)) { + return null; + } + List dtoList = deserializerMetadata4RefDto(dtosStr); + if (dtoList == null || dtoList.size() <= 0) { + return null; + } + List metadataList = new ArrayList<>(); + for (Metadata4RefDto dto : dtoList) { + Metadata4Ref metadata4Ref = new Metadata4Ref(); + metadata4Ref.setPackageHeader(dto.getPackageHeader()); + metadata4Ref.setMetadata(MetadataDtoConverter.asMetadata(dto.getMetadata())); + metadata4Ref.setServiceUnitInfo(dto.getServiceUnitInfo()); + metadataList.add(metadata4Ref); + } + return metadataList; + } + + private List deserializerMetadata4RefDto(String content) { + List result = new ArrayList<>(); + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + try { + result = mapper.readValue(content, new TypeReference>() { + }); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } + + public String serializerMetadataRtFilter(MetadataRTFilter filter) { + String result = ""; + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + try { + result = mapper.writeValueAsString(filter); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java new file mode 100644 index 0000000..a0b1d15 --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java @@ -0,0 +1,693 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager; + +import com.inspur.edp.i18n.resource.api.II18nResourceRTManager; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.I18nResource; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4Ref; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataCustomizationFilter; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.api.entity.MetadataRTFilter; +import com.inspur.edp.lcm.metadata.api.entity.ServiceUnitInfo; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.cache.MetadataCacheManager; +import com.inspur.edp.lcm.metadata.cache.MetadataDistCacheManager; +import com.inspur.edp.lcm.metadata.cache.MetadataRtDistCache; +import com.inspur.edp.lcm.metadata.cache.RtCacheHandler; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import com.inspur.edp.lcm.metadata.common.MetadataSerializer; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.common.configuration.I18nManagerHelper; +import com.inspur.edp.lcm.metadata.common.configuration.MetadataSerializerHelper; +import com.inspur.edp.lcm.metadata.common.context.RuntimeContext; +import com.inspur.edp.lcm.metadata.serverapi.MetadataRTServerService; +import com.inspur.edp.lcm.metadata.servermanager.persistent.RepositoryFactory; +import com.inspur.edp.lcm.metadata.servermanager.util.MetadataServerManagerUitls; +import com.inspur.edp.lcm.metadata.servermanager.util.MetadataUtils; +import com.inspur.edp.lcm.metadata.spi.MetadataI18nService; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import io.iec.edp.caf.commons.layeringcache.cache.Cache; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; +import javax.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import lombok.var; +import org.codehaus.plexus.util.StringUtils; + +/** + * @author zhaoleitr + */ +@Slf4j +public class MetadataRTServerServiceImpl implements MetadataRTServerService { + FileService fileService = new FileServiceImp(); + + private II18nResourceRTManager i18nResourceRtManager; + + private II18nResourceRTManager getI18nResourceRtManager() { + if (i18nResourceRtManager == null) { + i18nResourceRtManager = SpringBeanUtils.getBean(II18nResourceRTManager.class); + } + return i18nResourceRtManager; + } + + private final Lock lock = new ReentrantLock(); + private static String serverBasePath = ""; + private static String metadataAppPath = ""; + private static String metadataPlatformPath = ""; + private final MetadataServerManagerUitls utils = new MetadataServerManagerUitls(); + + /** + * 启动时加载所有元数据 + */ + @PostConstruct + private void init() { + log.info("Loading Metadata..."); + try { + ExecutorService executor = Executors.newCachedThreadPool(); + executor.submit( + this::loadAllMetadata); + } catch (Exception e) { + log.error("Loading Metadata Failed", e); + } + } + + @Override + public MetadataDto getMetadataDtoRTByID(String id) { + GspMetadata metadata = getMetadataRTByID(id); + return MetadataDtoConverter.asDto(metadata); + } + + private GspMetadata getMetadataRTByID(String metadataID) { + String metadataKey = RtCacheHandler.getMetadataCacheKey(metadataID, ""); + GspMetadata metadataCache = (GspMetadata) MetadataCacheManager.getMetadataInfo(metadataKey); + if (metadataCache != null) { + return metadataCache; + } + String metadataPackagePath = (String) MetadataCacheManager.getMetadataPathMapping(metadataKey); + if (metadataPackagePath == null || metadataPackagePath.isEmpty()) { +// throw new IllegalArgumentException("Could not find metadata, metadataid is " + metadataID); + return null; + } + GspMetadata metadata = getMetadataByIdAndMetadataPath(metadataID, metadataPackagePath); + RtCacheHandler.updateMetadataCache(metadataKey, metadata); + return metadata; + } + + public GspMetadata getMetadataByIdAndMetadataPath(String metadataId, String metadataPath) { + String entryName = metadataPath.substring(metadataPath.indexOf(MetadataUtils.getMetadataPackageExtension()) + MetadataUtils.getMetadataPackageExtension().length() + 1); + metadataPath = metadataPath.substring(0, metadataPath.indexOf(entryName) - 1); + GspMetadata metadata = null; + lock.lock(); + try { + String manifestStr = ""; + StringBuilder sb = new StringBuilder(); + File file = new File(metadataPath); + ZipFile zf = new ZipFile(file); + InputStream in = new BufferedInputStream(new FileInputStream(metadataPath)); + Charset utf8 = StandardCharsets.UTF_8; + ZipInputStream zipInputStream = new ZipInputStream(in, utf8); + ZipEntry zipEntry; + while ((zipEntry = zipInputStream.getNextEntry()) != null) { + if (zipEntry.toString().equals(entryName)) { + BufferedReader br; + br = new BufferedReader(new InputStreamReader(zf.getInputStream(zipEntry), utf8)); + try { + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + manifestStr = sb.toString(); + } catch (IOException e) { + log.error("Error in reading metadata"); + throw new IOException("Error in reading metadata in " + metadataPath, e); + } finally { + br.close(); + } + } + } + zipInputStream.close(); + in.close(); + zf.close(); + if (!manifestStr.isEmpty()) { + metadata = new MetadataSerializer().deserialize(manifestStr, GspMetadata.class); + } + + } catch (IOException ioe) { + log.error("构建元数据失败,元数据位置:" + metadataPath + "元数据id:" + metadataId, ioe); + } finally { + lock.unlock(); + } + if (metadata == null) { + throw new RuntimeException("Could not find metadata content!"); + } + return metadata; + } + + private GspMetadata getI18nMetadata(String metadataId, String language) { + if (language == null) { + language = RuntimeContext.getLanguage(); + } + //从缓存中获取元数据,缓存中的元数据认为是国际化的元数据内容 + //缓存中不存在元数据,获取基础元数据内容, + //根据基础元数据内容,获取国际化资源, + //根据合并接口合并元数据,并返回内容,添加缓存。 + String metadataKey = RtCacheHandler.getMetadataCacheKey(metadataId, language); + GspMetadata metadataCache = (GspMetadata) MetadataCacheManager.getMetadataInfo(metadataKey); + if (metadataCache != null) { + return metadataCache; + } + GspMetadata originalData = getMetadataRTByID(metadataId); + //获取多语资源,此处try为兼容各个未国际化的元数据 + try { + List resources = getI18nResourceRtManager().getI18nResource(originalData, language); + MetadataI18nService service = I18nManagerHelper.getInstance().getI18nManager(originalData.getHeader().getType()); + if (service != null && resources != null && resources.size() > 0) { + var result = service.merge(originalData, resources); + RtCacheHandler.updateMetadataCache(metadataKey, result); + return result; + } + } catch (Exception e) { + //TODO 表单强制获取资源项,获取不到时会报错,异常太多,暂时catch住 + } + return originalData; + } + + @Override + public MetadataDto getMetadataDto(String id) { + String language = RuntimeContext.getLanguage(); + return MetadataDtoConverter.asDto(getI18nMetadata(id, language)); + } + + @Override + public GspMetadata getMetadata(String id) { + String language = RuntimeContext.getLanguage(); + return getI18nMetadata(id, language); + } + + @Override + public List getMetadataListRecursivly(String path) { + List result = new ArrayList<>(); + try { + Map packages = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(path)); + if (packages != null && packages.size() > 0) { + for (Map.Entry valuePair : packages.entrySet()) { + MetadataPackage metadataPackage = valuePair.getValue(); + String metadataPackagePath = valuePair.getKey(); + for (GspMetadata item : metadataPackage.getMetadataList()) { + GspMetadata metadata = getMetadataByIdAndMetadataPath(item.getHeader().getId(), metadataPackagePath + item.getRelativePath()); + result.add(metadata); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("递归获取路径下元数据包中元数据列表报错,路径为" + path, e); + } + return result; + } + + public List getExtendableMetadataListRecursivly(String path) { + List result = new ArrayList<>(); + try { + Map packages = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(path)); + if (packages != null && packages.size() > 0) { + for (Map.Entry valuePair : packages.entrySet()) { + MetadataPackage metadataPackage = valuePair.getValue(); + String metadataPackagePath = valuePair.getKey(); + for (GspMetadata item : metadataPackage.getMetadataList()) { + if (item.getHeader().isExtendable()) { + GspMetadata metadata = getMetadataByIdAndMetadataPath(item.getHeader().getId(), metadataPackagePath + item.getRelativePath()); + result.add(metadata); + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("递归获取路径下元数据包中元数据列表报错,路径为" + path, e); + } + return result; + } + + @Override + public List getMetadataListFromPackage(String packagePath) { + List result = new ArrayList<>(); + + if (!fileService.isFileExist(packagePath)) { + throw new RuntimeException("元数据包不存在,元数据包路径为" + packagePath); + } + try { + MetadataPackage metadataPackage = RepositoryFactory.getInstance().getMetadataPackageRepository().getMetadataPackage(new File(packagePath)); + for (GspMetadata item : metadataPackage.getMetadataList()) { + GspMetadata metadata = getMetadataByIdAndMetadataPath(item.getHeader().getId(), packagePath + item.getRelativePath()); + result.add(metadata); + } + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } + + public List getMetadataListInfoFromPackage(String packagePath) { + List result = new ArrayList<>(); + + if (!fileService.isFileExist(packagePath)) { + throw new RuntimeException("元数据包不存在,元数据包路径为" + packagePath); + } + try { + MetadataPackage metadataPackage = RepositoryFactory.getInstance().getMetadataPackageRepository().getMetadataPackage(new File(packagePath)); + if (Objects.isNull(metadataPackage)) { + return null; + } + return metadataPackage.getMetadataList(); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public Map getMetadataPackagesRecursivly(String path) { + Map result; + try { + result = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(path)); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("递归获取路径下元数据包中元数据列表报错,路径为" + path, e); + } + return result; + } + + @Override + public void loadAllMetadata() { + String basePath = EnvironmentUtil.getBasePath(); + FileServiceImp fileService = new FileServiceImp(); + metadataAppPath = fileService.getCombinePath(basePath, "metadata/apps"); + metadataPlatformPath = fileService.getCombinePath(basePath, "metadata/platform"); + + //元数据包信息,<元数据包绝对路径,元数据包信息> + Map packageDicInApps; + Map packageDic; + List metadataInfoList = new ArrayList<>(); + try { + packageDicInApps = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(metadataAppPath)); + Map packageDicInPlatform = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(metadataPlatformPath)); + packageDic = Stream.concat(packageDicInApps.entrySet().stream(), packageDicInPlatform.entrySet().stream()) + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (value1, value2) -> value1)); + } catch (Exception e) { + log.error("Error in reading metadata in metadata/apps or platform", e); + throw new RuntimeException("Error in reading metadata in metadata/apps or platform", e); + } + if (packageDic.size() > 0) { + for (Map.Entry valuePair : packageDic.entrySet()) { + String metadataPackagePath = valuePair.getKey(); + MetadataPackage metadataPackage = valuePair.getValue(); + if (metadataPackage != null) { + RtCacheHandler.updateMetadataPackageCache(metadataPackage.getHeader().getName(), metadataPackage); + } + for (GspMetadata item : metadataPackage.getMetadataList()) { + // + languageID; + String metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); + MetadataCacheManager.addMetadataPathMapping(metadataKey, metadataPackagePath + item.getRelativePath()); + metadataInfoList.add(item); + } + MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey, metadataInfoList); + } + } + Cache metadataCache = MetadataDistCacheManager.getMetadataCache(); + metadataCache.clear(); + Cache metadataRtCache = MetadataRtDistCache.getMetadataCache(); + metadataRtCache.clear(); + + // 预加载序反列化器 + MetadataSerializerHelper.getInstance(); + } + + public void loadAllMetadataByPath(String path, String packagePath) { + FileServiceImp fileService = new FileServiceImp(); + String metadataAppPath = fileService.getCombinePath(path, "metadata/apps"); + String metadataPlatformPath = fileService.getCombinePath(path, "metadata/platform"); + + //元数据包信息,<元数据包绝对路径,元数据包信息> + Map packageDicInApps; + Map packageDic; + List metadataInfoList = new ArrayList<>(); + try { + packageDicInApps = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(metadataAppPath)); + Map packageDicInPlatform = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(metadataPlatformPath)); + Map packegeDicInDeployPath = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(packagePath)); + Map serverPackageDic = Stream.concat(packageDicInApps.entrySet().stream(), packageDicInPlatform.entrySet().stream()) + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (value1, value2) -> value1)); + packageDic = Stream.concat(serverPackageDic.entrySet().stream(), packegeDicInDeployPath.entrySet().stream()) + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (value1, value2) -> value1)); + } catch (Exception e) { + throw new RuntimeException("Error in reading metadata in metadata/apps or platform", e); + } + if (packageDic.size() > 0) { + for (Map.Entry valuePair : packageDic.entrySet()) { + String metadataPackagePath = valuePair.getKey(); + MetadataPackage metadataPackage = valuePair.getValue(); + if (metadataPackage != null) { + RtCacheHandler.updateMetadataPackageCache(metadataPackage.getHeader().getName(), metadataPackage); + } + for (GspMetadata item : metadataPackage.getMetadataList()) { + // + languageID; + String metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); + MetadataCacheManager.addMetadataPathMapping(metadataKey, metadataPackagePath + item.getRelativePath()); + metadataInfoList.add(item); + } + } + MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey, metadataInfoList); + } + // 预加载序反列化器 + MetadataSerializerHelper.getInstance(); + } + + public List getMetadataList(String metadataTypes) { + var result = getMetadataRefListWithTypes(metadataTypes); + return utils.buildMetadata4RefDto(result); + } + + @Override + public String getMetadataRefDtoList() { + List metadataList = getMetadataRefList(); + return utils.serializeMetadata4RefDtos(utils.buildMetadata4RefDto(metadataList)); + } + + @Override + public List getMetadataRefList() { + List metadataList = new ArrayList<>(); + //首先从缓存获取 + List packagesCache = (List) MetadataCacheManager.getAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + if (packagesCache != null && packagesCache.size() > 0) { + for (MetadataPackage pack : packagesCache) { + List metadata4Ref = getMetadata4Ref(pack, null); + metadataList.addAll(metadata4Ref); + } + return metadataList; + } + List metadataPackages = getMetadataPackages(); + for (MetadataPackage metadataPackage : metadataPackages) { + List metadata4Ref = getMetadata4Ref(metadataPackage, null); + metadataList.addAll(metadata4Ref); + } + MetadataCacheManager.addAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey, metadataPackages); + return metadataList; + } + + private List getMetadataPackages() { + + serverBasePath = EnvironmentUtil.getBasePath(); + FileServiceImp fileService = new FileServiceImp(); + metadataAppPath = fileService.getCombinePath(serverBasePath, "metadata/apps"); + metadataPlatformPath = fileService.getCombinePath(serverBasePath, "metadata/platform"); + + //元数据部署目录下遍历 + //List paths = new ArrayList<>(); + //找到目录下的所有元数据包mdpkg + //RepositoryFactory.getInstance().getMetadataPackageRepository().getMdpkgFilesPath(Utils.handlePath("metadata/apps"), paths); + //RepositoryFactory.getInstance().getMetadataPackageRepository().getMdpkgFilesPath(Utils.handlePath("metadata/platform"), paths); + + //缓存的包列表 + List metadataPackages = new ArrayList<>(); + //元数据包信息,<元数据包绝对路径,元数据包信息> + Map packageDicInApps; + Map packageDicInPlatform; + + try { + packageDicInApps = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(metadataAppPath)); + packageDicInPlatform = RepositoryFactory.getInstance().getMetadataPackageRepository().retrieveAllMdPkg(Utils.handlePath(metadataPlatformPath)); + } catch (Exception e) { + log.error("Error in reading metadata in metadata/apps or platform", e); + throw new RuntimeException("Error in reading metadata in metadata/apps or platform", e); + } + + if (packageDicInApps.values().size() > 0) { + metadataPackages.addAll(packageDicInApps.values()); + } + if (packageDicInPlatform.values().size() > 0) { + metadataPackages.addAll(packageDicInPlatform.values()); + } + return metadataPackages; + } + + @Override + public String getMetadataDtoListByFilter(String filter) { + MetadataRTFilter filterInfo = utils.deserializerMetadataRTFilter(filter); + List metadataList = getMetadataListByFilter(filterInfo); + return utils.serializeMetadata4RefDtos(utils.buildMetadata4RefDto(metadataList)); + } + + @Override + public List getMetadataListByFilter(MetadataRTFilter filter) { + + List metadataList; + // 获取所有元数据包 + metadataList = getMetadataRefList(); + // 根据AppCode进行过滤 + if (filter.getAppCode() != null) { + metadataList = metadataList.stream().filter(item -> item.getServiceUnitInfo() == null || item.getServiceUnitInfo().getAppCode().equals(filter.getAppCode())).collect(Collectors.toList()); + } + // 根据ServiceUnitCode进行过滤 + if (filter.getServiceUnitCode() != null) { + metadataList = metadataList.stream().filter(item -> item.getServiceUnitInfo() == null || item.getServiceUnitInfo().getServiceUnitCode().equals(filter.getServiceUnitCode())).collect(Collectors.toList()); + } + // 根据BizobjectID进行过滤 + if (filter.getBizobjectId() != null && filter.getBizobjectId().size() > 0) { + for (String eachBizobjectId : filter.getBizobjectId()) { + metadataList = metadataList.stream().filter(item -> item.getMetadata().getHeader().getBizobjectID().equals(eachBizobjectId)).collect(Collectors.toList()); + } + } + if (filter.getCode() != null) { + metadataList = metadataList.stream().filter(item -> item.getMetadata().getHeader().getCode() != null && item.getMetadata().getHeader().getCode().equals(filter.getCode())).collect(Collectors.toList()); + } + if (filter.getNameSpace() != null) { + metadataList = metadataList.stream().filter(item -> item.getMetadata().getHeader().getNameSpace() != null && item.getMetadata().getHeader().getNameSpace().equals(filter.getNameSpace())).collect(Collectors.toList()); + } + if (filter.getType() != null) { + metadataList = metadataList.stream().filter(item -> item.getMetadata().getHeader().getType() != null && item.getMetadata().getHeader().getType().equals(filter.getType())).collect(Collectors.toList()); + } + return metadataList; + } + + /*** + * @author zhongchq + * @param metadataTypes 想要获取的元数据类型 + * @return java.util.List + **/ + @Override + public String getMetadataRefDtoListWithTypes(String metadataTypes) { + List metadata4Refs = getMetadataRefListWithTypes(metadataTypes); + return utils.serializeMetadata4RefDtos(utils.buildMetadata4RefDto(metadata4Refs)); + + } + + @Override + public List getMetadataRefListWithTypes(String metadataTypes) { + List typeList; + if (metadataTypes == null || metadataTypes.isEmpty()) { + throw new RuntimeException("传入参数不能为空"); + } else { + String[] types = metadataTypes.split(","); + typeList = new ArrayList<>(Arrays.asList(types)); + } + List metadataList = new ArrayList<>(); + //首先从缓存获取 + List packagesCache = (List) MetadataCacheManager.getAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + if (packagesCache != null && packagesCache.size() > 0) { + for (MetadataPackage pack : packagesCache) { + List metadata4Ref = getMetadata4Ref(pack, typeList); + metadataList.addAll(metadata4Ref); + } + return metadataList; + } + + List metadataPackages = getMetadataPackages(); + for (MetadataPackage metadataPackage : metadataPackages) { + List metadata4Ref = getMetadata4Ref(metadataPackage, typeList); + metadataList.addAll(metadata4Ref); + } + + MetadataCacheManager.addAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey, metadataPackages); + return metadataList; + } + + private List getMetadata4Ref(MetadataPackage packageInfo, List metadataTypes) { + List metadata4RefList = new ArrayList<>(); + if (metadataTypes != null && metadataTypes.size() > 0) { + metadataTypes.forEach(type -> + { + var result = packageInfo.getMetadataList().stream().filter(item -> item.getHeader().getType().toLowerCase().equals(type.toLowerCase())).collect(Collectors.toList()); + if (result.size() > 0) { + result.forEach(metadata -> { + Metadata4Ref metadata4Ref = new Metadata4Ref(); + metadata4Ref.setMetadata(metadata); + metadata4Ref.setServiceUnitInfo(packageInfo.getServiceUnitInfo()); + metadata4Ref.setPackageHeader(packageInfo.getHeader()); + metadata4RefList.add(metadata4Ref); + }); + } + } + ); + } else { + packageInfo.getMetadataList().forEach(metadata -> { + Metadata4Ref metadata4Ref = new Metadata4Ref(); + metadata4Ref.setMetadata(metadata); + metadata4Ref.setServiceUnitInfo(packageInfo.getServiceUnitInfo()); + metadata4Ref.setPackageHeader(packageInfo.getHeader()); + metadata4RefList.add(metadata4Ref); + }); + } + return metadata4RefList; + } + + @Override + public MetadataDto getMetadataDtoBySemanticID(String metadataNamespace, String metadataCode, + String metadataTypeCode) { + GspMetadata metadata = getMetadataBySemanticId(metadataNamespace, metadataCode, metadataTypeCode); + return MetadataDtoConverter.asDto(metadata); + } + + private GspMetadata getMetadataBySemanticId(String metadataNamespace, String metadataCode, + String metadataTypeCode) { + List allMetadataInfo = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey); + if (allMetadataInfo != null) { + for (GspMetadata item : allMetadataInfo) { + if (item.getHeader().getNameSpace().toLowerCase().equals(metadataNamespace.toLowerCase()) + && item.getHeader().getCode().toLowerCase().equals(metadataCode.toLowerCase()) + && item.getHeader().getType().toLowerCase().equals(metadataTypeCode.toLowerCase())) { + return getMetadataRTByID(item.getHeader().getId()); + } + } + } + List allMetadataList = getMetadataList(metadataTypeCode); + if (allMetadataList != null) { + for (Metadata4RefDto item : allMetadataList) { + if (item.getMetadata().getNameSpace().toLowerCase().equals(metadataNamespace.toLowerCase()) + && item.getMetadata().getCode().toLowerCase().equals(metadataCode.toLowerCase())) { + return getMetadataRTByID(item.getMetadata().getId()); + } + } + } + return null; + } + + @Override + public ServiceUnitInfo getServiceUnitInfo(String metadataId) { + String metadataKey = RtCacheHandler.getMetadataCacheKey(metadataId, ""); + String metadataPackagePath = (String) MetadataCacheManager.getMetadataPathMapping(metadataKey); + if (metadataPackagePath == null || metadataPackagePath.isEmpty()) { + throw new IllegalArgumentException("Could not find metadata, metadataid is " + metadataId); + } + String entryName = metadataPackagePath.substring(metadataPackagePath.indexOf(MetadataUtils.getMetadataPackageExtension()) + MetadataUtils.getMetadataPackageExtension().length() + 1); + metadataPackagePath = metadataPackagePath.substring(0, metadataPackagePath.indexOf(entryName) - 1); + String metadataPackageName = new File(metadataPackagePath).getName(); + String metadataPackageNameWithoutSuffix = metadataPackageName.substring(0, metadataPackageName.indexOf(MetadataUtils.getMetadataPackageExtension())); + MetadataPackage metadataPackage = (MetadataPackage) MetadataCacheManager.getMetadataPackageInfo(metadataPackageNameWithoutSuffix); + return metadataPackage.getServiceUnitInfo(); + } + + @Override + public String getMetadataString(MetadataCustomizationFilter metadataCustomizationFilter) { + return getMetadataStrFromPackage(metadataCustomizationFilter.getMetadataId()); + } + + private String getMetadataStrFromPackage(String metadataID) { + String metadataKey = RtCacheHandler.getMetadataCacheKey(metadataID, ""); + String metadataPackagePath = (String) MetadataCacheManager.getMetadataPathMapping(metadataKey); + if (metadataPackagePath == null || metadataPackagePath.isEmpty()) { + return null; + } + String entryName = metadataPackagePath.substring(metadataPackagePath.indexOf(MetadataUtils.getMetadataPackageExtension()) + MetadataUtils.getMetadataPackageExtension().length() + 1); + metadataPackagePath = metadataPackagePath.substring(0, metadataPackagePath.indexOf(entryName) - 1); + String metadataStr = ""; + + lock.lock(); + try { + StringBuilder sb = new StringBuilder(); + File file = new File(metadataPackagePath); + ZipFile zf = new ZipFile(file); + InputStream in = new BufferedInputStream(new FileInputStream(metadataPackagePath)); + Charset utf8 = StandardCharsets.UTF_8; + ZipInputStream zipInputStream = new ZipInputStream(in, utf8); + ZipEntry zipEntry; + while ((zipEntry = zipInputStream.getNextEntry()) != null) { + if (zipEntry.toString().equals(entryName)) { + BufferedReader br; + br = new BufferedReader(new InputStreamReader(zf.getInputStream(zipEntry), utf8)); + try { + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + metadataStr = sb.toString(); + } catch (IOException e) { + log.error("Error in reading metadata"); + throw new IOException("Error in reading metadata in " + metadataPackagePath, e); + } finally { + br.close(); + } + } + } + zipInputStream.close(); + in.close(); + zf.close(); + } catch (IOException ioe) { + log.error("构建元数据失败,元数据位置:" + metadataPackagePath + "元数据id:" + metadataID, ioe); + } finally { + lock.unlock(); + } + if (StringUtils.isEmpty(metadataStr)) { + throw new RuntimeException("Could not find metadata " + metadataID + " from " + metadataPackagePath); + } + return metadataStr; + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/configuration/RestConfiguarion.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/configuration/RestConfiguarion.java new file mode 100644 index 0000000..a410c6a --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/configuration/RestConfiguarion.java @@ -0,0 +1,47 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.configuration; + +import com.inspur.edp.lcm.metadata.api.service.MetadataRTService; +import com.inspur.edp.lcm.metadata.rtservice.MetadataRTServiceImp; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Classname RestConfiguarion Description TODO Date 2019/8/28 14:14 + * + * @author zhongchq + * @version 1.0 + */ +//todo +//@Configuration(proxyBeanMethods = false) +@Configuration() +public class RestConfiguarion { + + @Bean + public MetadataRTService createMetadataRTService() { + return new MetadataRTServiceImp(); + } + +// @Bean +// public MetadataRT4WebApiService createMetadata4WebApiService(){ +// return new MetadataRT4WebApiServiceImp(); +// } +// @Bean +// public RESTEndpoint restEndpoint(MetadataRT4WebApiService metadataRT4WebApiService){ +// return new RESTEndpoint("/runtime/sys/v1.0/rt-metadatas",metadataRT4WebApiService); +// } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventBroker.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventBroker.java new file mode 100644 index 0000000..7daee29 --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventBroker.java @@ -0,0 +1,66 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.event; + +import io.iec.edp.caf.commons.event.CAFEventArgs; +import io.iec.edp.caf.commons.event.EventBroker; +import io.iec.edp.caf.commons.event.IEventListener; +import io.iec.edp.caf.commons.event.config.EventListenerData; +import io.iec.edp.caf.commons.event.config.EventListenerSettings; + +/** + * @author zhaoleitr + */ +public class MdPkgChangedEventBroker extends EventBroker { + + public MdPkgChangedEventManager mdPkgChangedEventManager; + + public MdPkgChangedEventBroker(EventListenerSettings settings) { + super(settings); + this.mdPkgChangedEventManager = new MdPkgChangedEventManager(); + this.init(); + } + + @Override + protected void onInit() { + this.eventManagerCollection.add(mdPkgChangedEventManager); + } + + public void fireMdPkgAddedEvent(CAFEventArgs e) { + this.mdPkgChangedEventManager.fireMdPkgAddedEvent(e); + + } + + public void fireMdPkgChangedEvent(CAFEventArgs e) { + this.mdPkgChangedEventManager.fireMdPkgChangedEvent(e); + } + + /** + * 测试异常是否被抛出 + */ + public IEventListener createEventListenerTest(EventListenerData eventListenerData) { + return this.createEventListener(eventListenerData); + } + + /** + * 测试注销事件 + * + * @param eventListener + */ + public void removeListenerTest(IEventListener eventListener) { + this.removeListener(eventListener); + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java new file mode 100644 index 0000000..b0414ba --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java @@ -0,0 +1,76 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.event; + +import com.inspur.edp.lcm.metadata.spi.event.MdPkgChangedEventListener; +import io.iec.edp.caf.commons.event.CAFEventArgs; +import io.iec.edp.caf.commons.event.EventManager; +import io.iec.edp.caf.commons.event.IEventListener; + +/** + * 元数据包变更监听mangaer + * + * @author zhaoleitr + */ +public class MdPkgChangedEventManager extends EventManager { + + /** + * 内部枚举类 + */ + enum MetadataRtEventType { + fireMdPkgAddedEvent, + fireMdPkgChangedEvent + } + + @Override + public String getEventManagerName() { + return "MdpkgChangedEventManager"; + } + + @Override + public boolean isHandlerListener(IEventListener iEventListener) { + return iEventListener instanceof MdPkgChangedEventListener; + } + + @Override + public void addListener(IEventListener iEventListener) { + if (iEventListener instanceof MdPkgChangedEventListener == false) { + throw new RuntimeException("指定的监听者没有实现IDemoEventListener接口"); + } + MdPkgChangedEventListener mdPkgChangedEventListener = (MdPkgChangedEventListener) iEventListener; + this.addEventHandler(MetadataRtEventType.fireMdPkgAddedEvent, mdPkgChangedEventListener, "fireMdPkgAddedEvent"); + this.addEventHandler(MetadataRtEventType.fireMdPkgChangedEvent, mdPkgChangedEventListener, "fireMdPkgChangedEvent"); + } + + @Override + public void removeListener(IEventListener iEventListener) { + if (iEventListener instanceof MdPkgChangedEventListener == false) { + throw new RuntimeException("指定的监听者没有实现IDemoEventListener接口"); + } + MdPkgChangedEventListener mdPkgChangedEventListener = (MdPkgChangedEventListener) iEventListener; + this.removeEventHandler(MetadataRtEventType.fireMdPkgAddedEvent, mdPkgChangedEventListener, "fireMdPkgAddedEvent"); + this.removeEventHandler(MetadataRtEventType.fireMdPkgChangedEvent, mdPkgChangedEventListener, "fireMdPkgChangedEvent"); + + } + + public void fireMdPkgAddedEvent(CAFEventArgs e) { + this.fire(MetadataRtEventType.fireMdPkgAddedEvent, e); + } + + public void fireMdPkgChangedEvent(CAFEventArgs e) { + this.fire(MetadataRtEventType.fireMdPkgChangedEvent, e); + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgAlterationMonitor.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgAlterationMonitor.java new file mode 100644 index 0000000..c827ddd --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgAlterationMonitor.java @@ -0,0 +1,105 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.monitor; + +import org.apache.commons.io.filefilter.FileFilterUtils; +import org.apache.commons.io.filefilter.HiddenFileFilter; +import org.apache.commons.io.filefilter.IOFileFilter; +import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; +import org.apache.commons.io.monitor.FileAlterationMonitor; +import org.apache.commons.io.monitor.FileAlterationObserver; + +public class MdpkgAlterationMonitor { + private String path; // 文件夹目录 + + private String fileSuffix; // 需要监听的文件名后缀 + + private long interval; // 监听间隔 + + private static final long DEFAULT_INTERVAL = 10 * 1000; // 默认监听间隔10s + + private boolean running = false; + + private FileAlterationListenerAdaptor listener; // 事件处理类对象 + + private FileAlterationMonitor monitor; + + public MdpkgAlterationMonitor() { + this.interval = DEFAULT_INTERVAL; + } + + public MdpkgAlterationMonitor(String path, String fileSuffix, FileAlterationListenerAdaptor listenerAdaptor) { + this.path = path; + this.fileSuffix = fileSuffix; + this.interval = DEFAULT_INTERVAL; + this.listener = listenerAdaptor; + } + + public MdpkgAlterationMonitor(String path, String fileSuffix, long interval, + FileAlterationListenerAdaptor listenerAdaptor) { + this.path = path; + this.fileSuffix = fileSuffix; + this.interval = interval; + this.listener = listenerAdaptor; + } + + /*** + * 开启监听 + */ + public void start() { + if (path == null) { + throw new IllegalStateException("Listen path must not be null"); + } + if (listener == null) { + throw new IllegalStateException("Listener must not be null"); + } + + IOFileFilter directories = FileFilterUtils.and( + FileFilterUtils.directoryFileFilter(), + HiddenFileFilter.VISIBLE); + IOFileFilter files = FileFilterUtils.and( + FileFilterUtils.fileFileFilter(), + FileFilterUtils.suffixFileFilter(fileSuffix)); + IOFileFilter filter = FileFilterUtils.or(directories, files); + // 设定观察者,监听文件 + FileAlterationObserver observer = new FileAlterationObserver(path, filter); + // 给观察者添加监听事件 + observer.addListener(listener); + + // 开启一个监视器,监听频率是5s一次 + // FileAlterationMonitor本身实现了 Runnable,是单独的一个线程,按照设定的时间间隔运行,默认间隔是 10s + monitor = new FileAlterationMonitor(interval); + + monitor.addObserver(observer); + + try { + monitor.start(); + running = true; + } catch (Exception e) { + e.printStackTrace(); + } + } + +// public void checkAndNotify() { +// if (running) { +// Iterator i$ = this.monitor.getObservers().iterator(); +// while(i$.hasNext()) { +// FileAlterationObserver observer = (FileAlterationObserver)i$.next(); +// observer.checkAndNotify(); +// } +// } +// } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java new file mode 100644 index 0000000..86d0006 --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java @@ -0,0 +1,197 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.monitor; + +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.cache.MetadataCacheManager; +import com.inspur.edp.lcm.metadata.cache.MetadataDistCacheManager; +import com.inspur.edp.lcm.metadata.cache.MetadataRtDistCache; +import com.inspur.edp.lcm.metadata.cache.RtCacheHandler; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.servermanager.event.MdPkgChangedEventBroker; +import com.inspur.edp.lcm.metadata.servermanager.persistent.RepositoryFactory; +import com.inspur.edp.lcm.metadata.spi.event.MdPkgChangedArgs; +import io.iec.edp.caf.commons.layeringcache.cache.Cache; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import io.iec.edp.caf.i18n.framework.api.language.EcpLanguage; +import io.iec.edp.caf.i18n.framework.api.language.ILanguageService; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.io.monitor.FileAlterationListenerAdaptor; + +public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { + + public MdpkgListenerAdapter() { + + } +// @Override +// public void onStart(FileAlterationObserver observer) { +// System.out.println("start"); +// super.onStart(observer); +// } +// +// @Override +// public void onStop(FileAlterationObserver observer) { +// System.out.println("stop"); +// super.onStop(observer); +// } + + @Override + public void onFileCreate(File file) { + try { + super.onFileCreate(file); + updateMdpkgAndMetadataCache(file, true); + + } catch (Exception e) { + System.out.println(e); + } + } + + @Override + public void onFileDelete(File file) { + try { + //更新缓存信息,文件删除时,具体缓存应该移除 + super.onFileDelete(file); + deleteMdpkgAndMetadataCache(file); + } catch (Exception e) { + System.out.println(e); + } + } + + @Override + public void onFileChange(File file) { + try { + //更新缓存信息 + super.onFileChange(file); + updateMdpkgAndMetadataCache(file, false); + } catch (Exception e) { + System.out.println(e); + } + + } + + private void updateMdpkgAndMetadataCache(File file, boolean isAdd) { + //更新缓存信息:包的信息会更新,因为所有后续获取内容,都依赖于已知的包的信息;所有的元数据内容不需要更新,仅需要移除。 + //当获取元数据时,如果缓存中没有元数据信息,会重新根据已知的包信息,重新加载元数据。 + //在更新元数据包缓存前,需要根据原有包的缓存信息,清理已有的元数据信息。 + //更新所有元数据信息列表 + //清理元数据信息、清理元数据引用信息 + //更新元数据包的信息:元数据包位置信息、元数据包中元数据列表信息、元数据包引用信息 + //更新元数据所在元数据包信息 + try { + Cache metadataCache = MetadataDistCacheManager.getMetadataCache(); + Cache metadataRtCache = MetadataRtDistCache.getMetadataCache(); + MetadataPackage metadataPackage = RepositoryFactory.getInstance().getMetadataPackageRepository().getMetadataPackage(file); + MetadataCacheManager.removeAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + //清理元数据内容缓存,将原有缓存的包中元数据列表从元数据内容缓存移除 + String metadataKey = ""; + List oldPackageMetadataList = (List) MetadataCacheManager.getMDManifestInfo(metadataPackage.getHeader().getName()); + List allMetadataList = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey); + if (oldPackageMetadataList != null && oldPackageMetadataList.size() > 0) { + for (GspMetadata item : oldPackageMetadataList) { + metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); + MetadataCacheManager.removeMetadataInfo(metadataKey); + MetadataCacheManager.removeMDDependence(metadataKey); + MetadataCacheManager.removeMetadataPathMapping(metadataKey); + + List languages = getLanguages(); + for (String language : languages) { + String key = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), language); + MetadataCacheManager.removeMetadataInfo(key); + metadataCache.evict(key); + metadataRtCache.evict(key);//把指定的缓存对象清除 + } + } + //清理并更新所有元数据缓存 + allMetadataList.removeAll(oldPackageMetadataList); + } + allMetadataList.addAll(metadataPackage.getMetadataList()); + MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey, allMetadataList); + //清理并更新包中<元数据标识,元数据所在位置信息缓存>,清理过程在旧包处理过程中 + String metadataPackagePath = Utils.handlePath(file.toString()); + for (GspMetadata item : metadataPackage.getMetadataList()) { + metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); + MetadataCacheManager.addMetadataPathMapping(metadataKey, metadataPackagePath + item.getRelativePath()); + } + //更新包缓存 + RtCacheHandler.updateMetadataPackageCache(metadataPackage.getHeader().getName(), metadataPackage); + + MdPkgChangedEventBroker broker = SpringBeanUtils.getBean(MdPkgChangedEventBroker.class); + MdPkgChangedArgs args = new MdPkgChangedArgs(); + args.setMetadataPackage(metadataPackage); + + if (isAdd) { + broker.fireMdPkgAddedEvent(args); + } else { + broker.fireMdPkgChangedEvent(args); + } + } catch (IOException e) { + throw new RuntimeException("update metadatapackage cache filed, package is " + file, e); + } + } + + private void deleteMdpkgAndMetadataCache(File file) { + //这时不需要获取元数据包中的内容,仅需要根据元数据包文件名称,移除内容即可。 + String packageFileName = file.getName(); + String packageName = packageFileName.substring(0, packageFileName.lastIndexOf(".")); + //清理元数据内容缓存,将原有缓存的包中元数据列表从元数据内容缓存移除 + String metadataKey = ""; + Cache metadataCache = MetadataDistCacheManager.getMetadataCache(); + Cache metadataRtCache = MetadataRtDistCache.getMetadataCache(); + + List oldPackageMetadataList = (List) MetadataCacheManager.getMDManifestInfo(packageName); + List allMetadataList = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey); + if (oldPackageMetadataList != null && oldPackageMetadataList.size() > 0) { + for (GspMetadata item : oldPackageMetadataList) { + metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); + MetadataCacheManager.removeMetadataInfo(metadataKey); + MetadataCacheManager.removeMDDependence(metadataKey); + MetadataCacheManager.removeMetadataPathMapping(metadataKey); + List languages = getLanguages(); + for (String language : languages) { + String key = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), language); + MetadataCacheManager.removeMetadataInfo(key); + metadataCache.evict(key); + metadataRtCache.evict(key); + } + } + //清理并更新所有元数据缓存 + allMetadataList.removeAll(oldPackageMetadataList); + } + //更新包缓存 + MetadataCacheManager.removeMetadataPackageInfo(packageName); + MetadataCacheManager.removeMDManifestInfo(packageName); + MetadataCacheManager.removeMPDependence(packageName); + MetadataCacheManager.removeAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + } + + private static List languages; + + private static List getLanguages() { + if (languages == null || languages.size() <= 0) { + languages = new ArrayList<>(); + ILanguageService laguageService = SpringBeanUtils.getBean(ILanguageService.class); + List ecpLanguages = laguageService.getEnabledLanguages(); + for (EcpLanguage language : ecpLanguages) { + languages.add(language.getCode()); + } + } + return languages; + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MonitorInitializer.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MonitorInitializer.java new file mode 100644 index 0000000..398d2eb --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MonitorInitializer.java @@ -0,0 +1,42 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.monitor; + +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import javax.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class MonitorInitializer { + private final String mdpkgSuffix = ".mdpkg"; + private final String metatdataPath = "metadata"; + + @PostConstruct + public void initMonitor() { + log.info("Start MdpkgMonitor..."); + + FileServiceImp fileService = new FileServiceImp(); + String monitorFilePath = fileService.getCombinePath(EnvironmentUtil.getBasePath(), metatdataPath); + // 创建过滤器 + + MdpkgAlterationMonitor monitor = new MdpkgAlterationMonitor( + monitorFilePath, + mdpkgSuffix, + new MdpkgListenerAdapter()); + monitor.start(); + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepository.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepository.java new file mode 100644 index 0000000..3b7224d --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepository.java @@ -0,0 +1,107 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.persistent; + +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * Classname IMetadataPackageRepository Description TODO Date 2019/8/21 16:55 + * + * @author zhongchq + * @version 1.0 + */ +public interface MetadataPackageRepository { + + /** + * 生成元数据包实体 从manifest中读取包信息 + * + * @param packagePath 包的manifest文件所在的目录 + * @return + */ + MetadataPackage getPackageEntity(String packagePath); + + /** + * 从包中获取元数据 + * + * @param metadataPath 元数据文件具体路径 + * @return + */ + GspMetadata getMetadataFromPackage(String metadataPath); + + /** + * 从指定目录下检索包文件 + * + * @param path 指定位置(目录),一般从服务端环境信息获取包部署路径。部署路径按照应用隔离,部署路径有多个 + * @param packageName 包名称 + * @return + */ + Map retrieveSingleMetadataPackage(String path, String packageName); + + /** + * 从指定目录下检索包文件 + * + * @param path 指定位置(目录),一般从服务端环境信息获取包部署路径。部署路径按照应用隔离,部署路径有多个 + * @return + */ + Map retrieveAllMdPkg(String path) throws IOException; + + /** + * 获取某一路径下的所有元数据包清单文件信息 + * + * @param originalPath + * @param manifestPath + */ + void getManifestFilesPath(String originalPath, List manifestPath); + + /** + * 获取某一路径下的所有元数据包清单文件信息 + * + * @param originalPath + * @param mdpkgPath + */ + void getMdpkgFilesPath(String originalPath, List mdpkgPath); + + /** + * 获取拼接路径信息 + * + * @param path1 + * @param path2 + * @return + */ + String getCombinePath(String path1, String path2); + + /** + * 获取目录名 + * + * @param path + * @return + */ + String getDirectoryName(String path); + + /** + * 根据元数据包文件,获取元数据包信息,读取manifest文件 + * + * @param packageFile + * @return MetadataPackage + */ + MetadataPackage getMetadataPackage(File packageFile) throws IOException; + +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java new file mode 100644 index 0000000..30b2c0e --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java @@ -0,0 +1,196 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.persistent; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackage; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.servermanager.util.MetadataUtils; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; +import lombok.extern.slf4j.Slf4j; + +/** + * Classname MetadataPackageRepositoryImp Description TODO Date 2019/8/21 17:04 + * + * @author zhongchq + * @version 1.0 + */ +@Slf4j +public class MetadataPackageRepositoryImp implements MetadataPackageRepository { + + // @Autowired //TODO 依赖注入会是null,此类还未被初始化。 + FileService fileService = new FileServiceImp(); + + ObjectMapper mapper = Utils.getMapper(); + + @Override + public MetadataPackage getPackageEntity(String packagePath) { + return null; + } + + @Override + public GspMetadata getMetadataFromPackage(String metadataPath) { + return null; + } + + @Override + public HashMap retrieveSingleMetadataPackage(String path, String packageName) { + return null; + } + + @Override + public HashMap retrieveAllMdPkg(String path) throws IOException { + HashMap packageDic = new HashMap<>(); + retrieveMdPkgRecursively(path, packageDic); + return packageDic; + } + + public void retrieveMdPkgRecursively(String path, HashMap packageDic) throws IOException { + if (path.isEmpty() || new File(path).getName().toLowerCase().equals("web")) { + return; + } + List files = fileService.getAllFiles(path); + if (files.size() > 0) { + List fileList = new ArrayList<>(); + for (File file : files) { + if (fileService.getExtension(file.toString()).equals(MetadataUtils.getMetadataPackageExtension())) { + fileList.add(file); + } + } + if (fileList != null && fileList.size() > 0) { + for (File file1 : fileList) { + try { + MetadataPackage metadataPackage = getMetadataPackage(file1); + packageDic.put(Utils.handlePath(file1.toString()), metadataPackage); + } catch (IOException e) { + e.printStackTrace(); + System.out.println(e.getMessage() + ":" + file1.getAbsolutePath()); + log.error(e.getMessage() + ":" + file1.getAbsolutePath()); + } + } + } + } + // 路径中目录 + List dirs = fileService.getDirectorys(path); + for (int i = 0; i < dirs.size(); i++) { + retrieveMdPkgRecursively(dirs.get(i).toString(), packageDic); + } + } + + @Override + public MetadataPackage getMetadataPackage(File packageFile) throws IOException { + String manifestStr = ""; + MetadataPackage metadataPackage; + StringBuilder sb = new StringBuilder(); + InputStream in = new BufferedInputStream(new FileInputStream(packageFile)); + ZipFile zf = new ZipFile(packageFile); + Charset utf8 = Charset.forName("UTF-8"); + ZipInputStream zipInputStream = new ZipInputStream(in, utf8); + ZipEntry zipEntry; + try { + while ((zipEntry = zipInputStream.getNextEntry()) != null) { + BufferedReader br = new BufferedReader( + new InputStreamReader(zf.getInputStream(zipEntry), "UTF-8")); + if (zipEntry.toString().equals(MetadataUtils.getManifestFileName())) { + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + manifestStr = sb.toString(); + } + br.close(); + } + } catch (IOException e) { + log.error("Error in reading mdpkg, Package is " + packageFile.getAbsolutePath(), e); + throw new RuntimeException("Error in reading mdpkg, Package is " + packageFile.getAbsolutePath(), e); + } finally { + zipInputStream.close(); + zf.close(); + in.close(); + } +// String jsonString = handleJsonString(manifestStr);//TODO可能会引起序列化失败 + try { + metadataPackage = mapper.readValue(manifestStr, MetadataPackage.class); + log.debug("元数据包:" + packageFile + "已加载。"); + } catch (Exception e) { + log.error("元数据包中manifest.json反序列化失败,元数据包为" + packageFile, e); + throw new RuntimeException("元数据包中manifest.json反序列化失败,元数据包为" + packageFile, e); + } + return metadataPackage; + } + + @Override + public void getManifestFilesPath(String originalPath, List manifestPath) { + + } + + @Override + public void getMdpkgFilesPath(String originalPath, List mdpkgPath) { + File dir = new File(originalPath); + List paths = fileService.getAllFiles(originalPath); + if (paths.size() > 0) { + paths.forEach(path -> { + String extension = fileService.getExtension(path); + if (extension.equals(MetadataUtils.getMetadataPackageExtension())) { + mdpkgPath.add(handlePath(path.toString())); + } + }); + searchChildPath4Mdpkg(originalPath, mdpkgPath, dir); + } else { + searchChildPath4Mdpkg(originalPath, mdpkgPath, dir); + } + } + + private void searchChildPath4Mdpkg(String originalPath, List mdpkgPath, File dir) { + List dirs = fileService.getDirectorys(dir.toString()); + if (dirs.size() > 0) { + for (int i = 0; i < dirs.size(); i++) { + String temPath = originalPath + "/" + fileService.getFileName(handlePath(dirs.get(i).toString())); + getMdpkgFilesPath(temPath, mdpkgPath); + } + } + } + + private String handlePath(String path) { + return path.replace("\\", "/"); + } + + @Override + public String getCombinePath(String path1, String path2) { + return null; + } + + @Override + public String getDirectoryName(String path) { + return null; + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/RepositoryFactory.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/RepositoryFactory.java new file mode 100644 index 0000000..aaa3677 --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/RepositoryFactory.java @@ -0,0 +1,46 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.persistent; + +/** + * Classname RepositoryFactory Description TODO Date 2019/8/21 16:47 + * + * @author zhongchq + * @version 1.0 + */ +public class RepositoryFactory { + + private static RepositoryFactory singleton = null; + + public RepositoryFactory() { + } + + public static RepositoryFactory getInstance() { + if (singleton == null) { + singleton = new RepositoryFactory(); + } + return singleton; + } + + private MetadataPackageRepository metadataPackageRepository; + + public MetadataPackageRepository getMetadataPackageRepository() { + if (metadataPackageRepository == null) { + metadataPackageRepository = new MetadataPackageRepositoryImp(); + } + return metadataPackageRepository; + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataServerManagerUitls.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataServerManagerUitls.java new file mode 100644 index 0000000..8f8df6d --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataServerManagerUitls.java @@ -0,0 +1,77 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4Ref; +import com.inspur.edp.lcm.metadata.api.entity.Metadata4RefDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.api.entity.MetadataRTFilter; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class MetadataServerManagerUitls { + + public List buildMetadata4RefDto(List metadata4Refs) { + if (metadata4Refs == null || metadata4Refs.size() <= 0) { + return null; + } + List metadata4RefDtos = new ArrayList<>(); + for (Metadata4Ref metadata4Ref : metadata4Refs) { + Metadata4RefDto dto = new Metadata4RefDto(); + MetadataDto metadataDto = MetadataDtoConverter.asDto(metadata4Ref.getMetadata()); + dto.setPackageHeader(metadata4Ref.getPackageHeader()); + dto.setMetadata(metadataDto); + dto.setServiceUnitInfo(metadata4Ref.getServiceUnitInfo()); + metadata4RefDtos.add(dto); + } + + return metadata4RefDtos; + } + + public String serializeMetadata4RefDtos(List metadataDtos) { + String result = ""; + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + try { + result = mapper.writeValueAsString(metadataDtos); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return result; + } + + public MetadataRTFilter deserializerMetadataRTFilter(String content) { + MetadataRTFilter result = null; + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); + mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + + try { + result = mapper.readValue(content, MetadataRTFilter.class); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataUtils.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataUtils.java new file mode 100644 index 0000000..6f4b7e0 --- /dev/null +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/util/MetadataUtils.java @@ -0,0 +1,35 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.lcm.metadata.servermanager.util; + +/** + * Classname MetadataUtils Description TODO Date 2019/8/20 16:43 + * + * @author zhongchq + * @version 1.0 + */ +public class MetadataUtils { + + public static String manifestFileName = "manifest.json"; + + public static String getManifestFileName() { + return manifestFileName; + } + + public static String getMetadataPackageExtension() { + return ".mdpkg"; + } +} diff --git a/model/framework/runtime-spi/pom.xml b/model/framework/runtime-spi/pom.xml index 2d92872..34de7a9 100644 --- a/model/framework/runtime-spi/pom.xml +++ b/model/framework/runtime-spi/pom.xml @@ -10,8 +10,6 @@ 4.0.0 ubml-model-framework-runtime-spi - - ubml-model-framework-runtime-spi ${project.version} diff --git a/model/framework/runtime-spi/src/main/java/com/inspur/edp/lcm/metadata/spi/event/MdPkgChangedArgs.java b/model/framework/runtime-spi/src/main/java/com/inspur/edp/lcm/metadata/spi/event/MdPkgChangedArgs.java index 035e44e..30ce52a 100644 --- a/model/framework/runtime-spi/src/main/java/com/inspur/edp/lcm/metadata/spi/event/MdPkgChangedArgs.java +++ b/model/framework/runtime-spi/src/main/java/com/inspur/edp/lcm/metadata/spi/event/MdPkgChangedArgs.java @@ -24,4 +24,12 @@ import io.iec.edp.caf.commons.event.CAFEventArgs; public class MdPkgChangedArgs extends CAFEventArgs { private MetadataPackage metadataPackage; + + public MetadataPackage getMetadataPackage() { + return metadataPackage; + } + + public void setMetadataPackage(MetadataPackage metadataPackage) { + this.metadataPackage = metadataPackage; + } } -- Gitee From ef28d5a31bc2358828a71ec9b7cd8c0c608eb3f3 Mon Sep 17 00:00:00 2001 From: Q-Lee Date: Tue, 11 May 2021 10:23:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dlcm-metadata-framework=E6=A8=A1=E5=9D=97=E4=B8=8B?= =?UTF-8?q?=E6=89=80=E6=9C=89checkstyle=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/ConfigData/FilterConfigData.java | 1 - .../IndexServerConfiguration.java | 10 +- .../metadata/cache/MetadataCacheManager.java | 142 +++++++++--------- .../lcm/metadata/cache/RtCacheHandler.java | 18 +-- .../lcm/metadata/common/FileServiceImp.java | 12 +- .../inspur/edp/lcm/metadata/common/Graph.java | 14 +- .../edp/lcm/metadata/common/MavenUtils.java | 8 +- .../inspur/edp/lcm/metadata/common/Utils.java | 6 +- .../edp/lcm/metadata/common/Vertex.java | 9 +- .../GspProjectConfigurationLoader.java | 4 +- .../MdExtRuleSerializerHelper.java | 50 +++--- .../configuration/MenuConfigLoader.java | 2 +- .../MetadataConfigurationLoader.java | 4 +- .../configuration/MetadataServiceHelper.java | 1 - .../common/logging/MvnStreamConsumer.java | 1 - .../lcm/metadata/common/util/CommandUtil.java | 29 ++-- .../lcm/metadata/common/util/EncryptUtil.java | 8 +- .../lcm/metadata/devcommon/ManagerUtils.java | 32 ++-- .../api/exception/MetadataExceptionCode.java | 2 +- .../lcm/metadata/core/I18nCoreService.java | 12 +- .../metadata/core/MetadataCoreManager.java | 8 +- .../core/MetadataProjectCoreService.java | 5 +- .../core/MetadataProjectServiceImp.java | 1 - .../lcm/metadata/core/PackageCoreService.java | 46 +++--- .../core/ProjectExtendCoreService.java | 11 +- .../core/config/JitRuntimeConfigLoader.java | 4 +- .../core/config/JitRuntimeHelper.java | 2 +- .../MetadataCreateEventListenerImpl.java | 4 +- .../core/exception/MvnExceptionHandler.java | 8 +- .../index/MetadataPackageIndexService.java | 22 +-- .../index/ProjectMetadataCacheService.java | 5 +- .../manager/MavenDeploymentForJarManager.java | 2 +- .../MavenDeploymentForMdpkgManager.java | 8 +- .../lcm/metadata/core/manager/PomManager.java | 2 +- .../MetadataProjectRepository.java | 2 +- .../core/persistence/MetadataRepository.java | 9 +- .../core/persistence/PomRepository.java | 16 +- .../core/sync/InstallJarRunnable.java | 6 +- .../extend/action/ExtractActionImpl.java | 3 +- .../edp/lcm/metadata/ref/MdpkgServiceImp.java | 4 +- model/framework/generator-api/pom.xml | 8 +- .../context/common/FileUtilsTest.java | 23 ++- model/framework/pom.xml | 10 +- .../rtservice/MetadataRTServiceImp.java | 3 +- .../MetadataRTServerServiceImpl.java | 21 ++- .../event/MdPkgChangedEventManager.java | 4 +- .../monitor/MdpkgListenerAdapter.java | 18 +-- .../MetadataPackageRepositoryImp.java | 3 +- 48 files changed, 309 insertions(+), 314 deletions(-) diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/FilterConfigData.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/FilterConfigData.java index ae0484e..1bbcbbf 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/FilterConfigData.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/ConfigData/FilterConfigData.java @@ -15,7 +15,6 @@ */ package com.inspur.edp.lcm.metadata.api.ConfigData; -import com.inspur.edp.lcm.metadata.api.ConfigData.BaseConfig; import java.io.Serializable; /** diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java index 1ab08dd..92472ba 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/api/entity/metadataindex/IndexServerConfiguration.java @@ -16,16 +16,16 @@ package com.inspur.edp.lcm.metadata.api.entity.metadataindex; public class IndexServerConfiguration { - private String IP; + private String ip; private String port; - public String getIP() { - return IP; + public String getIp() { + return ip; } - public void setIP(String IP) { - this.IP = IP; + public void setIp(String ip) { + this.ip = ip; } public String getPort() { diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java index 984b22c..04742a9 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/MetadataCacheManager.java @@ -30,211 +30,211 @@ import java.util.concurrent.locks.ReentrantLock; public class MetadataCacheManager { //元数据包基本信息 - private static final Map medataPackageInfo = new HashMap<>(); + private static final Map MEDATA_PACKAGE_INFO = new HashMap<>(); //元数据包清单列表信息 - private static final Map> metadataManifestInfo = new HashMap<>(); + private static final Map> METADATA_MANIFEST_INFO = new HashMap<>(); //元数据基础信息 - private static final Map metadataInfo = new HashMap<>(); + private static final Map METADATA_INFO = new HashMap<>(); //元数据依赖关系 - private static final Map metadataDependence = new HashMap<>(); + private static final Map METADATA_DEPENDENCE = new HashMap<>(); //元数据与元数据包名的映射关系 - private static final Map metadataPathMapping = new HashMap<>(); + private static final Map METADATA_PATH_MAPPING = new HashMap<>(); //所有的元数据包信息 - private static final Map> allMetadataPackageInfo = new HashMap<>(); + private static final Map> ALL_METADATA_PACKAGE_INFO = new HashMap<>(); //所有的元数据信息 - private static final Map> allMetadataInfo = new HashMap<>(); + private static final Map> ALL_METADATA_INFO = new HashMap<>(); private static Map> metadataListCache = new HashMap<>(); - private static final ReentrantLock lock = new ReentrantLock(); + private static final ReentrantLock LOCK = new ReentrantLock(); MetadataCacheManager() { } public static void removeMetadataInfo(String key) { - lock.lock(); + LOCK.lock(); try { - metadataInfo.remove(key); + METADATA_INFO.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static Object getMetadataInfo(String metadataKey) { - lock.lock(); + LOCK.lock(); try { - return metadataInfo.get(metadataKey); + return METADATA_INFO.get(metadataKey); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addMetadataInfo(String key, GspMetadata metadata) { - lock.lock(); + LOCK.lock(); try { - metadataInfo.put(key, metadata); + METADATA_INFO.put(key, metadata); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void removeMDDependence(String key) { - lock.lock(); + LOCK.lock(); try { - metadataDependence.remove(key); + METADATA_DEPENDENCE.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addMDDependence(String key, List refs) { - lock.lock(); + LOCK.lock(); try { - metadataDependence.put(key, refs); + METADATA_DEPENDENCE.put(key, refs); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void removeMetadataPackageInfo(String key) { - lock.lock(); + LOCK.lock(); try { - medataPackageInfo.remove(key); + MEDATA_PACKAGE_INFO.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addMetadataPackageInfo(String key, MetadataPackage value) { - lock.lock(); + LOCK.lock(); try { - medataPackageInfo.put(key, value); + MEDATA_PACKAGE_INFO.put(key, value); } finally { - lock.unlock(); + LOCK.unlock(); } } public static Object getMetadataPackageInfo(String key) { - lock.lock(); + LOCK.lock(); try { - return medataPackageInfo.get(key); + return MEDATA_PACKAGE_INFO.get(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void removeMDManifestInfo(String key) { - lock.lock(); + LOCK.lock(); try { - metadataManifestInfo.remove(key); + METADATA_MANIFEST_INFO.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addMDManifestInfo(String key, List value) { - lock.lock(); + LOCK.lock(); try { - metadataManifestInfo.put(key, value); + METADATA_MANIFEST_INFO.put(key, value); } finally { - lock.unlock(); + LOCK.unlock(); } } public static Object getMDManifestInfo(String key) { - lock.lock(); + LOCK.lock(); try { - return metadataManifestInfo.get(key); + return METADATA_MANIFEST_INFO.get(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void removeMPDependence(String key) { - lock.lock(); + LOCK.lock(); try { - metadataDependence.remove(key); + METADATA_DEPENDENCE.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addMPDependence(String key, List value) { - lock.lock(); + LOCK.lock(); try { - metadataDependence.put(key, value); + METADATA_DEPENDENCE.put(key, value); } finally { - lock.unlock(); + LOCK.unlock(); } } public static Object getMetadataPathMapping(String key) { - lock.lock(); + LOCK.lock(); try { - return metadataPathMapping.get(key); + return METADATA_PATH_MAPPING.get(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addMetadataPathMapping(String key, String value) { - lock.lock(); + LOCK.lock(); try { - metadataPathMapping.put(key, value); + METADATA_PATH_MAPPING.put(key, value); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void removeMetadataPathMapping(String key) { - lock.lock(); + LOCK.lock(); try { - metadataPathMapping.remove(key); + METADATA_PATH_MAPPING.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static Object getAllMetadataPackageInfo(String key) { - lock.lock(); + LOCK.lock(); try { - return allMetadataPackageInfo.get(key); + return ALL_METADATA_PACKAGE_INFO.get(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addAllMetadataPackageInfo(String key, List value) { - lock.lock(); + LOCK.lock(); try { - allMetadataPackageInfo.put(key, value); + ALL_METADATA_PACKAGE_INFO.put(key, value); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void removeAllMetadataPackageInfo(String key) { - lock.lock(); + LOCK.lock(); try { - allMetadataPackageInfo.remove(key); + ALL_METADATA_PACKAGE_INFO.remove(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static Object getAllMetadataInfo(String key) { - lock.lock(); + LOCK.lock(); try { - return allMetadataInfo.get(key); + return ALL_METADATA_INFO.get(key); } finally { - lock.unlock(); + LOCK.unlock(); } } public static void addAllMetadataInfo(String key, List value) { - lock.lock(); + LOCK.lock(); try { - allMetadataInfo.put(key, value); + ALL_METADATA_INFO.put(key, value); } finally { - lock.unlock(); + LOCK.unlock(); } } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java index eb31dda..b94e7fa 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/cache/RtCacheHandler.java @@ -21,21 +21,21 @@ import com.inspur.edp.lcm.metadata.common.context.RuntimeContext; public class RtCacheHandler { - public static final String allMetadataInfoCacheKey = "allMetadata"; - public static final String allPackagesCacheKey = "allPackages"; + public static final String ALL_METADATA_INFO_CACHE_KEY = "allMetadata"; + public static final String ALL_PACKAGES_CACHE_KEY = "allPackages"; - public static void updateMetadataPackageCache(String packageKey, MetadataPackage package_Renamed) { - if (package_Renamed.getHeader() != null) { + public static void updateMetadataPackageCache(String packageKey, MetadataPackage packageRenamed) { + if (packageRenamed.getHeader() != null) { MetadataCacheManager.removeMetadataPackageInfo(packageKey); - MetadataCacheManager.addMetadataPackageInfo(packageKey, package_Renamed); + MetadataCacheManager.addMetadataPackageInfo(packageKey, packageRenamed); } - if (package_Renamed.getMetadataList() != null) { + if (packageRenamed.getMetadataList() != null) { MetadataCacheManager.removeMDManifestInfo(packageKey); - MetadataCacheManager.addMDManifestInfo(packageKey, package_Renamed.getMetadataList()); + MetadataCacheManager.addMDManifestInfo(packageKey, packageRenamed.getMetadataList()); } - if (package_Renamed.getReference() != null) { + if (packageRenamed.getReference() != null) { MetadataCacheManager.removeMPDependence(packageKey); - MetadataCacheManager.addMPDependence(packageKey, package_Renamed.getReference()); + MetadataCacheManager.addMPDependence(packageKey, packageRenamed.getReference()); } } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/FileServiceImp.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/FileServiceImp.java index 2063e00..a8aa0a1 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/FileServiceImp.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/FileServiceImp.java @@ -483,7 +483,7 @@ public class FileServiceImp implements FileService { @Override public boolean renameDirectory(String fromDir, String toDir) throws IOException { File from = new File(fromDir); - if ((!from.exists() || !from.isDirectory())) { + if (!from.exists() || !from.isDirectory()) { final String message = "Directory does not exist: " + fromDir; throw new IOException(message); @@ -561,7 +561,6 @@ public class FileServiceImp implements FileService { // targetpath.substring("java"); // list.add(targetpath); // } -// System.out.println("正在访问:" + dir + " 目录"); // return FileVisitResult.CONTINUE; // } }); @@ -617,7 +616,7 @@ public class FileServiceImp implements FileService { String entryName; String targetFileName; byte[] buffer = new byte[4096]; - int bytes_read; + int bytesRead; Enumeration entrys = zipFile.entries(); // 获取ZIP文件里所有的文件条目的名字 while (entrys.hasMoreElements()) { // 循环遍历所有的文件条目的名字 zn = (ZipEntry) entrys.nextElement(); @@ -630,16 +629,14 @@ public class FileServiceImp implements FileService { new File(targetFileName).getParentFile().mkdirs();// 如果zn是文件,则创建父目录 } File targetFile = new File(targetFileName); // 否则创建文件 -// System.out.println("正在创建文件:" + targetFile.getAbsolutePath()); FileOutputStream os = new FileOutputStream(targetFile);// 打开文件输出流 InputStream is = zipFile.getInputStream(zn); // 从ZipFile对象中打开entry的输入流 - while ((bytes_read = is.read(buffer)) != -1) { - os.write(buffer, 0, bytes_read); + while ((bytesRead = is.read(buffer)) != -1) { + os.write(buffer, 0, bytesRead); } os.close(); // 关闭流 is.close(); } -// System.out.println("解压缩"+zipName+"成功!"); } catch (IOException err) { throw new ZipException("解压缩" + zipName + "失败: " + err); } @@ -733,7 +730,6 @@ public class FileServiceImp implements FileService { public String getRelPath(String a, String b) { a = Utils.handlePath(a).replace("//", "/"); b = Utils.handlePath(b).replace("//", "/"); - ; if (a.indexOf(':') > -1) { a = a.substring(a.indexOf(':') + 1); } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Graph.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Graph.java index d8c74fa..1db0529 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Graph.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Graph.java @@ -218,19 +218,17 @@ public class Graph { Vertex vertex; Edge edge; T label; - System.out.println("图是否为有向图:" + isDirect + ",图的顶点个数:" + getVertexCount() + ",图的总边个数:" + getEdgeCount()); +// "图是否为有向图:" + isDirect + ",图的顶点个数:" + getVertexCount() + ",图的总边个数:" + getEdgeCount() while (iteratorVertex.hasNext()) { vertex = iteratorVertex.next(); label = vertex.getLabel(); iteratorEdge = vertex.getEdgeIterator(); - System.out.println("顶点:" + label + ",以这个顶点为出发点的边的个数:" + getEdgeCount(label) + ",该顶点的权值为:" + vertex.getCost()); +// "顶点:" + label + ",以这个顶点为出发点的边的个数:" + getEdgeCount(label) + ",该顶点的权值为:" + vertex.getCost() while (iteratorEdge.hasNext()) { edge = iteratorEdge.next(); - System.out.print("边:从 " + label + " 到 " + edge.getEndVertex().getLabel() + " ,权值:" + edge.getWeight() + " "); +// "边:从 " + label + " 到 " + edge.getEndVertex().getLabel() + " ,权值:" + edge.getWeight() + " " } - System.out.println(); } - System.out.println(); } //下面与拓扑排序相关 @@ -245,7 +243,7 @@ public class Graph { Iterator> iterator = getVertexIterator(); while (iterator.hasNext()) { vertex = iterator.next(); - if ((vertex.isVisited() == false) && (vertex.getUnvisitedVertex() == null)) { + if ((!vertex.isVisited()) && (vertex.getUnvisitedVertex() == null)) { //返回一个出度为0(以该点出发的边数为0或者以该点出发的边的结束点都被访问过了),而且没有被访问过的顶点 return vertex; } @@ -267,13 +265,13 @@ public class Graph { vertex = getNextTuopoVertex(); if (vertex == null) { //如果得不到下一个出度为0的节点,直接返回stack - System.out.println("拓扑排序结束"); +// "拓扑排序结束" return stack; } //顶点入栈并被访问,遍历完成后,出栈就可以获得图的一个拓扑序列 stack.push(vertex); vertex.visit(); - System.out.println("拓扑排序:入栈节点:" + vertex.getLabel()); +// "拓扑排序:入栈节点:" + vertex.getLabel() } } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MavenUtils.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MavenUtils.java index 54b43bc..37d1c83 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MavenUtils.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MavenUtils.java @@ -16,11 +16,11 @@ package com.inspur.edp.lcm.metadata.common; public class MavenUtils { - public static final String pomFile = "pom.xml"; + public static final String POM_FILE = "pom.xml"; - public static final String tempFolder = "temp"; + public static final String TEMP_FOLDER = "temp"; - public static final String resourcesDir = "src/main/resources"; + public static final String RESOURCES_DIR = "src/main/resources"; - public static final String snapShot = "SNAPSHOT"; + public static final String SNAP_SHOT = "SNAPSHOT"; } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Utils.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Utils.java index 3932b5e..8d0bb30 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Utils.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Utils.java @@ -41,7 +41,7 @@ import java.util.zip.ZipOutputStream; import org.codehaus.plexus.util.StringUtils; public class Utils { - private static final Lock lock = new ReentrantLock(); + private static final Lock LOCK = new ReentrantLock(); //元数据工程后缀 private static String metadataProjSuffix; // pom后缀 @@ -260,7 +260,7 @@ public class Utils { if (metadataPostfixTypes != null && metadataPostfixTypes.size() > 0) { return metadataPostfixTypes; } - lock.lock(); + LOCK.lock(); try { if (metadataPostfixTypes != null && metadataPostfixTypes.size() > 0) { return metadataPostfixTypes; @@ -276,7 +276,7 @@ public class Utils { } catch (Exception e) { e.printStackTrace(); } finally { - lock.unlock(); + LOCK.unlock(); } return null; diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Vertex.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Vertex.java index aaacd01..688cbe4 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Vertex.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/Vertex.java @@ -94,6 +94,13 @@ public class Vertex { return result; } + @Override + public int hashCode() { + int result = 17; + result = 31 * result + (label == null ? 0 : label.hashCode()); + return result; + } + //下面与顶点的边相关 /** @@ -222,7 +229,7 @@ public class Vertex { while (iterator.hasNext()) { edge = iterator.next(); vertex = edge.getEndVertex(); - if (vertex.isVisited() == false) { + if (!vertex.isVisited()) { return vertex; } } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/GspProjectConfigurationLoader.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/GspProjectConfigurationLoader.java index 05f70cf..7480eca 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/GspProjectConfigurationLoader.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/GspProjectConfigurationLoader.java @@ -33,7 +33,7 @@ public class GspProjectConfigurationLoader implements Serializable { public static List gspProjectConfigurations; private static String fileName = "config/platform/common/lcm_gspprojectextend.json"; - private static final String sectionName = "ProjectConfiguration"; + private static final String SECTION_NAME = "ProjectConfiguration"; public GspProjectConfigurationLoader() { loadGspProjectConfigurations(); @@ -53,7 +53,7 @@ public class GspProjectConfigurationLoader implements Serializable { FileServiceImp fileService = new FileServiceImp(); fileName = fileService.getCombinePath(EnvironmentUtil.getServerRTPath(), fileName); if (gspProjectConfigurations == null || gspProjectConfigurations.size() <= 0) { - gspProjectConfigurations = metadataServiceHelper.getProjectConfiguration(fileName, sectionName); + gspProjectConfigurations = metadataServiceHelper.getProjectConfiguration(fileName, SECTION_NAME); return gspProjectConfigurations; } else { return gspProjectConfigurations; diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MdExtRuleSerializerHelper.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MdExtRuleSerializerHelper.java index 20e4bc4..d47f3ec 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MdExtRuleSerializerHelper.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MdExtRuleSerializerHelper.java @@ -18,32 +18,32 @@ package com.inspur.edp.lcm.metadata.common.configuration; import com.inspur.edp.lcm.metadata.api.ConfigData.MetadataConfiguration; import com.inspur.edp.lcm.metadata.spi.MdExtendRuleSerializer; -public class MdExtRuleSerializerHelper extends MetadataConfigurationLoader { - private static MdExtRuleSerializerHelper singleton = null; +public class MdExtRuleSerializerHelper extends MetadataConfigurationLoader { + private static MdExtRuleSerializerHelper singleton = null; - private MdExtRuleSerializerHelper(){ - } + private MdExtRuleSerializerHelper() { + } - public static MdExtRuleSerializerHelper getInstance(){ - if (singleton == null){ - singleton = new MdExtRuleSerializerHelper(); - } - return singleton; - } + public static MdExtRuleSerializerHelper getInstance() { + if (singleton == null) { + singleton = new MdExtRuleSerializerHelper(); + } + return singleton; + } - public MdExtendRuleSerializer getManager(String typeName) { - MdExtendRuleSerializer manager = null; - MetadataConfiguration data = getMetadataConfigurationData(typeName); - if (data != null&&data.getMdExtRuleSerializer()!=null){ - Class cls = null; - try { - cls = Class.forName(data.getMdExtRuleSerializer().getName()); - manager = (MdExtendRuleSerializer)cls.newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - return manager; - } + public MdExtendRuleSerializer getManager(String typeName) { + MdExtendRuleSerializer manager = null; + MetadataConfiguration data = getMetadataConfigurationData(typeName); + if (data != null && data.getMdExtRuleSerializer() != null) { + Class cls = null; + try { + cls = Class.forName(data.getMdExtRuleSerializer().getName()); + manager = (MdExtendRuleSerializer) cls.newInstance(); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + return manager; + } } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MenuConfigLoader.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MenuConfigLoader.java index 9d5d34b..78a1e08 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MenuConfigLoader.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MenuConfigLoader.java @@ -37,7 +37,7 @@ public class MenuConfigLoader { contents = fileService.fileRead(fileName); - String flag = status == true ? "on:" : "off:"; + String flag = status ? "on:" : "off:"; menuExtendConfiguration = contents.substring(contents.indexOf(flag) + flag.length(), contents.indexOf("\n", contents.indexOf(flag)) - 1); return menuExtendConfiguration; } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataConfigurationLoader.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataConfigurationLoader.java index ae28f17..744600b 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataConfigurationLoader.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataConfigurationLoader.java @@ -37,7 +37,7 @@ public class MetadataConfigurationLoader implements Serializable { @Getter public static List metadataConfigurations; private static String fileName = "config/platform/common/lcm_metadataextend.json"; - private static final String sectionName = "MetadataConfiguration"; + private static final String SECTION_NAME = "MetadataConfiguration"; public MetadataConfigurationLoader() { loadMetadataConfigurations(); @@ -58,7 +58,7 @@ public class MetadataConfigurationLoader implements Serializable { fileName = fileService.getCombinePath(EnvironmentUtil.getServerRTPath(), fileName); if (metadataConfigurations == null || metadataConfigurations.size() <= 0) { - metadataConfigurations = metadataServiceHelper.getMetadataConfigurationList(fileName, sectionName); + metadataConfigurations = metadataServiceHelper.getMetadataConfigurationList(fileName, SECTION_NAME); return metadataConfigurations; } else { return metadataConfigurations; diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataServiceHelper.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataServiceHelper.java index da4b380..787fb86 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataServiceHelper.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/configuration/MetadataServiceHelper.java @@ -15,7 +15,6 @@ */ package com.inspur.edp.lcm.metadata.common.configuration; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java index 476f7fb..3620543 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/logging/MvnStreamConsumer.java @@ -34,7 +34,6 @@ public class MvnStreamConsumer implements InvocationOutputHandler { @Override public void consumeLine(String line) { if (line.contains("[INFO]")) { -// System.out.println("mvn userId :"+CAFContext.current.getUserId()); LoggerDisruptorQueue.publishEvent(line, CAFContext.current.getUserId()); log.info(line); } else if (line.contains("[WARNING]")) { diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java index 086b1fb..882b03f 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/CommandUtil.java @@ -59,7 +59,6 @@ public class CommandUtil { if (line == null) { break; } - System.out.println(line); } p.waitFor(); @@ -379,7 +378,8 @@ public class CommandUtil { } // 对启动路径和运行参数的拼接 - public static String getCommandFormatStr(String proPath) {// 这样的思路就可以控制俩种参数的输入 + // 这样的思路就可以控制俩种参数的输入 + public static String getCommandFormatStr(String proPath) { return getCommandFormatStr(proPath, null); } @@ -403,7 +403,8 @@ public class CommandUtil { } // 通过cmd打开对应的文件 - public static void openDir(String fileDir) throws Exception {// 打开cmd,执行explorer + // 打开cmd,执行explorer + public static void openDir(String fileDir) throws Exception { Runtime.getRuntime().exec("cmd /c start explorer " + fileDir);// explorer.exe是Windows的程序管理器或者文件资源管理器 } @@ -416,10 +417,10 @@ public class CommandUtil { InputStreamReader ir = null; BufferedReader br = null; String line = ""; - String LISTENING_STATE_TYPE = "LISTENING";// 状态值 + String listeningStateType = "LISTENING";// 状态值 String[] array; try { - Process p = Runtime.getRuntime().exec("cmd /c netstat /ano | findstr [ | findstr " + pid + " | findstr " + LISTENING_STATE_TYPE); + Process p = Runtime.getRuntime().exec("cmd /c netstat /ano | findstr [ | findstr " + pid + " | findstr " + listeningStateType); is = p.getInputStream(); ir = new InputStreamReader(is); br = new BufferedReader(ir); @@ -464,14 +465,14 @@ public class CommandUtil { InputStreamReader ir = null; BufferedReader br = null; String line = null; - String TCP_TYPE = "TCP"; - String UDP_TYPE = "UDP"; - String LISTENING_STATE_TYPE = "LISTENING";// 状态值 + String tcpType = "TCP"; + String udpType = "UDP"; + String listeningStateType = "LISTENING";// 状态值 Map> portMap = new HashMap<>(); List tcpPortList = new ArrayList<>(); List udpPortList = new ArrayList<>(); - portMap.put(TCP_TYPE, tcpPortList); - portMap.put(UDP_TYPE, udpPortList); + portMap.put(tcpType, tcpPortList); + portMap.put(udpType, udpPortList); String[] array; try { Process p = Runtime.getRuntime().exec("netstat /ano"); @@ -481,8 +482,8 @@ public class CommandUtil { do { if (line.indexOf(pid) != -1) { line = line.replaceFirst("\\s+", ""); - if (line.indexOf(TCP_TYPE) != -1) { - if (line.indexOf(LISTENING_STATE_TYPE) != -1) { + if (line.indexOf(tcpType) != -1) { + if (line.indexOf(listeningStateType) != -1) { array = line.split("\\s+"); String port = array[1].split(":")[1]; tcpPortList.add(port); @@ -602,8 +603,8 @@ public class CommandUtil { } public static boolean isWindows() { - String OS = System.getProperty("os.name").toLowerCase(); - boolean isWindows = OS.startsWith("windows"); + String os = System.getProperty("os.name").toLowerCase(); + boolean isWindows = os.startsWith("windows"); return isWindows; } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java index 73adf48..e5cd47e 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/util/EncryptUtil.java @@ -22,12 +22,12 @@ import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class EncryptUtil { - final static BASE64Decoder decoder = new BASE64Decoder(); - final static BASE64Encoder encoder = new BASE64Encoder(); + final static BASE64Decoder DECODER = new BASE64Decoder(); + final static BASE64Encoder ENCODER = new BASE64Encoder(); public static String decryptInBASE64(String decryptString) { try { - return new String(decoder.decodeBuffer(decryptString), StandardCharsets.UTF_8); + return new String(DECODER.decodeBuffer(decryptString), StandardCharsets.UTF_8); } catch (Exception e) { throw new RuntimeException("配置解密失败, 请重新配置或者联系系统管理员。", e); } @@ -38,7 +38,7 @@ public class EncryptUtil { return ""; } try { - return encoder.encode(encodeString.getBytes(StandardCharsets.UTF_8.name())); + return ENCODER.encode(encodeString.getBytes(StandardCharsets.UTF_8.name())); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/devcommon/ManagerUtils.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/devcommon/ManagerUtils.java index 020a72c..21fdb96 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/devcommon/ManagerUtils.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/devcommon/ManagerUtils.java @@ -19,10 +19,10 @@ import com.inspur.edp.lcm.metadata.common.FileServiceImp; import com.inspur.edp.lcm.metadata.common.configuration.WorkspaceHelper; public class ManagerUtils { - public static final String Spring_Shell_Flag_Name = "spring-shell"; - public static final String Spring_Shell_Flag_True = "1"; - public static final boolean Shell_Flag = Spring_Shell_Flag_True.equals(System.getProperty(Spring_Shell_Flag_Name)); - private static final FileServiceImp fileService = new FileServiceImp(); + public static final String SPRING_SHELL_FLAG_NAME = "spring-shell"; + public static final String SPRING_SHELL_FLAG_TRUE = "1"; + public static final boolean SHELL_FLAG = SPRING_SHELL_FLAG_TRUE.equals(System.getProperty(SPRING_SHELL_FLAG_NAME)); + private static final FileServiceImp FILE_SERVICE = new FileServiceImp(); /** * 获取开发根路径 */ @@ -31,28 +31,28 @@ public class ManagerUtils { private static String metadataPackageLocation; public static String getDevRootPath() { - if (Shell_Flag) { + if (SHELL_FLAG) { return devRootPath; } return WorkspaceHelper.getInstance().getDevRootPath(); } public static void setDevRootPath(String path) { - if (Shell_Flag) { + if (SHELL_FLAG) { devRootPath = path; } } public static String getMetadataPackageLocation() { - if (Shell_Flag) { + if (SHELL_FLAG) { return metadataPackageLocation; } - return fileService.getCombinePath(getDevRootPath(), "packages"); + return FILE_SERVICE.getCombinePath(getDevRootPath(), "packages"); } public static void setMetadataPackageLocation(String metadataPackageLoc) { - if (Shell_Flag) { + if (SHELL_FLAG) { metadataPackageLocation = metadataPackageLoc; } } @@ -63,7 +63,7 @@ public class ManagerUtils { */ public static String getAbsolutePath(String path) { path = handlePath(path); - if (Shell_Flag) { + if (SHELL_FLAG) { if (isAbsolutePath(path)) { return path; } else { @@ -84,7 +84,7 @@ public class ManagerUtils { if (path.startsWith("/")) { path = path.substring(1); } - String absolutePath = fileService.getCombinePath(devRootPath, path); + String absolutePath = FILE_SERVICE.getCombinePath(devRootPath, path); // TODO 判断路径是否存在 return handlePath(absolutePath); } @@ -98,22 +98,22 @@ public class ManagerUtils { } public static String getMavenStoragePath() { - if (Shell_Flag) { + if (SHELL_FLAG) { return mavenStoragePath; } - return fileService.getCombinePath(getDevRootPath(), "maven"); + return FILE_SERVICE.getCombinePath(getDevRootPath(), "maven"); } public static void setMavenStoragePath(String mavenStorageP) { - if (Shell_Flag) { + if (SHELL_FLAG) { mavenStoragePath = mavenStorageP; } } public static String getRalativePath(String relativeFullPath) { String relativePath; - if (!getDevRootPath().isEmpty() && fileService.startWith(relativeFullPath, getDevRootPath())) { - relativePath = fileService.getRelPath(relativeFullPath, getDevRootPath()); + if (!getDevRootPath().isEmpty() && FILE_SERVICE.startWith(relativeFullPath, getDevRootPath())) { + relativePath = FILE_SERVICE.getRelPath(relativeFullPath, getDevRootPath()); } else { relativePath = relativeFullPath; } diff --git a/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java b/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java index f0766d0..45feca0 100644 --- a/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java +++ b/model/framework/devtime-api/src/main/java/com/inspur/edp/lcm/metadata/api/exception/MetadataExceptionCode.java @@ -16,5 +16,5 @@ package com.inspur.edp.lcm.metadata.api.exception; public class MetadataExceptionCode { - public final String Unknown = "GSP_LCM_Meta_0000"; + public final String unknown = "GSP_LCM_Meta_0000"; } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/I18nCoreService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/I18nCoreService.java index a781878..89ee2ca 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/I18nCoreService.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/I18nCoreService.java @@ -39,8 +39,8 @@ public class I18nCoreService { private final MetadataCoreManager metadataCoreManager = new MetadataCoreManager(); - private final String RESOURCE_METADATA_TYPE = "ResourceMetadata"; - private final String LINGUISTIC_RESOURCE_METADATA_TYPE = "LinguisticResource"; + private final String resourceMetadataType = "ResourceMetadata"; + private final String linguisticResourceMetadataType = "LinguisticResource"; public static I18nCoreService getInstance() { if (sigleton == null) { @@ -102,7 +102,7 @@ public class I18nCoreService { header.setFileName(resourceMetadataFileName); header.setNameSpace(metadata.getHeader().getNameSpace()); header.setBizObjectId(metadata.getHeader().getBizObjectId()); - header.setType(RESOURCE_METADATA_TYPE); + header.setType(resourceMetadataType); resourceMetadata.setHeader(header); } II18nResourceDTManager i18nResourceDTManager = SpringBeanUtils.getBean(II18nResourceDTManager.class); @@ -136,7 +136,7 @@ public class I18nCoreService { private String getResourceMetadataFileName(GspMetadata metadata) { String metadataSuffix = getMetadataSuffix(metadata.getHeader().getType()); - String resourceMetadataSuffix = getMetadataSuffix(RESOURCE_METADATA_TYPE); + String resourceMetadataSuffix = getMetadataSuffix(resourceMetadataType); return metadata.getHeader().getCode() + metadataSuffix + resourceMetadataSuffix; } @@ -193,7 +193,7 @@ public class I18nCoreService { header.setFileName(languageMetadataFileName); header.setNameSpace(metadata.getHeader().getNameSpace()); header.setBizObjectId(metadata.getHeader().getBizObjectId()); - header.setType(LINGUISTIC_RESOURCE_METADATA_TYPE); + header.setType(linguisticResourceMetadataType); languageMetadata.setHeader(header); } II18nResourceDTManager i18nResourceDTManager = SpringBeanUtils.getBean(II18nResourceDTManager.class); @@ -209,7 +209,7 @@ public class I18nCoreService { private String getLanguageMetadataFileName(GspMetadata metadata) { String language = metadata.getHeader().getLanguage(); String metadataSuffix = getMetadataSuffix(metadata.getHeader().getType()); - String linguisticMetadataSuffix = getMetadataSuffix(LINGUISTIC_RESOURCE_METADATA_TYPE); + String linguisticMetadataSuffix = getMetadataSuffix(linguisticResourceMetadataType); return metadata.getHeader().getCode() + metadataSuffix + "." + language + linguisticMetadataSuffix; } } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataCoreManager.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataCoreManager.java index 4cdb631..7d2e459 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataCoreManager.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataCoreManager.java @@ -739,7 +739,7 @@ public class MetadataCoreManager { try { String pageWebapiOfIndexServer = IndexServerManager.getInstance().getPageWebapiOfIndexServerWithProcessMode(); - // pageWebapiOfIndexServer = pageWebapiOfIndexServer.replace("10.24.15.33", "localhost"); +// pageWebapiOfIndexServer = pageWebapiOfIndexServer.replace("10.24.15.33", "localhost"); ProcessMode processMode = metadataProjInfo.getMetadataPackageInfo().getProcessMode() == null ? ProcessMode.GENERATION : metadataProjInfo.getMetadataPackageInfo().getProcessMode(); MetadataInfoFilterWithProcessMode filter = getMetadataInfoFilter(text, typeList, page, pageSize, pageIndex, selectedPackageSource, path, isFilterByRefs, processMode); PageMetadataInfoWithProcessMode pageMetadataInfoWithProcessMode = RestTemplateService.instance.getObjectByPost(pageWebapiOfIndexServer, filter); @@ -748,7 +748,7 @@ public class MetadataCoreManager { } catch (Exception e) { String pageWebapiOfIndexServer = IndexServerManager.getInstance().getPageWebapiOfIndexServer(); - // pageWebapiOfIndexServer = pageWebapiOfIndexServer.replace("10.24.15.33", "localhost"); +// pageWebapiOfIndexServer = pageWebapiOfIndexServer.replace("10.24.15.33", "localhost"); MetadataInfoFilter filter = getMetadataInfoFilter(text, typeList, page, pageSize, pageIndex, selectedPackageSource, path, isFilterByRefs); PageMetadataInfo pageMetadataInfo = RestTemplateService.instance.getObjectByPost(pageWebapiOfIndexServer, filter); List metadataInfos = pageMetadataInfo.getMetadataInfos(); @@ -1015,7 +1015,7 @@ public class MetadataCoreManager { metadataIndexRepoItemDto.setProcessMode(ProcessMode.GENERATION.toString()); metadataIndexRepoItemDtoList.add(metadataIndexRepoItemDto); }); - if ((version.getMavenInfos() == null || version.getMavenInfos().size() < 1)) { + if (version.getMavenInfos() == null || version.getMavenInfos().size() < 1) { indexDto.setRepoPkg(new ArrayList<>()); } else { indexDto.setRepoPkg(metadataIndexRepoItemDtoList); @@ -1053,7 +1053,7 @@ public class MetadataCoreManager { metadataIndexRepoItemDto.setProcessMode(maveninfo.getProcessMode()); metadataIndexRepoItemDtoList.add(metadataIndexRepoItemDto); }); - if ((version.getMavenInfos() == null || version.getMavenInfos().size() < 1)) { + if (version.getMavenInfos() == null || version.getMavenInfos().size() < 1) { indexDto.setRepoPkg(new ArrayList<>()); } else { indexDto.setRepoPkg(metadataIndexRepoItemDtoList); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectCoreService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectCoreService.java index 327e871..f947042 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectCoreService.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectCoreService.java @@ -44,7 +44,6 @@ import java.util.List; import java.util.Map; import java.util.Stack; import java.util.concurrent.ConcurrentHashMap; -import lombok.var; import org.codehaus.plexus.util.StringUtils; public class MetadataProjectCoreService { @@ -607,7 +606,7 @@ public class MetadataProjectCoreService { getAllFilesUnderDir(filePathList, temPath); } } - var paths = fileService.getAllFiles(dirPath); + List paths = fileService.getAllFiles(dirPath); if (paths.size() > 0) { for (File path : paths) { filePathList.add(Utils.handlePath(path.getPath())); @@ -718,7 +717,7 @@ public class MetadataProjectCoreService { break; } } catch (Exception e) { - System.out.println("无法读取工程" + projPath + "的信息。"); +// "无法读取工程" + projPath + "的信息。" } } boInfo.setProjectCount(projPaths.size()); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectServiceImp.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectServiceImp.java index ed88181..aca29e8 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectServiceImp.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/MetadataProjectServiceImp.java @@ -113,7 +113,6 @@ public class MetadataProjectServiceImp implements MetadataProjectService { if (StringUtils.isEmpty(path)) { throw new RuntimeException("路径不能为空"); } - ; //全路径 String absolutePath = ManagerUtils.getAbsolutePath(path); projectCoreService.createGspProject(absolutePath, projectData); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageCoreService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageCoreService.java index 773820a..2a8bb8c 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageCoreService.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/PackageCoreService.java @@ -205,7 +205,7 @@ public class PackageCoreService { e.printStackTrace(); } if (!errorMsgs.isEmpty()) { - String log = ("[LCM Error]以下工程批量操作失败,请排除问题后重新编译:"); + String log = "[LCM Error]以下工程批量操作失败,请排除问题后重新编译:"; LoggerDisruptorQueue.publishEvent(log, CAFContext.current.getUserId()); for (String msg : errorMsgs) { LoggerDisruptorQueue.publishEvent("[LCM Error]" + msg, CAFContext.current.getUserId()); @@ -283,7 +283,7 @@ public class PackageCoreService { } String metadataPath = fileServiceImp.getCombinePath(absolutePath, Utils.getMetadataProjPath()); - String pomPath = fileServiceImp.getCombinePath(metadataPath, MavenUtils.pomFile); + String pomPath = fileServiceImp.getCombinePath(metadataPath, MavenUtils.POM_FILE); ProcessMode processMode = metadataProjectCoreService.getProcessMode(absolutePath); try { // 创建pom @@ -291,7 +291,7 @@ public class PackageCoreService { pomManager.createPomForDependencyCopy(refs, pomPath); // copy dependency - downloadPath = fileServiceImp.getCombinePath(mavenPath, MavenUtils.tempFolder); + downloadPath = fileServiceImp.getCombinePath(mavenPath, MavenUtils.TEMP_FOLDER); copyDependencies(metadataPath, mavenPath, downloadPath, forceUpdateFlag); // 解压并复制下载的元数据包到maven目录下 @@ -370,14 +370,14 @@ public class PackageCoreService { //添加api依赖 String apiPath = fileServiceImp.getApiModulePath(absolutePath); if (apiPath != null && !apiPath.isEmpty()) { - String pomApi = fileServiceImp.getCombinePath(fileServiceImp.getApiModulePath(absolutePath), MavenUtils.pomFile); + String pomApi = fileServiceImp.getCombinePath(fileServiceImp.getApiModulePath(absolutePath), MavenUtils.POM_FILE); if (fileServiceImp.isFileExist(pomApi)) { addProjectDependency(pomApi, groupId, artifactId, version); } } } finally { - String metadataPomPath = fileServiceImp.getCombinePath(metadataPath, MavenUtils.pomFile); + String metadataPomPath = fileServiceImp.getCombinePath(metadataPath, MavenUtils.POM_FILE); //删除pom.xml if (fileServiceImp.isFileExist(metadataPomPath)) { fileServiceImp.fileDelete(metadataPomPath); @@ -466,7 +466,7 @@ public class PackageCoreService { } String codepath = projPath + File.separator + "java" + File.separator + Utils.getMavenProName(); - String apiPomPath = fileServiceImp.getApiModulePath(projPath) + File.separator + MavenUtils.pomFile; + String apiPomPath = fileServiceImp.getApiModulePath(projPath) + File.separator + MavenUtils.POM_FILE; String revertCommand = "versions:revert"; String commitCommand = "versions:commit"; String command = String.format("versions:set -DnewVersion=%s", version); @@ -482,7 +482,7 @@ public class PackageCoreService { list = model.getDependencies(); for (Dependency dependency : list) { if (dependency.getVersion() != null) { - if (dependency.getVersion().endsWith(MavenUtils.snapShot)) { + if (dependency.getVersion().endsWith(MavenUtils.SNAP_SHOT)) { dependency.setVersion(dependenciesVersion); } } @@ -555,16 +555,16 @@ public class PackageCoreService { //接下来拷贝元数据 String moduleApiPath; String codePath = proPath + File.separator + "java" + File.separator + Utils.getMavenProName(); - String codePom = fileServiceImp.getCombinePath(codePath, MavenUtils.pomFile); + String codePom = fileServiceImp.getCombinePath(codePath, MavenUtils.POM_FILE); String apiPomPath; String metadataBin = File.separator + "metadata" + File.separator + "bin"; String metadataBinPath = proPath + metadataBin; String metadataPath = File.separator + "metadata"; String metadataDir = proPath + metadataPath; - String metadataTempDir = fileServiceImp.getCombinePath(metadataDir, MavenUtils.tempFolder); + String metadataTempDir = fileServiceImp.getCombinePath(metadataDir, MavenUtils.TEMP_FOLDER); if (isModelExist) { moduleApiPath = fileServiceImp.getApiModulePath(proPath); - apiPomPath = fileServiceImp.getCombinePath(moduleApiPath, MavenUtils.pomFile); + apiPomPath = fileServiceImp.getCombinePath(moduleApiPath, MavenUtils.POM_FILE); //读mdproj获取依赖信息 metadataProject = metadataProjectCoreService.getMetadataProjInfo(metadataDir); List refsList = metadataProject.getMavenPackageRefs(); @@ -572,7 +572,7 @@ public class PackageCoreService { //获取api module的groupId,artifactId,version apiModuleInfo = getApiModuleInfo(apiPomPath); if (apiModuleInfo != null) { - boolean isSnapshot = apiModuleInfo.getVersion().endsWith(MavenUtils.snapShot); + boolean isSnapshot = apiModuleInfo.getVersion().endsWith(MavenUtils.SNAP_SHOT); setRepoUrl(codePom, repoUrl, repoId, isSnapshot); } createPomForDeploy(apiModuleInfo, refsList, metadataTempDir, repoUrl, repoId, dependencyVersion); @@ -595,7 +595,7 @@ public class PackageCoreService { throw new RuntimeException("找不到元数据包,请先编译!"); } String metadataFullPath = metadataBinPath + File.separator + metadaPackageName; - String destPath = metadataTempDir + File.separator + MavenUtils.resourcesDir + File.separator + metadaPackageName; + String destPath = metadataTempDir + File.separator + MavenUtils.RESOURCES_DIR + File.separator + metadaPackageName; try { fileServiceImp.fileCopy(metadataFullPath, destPath); } catch (IOException e) { @@ -838,7 +838,7 @@ public class PackageCoreService { } // 是临时包则下载;maven文件夹下需要元数据包和pom文件,缺一则下载;packages文件夹下需要元数据包,缺少则下载 - boolean installFlag = ref.getVersion().contains(MavenUtils.snapShot) && force; + boolean installFlag = ref.getVersion().contains(MavenUtils.SNAP_SHOT) && force; if (!installFlag) { List fileInMaven = fileServiceImp.getAllFiles(mavenPath + File.separator + ref.getGroupId() + "-" + ref.getArtifactId() + "-" + ref.getVersion()); installFlag = fileInMaven.size() < 2; @@ -1046,7 +1046,7 @@ public class PackageCoreService { private boolean createPomAndDownloadMdproj(String groupid, String artifactid, String version, String path, Boolean forceUpdateFlag, String mavenPath) throws IOException { - File pomFile = new File(fileServiceImp.getCombinePath(path, MavenUtils.pomFile)); + File pomFile = new File(fileServiceImp.getCombinePath(path, MavenUtils.POM_FILE)); if (!pomFile.exists()) { if (pomFile.createNewFile()) { log.debug("创建下载pom.xml完成"); @@ -1070,7 +1070,7 @@ public class PackageCoreService { MavenXpp3Writer mavenXpp3Writer = new MavenXpp3Writer(); mavenXpp3Writer.write(fileOutputStream, model); fileOutputStream.close(); - downloadPath = fileServiceImp.getCombinePath(mavenPath, MavenUtils.tempFolder); + downloadPath = fileServiceImp.getCombinePath(mavenPath, MavenUtils.TEMP_FOLDER); //获取排除的artifact MetadataProject metadataProject = metadataProjectCoreService.getMetadataProjInfo(metadataProjectCoreService.getProjPath(path)); @@ -1132,7 +1132,7 @@ public class PackageCoreService { throw new IllegalArgumentException("工程路径不能为空"); } if (ref.getGroupId() != null && ref.getArtifactId() != null && ref.getVersion() != null) { - if (ref.getVersion().contains(MavenUtils.snapShot)) { + if (ref.getVersion().contains(MavenUtils.SNAP_SHOT)) { try { installMdpkg(ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), path, mavenPath, packagePath); } catch (IOException e) { @@ -1162,19 +1162,19 @@ public class PackageCoreService { log.debug("创建打包目录完成"); } } - File pom_file = new File(fileServiceImp.getCombinePath(pomDir.toString(), MavenUtils.pomFile)); - if (!pom_file.exists()) { - if (pom_file.createNewFile()) { + File pomFile = new File(fileServiceImp.getCombinePath(pomDir.toString(), MavenUtils.POM_FILE)); + if (!pomFile.exists()) { + if (pomFile.createNewFile()) { log.debug("创建打包pom.xml完成"); } } - try (FileOutputStream fileOutputStream = new FileOutputStream(pom_file)) { + try (FileOutputStream fileOutputStream = new FileOutputStream(pomFile)) { Model model = new Model(); //构造父pom信息 Parent parent = new Parent(); parent.setArtifactId("metadata-parent"); parent.setGroupId("com.inspur.edp"); - boolean isSnotshot = apiModuleInfo.getVersion().endsWith(MavenUtils.snapShot); + boolean isSnotshot = apiModuleInfo.getVersion().endsWith(MavenUtils.SNAP_SHOT); parent.setVersion("0.1.0"); model.setParent(parent); model.setArtifactId(info.getArtifactId()); @@ -1190,7 +1190,7 @@ public class PackageCoreService { Dependency dependency = new Dependency(); dependency.setGroupId(ref.getGroupId()); dependency.setArtifactId(ref.getArtifactId()); - if (dependencyVersion != null && ref.getVersion().endsWith(MavenUtils.snapShot)) { + if (dependencyVersion != null && ref.getVersion().endsWith(MavenUtils.SNAP_SHOT)) { dependency.setVersion("m" + dependencyVersion); } else { @@ -1224,7 +1224,7 @@ public class PackageCoreService { } private boolean createSrcDir(String mdpkgPath) { - String resDir = mdpkgPath + File.separator + MavenUtils.resourcesDir; + String resDir = mdpkgPath + File.separator + MavenUtils.RESOURCES_DIR; File resourceFile = new File(resDir); return resourceFile.mkdirs(); } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java index 8b405c4..9eb015d 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/ProjectExtendCoreService.java @@ -99,7 +99,7 @@ public class ProjectExtendCoreService { List extractConfigrationList = ExtractHelper.getInstance().getExtractConfigrationList(); extractConfigrationList.forEach(item -> { if (item.isEnable()) { - if (extractContext.getDeployType() != null && ("WEB").equals(item.getTypeCode()) && !"all".equals(extractContext.getDeployType()) && !extractContext.getDeployType().contains("web")) { + if (extractContext.getDeployType() != null && "WEB".equals(item.getTypeCode()) && !"all".equals(extractContext.getDeployType()) && !extractContext.getDeployType().contains("web")) { return; } ExtractAction extractAction = ExtractHelper.getInstance().getManager(item.getTypeCode()); @@ -239,12 +239,14 @@ public class ProjectExtendCoreService { List disabledExtsList = disabledExts.isEmpty() ? new ArrayList<>() : Arrays.asList(disabledExts.split(",")); for (String projPath : projPaths) { - System.out.println("正在编译:" + projPath); + //todo +// "正在编译:" + projPath String projectMetadataPath = Paths.get(projPath).resolve(Utils.getMetadataProjPath()).toString(); MetadataCompilerContext metadataCompilerContext = new MetadataCompilerContext(); metadataCompilerContext.setProjectPath(projectMetadataPath); compile(metadataCompilerContext, extsList, disabledExtsList); - System.out.println("编译完成:" + projPath); + //todo +// "编译完成:" + projPath } return null; @@ -265,7 +267,8 @@ public class ProjectExtendCoreService { if (manager != null) { manager.metadataCompile(metadataCompilerContext); } else { - System.out.println(item.getTypeCode() + "无法获取类"); + //todo +// item.getTypeCode() + "无法获取类" } } } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java index fde9144..b49f2c4 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeConfigLoader.java @@ -30,7 +30,7 @@ import lombok.Setter; public class JitRuntimeConfigLoader { - private static final String sectionName = "JitRuntimeConfigration"; + private static final String SECTION_NAME = "JitRuntimeConfigration"; @Getter @Setter static JitRuntimeConfigration jitRuntimeConfigration; @@ -51,7 +51,7 @@ public class JitRuntimeConfigLoader { FileServiceImp fileService = new FileServiceImp(); String fileContents = fileService.fileRead(fileName); JsonNode jsonNode = objectMapper.readTree(fileContents); - String jitRuntimeConfigrationJson = jsonNode.findValue(sectionName).toString(); + String jitRuntimeConfigrationJson = jsonNode.findValue(SECTION_NAME).toString(); jitRuntimeConfigration = objectMapper.readValue(jitRuntimeConfigrationJson, new TypeReference() { }); return jitRuntimeConfigration; diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java index 16aec0f..db603ec 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/config/JitRuntimeHelper.java @@ -42,7 +42,7 @@ public class JitRuntimeHelper extends JitRuntimeConfigLoader { public JitRuntimeAction getManager() { JitRuntimeAction manager = null; JitRuntimeConfigration data = getJitRuntimeConfigration(); - if (data != null && data.getEnable() == true) { + if (data != null && data.getEnable()) { Class cls = null; if (data.getAction() != null) { try { diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/event/MetadataCreateEventListenerImpl.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/event/MetadataCreateEventListenerImpl.java index 06bde56..729f257 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/event/MetadataCreateEventListenerImpl.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/event/MetadataCreateEventListenerImpl.java @@ -22,11 +22,11 @@ public class MetadataCreateEventListenerImpl implements MetadataCreateEventListe @Override public void fireMetadataCreatingEvent(MetadataEventArgs args) { - System.out.println("fireMetadataCreatingEvent"); +// "fireMetadataCreatingEvent" } @Override public void fireMetadataCreatedEvent(MetadataEventArgs args) { - System.out.println("fireMetadataCreatedEvent"); +// "fireMetadataCreatedEvent" } } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/exception/MvnExceptionHandler.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/exception/MvnExceptionHandler.java index 5bac860..b78a851 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/exception/MvnExceptionHandler.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/exception/MvnExceptionHandler.java @@ -18,7 +18,7 @@ package com.inspur.edp.lcm.metadata.core.exception; import io.iec.edp.caf.commons.exception.handle.DefaultExceptionHandler; public class MvnExceptionHandler extends DefaultExceptionHandler { - private static final String errorKeyword = "[ERROR]"; + private static final String ERROR_KEYWORD = "[ERROR]"; private String messageHandled = ""; public String handleMessage(String message) { @@ -103,10 +103,10 @@ public class MvnExceptionHandler extends DefaultExceptionHandler { String errorString = ""; final int keywordIndex = message.indexOf(keyword); if (keywordIndex > -1) { - int lastErrorIndex = message.substring(0, keywordIndex).lastIndexOf(errorKeyword); - lastErrorIndex = lastErrorIndex == -1 ? errorKeyword.length() : lastErrorIndex + errorKeyword.length(); + int lastErrorIndex = message.substring(0, keywordIndex).lastIndexOf(ERROR_KEYWORD); + lastErrorIndex = lastErrorIndex == -1 ? ERROR_KEYWORD.length() : lastErrorIndex + ERROR_KEYWORD.length(); - int nextErrorIndex = message.substring(keywordIndex).indexOf(errorKeyword) + keywordIndex; + int nextErrorIndex = message.substring(keywordIndex).indexOf(ERROR_KEYWORD) + keywordIndex; if (nextErrorIndex == -1) { errorString = message.substring(lastErrorIndex).trim(); } else { diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/MetadataPackageIndexService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/MetadataPackageIndexService.java index 5281c6c..600d246 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/MetadataPackageIndexService.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/MetadataPackageIndexService.java @@ -35,11 +35,11 @@ public class MetadataPackageIndexService { FileServiceImp fileServiceImp = new FileServiceImp(); - protected String KEY_CONNECTOR = "_"; + protected String keyConnector = "_"; - protected String LINE = "-"; + protected String line = "-"; - protected String FEATURE_IN_NAME = "-api-"; + protected String featureInName = "-api-"; public String location; @@ -93,8 +93,8 @@ public class MetadataPackageIndexService { private void update(List retainKeys) { for (String key : retainKeys) { - String[] fileNameArray = key.split(KEY_CONNECTOR); - if (!fileNameArray[1].contains(LINE) || fileNameArray[1].endsWith(Utils.getVersionSuffix())) { + String[] fileNameArray = key.split(keyConnector); + if (!fileNameArray[1].contains(line) || fileNameArray[1].endsWith(Utils.getVersionSuffix())) { Long lastModified = new File(location + File.separator + fileNameArray[1] + File.separator + fileNameArray[0]).lastModified(); boolean changeFlag = lastModified - metadataPackageIndexHashMap.get(key).getLastModified() != 0; if (changeFlag) { @@ -107,7 +107,7 @@ public class MetadataPackageIndexService { private void insert(List insertKeys) { for (String key : insertKeys) { - String[] fileNameArray = key.split(KEY_CONNECTOR); + String[] fileNameArray = key.split(keyConnector); File dir = new File(location + File.separator + fileNameArray[1]); getSingleMetadataPackageForIndex(dir); } @@ -159,8 +159,8 @@ public class MetadataPackageIndexService { metadataPackageForIndex.setLocation(file.getAbsolutePath()); metadataPackageForIndex.setLastModified(file.lastModified()); metadataPackageForIndex.setSourceName(dir.getName()); - if (dir.getName().contains(FEATURE_IN_NAME)) { - String sourceVersion = dir.getName().substring(dir.getName().lastIndexOf(FEATURE_IN_NAME) + FEATURE_IN_NAME.length()); + if (dir.getName().contains(featureInName)) { + String sourceVersion = dir.getName().substring(dir.getName().lastIndexOf(featureInName) + featureInName.length()); metadataPackageForIndex.setSourceVersion(sourceVersion); } } @@ -174,7 +174,7 @@ public class MetadataPackageIndexService { } protected String handleKey(String metadataPackageName, String name) { - String key = metadataPackageName + KEY_CONNECTOR + name; + String key = metadataPackageName + keyConnector + name; return key; } @@ -215,7 +215,7 @@ public class MetadataPackageIndexService { if (depFileLocation != null) { Model model = getModel(depFileLocation); model.getDependencies().forEach(dependency -> { - String gav = dependency.getGroupId() + LINE + dependency.getArtifactId() + LINE + dependency.getVersion(); + String gav = dependency.getGroupId() + line + dependency.getArtifactId() + line + dependency.getVersion(); metadataPackageIndexHashMap.keySet().forEach(key -> { if (key.endsWith(gav)) { depMetadataPackages.put(key, metadataPackageIndexHashMap.get(key)); @@ -236,7 +236,7 @@ public class MetadataPackageIndexService { } } if (!existFlag) { - String key = depMetadataPackageName + KEY_CONNECTOR + depMetadataPackageName; + String key = depMetadataPackageName + keyConnector + depMetadataPackageName; depMetadataPackages.put(key, MetadataPackageIndexServiceForPackages.getInstance(null).getMetadataPackageIndexForPackagesHashMap().get(key)); } }); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/ProjectMetadataCacheService.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/ProjectMetadataCacheService.java index f261d43..04646f9 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/ProjectMetadataCacheService.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/index/ProjectMetadataCacheService.java @@ -192,8 +192,7 @@ public class ProjectMetadataCacheService { references.put(key, metadataPackageIndexForPackagesHashMap.get(key)); return; } - - System.out.println("找不到对元数据包" + metadataPackageName + "的引用。"); +// "找不到对元数据包" + metadataPackageName + "的引用。" }); // 存在多余的maven引用 @@ -338,7 +337,7 @@ public class ProjectMetadataCacheService { if (ref != null && ref.getMetadataIds() != null) { ref.getMetadataIds().forEach(metadataId -> metadataPackageLocations.put(metadataId, ref.getLocation())); } else { - System.out.println("ref:" + ref.getLocation()); +// "ref:" + ref.getLocation() } }); projectMetadataCache.setMetadataPackageLocations(metadataPackageLocations); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForJarManager.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForJarManager.java index a9a55e1..ee772e8 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForJarManager.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForJarManager.java @@ -88,7 +88,7 @@ public class MavenDeploymentForJarManager extends MavenDeploymentManager { } private void setCodeRepoUrl(String projPath, String repoId) { - String codePomPath = projPath + File.separator + "java" + File.separator + Utils.getMavenProName() + File.separator + MavenUtils.pomFile; + String codePomPath = projPath + File.separator + "java" + File.separator + Utils.getMavenProName() + File.separator + MavenUtils.POM_FILE; pomManager.setRepoUrl(codePomPath, repoId); } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForMdpkgManager.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForMdpkgManager.java index 1c46b01..2653564 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForMdpkgManager.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/MavenDeploymentForMdpkgManager.java @@ -74,8 +74,8 @@ public class MavenDeploymentForMdpkgManager extends MavenDeploymentManager { this.dependencyVersion = dependencyVersion; this.mavenPath = mavenPath; metadataBinPath = projPath + File.separator + "metadata" + File.separator + "bin"; - metadataTempDir = fileServiceImp.getCombinePath(projPath + File.separator + "metadata", MavenUtils.tempFolder); - metadataPomPath = fileServiceImp.getCombinePath(metadataTempDir, MavenUtils.pomFile); + metadataTempDir = fileServiceImp.getCombinePath(projPath + File.separator + "metadata", MavenUtils.TEMP_FOLDER); + metadataPomPath = fileServiceImp.getCombinePath(metadataTempDir, MavenUtils.POM_FILE); beforeDeploy(); @@ -122,7 +122,7 @@ public class MavenDeploymentForMdpkgManager extends MavenDeploymentManager { mdpkgPath = metadataProjectCoreService.getMdpkgPath(projPath); Utils.checkEmpty(mdpkgPath, "未找到元数据包,请先编译:" + projPath); createSrcDir(metadataTempDir); - String destPath = metadataTempDir + File.separator + MavenUtils.resourcesDir + File.separator + new File(mdpkgPath).getName(); + String destPath = metadataTempDir + File.separator + MavenUtils.RESOURCES_DIR + File.separator + new File(mdpkgPath).getName(); try { fileServiceImp.fileCopy(mdpkgPath, destPath); } catch (IOException e) { @@ -176,7 +176,7 @@ public class MavenDeploymentForMdpkgManager extends MavenDeploymentManager { } private boolean createSrcDir(String mdpkgPath) { - String resDir = mdpkgPath + File.separator + MavenUtils.resourcesDir; + String resDir = mdpkgPath + File.separator + MavenUtils.RESOURCES_DIR; File resourceFile = new File(resDir); return resourceFile.mkdirs(); } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/PomManager.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/PomManager.java index 2902b4f..7fd3c58 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/PomManager.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/manager/PomManager.java @@ -39,7 +39,7 @@ public class PomManager { public void setRepoUrl(String pomPath, String repoId) { final Model model = getModel(pomPath); - final DistributionManagement distributionManagement = RepositoryFactory.getInstance().getMavenSettingsRepository().getDistributionManagement(repoId, model.getVersion().endsWith(MavenUtils.snapShot)); + final DistributionManagement distributionManagement = RepositoryFactory.getInstance().getMavenSettingsRepository().getDistributionManagement(repoId, model.getVersion().endsWith(MavenUtils.SNAP_SHOT)); model.setDistributionManagement(distributionManagement); writeModel(pomPath, model); } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataProjectRepository.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataProjectRepository.java index 5505857..a1e72a9 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataProjectRepository.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataProjectRepository.java @@ -109,7 +109,7 @@ public class MetadataProjectRepository { e.printStackTrace(); } } - String feature = flag == true ? " -U" : ""; + String feature = flag ? " -U" : ""; fileService.fileUpdate(filePath, feature, false); } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataRepository.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataRepository.java index 00db729..e7965ee 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataRepository.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/MetadataRepository.java @@ -25,15 +25,14 @@ import com.inspur.edp.lcm.metadata.common.Utils; import java.io.File; import java.io.IOException; import java.util.List; -import lombok.var; public class MetadataRepository { private FileServiceImp fileService = new FileServiceImp(); MetadataSerializer metadataSerializer = new MetadataSerializer(); public GspMetadata load(String absolutePath) { - var fileString = fileService.fileRead(absolutePath); - var metadata = metadataSerializer.deserialize(fileString, GspMetadata.class); + String fileString = fileService.fileRead(absolutePath); + GspMetadata metadata = metadataSerializer.deserialize(fileString, GspMetadata.class); metadata.setRelativePath(absolutePath.substring(0, Utils.handlePath(absolutePath).lastIndexOf('/'))); return metadata; } @@ -58,7 +57,7 @@ public class MetadataRepository { } public void getMetadatasUnderDir(List mdPathList, String dirPath) { - var dirs = fileService.getDirectorys(dirPath); + List dirs = fileService.getDirectorys(dirPath); if (dirs.size() > 0) { for (int i = 0; i < dirs.size(); i++) { String dirName = fileService.getFileName(Utils.handlePath(dirs.get(i).getPath())); @@ -68,7 +67,7 @@ public class MetadataRepository { } } } - var paths = fileService.getAllFiles(dirPath); + List paths = fileService.getAllFiles(dirPath); if (paths.size() > 0) { for (File path : paths) { mdPathList.add(Utils.handlePath(path.getPath())); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/PomRepository.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/PomRepository.java index dd0af2d..e098b17 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/PomRepository.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/persistence/PomRepository.java @@ -34,11 +34,11 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; public class PomRepository { - private final String GROUP_ID = "com.inspur.edp"; - private final String ARTIFACT_ID = "download-tools"; - private final String VERSION = "0.1.0-SNAPSHOT"; - private final String MODEL_VERSION = "4.0.0"; - private final String PACKAGING = "pom"; + private final String groupId = "com.inspur.edp"; + private final String artifactId = "download-tools"; + private final String version = "0.1.0-SNAPSHOT"; + private final String modelVersion = "4.0.0"; + private final String packaging = "pom"; FileServiceImp fileServiceImp = new FileServiceImp(); @@ -76,7 +76,7 @@ public class PomRepository { fileServiceImp.createFile(pomPath); // 创建model并写入 final List dependencies = createDependencies(refs, PackageType.zip.toString()); - final Model model = createModel(GROUP_ID, ARTIFACT_ID, VERSION, MODEL_VERSION, PACKAGING, dependencies); + final Model model = createModel(groupId, artifactId, version, modelVersion, packaging, dependencies); writeModel(pomPath, model); } @@ -101,7 +101,7 @@ public class PomRepository { model.setModelVersion("4.0.0"); model.setPackaging("metadata-pack"); - final boolean isSnotshot = sourceModel.getVersion().endsWith(MavenUtils.snapShot); + final boolean isSnotshot = sourceModel.getVersion().endsWith(MavenUtils.SNAP_SHOT); DistributionManagement distributionManagement = RepositoryFactory.getInstance().getMavenSettingsRepository().getDistributionManagement(repoId, isSnotshot); model.setDistributionManagement(distributionManagement); @@ -111,7 +111,7 @@ public class PomRepository { Dependency dependency = new Dependency(); dependency.setGroupId(sourceDependency.getGroupId()); dependency.setArtifactId(sourceDependency.getArtifactId()); - boolean dependencyVersionFlag = dependencyVersion != null && sourceDependency.getVersion().endsWith(MavenUtils.snapShot); + boolean dependencyVersionFlag = dependencyVersion != null && sourceDependency.getVersion().endsWith(MavenUtils.SNAP_SHOT); String actingVersion = "m" + (dependencyVersionFlag ? dependencyVersion : sourceDependency.getVersion()); dependency.setVersion(actingVersion); dependency.setType("zip"); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/sync/InstallJarRunnable.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/sync/InstallJarRunnable.java index 211faa0..8b0d6cd 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/sync/InstallJarRunnable.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/core/sync/InstallJarRunnable.java @@ -35,7 +35,7 @@ public class InstallJarRunnable implements Runnable { protected final FileServiceImp fileServiceImp = new FileServiceImp(); protected final MavenUtilsCore mavenUtilsCore = new MavenUtilsCore(); private List downloadMdpkgPaths; - private String FEATURE_IN_NAME = "-api-"; + private String featureInName = "-api-"; @Override public void run() { @@ -75,8 +75,8 @@ public class InstallJarRunnable implements Runnable { String dirName = new File(new File(path).getParent()).getName(); MavenPackageRefs mavenPackageRefs = new MavenPackageRefs(); String groupId = dirName.substring(0, dirName.indexOf("-")); - String version = dirName.substring(dirName.lastIndexOf(FEATURE_IN_NAME) + FEATURE_IN_NAME.length() + 1); - String artifactId = dirName.substring(dirName.indexOf("-") + 1, dirName.lastIndexOf(FEATURE_IN_NAME) + FEATURE_IN_NAME.length() - 1); + String version = dirName.substring(dirName.lastIndexOf(featureInName) + featureInName.length() + 1); + String artifactId = dirName.substring(dirName.indexOf("-") + 1, dirName.lastIndexOf(featureInName) + featureInName.length() - 1); mavenPackageRefs.setGroupId(groupId); mavenPackageRefs.setArtifactId(artifactId); mavenPackageRefs.setVersion(version); diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java index d5af8be..3fd83a9 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/extend/action/ExtractActionImpl.java @@ -80,7 +80,8 @@ public class ExtractActionImpl implements ExtractAction { return files[0].getPath(); } } - System.out.println("无" + module + "jar包。"); + //todo +// "无" + module + "jar包。" return ""; } diff --git a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java index f31dc01..425bbad 100644 --- a/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java +++ b/model/framework/devtime-core/src/main/java/com/inspur/edp/lcm/metadata/ref/MdpkgServiceImp.java @@ -137,8 +137,8 @@ public class MdpkgServiceImp implements MdpkgService { } @Override - public void addProjectDependency(String pomp_ath, String groupId, String artifactId, String version) { - packageCoreService.addProjectDependency(pomp_ath, groupId, artifactId, version); + public void addProjectDependency(String pompAth, String groupId, String artifactId, String version) { + packageCoreService.addProjectDependency(pompAth, groupId, artifactId, version); } @Override diff --git a/model/framework/generator-api/pom.xml b/model/framework/generator-api/pom.xml index 6526661..bd95e60 100644 --- a/model/framework/generator-api/pom.xml +++ b/model/framework/generator-api/pom.xml @@ -25,10 +25,10 @@ 0.9.0-SNAPSHOT compile - - org.springframework.boot - spring-boot-starter-test - + + + + diff --git a/model/framework/generator-api/src/test/java/com/inspur/edp/jittojava/context/common/FileUtilsTest.java b/model/framework/generator-api/src/test/java/com/inspur/edp/jittojava/context/common/FileUtilsTest.java index 7f53b07..7d6f136 100644 --- a/model/framework/generator-api/src/test/java/com/inspur/edp/jittojava/context/common/FileUtilsTest.java +++ b/model/framework/generator-api/src/test/java/com/inspur/edp/jittojava/context/common/FileUtilsTest.java @@ -1,20 +1,19 @@ package com.inspur.edp.jittojava.context.common; -import org.junit.Assert; -import org.junit.Test; -import org.springframework.boot.test.context.SpringBootTest; +//import org.junit.Assert; +//import org.junit.Test; +//import org.springframework.boot.test.context.SpringBootTest; +//import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.is; - -@SpringBootTest +//@SpringBootTest public class FileUtilsTest { private static String TEST_FILE_NAME = "/fileUtils-test-file.txt"; private static String EXPECT_RESULT = "junit test"; - @Test - public void fileReadTest() { - String testFilePath = this.getClass().getResource(TEST_FILE_NAME).getPath(); - String content = FileUtils.fileRead(testFilePath); - Assert.assertThat(content, is(EXPECT_RESULT)); - } +// @Test +// public void fileReadTest() { +// String testFilePath = this.getClass().getResource(TEST_FILE_NAME).getPath(); +// String content = FileUtils.fileRead(testFilePath); +// Assert.assertThat(content, is(EXPECT_RESULT)); +// } } \ No newline at end of file diff --git a/model/framework/pom.xml b/model/framework/pom.xml index cce6c08..1a25352 100644 --- a/model/framework/pom.xml +++ b/model/framework/pom.xml @@ -51,11 +51,11 @@ - - org.springframework.boot - spring-boot-starter-test - ${spring-boot.version} - + + + + + com.alibaba fastjson diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java index f74189d..512e9e1 100644 --- a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/rtservice/MetadataRTServiceImp.java @@ -37,7 +37,6 @@ import io.iec.edp.caf.rpc.api.service.RpcClient; import java.util.LinkedHashMap; import java.util.List; import lombok.extern.slf4j.Slf4j; -import lombok.var; @Slf4j public class MetadataRTServiceImp implements MetadataRTService { @@ -95,7 +94,7 @@ public class MetadataRTServiceImp implements MetadataRTService { List resources = SpringBeanUtils.getBean(II18nResourceRTManager.class).getI18nResource(metadata, language); MetadataI18nService service = I18nManagerHelper.getInstance().getI18nManager(metadata.getHeader().getType()); if (service != null && resources != null && resources.size() > 0) { - var result = service.merge(metadata, resources); + GspMetadata result = service.merge(metadata, resources); RtCacheHandler.updateMetadataCache(metadataKey, result); return result; } diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java index a0b1d15..b2989c5 100644 --- a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java @@ -70,7 +70,6 @@ import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; -import lombok.var; import org.codehaus.plexus.util.StringUtils; /** @@ -201,7 +200,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { List resources = getI18nResourceRtManager().getI18nResource(originalData, language); MetadataI18nService service = I18nManagerHelper.getInstance().getI18nManager(originalData.getHeader().getType()); if (service != null && resources != null && resources.size() > 0) { - var result = service.merge(originalData, resources); + GspMetadata result = service.merge(originalData, resources); RtCacheHandler.updateMetadataCache(metadataKey, result); return result; } @@ -353,7 +352,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { MetadataCacheManager.addMetadataPathMapping(metadataKey, metadataPackagePath + item.getRelativePath()); metadataInfoList.add(item); } - MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey, metadataInfoList); + MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.ALL_METADATA_INFO_CACHE_KEY, metadataInfoList); } } Cache metadataCache = MetadataDistCacheManager.getMetadataCache(); @@ -405,14 +404,14 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { metadataInfoList.add(item); } } - MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey, metadataInfoList); + MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.ALL_METADATA_INFO_CACHE_KEY, metadataInfoList); } // 预加载序反列化器 MetadataSerializerHelper.getInstance(); } public List getMetadataList(String metadataTypes) { - var result = getMetadataRefListWithTypes(metadataTypes); + List result = getMetadataRefListWithTypes(metadataTypes); return utils.buildMetadata4RefDto(result); } @@ -426,7 +425,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { public List getMetadataRefList() { List metadataList = new ArrayList<>(); //首先从缓存获取 - List packagesCache = (List) MetadataCacheManager.getAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + List packagesCache = (List) MetadataCacheManager.getAllMetadataPackageInfo(RtCacheHandler.ALL_PACKAGES_CACHE_KEY); if (packagesCache != null && packagesCache.size() > 0) { for (MetadataPackage pack : packagesCache) { List metadata4Ref = getMetadata4Ref(pack, null); @@ -439,7 +438,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { List metadata4Ref = getMetadata4Ref(metadataPackage, null); metadataList.addAll(metadata4Ref); } - MetadataCacheManager.addAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey, metadataPackages); + MetadataCacheManager.addAllMetadataPackageInfo(RtCacheHandler.ALL_PACKAGES_CACHE_KEY, metadataPackages); return metadataList; } @@ -541,7 +540,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { } List metadataList = new ArrayList<>(); //首先从缓存获取 - List packagesCache = (List) MetadataCacheManager.getAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + List packagesCache = (List) MetadataCacheManager.getAllMetadataPackageInfo(RtCacheHandler.ALL_PACKAGES_CACHE_KEY); if (packagesCache != null && packagesCache.size() > 0) { for (MetadataPackage pack : packagesCache) { List metadata4Ref = getMetadata4Ref(pack, typeList); @@ -556,7 +555,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { metadataList.addAll(metadata4Ref); } - MetadataCacheManager.addAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey, metadataPackages); + MetadataCacheManager.addAllMetadataPackageInfo(RtCacheHandler.ALL_PACKAGES_CACHE_KEY, metadataPackages); return metadataList; } @@ -565,7 +564,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { if (metadataTypes != null && metadataTypes.size() > 0) { metadataTypes.forEach(type -> { - var result = packageInfo.getMetadataList().stream().filter(item -> item.getHeader().getType().toLowerCase().equals(type.toLowerCase())).collect(Collectors.toList()); + List result = packageInfo.getMetadataList().stream().filter(item -> item.getHeader().getType().toLowerCase().equals(type.toLowerCase())).collect(Collectors.toList()); if (result.size() > 0) { result.forEach(metadata -> { Metadata4Ref metadata4Ref = new Metadata4Ref(); @@ -598,7 +597,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { private GspMetadata getMetadataBySemanticId(String metadataNamespace, String metadataCode, String metadataTypeCode) { - List allMetadataInfo = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey); + List allMetadataInfo = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.ALL_METADATA_INFO_CACHE_KEY); if (allMetadataInfo != null) { for (GspMetadata item : allMetadataInfo) { if (item.getHeader().getNameSpace().toLowerCase().equals(metadataNamespace.toLowerCase()) diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java index b0414ba..fea5b06 100644 --- a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/event/MdPkgChangedEventManager.java @@ -47,7 +47,7 @@ public class MdPkgChangedEventManager extends EventManager { @Override public void addListener(IEventListener iEventListener) { - if (iEventListener instanceof MdPkgChangedEventListener == false) { + if (!(iEventListener instanceof MdPkgChangedEventListener)) { throw new RuntimeException("指定的监听者没有实现IDemoEventListener接口"); } MdPkgChangedEventListener mdPkgChangedEventListener = (MdPkgChangedEventListener) iEventListener; @@ -57,7 +57,7 @@ public class MdPkgChangedEventManager extends EventManager { @Override public void removeListener(IEventListener iEventListener) { - if (iEventListener instanceof MdPkgChangedEventListener == false) { + if (!(iEventListener instanceof MdPkgChangedEventListener)) { throw new RuntimeException("指定的监听者没有实现IDemoEventListener接口"); } MdPkgChangedEventListener mdPkgChangedEventListener = (MdPkgChangedEventListener) iEventListener; diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java index 86d0006..f253760 100644 --- a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/monitor/MdpkgListenerAdapter.java @@ -42,13 +42,11 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { } // @Override // public void onStart(FileAlterationObserver observer) { -// System.out.println("start"); // super.onStart(observer); // } // // @Override // public void onStop(FileAlterationObserver observer) { -// System.out.println("stop"); // super.onStop(observer); // } @@ -59,7 +57,7 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { updateMdpkgAndMetadataCache(file, true); } catch (Exception e) { - System.out.println(e); + //todo } } @@ -70,7 +68,7 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { super.onFileDelete(file); deleteMdpkgAndMetadataCache(file); } catch (Exception e) { - System.out.println(e); + //todo } } @@ -81,7 +79,7 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { super.onFileChange(file); updateMdpkgAndMetadataCache(file, false); } catch (Exception e) { - System.out.println(e); + //todo } } @@ -98,11 +96,11 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { Cache metadataCache = MetadataDistCacheManager.getMetadataCache(); Cache metadataRtCache = MetadataRtDistCache.getMetadataCache(); MetadataPackage metadataPackage = RepositoryFactory.getInstance().getMetadataPackageRepository().getMetadataPackage(file); - MetadataCacheManager.removeAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + MetadataCacheManager.removeAllMetadataPackageInfo(RtCacheHandler.ALL_PACKAGES_CACHE_KEY); //清理元数据内容缓存,将原有缓存的包中元数据列表从元数据内容缓存移除 String metadataKey = ""; List oldPackageMetadataList = (List) MetadataCacheManager.getMDManifestInfo(metadataPackage.getHeader().getName()); - List allMetadataList = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey); + List allMetadataList = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.ALL_METADATA_INFO_CACHE_KEY); if (oldPackageMetadataList != null && oldPackageMetadataList.size() > 0) { for (GspMetadata item : oldPackageMetadataList) { metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); @@ -122,7 +120,7 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { allMetadataList.removeAll(oldPackageMetadataList); } allMetadataList.addAll(metadataPackage.getMetadataList()); - MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey, allMetadataList); + MetadataCacheManager.addAllMetadataInfo(RtCacheHandler.ALL_METADATA_INFO_CACHE_KEY, allMetadataList); //清理并更新包中<元数据标识,元数据所在位置信息缓存>,清理过程在旧包处理过程中 String metadataPackagePath = Utils.handlePath(file.toString()); for (GspMetadata item : metadataPackage.getMetadataList()) { @@ -156,7 +154,7 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { Cache metadataRtCache = MetadataRtDistCache.getMetadataCache(); List oldPackageMetadataList = (List) MetadataCacheManager.getMDManifestInfo(packageName); - List allMetadataList = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.allMetadataInfoCacheKey); + List allMetadataList = (List) MetadataCacheManager.getAllMetadataInfo(RtCacheHandler.ALL_METADATA_INFO_CACHE_KEY); if (oldPackageMetadataList != null && oldPackageMetadataList.size() > 0) { for (GspMetadata item : oldPackageMetadataList) { metadataKey = RtCacheHandler.getMetadataCacheKey(item.getHeader().getId(), ""); @@ -178,7 +176,7 @@ public class MdpkgListenerAdapter extends FileAlterationListenerAdaptor { MetadataCacheManager.removeMetadataPackageInfo(packageName); MetadataCacheManager.removeMDManifestInfo(packageName); MetadataCacheManager.removeMPDependence(packageName); - MetadataCacheManager.removeAllMetadataPackageInfo(RtCacheHandler.allPackagesCacheKey); + MetadataCacheManager.removeAllMetadataPackageInfo(RtCacheHandler.ALL_PACKAGES_CACHE_KEY); } private static List languages; diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java index 30b2c0e..3e8a7d5 100644 --- a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/persistent/MetadataPackageRepositoryImp.java @@ -93,7 +93,8 @@ public class MetadataPackageRepositoryImp implements MetadataPackageRepository { packageDic.put(Utils.handlePath(file1.toString()), metadataPackage); } catch (IOException e) { e.printStackTrace(); - System.out.println(e.getMessage() + ":" + file1.getAbsolutePath()); + //todo +// e.getMessage() + ":" + file1.getAbsolutePath() log.error(e.getMessage() + ":" + file1.getAbsolutePath()); } } -- Gitee From 58f9fc3d143a30d278f96b20d1b94d5d0e5f8239 Mon Sep 17 00:00:00 2001 From: Q-Lee Date: Tue, 11 May 2021 17:10:04 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9Ametadata-jit-to-?= =?UTF-8?q?java=E5=B7=A5=E7=A8=8B=E4=BB=A3=E7=A0=81=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/framework/common/pom.xml | 6 + model/framework/generator-api/pom.xml | 11 + .../edp/jittojava/context/JitContext.java | 2 +- model/framework/generator-core/pom.xml | 8 + .../edp/jittojava/action/AfterGenerator.java | 49 ++ .../inspur/edp/jittojava/action/Utils.java | 72 +++ .../edp/jittojava/core/CommonServiceCore.java | 102 ++++ .../edp/jittojava/core/CommonServiceImp.java | 61 ++ .../jittojava/core/GenerateServiceCore.java | 118 ++++ .../jittojava/core/GenerateServiceImp.java | 109 ++++ .../edp/jittojava/core/JitCompilerHelper.java | 90 +++ .../inspur/edp/jittojava/core/JitUtils.java | 136 +++++ .../jittojava/core/MavenDependencyConst.java | 34 ++ .../core/config/ServiceAutoConfiguration.java | 44 ++ .../core/manager/GeneratorManager.java | 566 ++++++++++++++++++ .../core/manager/GeneratorManagerFactory.java | 36 ++ .../GeneratorManagerForGeneration.java} | 17 +- .../GeneratorManagerForInterpretation.java | 117 ++++ .../core/persistence/GenerateRepository.java | 134 +++++ .../core/persistence/RepositoryFactory.java | 39 ++ .../edp/jittojava/temp/AfterGenerator.java | 70 +++ .../jittojava/temp/MavenDependencyConst.java | 34 ++ .../com/inspur/edp/jittojava/temp/Utils.java | 141 +++++ model/framework/generator-webapi/pom.xml | 30 + .../jittojava/webapi/GenerateController.java | 51 ++ .../webapi/config/Configuration.java | 38 ++ model/framework/pom.xml | 7 + 27 files changed, 2114 insertions(+), 8 deletions(-) create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/AfterGenerator.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/Utils.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceImp.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceCore.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceImp.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitUtils.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/MavenDependencyConst.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/config/ServiceAutoConfiguration.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerFactory.java rename model/framework/{generator-api/src/main/java/com/inspur/edp/jittojava/context/temp/ModuleGenerator.java => generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForGeneration.java} (59%) create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForInterpretation.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/RepositoryFactory.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/AfterGenerator.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/MavenDependencyConst.java create mode 100644 model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java create mode 100644 model/framework/generator-webapi/pom.xml create mode 100644 model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/GenerateController.java create mode 100644 model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/config/Configuration.java diff --git a/model/framework/common/pom.xml b/model/framework/common/pom.xml index bad6930..5e269a1 100644 --- a/model/framework/common/pom.xml +++ b/model/framework/common/pom.xml @@ -42,6 +42,12 @@ com.inspur.edp lcm-project-deployer-spi + + + lcm-metadata-api + com.inspur.edp + + org.apache.maven diff --git a/model/framework/generator-api/pom.xml b/model/framework/generator-api/pom.xml index bd95e60..4ea0623 100644 --- a/model/framework/generator-api/pom.xml +++ b/model/framework/generator-api/pom.xml @@ -13,6 +13,17 @@ ubml-model-framework-generator-api + + com.inspur.edp + caf-generator + + + lcm-metadata-api + com.inspur.edp + + + + org.openatom.ubml ubml-model-framework-common diff --git a/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java b/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java index 345f062..7f40fd5 100644 --- a/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java +++ b/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/JitContext.java @@ -15,8 +15,8 @@ */ package com.inspur.edp.jittojava.context; +import com.inspur.edp.caf.generator.module.ModuleGenerator; import com.inspur.edp.jittojava.context.temp.ModuleGenerateInfo; -import com.inspur.edp.jittojava.context.temp.ModuleGenerator; import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; import com.inspur.edp.lcm.metadata.api.entity.GspProject; import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; diff --git a/model/framework/generator-core/pom.xml b/model/framework/generator-core/pom.xml index e9652f8..6e552f5 100644 --- a/model/framework/generator-core/pom.xml +++ b/model/framework/generator-core/pom.xml @@ -18,4 +18,12 @@ 8 + + + org.openatom.ubml + ubml-model-framework-generator-spi + ${project.version} + + + \ No newline at end of file diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/AfterGenerator.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/AfterGenerator.java new file mode 100644 index 0000000..ce078e2 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/AfterGenerator.java @@ -0,0 +1,49 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.action; + +import com.inspur.edp.jittojava.core.GenerateServiceCore; +import com.inspur.edp.jittojava.spi.AfterGeneratorAction; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import java.io.IOException; +import java.nio.file.Paths; + +/** + * @Classname AfterGenerator + * @Description TODO + * @Date 2019/12/24 17:18 + * @Created by liu_bintr + * @Version 1.0 + */ +public class AfterGenerator implements AfterGeneratorAction { + GenerateServiceCore generateService = new GenerateServiceCore(); + Utils utils = new Utils(); + + @Override + public void afterGenerator(String projPath) { + FileServiceImp fileService = new FileServiceImp(); + String runtimePath = Paths.get(projPath).resolve("java/code/runtime").toString(); + if (fileService.isDirectoryExist(runtimePath)) { + try { + fileService.deleteAllFilesUnderDirectory(runtimePath); + } catch (IOException e) { + throw new RuntimeException(e); + } + generateService.removeRuntimeModule(projPath); + } + generateService.modifyPom(projPath, utils.getExtendDependency()); + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/Utils.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/Utils.java new file mode 100644 index 0000000..1620d0d --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/action/Utils.java @@ -0,0 +1,72 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.action; + +import com.inspur.edp.jittojava.context.entity.MavenDependency; +import com.inspur.edp.jittojava.core.MavenDependencyConst; +import java.util.ArrayList; +import java.util.List; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +/** + * @Classname Utils + * @Description TODO + * @Date 2019/12/24 17:20 + * @Created by liu_bintr + * @Version 1.0 + */ +public class Utils { + + public ArrayList getExtendDependency() { + String extendDependencyPath = + this.getClass().getResource("/CommonExtendMavenDependency.xml").toString(); + return readInternalDependency(extendDependencyPath); + } + + private ArrayList readInternalDependency(String defaultDependencyPath) { + ArrayList result = new ArrayList<>(); + Document doc = readDocument(defaultDependencyPath); + Element rootElement = doc.getRootElement(); + List list = rootElement.elements(); + for (int i = 0; i < list.size(); i++) { + Element ele = (Element) list.get(i); + result.add(new MavenDependency(getTagValue(ele, MavenDependencyConst.groupId), getTagValue(ele, MavenDependencyConst.artifactId), + getTagValue(ele, MavenDependencyConst.version), getTagValue(ele, MavenDependencyConst.file))); + } + return result; + } + + private Document readDocument(String filePath) { + SAXReader sr = new SAXReader(); + try { + return sr.read(filePath); + } catch (DocumentException e) { + throw new RuntimeException("无效路径" + filePath); + } + } + + private String getTagValue(Element ele, String tagName) { + Element tagElement = (Element) ele.element(tagName); + if (tagElement == null) { + return null; + } + return tagElement.getText(); + } + +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java new file mode 100644 index 0000000..ed4cb09 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java @@ -0,0 +1,102 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +import com.inspur.edp.jittojava.context.service.CommonService; +import com.inspur.edp.lcm.metadata.common.Utils; +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Classname CommonServiceCore Description 实现类 Date 2019/8/8 16:42 + * + * @author zhongchq + * @version 1.0 + */ +public class CommonServiceCore implements CommonService { + + @Override + public String getProjectPath(String absJavaPath) { + //java目录下进行判断 + File file = new File(absJavaPath); + if (file.isDirectory()) { + File[] files = file.listFiles(); + if (files.length == 0) { + return null; + } + //遍历java目录下目录 + for (int i = 0; i < files.length; i++) { + //对目录进行判断 + if (files[i].isDirectory()) { + File[] fileInPoject = files[i].listFiles(); + for (File file1 : fileInPoject) { + if (file1.isFile() && file1.toString().contains("pom.xml")) { + return Utils.handlePath(file1.getParent().substring(file1.toString().indexOf("java"))); + } + } + } + } + } + return null; + } + + @Override + public List getJarPath(String absJavaPath) { + Path path = Paths.get(absJavaPath); + List filename = new ArrayList<>(); + try { + Files.walkFileTree(path + , new SimpleFileVisitor() { + // 访问文件时触发 + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.toString().endsWith(".jar")) { + String filepaths = file.toString(); + if (filepaths.contains("out") || filepaths.contains("target")) { + filename.add(Utils.handlePath(filepaths.substring(filepaths.indexOf("java")))); + } + return FileVisitResult.CONTINUE; + } + return FileVisitResult.CONTINUE; + } +// +// // 访问目录时触发 +// @Override +// public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { +// if (dir.endsWith("target")) { +// String targetpath = dir.getParent().toAbsolutePath().toString().su +// targetpath.substring("java"); +// list.add(targetpath); +// } +// System.out.println("正在访问:" + dir + " 目录"); +// return FileVisitResult.CONTINUE; +// } + }); + } catch (IOException e) { + e.printStackTrace(); + } + Collections.sort(filename); + return filename; + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceImp.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceImp.java new file mode 100644 index 0000000..a1152d6 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceImp.java @@ -0,0 +1,61 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +import com.inspur.edp.jittojava.context.service.CommonService; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.core.MetadataProjectServiceImp; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import java.util.List; + +/** + * Classname CommonServiceImp Description 实现类 Date 2019/8/8 16:42 + * + * @author zhongchq + * @version 1.0 + */ +public class CommonServiceImp implements CommonService { + + FileService fileService = new FileServiceImp(); + + MetadataProjectService metadataProjectService = new MetadataProjectServiceImp(); + + CommonServiceCore commonServiceCore = new CommonServiceCore(); + + /** + * @param proPath 相对路径 + * @return java.lang.String + * @throws + * @author zhongchq + **/ + @Override + public String getProjectPath(String proPath) { + String javaPath = fileService.getCombinePath(metadataProjectService.getProjPath(proPath), "java"); + String absJavaPath = ManagerUtils.getAbsolutePath(javaPath); + + return commonServiceCore.getProjectPath(absJavaPath); + + } + + @Override + public List getJarPath(String proPath) { + String javaPath = fileService.getCombinePath(metadataProjectService.getProjPath(proPath), "java"); + String absJavaPath = ManagerUtils.getAbsolutePath(javaPath); + return commonServiceCore.getJarPath(absJavaPath); + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceCore.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceCore.java new file mode 100644 index 0000000..1ab8798 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceCore.java @@ -0,0 +1,118 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +import com.inspur.edp.jittojava.context.entity.MavenDependency; +import com.inspur.edp.jittojava.core.manager.GeneratorManager; +import com.inspur.edp.jittojava.core.manager.GeneratorManagerFactory; +import com.inspur.edp.lcm.metadata.common.Utils; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.dom4j.Document; +import org.dom4j.Element; + +@Slf4j +public class GenerateServiceCore { + public void generate(String absolutePath, String mavenPath) throws Exception { + final GeneratorManager generatorManager = GeneratorManagerFactory.createGeneratorManager(absolutePath); + generatorManager.generate(absolutePath, mavenPath); + } + + public void generateApi(String absolutePath, String mavenPath) throws Exception { + final GeneratorManager generatorManager = GeneratorManagerFactory.createGeneratorManager(absolutePath); + generatorManager.generateApi(absolutePath, mavenPath); + } + + public void removeRuntimeModule(String absolutePath) { + String pomPath = getPomFilePath(absolutePath); + Model model = getModel(pomPath); + List modules = model.getModules(); + List newMudules = modules.stream().filter(module -> !"runtime".equals(module)).collect(Collectors.toList()); + model.setModules(newMudules); + writeModel(pomPath, model); + } + + public void writeModel(String pomPath, Model model) { + File pom = new File(pomPath); + if (!pom.exists()) { + pom.getParentFile().mkdirs(); + try { + pom.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try (FileOutputStream fileOutputStream = new FileOutputStream(pomPath)) { + MavenXpp3Writer mavenXpp3Writer = new MavenXpp3Writer(); + mavenXpp3Writer.write(fileOutputStream, model); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public Model getModel(String pomPath) { + try (FileInputStream fis = new FileInputStream(pomPath)) { + MavenXpp3Reader reader = new MavenXpp3Reader(); + final Model model = reader.read(fis); + return model; + } catch (IOException | XmlPullParserException e) { + throw new RuntimeException(e); + } + } + + public void modifyPom(String absolutePath, List mavenDependencyList) { + if (mavenDependencyList == null || mavenDependencyList.size() == 0) { + return; + } + String pomPath = getPomFilePath(absolutePath); + Document doc = JitUtils.readDocument(pomPath); + Element projectElement = doc.getRootElement(); + Element dependenciesElement = projectElement.element(MavenDependencyConst.dependencies); + + if (dependenciesElement == null) { + dependenciesElement = projectElement.addElement(MavenDependencyConst.dependencies); + } + List existValues = dependenciesElement.elements(); + ArrayList existDependencies = JitUtils.readExistDependencies(existValues); + for (MavenDependency newDependency : mavenDependencyList) { + if (JitUtils.checkContainDependency(newDependency, existDependencies)) { + continue; + } + JitUtils.addDependencyDom(newDependency, dependenciesElement); + } + JitUtils.saveDocument(doc, new File(pomPath)); + } + + private String getPomFilePath(String projPath) { + String javaPath = Paths.get(projPath).resolve("java").toString(); + String javaProjPath = Paths.get(javaPath).resolve(Utils.getMavenProName()).toString(); + String pomFilePath = Paths.get(javaProjPath).resolve("pom.xml").toString(); + + return pomFilePath; + } + +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceImp.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceImp.java new file mode 100644 index 0000000..fb19618 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/GenerateServiceImp.java @@ -0,0 +1,109 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +import com.inspur.edp.jittojava.context.GenerateService; +import com.inspur.edp.jittojava.context.entity.MavenDependency; +import com.inspur.edp.lcm.metadata.api.service.FileService; +import com.inspur.edp.lcm.metadata.devcommon.ManagerUtils; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import lombok.extern.slf4j.Slf4j; +import org.codehaus.plexus.util.StringUtils; + +@Slf4j +public class GenerateServiceImp implements GenerateService { + + GenerateServiceCore generateServiceCore = new GenerateServiceCore(); + + @Override + public void generate(String path) throws Exception { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + generateServiceCore.generate(absolutePath, mavenPath); + } + + @Override + public void generateApi(String path) throws Exception { + String absolutePath = ManagerUtils.getAbsolutePath(path); + String mavenPath = ManagerUtils.getMavenStoragePath(); + generateServiceCore.generateApi(absolutePath, mavenPath); + } + + @Override + public void modifyPom(String projPath, List mavenDependencyList) { + String absolutePath = ManagerUtils.getAbsolutePath(projPath); + generateServiceCore.modifyPom(absolutePath, mavenDependencyList); + } + + @Override + public void addProperties(String codePath, String propertyKey, String property) { + String factoriesFilePath = Paths.get(codePath).getParent().resolve(JitUtils.getSpringPeopertiesPath()).toString(); + FileService fileService = SpringBeanUtils.getBean(FileService.class); + if (!fileService.isFileExist(factoriesFilePath)) { + try { + fileService.createDirectory(Paths.get(factoriesFilePath).getParent().toString()); + fileService.createFile(factoriesFilePath); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + Properties properties = loadProperties(factoriesFilePath); + String valueStr = properties.getProperty(propertyKey); + if (StringUtils.isEmpty(valueStr)) { + properties.put(propertyKey, property); + updatePropertyFile(factoriesFilePath, properties); + } else { + List values = Arrays.asList(valueStr.split(",").clone()); + if (!values.contains(property)) { + valueStr = valueStr + "," + property; + properties.put(propertyKey, valueStr); + updatePropertyFile(factoriesFilePath, properties); + } + } + } + + public Properties loadProperties(String paramFile) { + Properties props = new Properties();//使用Properties类来加载属性文件 + try { + FileInputStream iFile = new FileInputStream(paramFile); + props.load(iFile); + iFile.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return props; + } + + private void updatePropertyFile(String filePath, Properties properties) { + try { + FileService fileService = SpringBeanUtils.getBean(FileService.class); + fileService.fileUpdate(filePath, "", false); + FileOutputStream oFile = new FileOutputStream(filePath, true); + properties.store(oFile, ""); + oFile.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java new file mode 100644 index 0000000..fbf85c8 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java @@ -0,0 +1,90 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +import com.inspur.edp.jittojava.context.common.JitCompilerConfigLoader; +import com.inspur.edp.jittojava.context.entity.JitCompilerConfigration; +import com.inspur.edp.jittojava.spi.AfterGeneratorAction; +import com.inspur.edp.jittojava.spi.JitAction; +import java.util.List; + +/** + * @Classname JitCompilerHelper + * @Description TODO + * @Date 2019/7/29 16:06 + * @Created by zhongchq + * @Version 1.0 + */ +public class JitCompilerHelper extends JitCompilerConfigLoader { + + private static JitCompilerHelper singleton = null; + + public JitCompilerHelper() { + } + + public static JitCompilerHelper getInstance() { + if (singleton == null) { + singleton = new JitCompilerHelper(); + } + return singleton; + } + + /** + * @param typeName + * @return com.inspur.edp.lcm.metadata.spi.MetadataContentSerializer + * @throws + * @author zhongchq + * @description 返回各元数据序列化器 + * @date 9:34 2019/7/24 + **/ + public JitAction getManager(String typeName) { + JitAction manager = null; + JitCompilerConfigration data = getCompilerConfigurations(typeName); + if (data != null && data.getEnable() == true) { + Class cls = null; + if (data.getBeforeCompiler() != null) { + try { + cls = Class.forName(data.getBeforeCompiler().getName()); + manager = (JitAction) cls.newInstance(); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + return manager; + } + + public AfterGeneratorAction getAfterActionManager(String typeName) { + AfterGeneratorAction manager = null; + JitCompilerConfigration data = getCompilerConfigurations(typeName); + if (data != null && data.getEnable() == true) { + Class cls = null; + if (data.getAfterCompiler() != null) { + try { + cls = Class.forName(data.getAfterCompiler().getName()); + manager = (AfterGeneratorAction) cls.newInstance(); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + return manager; + } + + public List getCompilerTypeList() { + return getCompilerConfigurations(); + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitUtils.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitUtils.java new file mode 100644 index 0000000..576ef49 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitUtils.java @@ -0,0 +1,136 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +import com.inspur.edp.jittojava.context.entity.MavenDependency; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.SAXReader; +import org.dom4j.io.XMLWriter; + +/** + * @Classname JitUtils + * @Description TODO + * @Date 2019/12/16 16:30 + * @Created by liu_bintr + * @Version 1.0 + */ +public class JitUtils { + public static String getArchetypePath() { + return "platform/dev/main/libs/resources/archetypefront"; + } + + public static String getSpringPeopertiesPath() { + return "resources/META-INF/spring.factories"; + } + + public static String getArchetypeArtifactId() { + return "bf-df-bank-front-archetype"; + } + + public static String getArchetypeTarget() { + return "target/" + getArchetypeArtifactId() + "-0.1.3.jar"; + } + + public static String getCompArchetypePath() { + return "platform/dev/main/libs/resources/archetypefront-comp"; + } + + public static String getCompArchetypeArtifactId() { + return "archetype-comp"; + } + + public static String getCompArchetypeTarget() { + return "target/" + getCompArchetypeArtifactId() + "-0.1.3.jar"; + } + + public static Document readDocument(String filePath) { + SAXReader sr = new SAXReader(); + try { + return sr.read(filePath); + } catch (DocumentException e) { + throw new RuntimeException("无效路径" + filePath); + } + } + + public static ArrayList readExistDependencies(List existValues) { + ArrayList list = new ArrayList<>(); + if (existValues == null || existValues.size() == 0) { + return list; + } + for (int i = 0; i < existValues.size(); i++) { + Element ele = (Element) existValues.get(i); + list.add(new MavenDependency(getTagValue(ele, MavenDependencyConst.groupId), getTagValue(ele, MavenDependencyConst.artifactId), + getTagValue(ele, MavenDependencyConst.version))); + } + return list; + } + + public static boolean checkContainDependency(MavenDependency dependency, ArrayList dependencies) { + for (MavenDependency item : dependencies) { + if (item.equals(dependency)) { + return true; + } + } + return false; + } + + public static void addDependencyDom(MavenDependency dependency, Element parentElement) { + Element element = parentElement.addElement(MavenDependencyConst.dependency); + Element gourpId = element.addElement(MavenDependencyConst.groupId); + Element artifactId = element.addElement(MavenDependencyConst.artifactId); + gourpId.setText(dependency.getGroupId()); + artifactId.setText(dependency.getArtifactId()); + if (dependency.getVersion() != null && !dependency.getVersion().isEmpty()) { + Element version = element.addElement(MavenDependencyConst.version); + version.setText(dependency.getVersion()); + } + } + + public static void saveDocument(Document document, File xmlFile) { + Writer osWrite = null;// 创建输出流 + try { + osWrite = new OutputStreamWriter(new FileOutputStream(xmlFile)); + + OutputFormat format = OutputFormat.createPrettyPrint(); // 获取输出的指定格式 + format.setEncoding("UTF-8");// 设置编码 ,确保解析的xml为UTF-8格式 + XMLWriter writer = new XMLWriter(osWrite, format);// XMLWriter + // 指定输出文件以及格式 + writer.write(document);// 把document写入xmlFile指定的文件(可以为被解析的文件或者新创建的文件) + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static String getTagValue(Element ele, String tagName) { + Element tagElement = (Element) ele.element(tagName); + if (tagElement == null) { + return null; + } + return tagElement.getText(); + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/MavenDependencyConst.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/MavenDependencyConst.java new file mode 100644 index 0000000..c569dac --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/MavenDependencyConst.java @@ -0,0 +1,34 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core; + +/** + * @Classname MavenDependencyConst + * @Description TODO + * @Date 2019/12/16 16:36 + * @Created by liu_bintr + * @Version 1.0 + */ +public class MavenDependencyConst { + public static String groupId = "groupId"; + public static String artifactId = "artifactId"; + public static String version = "version"; + public static String file = "file"; + public static String dependency = "dependency"; + public static String dependencies = "dependencies"; + + public static String modules = "modules"; +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/config/ServiceAutoConfiguration.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/config/ServiceAutoConfiguration.java new file mode 100644 index 0000000..3fba2b6 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/config/ServiceAutoConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core.config; + +import com.inspur.edp.jittojava.context.GenerateService; +import com.inspur.edp.jittojava.context.service.CommonService; +import com.inspur.edp.jittojava.core.CommonServiceImp; +import com.inspur.edp.jittojava.core.GenerateServiceImp; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Classname ServiceAutoConfiguration + * @Description TODO + * @Date 2019/7/30 13:43 + * @Created by liu_bintr + * @Version 1.0 + */ +@Configuration +public class ServiceAutoConfiguration { + + @Bean + public CommonService createCommonService() { + return new CommonServiceImp(); + } + + @Bean + public GenerateService createGenerateService() { + return new GenerateServiceImp(); + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java new file mode 100644 index 0000000..3e2e153 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java @@ -0,0 +1,566 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core.manager; + +import com.inspur.edp.caf.generator.compileunit.CompileUnitGenerator; +import com.inspur.edp.caf.generator.module.ModuleGenerator; +import com.inspur.edp.jittojava.context.JitContext; +import com.inspur.edp.jittojava.context.entity.JitCompilerConfigration; +import com.inspur.edp.jittojava.core.CommonServiceCore; +import com.inspur.edp.jittojava.core.JitCompilerHelper; +import com.inspur.edp.jittojava.core.JitUtils; +import com.inspur.edp.jittojava.core.persistence.RepositoryFactory; +import com.inspur.edp.jittojava.spi.AfterGeneratorAction; +import com.inspur.edp.jittojava.spi.JitAction; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; +import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenPackageRefs; +import com.inspur.edp.lcm.metadata.api.service.MdpkgService; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import com.inspur.edp.lcm.metadata.common.Utils; +import com.inspur.edp.lcm.metadata.core.GspProjectCoreService; +import com.inspur.edp.lcm.metadata.core.MavenUtilsCore; +import com.inspur.edp.lcm.metadata.core.MetadataCoreManager; +import com.inspur.edp.lcm.metadata.core.MetadataProjectCoreService; +import com.inspur.lcm.metadata.logging.LoggerDisruptorQueue; +import io.iec.edp.caf.boot.context.CAFContext; +import io.iec.edp.caf.common.environment.EnvironmentUtil; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import lombok.var; +import org.apache.commons.io.FileUtils; +import org.apache.maven.model.Model; +import org.apache.maven.model.Parent; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +@Slf4j +public class GeneratorManager { + MetadataProjectCoreService metadataProjectCoreService = new MetadataProjectCoreService(); + GspProjectCoreService gspProjectCoreService = new GspProjectCoreService(); + MavenUtilsCore mavenUtilsCore = new MavenUtilsCore(); + MetadataCoreManager metadataCoreManager = new MetadataCoreManager(); + FileServiceImp fileService = new FileServiceImp(); + CommonServiceCore commonServiceCore = new CommonServiceCore(); + MdpkgService mdpkgService = SpringBeanUtils.getBean(MdpkgService.class); + + protected List metadataList = new ArrayList<>(); + protected JitContext jitContext; + protected final String fixedPath = "src/main/java"; + protected boolean isModelExist; + protected boolean isOldProject = false; + protected Model model; + + protected String archetypePath; + protected String archetypeTarget; + protected String archetypeArtifactId; + protected String refModule; + + public void generate(String absolutePath, String mavenPath) throws Exception { + beforeGenerate(absolutePath); + try { + //构建生成上下文 + jitContext = buildJitContext(absolutePath); + //创建maven工程与模块 + createMavenProject(jitContext, mavenPath); + //生成源代码 + generateCode(jitContext); + //生成后事件 + afterGenerate(absolutePath); + } finally { + isOldProject = false; + } + } + + public void generateApi(String absolutePath, String mavenPath) throws Exception { + try { + //构建生成上下文 + jitContext = buildJitContext(absolutePath); + //创建maven工程与模块 + createMavenProject(jitContext, mavenPath); + //生成api代码 + generateApi(jitContext); + } finally { + } + } + + protected void generateApi(JitContext jitContext) { + //获取所有注册的Jit类型 + List compilerTypeList = JitCompilerHelper.getInstance().getCompilerTypeList(); + generateApiCode(compilerTypeList, jitContext); + } + + protected void generateCode(JitContext jitContext) { + //获取所有注册的Jit类型 + List compilerTypeList = JitCompilerHelper.getInstance().getCompilerTypeList(); + + generateApiCode(compilerTypeList, jitContext); + + generateCoreCode(compilerTypeList, jitContext); + } + + protected void generateApiCode(List compilerTypeList, JitContext jitContext) { + String loStr = "开始:生成API代码"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + //组织API生成的上下文 + generateApiCode(compilerTypeList); + //生成API代码 + jitContext.getApiModuleGenerator().initialize(); + jitContext.getApiModuleGenerator().generate(); + loStr = "完成:生成API代码"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + + protected void generateApiCode(List compilerTypeList) { + //组织api代码生成路径 + setPath("api"); + metadataList.forEach(item -> { + for (JitCompilerConfigration config : compilerTypeList) { + if (item.getHeader().getType().equals(config.getTypeCode())) { + // 获取元数据实体传给各元数据编译器 + if (item.getHeader().getFileName() == null) { + throw new IllegalArgumentException("路径" + item.getRelativePath() + "下有元数据FileName属性为空,请检查"); + } + GspMetadata metadata = metadataCoreManager.loadMetadata(item.getHeader().getFileName(), item.getRelativePath()); + if (metadata == null) { + String loStr = "没有拿到元数据"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + + jitContext.setMetadata(metadata); + + if (jitContext.getMetadataCache(metadata.getHeader().getId()) == null) { + jitContext.setMetadataCache(metadata.getHeader().getId(), metadata); + } + + JitAction jitAction = JitCompilerHelper.getInstance().getManager(item.getHeader().getType()); + if (jitAction != null) { + String loStr = "jitInfo " + jitAction.toString(); + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + if (jitAction != null) { + jitAction.generateApi(jitContext); + } + } + } + }); + } + + protected void generateCoreCode(List compilerTypeList, JitContext jitContext) { + String loStr = "开始:生成CORE代码"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + //组织CORE生成的上下文 + generateCoreCode(compilerTypeList); + //生成CORE代码 + jitContext.getCoreModuleGenerator().initialize(); + jitContext.getCoreModuleGenerator().generate(); + loStr = "完成:生成CORE代码"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + + protected void generateCoreCode(List compilerTypeList) { + //组织api代码生成路径 + setPath("core"); + metadataList.forEach(item -> { + for (JitCompilerConfigration config : compilerTypeList) { + if (item.getHeader().getType().equals(config.getTypeCode())) { + // 获取元数据实体传给各元数据编译器 + var metadata = metadataCoreManager.loadMetadata(item.getHeader().getFileName(), item.getRelativePath()); + jitContext.setMetadata(metadata); + if (jitContext.getMetadataCache(metadata.getHeader().getId()) == null) { + jitContext.setMetadataCache(metadata.getHeader().getId(), metadata); + } + JitAction jitAction = JitCompilerHelper.getInstance().getManager(item.getHeader().getType()); + if (jitAction != null) { + jitAction.generateCore(jitContext); + } + } + } + }); + } + + protected void afterGenerate(String absolutePath) { + String loStr = "开始:生成后事件"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + List metadataTypes = new ArrayList<>(); + List metadataList = metadataCoreManager.getMetadataList(absolutePath); + if (metadataList == null || metadataList.size() <= 0) { + return; + } + metadataTypes.add("CommonExtend"); + metadataList.forEach(item -> { + if (!metadataTypes.contains(item.getHeader().getType())) { + metadataTypes.add(item.getHeader().getType()); + } + }); + metadataTypes.forEach(type -> { + AfterGeneratorAction action = JitCompilerHelper.getInstance().getAfterActionManager(type); + if (action != null) { + action.afterGenerator(absolutePath); + } + }); + + ArrayList types = new ArrayList<>(); + types.add("api_src"); + types.add("metadata"); + metadataProjectCoreService.setSourceDataModifiedTime(absolutePath, types); + loStr = "完成:生成后事件"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + + protected void beforeGenerate(String absolutePath) { + SpringBeanUtils.getBean(MdpkgService.class).restore(absolutePath, false); + } + + protected void setPath(String flag) { + String javaProjectPath = fileService.getCombinePath(jitContext.getGspProjectpath(), Utils.getJavaProjectPath()); + + String artifactID; + String dir; + if (isOldProject) { + artifactID = getArtifactId(jitContext); + dir = artifactID + "-" + flag; + } else { + dir = flag; + artifactID = Utils.getMavenProName(); + } + String codePath = Paths.get(javaProjectPath).resolve(artifactID).resolve(dir).resolve(fixedPath).toString(); + String resPath = Paths.get(javaProjectPath).resolve(artifactID).resolve(dir).resolve(Utils.getResourcesPath()).toString(); + jitContext.setCodePath(codePath); + jitContext.setResourcePath(resPath); + } + + protected JitContext buildJitContext(String absolutePath) { + String loStr = "开始:构建生成上下文"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + //构建上下文内容,此处需要确定是否包含工程信息,元数据信息等 + var context = new JitContext(); + try { + context.setGspProjectpath(absolutePath); + Utils.setMetadataPath(absolutePath); + var gspProjectInfo = gspProjectCoreService.getGspProjectInfo(absolutePath); + var metadataProjectInfo = metadataProjectCoreService.getMetadataProjInfo(absolutePath); + context.setMetadataProjectInfo(metadataProjectInfo); + context.setGspProjectInfo(gspProjectInfo); + context.setApiModuleGenerator(new ModuleGenerator() { + @Override + protected ArrayList getCompileUnitGenrators() { + return null; + } + }); + context.setCoreModuleGenerator(new ModuleGenerator() { + @Override + protected ArrayList getCompileUnitGenrators() { + return null; + } + }); + MetadataCoreManager metadataCoreManager = new MetadataCoreManager(); + this.metadataList = metadataCoreManager.getMetadataList(absolutePath); +// MetadataDevCacheManager.setMetadataListInProjectCache(new File(absolutePath).getName(), this.metadataList); +// List refProjPaths = new ArrayList<>(); +// metadataProjectCoreService.getRefProjPaths(absolutePath, refProjPaths); +// for (String projPath : refProjPaths) { +// List metadataList = metadataCoreManager.getMetadataList(projPath); +// MetadataDevCacheManager.setMetadataListInProjectCache(new File(projPath).getName(), metadataList); +// } + } catch (Exception e) { + e.printStackTrace(); + } + loStr = "结束:构建生成上下文"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + return context; + } + + protected void createMavenProject(JitContext jitContext, String mavenPath) throws Exception { + String loStr = "开始:创建maven工程"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + + // 模板 + installArchetype(mavenPath); + + // 判断maven模板是否生成 + String javaProjectPath = fileService.getCombinePath(jitContext.getGspProjectpath(), Utils.getJavaProjectPath()); + isModelExist = isModelExist(javaProjectPath); + + // 生成模板工程的过程中如果同名工程存在,maven会报错. + if (!isModelExist) { + generateArchetype(javaProjectPath, mavenPath); + } else { + // 清理api和core + clearCode(javaProjectPath); + } + updateEdpParentVersion(javaProjectPath); + + updateModuleRefs(javaProjectPath, mavenPath); + + loStr = "完成:创建maven工程"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + + protected void updateModuleRefs(String javaProjectPath, String mavenPath) { + String refPomPath = javaProjectPath + File.separator + "code" + File.separator + refModule + File.separator + Utils.getPomFile(); + String metadataPath = javaProjectPath.substring(0, javaProjectPath.length() - 4) + "metadata"; + if (fileService.isFileExist(refPomPath)) { + MetadataProject metadataProject = metadataCoreManager.getMetadataProjInfo(metadataPath); + if (metadataProject.getMavenPackageRefs() != null && metadataProject.getMavenPackageRefs().size() > 0) { + final List generationMavenPackageRefs = getGenerationMavenPackageRefs(metadataProject, mavenPath); + RepositoryFactory.getInstance().getGenerateRepository().updateModuleRefs(refPomPath, generationMavenPackageRefs, true); + } + } + } + + protected List getGenerationMavenPackageRefs(MetadataProject metadataProject, String mavenPath) { + return metadataProject.getMavenPackageRefs(); + } + + protected void updateEdpParentVersion(String javaProjectPath) throws IOException { + String pomPath = javaProjectPath + File.separator + Utils.getMavenProName() + File.separator + Utils.getPomFile(); + if (fileService.isFileExist(pomPath)) { + String version = getEdpParentVersionInProject(pomPath); + String nVersion = Utils.getEdpParentVersion(); + if (checkVersion(version, nVersion)) { + updateEdpParentVersionInProject(pomPath, nVersion); + } + } + } + + protected void updateEdpParentVersionInProject(String path, String version) throws IOException { + FileOutputStream fileOutputStream = null; + try { + Parent parent = model.getParent(); + parent.setVersion(version); + model.setParent(parent); + fileOutputStream = new FileOutputStream(path); + MavenXpp3Writer mavenXpp3Writer = new MavenXpp3Writer(); + mavenXpp3Writer.write(fileOutputStream, model); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (!(null == fileOutputStream)) { + fileOutputStream.close(); + } + } + } + + protected String getEdpParentVersionInProject(String path) throws IOException { + FileInputStream fis = null; + try { + fis = new FileInputStream(path); + MavenXpp3Reader reader = new MavenXpp3Reader(); + model = reader.read(fis); + return model.getParent().getVersion(); + } catch (XmlPullParserException | IOException e) { + e.printStackTrace(); + } finally { + if (!(null == fis)) { + fis.close(); + } + } + return null; + } + + protected boolean checkVersion(String oldVersion, String newVersion) { + String[] minerOldVersion = oldVersion.split("\\."); + String[] minerNewVersion = newVersion.split("\\."); + for (int i = 0; i < minerNewVersion.length; i++) { + if (Integer.parseInt(minerNewVersion[i]) > Integer.parseInt(minerOldVersion[i])) { + return true; + } + } + return false; + } + + protected boolean isModelExist(String javaProjectPath) { + if (!fileService.isDirectoryExist(javaProjectPath)) { + fileService.createDirectory(javaProjectPath); + } + String relativeCodePath = commonServiceCore.getProjectPath(javaProjectPath); + if (relativeCodePath == null) { + isModelExist = false; + } else { + String absoluteCodePath = fileService.getCombinePath(jitContext.getGspProjectpath(), relativeCodePath); + List list = fileService.getAllFiles(absoluteCodePath); + for (File file : list) { + if (file.toString().endsWith(Utils.getPomFile())) { + return true; + } + } + } + return false; + } + + protected void clearCode(String javaProjectPath) throws IOException { + /** + * 由于路径过长,需要优化长度。考虑生成代码兼容问题。判断是否是老工程。老工程将代码继续生成在老工程下 + * 根据api module的名称即可 + */ + String relativeCodePath = commonServiceCore.getProjectPath(javaProjectPath); + String absoluteCodePath = fileService.getCombinePath(jitContext.getGspProjectpath(), relativeCodePath); + List allModuleName = fileService.getDirectorys(absoluteCodePath); + for (File module : allModuleName) { + if (module.getName().startsWith(jitContext.getGspProjectInfo().getAppCode().toLowerCase())) { + isOldProject = true; + } + if (module.getName().endsWith("api")) { + if (fileService.isDirectoryExist(module.toString() + File.separator + fixedPath)) { + fileService.deleteAllFilesUnderDirectory(module.toString() + File.separator + fixedPath); + clearProperties(jitContext, module.getName()); + } + } else if (module.getName().endsWith("core")) { + if (fileService.isDirectoryExist(module.toString() + File.separator + fixedPath)) { + fileService.deleteAllFilesUnderDirectory(module.toString() + File.separator + fixedPath); + clearProperties(jitContext, module.getName()); + } + } + } + } + + protected void installArchetype(String mavenPath) { + final String absoluteArchetypePath = fileService.getCombinePath(EnvironmentUtil.getServerRTPath(), archetypePath); + final String absoluteArchetypeTargetPath = fileService.getCombinePath(absoluteArchetypePath, archetypeTarget); + if (!fileService.isFileExist(absoluteArchetypeTargetPath)) { + //将程序运行目录中的maven模板安装到本地仓库 + String loStr = "开始:创建Maven模板"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + if (mavenUtilsCore.exeMavenCommand(absoluteArchetypePath, mavenPath, "install")) { + loStr = "完成:创建Maven模板"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } else { + throw new RuntimeException("Maven模板创建失败,请检查Maven配置"); + } + } + } + + private void clearProperties(JitContext context, String module) { + String factoriesFilePath = context.getGspProjectpath() + "/java/code/" + module + "/src/main/" + JitUtils.getSpringPeopertiesPath(); + if (fileService.isFileExist(factoriesFilePath)) { + fileService.fileUpdate(factoriesFilePath, "", false); + } + } + + protected void generateArchetype(String javaProjectPath, String mavenPath) throws IOException { + String loStr = "开始:生成maven模板"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + final String groupId = getGroupId(jitContext); + final String artifactId = getArtifactId(jitContext); + String mvnCommand = String.format("archetype:generate -DarchetypeCatalog=local -DarchetypeArtifactId=%s -DarchetypeGroupId=com.inspur.edp -DarchetypeVersion=0.1.3 -DgroupId=%s -DartifactId=%s -Dversion=0.1.0-SNAPSHOT -Dpackage=com.inspur -DinteractiveMode=false", archetypeArtifactId, groupId, artifactId); + if (mavenUtilsCore.exeMavenCommand(javaProjectPath, mavenPath, mvnCommand)) { + loStr = "完成:生成maven模板"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } else { + throw new RuntimeException("生成maven模板失败,请检查Maven配置"); + } + String javaProPath = javaProjectPath + File.separator + artifactId; + //重命名生成的目录 + renameDir(javaProjectPath, javaProPath); + } + + protected void renameDir(String basedir, String pro) throws IOException { + String final_proName = basedir + File.separator + Utils.getMavenProName(); + if (fileService.isDirectoryExist(final_proName)) { + String compPath = final_proName + File.separator + "comp"; + if (fileService.isDirectoryExist(compPath)) { + FileUtils.copyDirectory(new File(compPath), new File(pro + File.separator + "comp")); + } + try { + fileService.deleteAllFilesUnderDirectory(final_proName); + } catch (Exception e) { + + } finally { + if (fileService.isDirectoryExist(final_proName)) { + FileUtils.copyDirectory(new File(pro), new File(final_proName)); + fileService.deleteAllFilesUnderDirectory(pro); + } else { + boolean renameResult = fileService.renameDirectory(pro, final_proName); + if (!renameResult) { + throw new RuntimeException("重命名异常,原目录已存在"); + } + if (fileService.isFileExist(final_proName + File.separator + "pom.xml")) { + String loStr = "重命名目录成功!"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } else { + String loStr = "重命名目录失败!"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + } + } + } else { + boolean renameResult = fileService.renameDirectory(pro, final_proName); + if (!renameResult) { + throw new RuntimeException("重命名异常,原目录已存在"); + } + if (fileService.isFileExist(final_proName + File.separator + "pom.xml")) { + String loStr = "重命名目录成功!"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } else { + String loStr = "重命名目录失败!"; + log.info(loStr); + LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); + } + } + } + + protected String getArtifactId(JitContext jitContext) { + String appCode = jitContext.getGspProjectInfo().getAppCode().toLowerCase(); + String suCode = jitContext.getGspProjectInfo().getServiceUnitCode().toLowerCase(); + String boCode = jitContext.getGspProjectInfo().getMetadataProjectName().toLowerCase(); + if (boCode.startsWith("bo-")) { + boCode = boCode.substring(boCode.indexOf("-") + 1); + } + String artifactId = String.format("%s-%s-%s", appCode, suCode, boCode); + + return artifactId; + } + + protected String getGroupId(JitContext jitContext) { + String groupId; + String prepareGroupId = jitContext.getGspProjectInfo().getProjectNameSpace().toLowerCase(); + String firstGroupId = "com."; + if (!prepareGroupId.contains(".")) { + return firstGroupId + prepareGroupId; + } + String[] subGroupId = prepareGroupId.split("\\."); + groupId = firstGroupId + (subGroupId[0] + "." + subGroupId[1]).toLowerCase(); + return groupId; + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerFactory.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerFactory.java new file mode 100644 index 0000000..68d6fa8 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerFactory.java @@ -0,0 +1,36 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core.manager; + +import com.inspur.edp.lcm.metadata.api.entity.ProcessMode; +import com.inspur.edp.lcm.metadata.api.service.MetadataProjectService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; + +public class GeneratorManagerFactory { + public static GeneratorManager createGeneratorManager(String projPath) { + final ProcessMode processMode = SpringBeanUtils.getBean(MetadataProjectService.class).getProcessMode(projPath); + GeneratorManager generatorManager; + switch (processMode.toString()) { + case "interpretation": + generatorManager = new GeneratorManagerForInterpretation(); + break; + default: + generatorManager = new GeneratorManagerForGeneration(); + break; + } + return generatorManager; + } +} diff --git a/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/temp/ModuleGenerator.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForGeneration.java similarity index 59% rename from model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/temp/ModuleGenerator.java rename to model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForGeneration.java index ae417d2..210f460 100644 --- a/model/framework/generator-api/src/main/java/com/inspur/edp/jittojava/context/temp/ModuleGenerator.java +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForGeneration.java @@ -13,12 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.inspur.edp.jittojava.context.temp; +package com.inspur.edp.jittojava.core.manager; -/** - * The type ModuleGenerator - * - * @author: Jack Lee - */ -public class ModuleGenerator { +import com.inspur.edp.jittojava.core.JitUtils; + +public class GeneratorManagerForGeneration extends GeneratorManager { + public GeneratorManagerForGeneration() { + archetypePath = JitUtils.getArchetypePath(); + archetypeTarget = JitUtils.getArchetypeTarget(); + archetypeArtifactId = JitUtils.getArchetypeArtifactId(); + refModule = "api"; + } } diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForInterpretation.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForInterpretation.java new file mode 100644 index 0000000..94317fc --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManagerForInterpretation.java @@ -0,0 +1,117 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core.manager; + +import com.inspur.edp.jittojava.context.JitContext; +import com.inspur.edp.jittojava.core.JitUtils; +import com.inspur.edp.lcm.metadata.api.entity.MetadataPackageHeader; +import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; +import com.inspur.edp.lcm.metadata.api.entity.ProcessMode; +import com.inspur.edp.lcm.metadata.api.entity.ProjectHeader; +import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenPackageRefs; +import com.inspur.edp.lcm.metadata.common.Utils; +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class GeneratorManagerForInterpretation extends GeneratorManager { + + public GeneratorManagerForInterpretation() { + archetypePath = JitUtils.getCompArchetypePath(); + archetypeTarget = JitUtils.getCompArchetypeTarget(); + archetypeArtifactId = JitUtils.getCompArchetypeArtifactId(); + refModule = "comp"; + } + + @Override + public void generate(String absolutePath, String mavenPath) throws Exception { + try { + //构建生成上下文 + jitContext = buildJitContext(absolutePath); + //创建maven工程与模块 + createMavenProject(jitContext, mavenPath); + //生成后事件 + afterGenerate(absolutePath); + } finally { + } + } + + @Override + public void generateApi(String absolutePath, String mavenPath) { + } + + @Override + protected void beforeGenerate(String absolutePath) { + } + + @Override + protected void clearCode(String javaProjectPath) { + } + + @Override + protected void generateCode(JitContext jitContext) { + } + + @Override + protected List getGenerationMavenPackageRefs(MetadataProject metadataProject, String mavenPath) { + List generationMavenPackageRefsWithVersion = new ArrayList<>(); + if (metadataProject.getMavenPackageRefs() != null && metadataProject.getMavenPackageRefs().size() > 0) { + for (MavenPackageRefs mavenPackageRefs : metadataProject.getMavenPackageRefs()) { + // 如果有bo内引用,可以根据bo内引用确定元数据包名 + if (metadataProject.getProjectRefs() != null && metadataProject.getProjectRefs().size() > 0) { + final String[] split = mavenPackageRefs.getArtifactId().split("-"); + String projectName = split[2]; + String projectNameOrElse = "bo-" + split[2]; + final ProjectHeader projectHeader = metadataProject.getProjectRefs().stream().filter(ref -> ref.getProjectPath().endsWith(projectName) || ref.getProjectPath().endsWith(projectNameOrElse)).findFirst().orElse(null); + if (projectHeader != null) { + final MetadataPackageHeader metadataPackageHeader = metadataProject.getMetadataPackageRefs().stream().filter(ref -> ref.getName().equals(projectHeader.getName())).findFirst().orElse(null); + if (metadataPackageHeader != null) { + if (metadataPackageHeader.getProcessMode() == null || ProcessMode.GENERATION.equals(metadataPackageHeader.getProcessMode())) { + generationMavenPackageRefsWithVersion.add(mavenPackageRefs); + } + continue; + } + } + } + + // 如果不是bo内引用,则去maven文件夹下去找元数据包名 + File mavenPackagePath = Paths.get(mavenPath).resolve(mavenPackageRefs.getGroupId() + "-" + mavenPackageRefs.getArtifactId() + "-" + mavenPackageRefs.getVersion()).toFile(); + // 如果不存在,先install + if (!mavenPackagePath.exists()) { + try { + mdpkgService.installMdpkg(mavenPackageRefs.getGroupId(), mavenPackageRefs.getArtifactId(), mavenPackageRefs.getVersion(), jitContext.getGspProjectpath(), false); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (!mavenPackagePath.exists()) { + continue; + } + final File mdpkgFile = Arrays.stream(mavenPackagePath.listFiles()).filter(file -> file.getName().endsWith(Utils.getMetadataPackageExtension())).findFirst().orElse(null); + if (mdpkgFile != null) { + final MetadataPackageHeader metadataPackageHeader = metadataProject.getMetadataPackageRefs().stream().filter(header -> (header.getName() + Utils.getMetadataPackageExtension()).equals(mdpkgFile.getName())).findFirst().orElse(null); + if (metadataPackageHeader != null && (metadataPackageHeader.getProcessMode() == null || ProcessMode.GENERATION.equals(metadataPackageHeader.getProcessMode()))) { + generationMavenPackageRefsWithVersion.add(mavenPackageRefs); + } + } + } + } + return generationMavenPackageRefsWithVersion; + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java new file mode 100644 index 0000000..52d6f0c --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java @@ -0,0 +1,134 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core.persistence; + +import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenPackageRefs; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +public class GenerateRepository { + + public void updateModuleRefs(String pomPath, List mavenPackageRefs, boolean appendFlag) { + if (mavenPackageRefs == null || mavenPackageRefs.size() < 1) { + return; + } + + Model model = getModel(pomPath); + if (model == null) { + throw new RuntimeException("解析pom失败:" + pomPath); + } + + if (appendFlag && dependenciesContainsAll(model.getDependencies(), mavenPackageRefs)) { + return; + } + + List dependencies = appendFlag ? getDependencies(model.getDependencies(), mavenPackageRefs) : getDependencies(mavenPackageRefs); + model.setDependencies(dependencies); + saveModel(pomPath, model); + } + + private boolean dependenciesContainsAll(List dependencies, List mavenPackageRefs) { + if (mavenPackageRefs == null) { + return true; + } + for (MavenPackageRefs ref : mavenPackageRefs) { + boolean existFlag = false; + for (Dependency dependency : dependencies) { + if (dependency.getGroupId().equals(ref.getGroupId()) + && dependency.getArtifactId().equals(ref.getArtifactId()) + && dependency.getVersion().equals(ref.getVersion().substring(1))) { + existFlag = true; + break; + } + } + if (existFlag == false) { + return false; + } + } + return true; + } + + private List getDependencies(List mavenPackageRefs) { + ArrayList dependencies = new ArrayList<>(); + mavenPackageRefs.forEach(ref -> { + Dependency dependency = new Dependency(); + dependency.setGroupId(ref.getGroupId()); + dependency.setArtifactId(ref.getArtifactId()); + dependency.setVersion(ref.getVersion().substring(1)); + dependencies.add(dependency); + }); + return dependencies; + } + + private List getDependencies(List dependencies, List mavenPackageRefs) { + if (dependencies == null) { + dependencies = new ArrayList<>(); + } + List finalDependencies = dependencies; + mavenPackageRefs.forEach(ref -> { + int existInt = -1; + for (int i = 0; i < finalDependencies.size(); i++) { + if (ref.getArtifactId().equals(finalDependencies.get(i).getArtifactId()) + && ref.getGroupId().equals(finalDependencies.get(i).getGroupId())) { + existInt = i; + break; + } + } + if (existInt != -1) { + finalDependencies.get(existInt).setVersion(ref.getVersion().substring(1)); + } else { + Dependency dependency = new Dependency(); + dependency.setGroupId(ref.getGroupId()); + dependency.setArtifactId(ref.getArtifactId()); + dependency.setVersion(ref.getVersion().substring(1)); + finalDependencies.add(dependency); + } + }); + return finalDependencies; + } + + private Model getModel(String pomPath) { + try { + FileInputStream fis = new FileInputStream(pomPath); + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(fis); + fis.close(); + return model; + } catch (XmlPullParserException | IOException e) { + e.printStackTrace(); + } + return null; + } + + private void saveModel(String pomPath, Model model) { + MavenXpp3Writer writer = new MavenXpp3Writer(); + try { + FileOutputStream fos = new FileOutputStream(pomPath); + writer.write(fos, model); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/RepositoryFactory.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/RepositoryFactory.java new file mode 100644 index 0000000..305336b --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/RepositoryFactory.java @@ -0,0 +1,39 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.core.persistence; + +public class RepositoryFactory { + private RepositoryFactory() { + } + + private static RepositoryFactory instance; + + public static RepositoryFactory getInstance() { + if (instance == null) { + instance = new RepositoryFactory(); + } + return instance; + } + + private GenerateRepository generateRepository; + + public GenerateRepository getGenerateRepository() { + if (generateRepository == null) { + generateRepository = new GenerateRepository(); + } + return generateRepository; + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/AfterGenerator.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/AfterGenerator.java new file mode 100644 index 0000000..0d903c4 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/AfterGenerator.java @@ -0,0 +1,70 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.temp; + +import com.inspur.edp.jittojava.context.entity.MavenDependency; +import com.inspur.edp.jittojava.core.GenerateServiceCore; +import com.inspur.edp.jittojava.spi.AfterGeneratorAction; +import com.inspur.edp.lcm.metadata.common.FileServiceImp; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.ArrayList; + +/** + * @Classname AfterGenerator + * @Description TODO + * @Date 2019/12/17 16:02 + * @Created by liu_bintr + * @Version 1.0 + */ +public class AfterGenerator implements AfterGeneratorAction { + + GenerateServiceCore generateService = new GenerateServiceCore(); + Utils utils = new Utils(); + + @Override + public void afterGenerator(String projPath) { + addProjectDependency(projPath, null, utils.getDefaultDependency()); + FileServiceImp fileService = new FileServiceImp(); + String runtimePath = Paths.get(projPath).resolve("java/code/runtime").toString(); + if (fileService.isDirectoryExist(runtimePath)) { + try { + fileService.deleteAllFilesUnderDirectory(runtimePath); + } catch (IOException e) { + throw new RuntimeException(e); + } + generateService.removeRuntimeModule(projPath); + } + generateService.modifyPom(projPath, utils.getExtendDependency()); + generateService.modifyPom(projPath, utils.getSgfExtendDependency()); + } + + public void addProjectDependency(String projectPath, String currentJarPath, + ArrayList dependencyArrayList) { + String javaPath = getJavaProjPath(projectPath); + // 安装jar包到maven仓库 + Utils.installPackage(javaPath, currentJarPath, dependencyArrayList); + // 修改pom文件 + generateService.modifyPom(projectPath, dependencyArrayList); + } + + private String getJavaProjPath(String projPath) { + String javaPath = Paths.get(projPath).resolve("java").toString(); + String javaProjPath = Paths.get(javaPath).resolve(com.inspur.edp.lcm.metadata.common.Utils.getMavenProName()).toString(); + + return javaProjPath; + } +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/MavenDependencyConst.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/MavenDependencyConst.java new file mode 100644 index 0000000..8e6d308 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/MavenDependencyConst.java @@ -0,0 +1,34 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.temp; + +/** + * @Classname MavenDependencyConst + * @Description TODO + * @Date 2019/12/16 16:36 + * @Created by liu_bintr + * @Version 1.0 + */ +public class MavenDependencyConst { + public static String groupId = "groupId"; + public static String artifactId = "artifactId"; + public static String version = "version"; + public static String file = "file"; + public static String dependency = "dependency"; + public static String dependencies = "dependencies"; + + public static String modules = "modules"; +} diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java new file mode 100644 index 0000000..bbd5197 --- /dev/null +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java @@ -0,0 +1,141 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.temp; + +import com.inspur.edp.jittojava.context.entity.MavenDependency; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +/** + * @Classname Utils + * @Description TODO + * @Date 2019/12/17 16:05 + * @Created by liu_bintr + * @Version 1.0 + */ +public class Utils { + public static void installPackage(String projectPath, String currentJarPath, + ArrayList dependencyArrayList) { + // 组装命令 + String command = String.format("cmd /c cd %s", projectPath); + Process process = null; + if (currentJarPath != null && !currentJarPath.isEmpty()) { + String addDependencyCommand = "mvn install:install-file -DgroupId=%1$s " + + "-DartifactId=%2$s -Dversion=%3$s -Dpackaging=jar -Dfile=%4$s"; + for (MavenDependency dependency : dependencyArrayList) { + String addCommand = String.format(addDependencyCommand, dependency.getGroupId(), + dependency.getArtifactId(), dependency.getVersion(), getPathString(String.format(currentJarPath + "\\%1$s", + dependency.getFile()))); + command = command.concat(" && " + addCommand); + } + } + excecuteCommand(process, command, "添加bef相关jar包"); + } + + public static void excecuteCommand(Process process, String command, String funcMessage) { + // 执行命令 + try { + process = Runtime.getRuntime().exec(command); + log(funcMessage + "开始..."); + BufferedReader reader = new BufferedReader(new InputStreamReader( + process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + log(line); + } + process.waitFor(); + if (process.exitValue() == 1) { + log(funcMessage + "失败"); + } + log(funcMessage + "完成"); + process.destroy(); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } + + public static void log(String message) { + Boolean showLog = true; + if (showLog) { + System.out.println(message); + } + } + + public static String getAbsolutePathString(String path) { + return new File(path).getAbsolutePath(); + } + + public ArrayList getExtendDependency() { + String extendDependencyPath = + this.getClass().getResource("/BefExtendMavenDependency.xml").toString(); + return readInternalDependency(extendDependencyPath); + } + + private ArrayList readInternalDependency(String defaultDependencyPath) { + ArrayList result = new ArrayList<>(); + Document doc = readDocument(defaultDependencyPath); + Element rootElement = doc.getRootElement(); + List list = rootElement.elements(); + for (int i = 0; i < list.size(); i++) { + Element ele = (Element) list.get(i); + result.add(new MavenDependency(getTagValue(ele, MavenDependencyConst.groupId), getTagValue(ele, MavenDependencyConst.artifactId), + getTagValue(ele, MavenDependencyConst.version), getTagValue(ele, MavenDependencyConst.file))); + } + return result; + } + + private Document readDocument(String filePath) { + SAXReader sr = new SAXReader(); + try { + return sr.read(filePath); + } catch (DocumentException e) { + throw new RuntimeException("无效路径" + filePath); + } + } + + private String getTagValue(Element ele, String tagName) { + Element tagElement = (Element) ele.element(tagName); + if (tagElement == null) { + return null; + } + return tagElement.getText(); + } + + private static String getPathString(String path) { + return getAbsolutePathString(path); + } + + public ArrayList getDefaultDependency() { + String defaultDependencyPath = + this.getClass().getResource("/BefProjectMavenDependency.xml").toString(); + return readInternalDependency(defaultDependencyPath); + } + + public ArrayList getSgfExtendDependency() { + String extendDependencyPath = + this.getClass().getResource("/SgfExtendMavenDependency.xml").toString(); + return readInternalDependency(extendDependencyPath); + } + +} diff --git a/model/framework/generator-webapi/pom.xml b/model/framework/generator-webapi/pom.xml new file mode 100644 index 0000000..1153e91 --- /dev/null +++ b/model/framework/generator-webapi/pom.xml @@ -0,0 +1,30 @@ + + + + ubml-model-framework + org.openatom.ubml + 0.9.0-SNAPSHOT + + 4.0.0 + ubml-model-framework-generator-webapi ${project.version} + + + org.openatom.ubml + ubml-model-framework-generator-api + ${project.version} + + + io.iec.edp + caf-boot-starter-rest-server + + + ubml-model-framework-generator-webapi + + + 8 + 8 + + + \ No newline at end of file diff --git a/model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/GenerateController.java b/model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/GenerateController.java new file mode 100644 index 0000000..a4872eb --- /dev/null +++ b/model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/GenerateController.java @@ -0,0 +1,51 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.webapi; + +import com.inspur.edp.jittojava.context.GenerateService; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import lombok.extern.slf4j.Slf4j; + +/** + * @Classname GenerateServiceWebApiImp + * @Description TODO + * @Date 2019/12/16 17:21 + * @Created by liu_bintr + * @Version 1.0 + */ +@Slf4j +@Path("/") +@Produces(MediaType.APPLICATION_JSON) +public class GenerateController { + + GenerateService generateService = SpringBeanUtils.getBean(GenerateService.class); + + @POST + public void generate(@QueryParam(value = "path") String path) throws Exception { + generateService.generate(path); + } + + @POST + @Path("/generateapi") + public void generateApi(@QueryParam(value = "path") String path) throws Exception { + generateService.generateApi(path); + } +} diff --git a/model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/config/Configuration.java b/model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/config/Configuration.java new file mode 100644 index 0000000..665dda3 --- /dev/null +++ b/model/framework/generator-webapi/src/main/java/com/inspur/edp/jittojava/webapi/config/Configuration.java @@ -0,0 +1,38 @@ +/* + * Copyright © OpenAtom Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.inspur.edp.jittojava.webapi.config; + +import com.inspur.edp.jittojava.webapi.GenerateController; +import io.iec.edp.caf.rest.RESTEndpoint; +import org.springframework.context.annotation.Bean; + +/** + * Classname Configuration Description TODO Date 2019/12/17 10:19 + * + * @author zhongchq + * @version 1.0 + */ +public class Configuration { + + @Bean + public RESTEndpoint generateEndpoint() { + return new RESTEndpoint( + "/dev/main/v1.0/generator", + new GenerateController() + ); + } + +} diff --git a/model/framework/pom.xml b/model/framework/pom.xml index 1a25352..48eebed 100644 --- a/model/framework/pom.xml +++ b/model/framework/pom.xml @@ -25,6 +25,7 @@ generator-api generator-spi generator-core + generator-webapi @@ -39,6 +40,7 @@ 0.3.2 0.3.8 0.3.2 + 0.1.0-SNAPSHOT 0.1.4 0.1.25 @@ -103,6 +105,11 @@ caf-rpc-api ${caf-rpc-api.version} + + com.inspur.edp + caf-generator + ${caf-generator.version} + com.inspur.edp -- Gitee From 2fa5935a85fee106031cb2232c8019ba5cf1a8db Mon Sep 17 00:00:00 2001 From: Q-Lee Date: Tue, 11 May 2021 17:31:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dgenerator-xx=E6=A8=A1=E5=9D=97=E4=B8=8B=E6=89=80?= =?UTF-8?q?=E6=9C=89checkstyle=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../initializer/ExternalApiInitializer.java | 2 +- .../provider/ExternalApiMetadataBuilder.java | 6 ++-- .../metadata/common/MetadataDtoConverter.java | 6 ++-- .../edp/jittojava/core/CommonServiceCore.java | 1 - .../edp/jittojava/core/JitCompilerHelper.java | 4 +-- .../core/manager/GeneratorManager.java | 30 +++++++++---------- .../core/persistence/GenerateRepository.java | 2 +- .../com/inspur/edp/jittojava/temp/Utils.java | 3 +- .../MetadataRTServerServiceImpl.java | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java index e2fac1e..899c6d2 100644 --- a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java +++ b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/initializer/ExternalApiInitializer.java @@ -38,7 +38,7 @@ public class ExternalApiInitializer implements MetadataContentManager { eapi.setName(metadata.getHeader().getName()); eapi.setVersion("1.0"); eapi.getService().setId(UUID.randomUUID().toString()); - eapi.setBusinessObject(metadata.getHeader().getBizobjectID()); + eapi.setBusinessObject(metadata.getHeader().getBizObjectId()); //TODO:后续添加SU/APP/RouteURL信息 metadata.setContent(eapi); } diff --git a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java index 25a18a6..aba1d67 100644 --- a/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java +++ b/model/externalapi/devtime-core/src/main/java/org/openatom/ubml/model/externalapi/devtime/core/provider/ExternalApiMetadataBuilder.java @@ -99,7 +99,7 @@ public class ExternalApiMetadataBuilder { eApi.setId(eapiMetadata.getHeader().getId()); eApi.setCode(eapiMetadata.getHeader().getCode()); eApi.setName(eapiMetadata.getHeader().getName()); - eApi.setBusinessObject(eapiMetadata.getHeader().getBizobjectID()); + eApi.setBusinessObject(eapiMetadata.getHeader().getBizObjectId()); //TODO:set app&su eApi.setApplication(null); eApi.setMicroServiceUnit(null); @@ -179,11 +179,11 @@ public class ExternalApiMetadataBuilder { metadata.getHeader().setCode(vo.getHeader().getCode()); metadata.getHeader().setName(vo.getHeader().getName()); metadata.getHeader().setExtendable(vo.getHeader().isExtendable()); - if (StringUtils.isBlank(vo.getHeader().getBizobjectID())) { + if (StringUtils.isBlank(vo.getHeader().getBizObjectId())) { throw new RuntimeException( String.format("VO元数据【%s(ID:%s)】的业务对象不能为空", vo.getHeader().getCode(), vo.getHeader().getId())); } - metadata.getHeader().setBizobjectID(vo.getHeader().getBizobjectID()); + metadata.getHeader().setBizObjectId(vo.getHeader().getBizObjectId()); metadata.getHeader().setType(Constants.EXTERNAL_API_METADATA_TYPE); metadata.getHeader().setFileName(vo.getHeader().getCode() + EAPI_SUFFIX_NAME); metadata.setRelativePath(getEapiRelativePath(path)); diff --git a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java index c089ef6..3afbc00 100644 --- a/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java +++ b/model/framework/common/src/main/java/com/inspur/edp/lcm/metadata/common/MetadataDtoConverter.java @@ -49,7 +49,7 @@ public class MetadataDtoConverter { return null; } MetadataDto metadataDto = new MetadataDto(); - metadataDto.setBizobjectID(metadata.getHeader().getBizobjectID()); + metadataDto.setBizobjectID(metadata.getHeader().getBizObjectId()); metadataDto.setType(metadata.getHeader().getType()); metadataDto.setId(metadata.getHeader().getId()); metadataDto.setCode(metadata.getHeader().getCode()); @@ -59,7 +59,7 @@ public class MetadataDtoConverter { metadataDto.setLanguage(metadata.getHeader().getLanguage()); metadataDto.setRelativePath(metadata.getRelativePath()); //GspMetadata没有此属性 - metadataDto.setIsTranslating(metadata.getHeader().isTranslating()); + metadataDto.setTranslating(metadata.getHeader().getTranslating()); metadataDto.setExtendProperty(metadata.getExtendProperty()); metadataDto.setExtendable(metadata.getHeader().isExtendable()); metadataDto.setExtented(metadata.isExtended()); @@ -125,7 +125,7 @@ public class MetadataDtoConverter { GspMetadata metadata = new GspMetadata(); metadata.setHeader(new MetadataHeader()); metadata.getHeader().setId(metadataDto.getId()); - metadata.getHeader().setBizobjectID(metadataDto.getBizobjectID()); + metadata.getHeader().setBizObjectId(metadataDto.getBizobjectID()); metadata.getHeader().setNameSpace(metadataDto.getNameSpace()); metadata.getHeader().setType(metadataDto.getType()); metadata.getHeader().setFileName(metadataDto.getFileName()); diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java index ed4cb09..b80e8e1 100644 --- a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/CommonServiceCore.java @@ -89,7 +89,6 @@ public class CommonServiceCore implements CommonService { // targetpath.substring("java"); // list.add(targetpath); // } -// System.out.println("正在访问:" + dir + " 目录"); // return FileVisitResult.CONTINUE; // } }); diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java index fbf85c8..46f34eb 100644 --- a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/JitCompilerHelper.java @@ -53,7 +53,7 @@ public class JitCompilerHelper extends JitCompilerConfigLoader { public JitAction getManager(String typeName) { JitAction manager = null; JitCompilerConfigration data = getCompilerConfigurations(typeName); - if (data != null && data.getEnable() == true) { + if (data != null && data.getEnable()) { Class cls = null; if (data.getBeforeCompiler() != null) { try { @@ -70,7 +70,7 @@ public class JitCompilerHelper extends JitCompilerConfigLoader { public AfterGeneratorAction getAfterActionManager(String typeName) { AfterGeneratorAction manager = null; JitCompilerConfigration data = getCompilerConfigurations(typeName); - if (data != null && data.getEnable() == true) { + if (data != null && data.getEnable()) { Class cls = null; if (data.getAfterCompiler() != null) { try { diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java index 3e2e153..d32b9c2 100644 --- a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/manager/GeneratorManager.java @@ -26,6 +26,7 @@ import com.inspur.edp.jittojava.core.persistence.RepositoryFactory; import com.inspur.edp.jittojava.spi.AfterGeneratorAction; import com.inspur.edp.jittojava.spi.JitAction; import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.GspProject; import com.inspur.edp.lcm.metadata.api.entity.MetadataProject; import com.inspur.edp.lcm.metadata.api.mvnEntity.MavenPackageRefs; import com.inspur.edp.lcm.metadata.api.service.MdpkgService; @@ -47,7 +48,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import lombok.extern.slf4j.Slf4j; -import lombok.var; import org.apache.commons.io.FileUtils; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; @@ -192,7 +192,7 @@ public class GeneratorManager { for (JitCompilerConfigration config : compilerTypeList) { if (item.getHeader().getType().equals(config.getTypeCode())) { // 获取元数据实体传给各元数据编译器 - var metadata = metadataCoreManager.loadMetadata(item.getHeader().getFileName(), item.getRelativePath()); + GspMetadata metadata = metadataCoreManager.loadMetadata(item.getHeader().getFileName(), item.getRelativePath()); jitContext.setMetadata(metadata); if (jitContext.getMetadataCache(metadata.getHeader().getId()) == null) { jitContext.setMetadataCache(metadata.getHeader().getId(), metadata); @@ -264,12 +264,12 @@ public class GeneratorManager { log.info(loStr); LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); //构建上下文内容,此处需要确定是否包含工程信息,元数据信息等 - var context = new JitContext(); + JitContext context = new JitContext(); try { context.setGspProjectpath(absolutePath); Utils.setMetadataPath(absolutePath); - var gspProjectInfo = gspProjectCoreService.getGspProjectInfo(absolutePath); - var metadataProjectInfo = metadataProjectCoreService.getMetadataProjInfo(absolutePath); + GspProject gspProjectInfo = gspProjectCoreService.getGspProjectInfo(absolutePath); + MetadataProject metadataProjectInfo = metadataProjectCoreService.getMetadataProjInfo(absolutePath); context.setMetadataProjectInfo(metadataProjectInfo); context.setGspProjectInfo(gspProjectInfo); context.setApiModuleGenerator(new ModuleGenerator() { @@ -493,26 +493,26 @@ public class GeneratorManager { } protected void renameDir(String basedir, String pro) throws IOException { - String final_proName = basedir + File.separator + Utils.getMavenProName(); - if (fileService.isDirectoryExist(final_proName)) { - String compPath = final_proName + File.separator + "comp"; + String finalProname = basedir + File.separator + Utils.getMavenProName(); + if (fileService.isDirectoryExist(finalProname)) { + String compPath = finalProname + File.separator + "comp"; if (fileService.isDirectoryExist(compPath)) { FileUtils.copyDirectory(new File(compPath), new File(pro + File.separator + "comp")); } try { - fileService.deleteAllFilesUnderDirectory(final_proName); + fileService.deleteAllFilesUnderDirectory(finalProname); } catch (Exception e) { } finally { - if (fileService.isDirectoryExist(final_proName)) { - FileUtils.copyDirectory(new File(pro), new File(final_proName)); + if (fileService.isDirectoryExist(finalProname)) { + FileUtils.copyDirectory(new File(pro), new File(finalProname)); fileService.deleteAllFilesUnderDirectory(pro); } else { - boolean renameResult = fileService.renameDirectory(pro, final_proName); + boolean renameResult = fileService.renameDirectory(pro, finalProname); if (!renameResult) { throw new RuntimeException("重命名异常,原目录已存在"); } - if (fileService.isFileExist(final_proName + File.separator + "pom.xml")) { + if (fileService.isFileExist(finalProname + File.separator + "pom.xml")) { String loStr = "重命名目录成功!"; log.info(loStr); LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); @@ -524,11 +524,11 @@ public class GeneratorManager { } } } else { - boolean renameResult = fileService.renameDirectory(pro, final_proName); + boolean renameResult = fileService.renameDirectory(pro, finalProname); if (!renameResult) { throw new RuntimeException("重命名异常,原目录已存在"); } - if (fileService.isFileExist(final_proName + File.separator + "pom.xml")) { + if (fileService.isFileExist(finalProname + File.separator + "pom.xml")) { String loStr = "重命名目录成功!"; log.info(loStr); LoggerDisruptorQueue.publishEvent("[INFO] " + loStr, CAFContext.current.getUserId()); diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java index 52d6f0c..a7dd851 100644 --- a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/core/persistence/GenerateRepository.java @@ -62,7 +62,7 @@ public class GenerateRepository { break; } } - if (existFlag == false) { + if (!existFlag) { return false; } } diff --git a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java index bbd5197..6fb5ba3 100644 --- a/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java +++ b/model/framework/generator-core/src/main/java/com/inspur/edp/jittojava/temp/Utils.java @@ -78,7 +78,8 @@ public class Utils { public static void log(String message) { Boolean showLog = true; if (showLog) { - System.out.println(message); + //todo +// message } } diff --git a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java index b2989c5..749c351 100644 --- a/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java +++ b/model/framework/runtime-core/src/main/java/com/inspur/edp/lcm/metadata/servermanager/MetadataRTServerServiceImpl.java @@ -502,7 +502,7 @@ public class MetadataRTServerServiceImpl implements MetadataRTServerService { // 根据BizobjectID进行过滤 if (filter.getBizobjectId() != null && filter.getBizobjectId().size() > 0) { for (String eachBizobjectId : filter.getBizobjectId()) { - metadataList = metadataList.stream().filter(item -> item.getMetadata().getHeader().getBizobjectID().equals(eachBizobjectId)).collect(Collectors.toList()); + metadataList = metadataList.stream().filter(item -> item.getMetadata().getHeader().getBizObjectId().equals(eachBizobjectId)).collect(Collectors.toList()); } } if (filter.getCode() != null) { -- Gitee