From 2eefc5bacf788e9dcdfa7e4a16878aef2bbc6816 Mon Sep 17 00:00:00 2001 From: hanll02 Date: Thu, 8 Sep 2022 19:41:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=86=E5=9B=BE=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=B1=82=E6=8F=90=E4=BE=9Bmanager=E4=BB=A5=E5=8F=8Aweapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 144 ++++ view-object-manager/pom.xml | 150 ++++ .../main/resources/META-INF/spring.factories | 1 + view-object-webapi/pom.xml | 76 ++ .../BffMetadataRtWebApiServiceAutoConfig.java | 19 + .../BffRtWebApiServiceAutoConfig.java | 21 + .../rtwebapi/VMCodeGenController.java | 164 ++++ .../rtwebapi/VMMetadataController.java | 161 ++++ .../webapi/BffWebApiServiceAutoConfig.java | 21 + .../webapi/BffWebApiServiceConfig.java | 21 + .../viewmodel/webapi/VMCodeGenController.java | 407 +++++++++ .../viewmodel/webapi/ViewModelController.java | 794 ++++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + 13 files changed, 1980 insertions(+) create mode 100644 pom.xml create mode 100644 view-object-manager/pom.xml create mode 100644 view-object-manager/src/main/resources/META-INF/spring.factories create mode 100644 view-object-webapi/pom.xml create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffMetadataRtWebApiServiceAutoConfig.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffRtWebApiServiceAutoConfig.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMCodeGenController.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMMetadataController.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceAutoConfig.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceConfig.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/VMCodeGenController.java create mode 100644 view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/ViewModelController.java create mode 100644 view-object-webapi/src/main/resources/META-INF/spring.factories diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..758a066 --- /dev/null +++ b/pom.xml @@ -0,0 +1,144 @@ + + + + + + io.iec.edp + caf-boot-parent + 0.3.6 + + + 4.0.0 + + com.inspur.edp + viewObject-model + pom + 0.1.1 + + + view-object-manager + view-object-webapi + + + 0.2.23 + 0.1.16 + 0.2.16 + 0.1.5 + 0.1.28 + 0.1.28 + 0.1.24 + 0.1.15 + + + + + com.inspur.edp + cef-designtime-api + ${cef.designtime.version} + + + com.inspur.edp + das-commonmodel + ${das.commonmodel.designtime.version} + + + com.inspur.edp + bef-bizentity + ${bef.designtime.version} + + + com.inspur.edp + caf-cef-rt-api + ${caf.cef.schema.version} + + + com.inspur.edp + caf-cef-rt-spi + ${caf.cef.schema.version} + + + com.inspur.edp + caf-cef-schema + ${caf.cef.schema.version} + + + com.inspur.edp + caf-cef-schema-base + ${caf.cef.schema.version} + + + com.inspur.edp + lcm-metadata-api + ${lcm.metadata.version} + + + com.inspur.edp + lcm-metadata-spi + ${lcm.metadata.spi.version} + + + com.inspur.edp + metadata-to-java-core + ${lcm.metadata.version} + + + com.inspur.edp + metadata-to-java-context + 0.1.4 + + + com.inspur.edp + metadata-rtcustomization-spi + ${metadata.rtcustomization.version} + + + com.inspur.edp + metadata-rtcustomization-api + 0.1.28 + + + com.inspur.edp + metadata-deploy-api + ${metadata.deploy.version} + + + + + + + gsp-snapshots-repo + https://repos.iec.io/repository/maven-gsp-snapshots/ + + + gsp-releases-repo + https://repos.iec.io/repository/maven-gsp-releases/ + + + + + gsp-releases-repo + https://repos.iec.io/repository/maven-gsp-releases/ + + + gsp-snapshots-repo + https://repos.iec.io/repository/maven-gsp-snapshots/ + + + diff --git a/view-object-manager/pom.xml b/view-object-manager/pom.xml new file mode 100644 index 0000000..8ba01fc --- /dev/null +++ b/view-object-manager/pom.xml @@ -0,0 +1,150 @@ + + + + + 4.0.0 + + + com.inspur.edp + viewObject-model + 0.1.1 + + + + view-object-manager + 0.1.1 + + + + com.inspur.edp + das-commonmodel + + + com.inspur.edp + lcm-metadata-api + + + com.inspur.edp + caf-cef-rt-api + + + com.inspur.edp + caf-cef-rt-spi + + + com.inspur.edp + lcm-metadata-spi + + + com.inspur.edp + metadata-rtcustomization-api + 0.1.28 + + + com.inspur.edp + metadata-deploy-api + + + com.inspur.edp + lcm-logging-service + 0.1.4 + + + com.inspur.edp + bef-component + 0.1.0 + + + io.iec.edp + caf-boot-commons-json + + + com.inspur.edp + common-component-api + 0.1.40 + + + com.inspur.edp + metadata-businesstype-api + 0.1.2 + compile + + + io.iec.edp + caf-rpc-api + 0.3.4 + + + com.inspur.edp + cef-variable-dtgenerator + 0.1.0-SNAPSHOT + + + com.inspur.edp + lcm-fs-api + 0.1.0 + compile + + + com.inspur.edp + caf-cef-dt-spi + 0.1.7 + + + com.inspur.edp + metadata-rtcustomization-server-api + 0.1.23 + compile + + + com.inspur.edp + bff-engine-core + 0.1.4 + + + com.inspur.edp + metadata-rtcustomization-spi + + + com.inspur.edp + task-api + 0.3.27 + + + com.inspur.edp + wf-runtime-api + 0.3.23 + + + com.inspur.edp + view-object-model + ${project.version} + compile + + + com.inspur.edp.cef.designtime.core + com.inspur.edp.cef.designtime.core + 0.1.1 + system + ${project.basedir}/../ref/com.inspur.edp.cef.designtime.core.jar + + + + diff --git a/view-object-manager/src/main/resources/META-INF/spring.factories b/view-object-manager/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..f5570a8 --- /dev/null +++ b/view-object-manager/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.inspur.edp.formserver.vmmanager.extendinfo.config.GspVoExtendInfoConfig,com.inspur.edp.formserver.vmmanager.vmdtconsistencycheckevent.VmDtConsistencyCheckConf,com.inspur.edp.formserver.vmmanager.accessory.Configuration,com.inspur.edp.formserver.vmmanager.commonstructure.VMEntitySchemaConfiguration,com.inspur.edp.formserver.vmmanager.config.VMManagerConfig,com.inspur.edp.formserver.vmmanager.pushchangesetevent.PushVmChangeSetConf,com.inspur.edp.formserver.vmmanager.config.MdPkgDeployConfig,com.inspur.edp.formserver.voextendinfo.server.core.config.GspVoExtendInfoRpcConfig diff --git a/view-object-webapi/pom.xml b/view-object-webapi/pom.xml new file mode 100644 index 0000000..61c138c --- /dev/null +++ b/view-object-webapi/pom.xml @@ -0,0 +1,76 @@ + + + + + 4.0.0 + + + com.inspur.edp + viewObject-model + 0.1.1 + + + view-object-webapi + 0.1.1 + + + + jakarta.ws.rs + jakarta.ws.rs-api + 2.1.5 + + + jakarta.ws.rs + jakarta.ws.rs-api + + + com.inspur.edp + view-object-model + ${project.version} + + + com.inspur.edp + view-object-manager + ${project.version} + + + com.inspur.edp + bef-bizentity + + + com.inspur.edp + lcm-metadata-api + + + com.inspur.edp + metadata-businesstype-api + 0.1.2 + compile + + + com.inspur.edp + web-help-metadata + 0.1.9 + compile + + + + + diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffMetadataRtWebApiServiceAutoConfig.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffMetadataRtWebApiServiceAutoConfig.java new file mode 100644 index 0000000..6d792e7 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffMetadataRtWebApiServiceAutoConfig.java @@ -0,0 +1,19 @@ +package com.inspur.edp.formserver.viewmodel.rtwebapi; + +import io.iec.edp.caf.rest.RESTEndpoint; +import org.springframework.context.annotation.Bean; + +public class BffMetadataRtWebApiServiceAutoConfig { + @Bean + public VMMetadataController getRtBffMetadataRtWebApi() { + return new VMMetadataController(); + } + + @Bean + public RESTEndpoint getBffRtMetadataRtWebApiEndpoint(VMMetadataController genService){ + return new RESTEndpoint( + "/runtime/lcm/v1.0/bff/metadata", + genService + ); + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffRtWebApiServiceAutoConfig.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffRtWebApiServiceAutoConfig.java new file mode 100644 index 0000000..1823721 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/BffRtWebApiServiceAutoConfig.java @@ -0,0 +1,21 @@ +package com.inspur.edp.formserver.viewmodel.rtwebapi; + +import io.iec.edp.caf.rest.RESTEndpoint; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class BffRtWebApiServiceAutoConfig { + @Bean + public VMCodeGenController getRtBffWebApi() { + return new VMCodeGenController(); + } + + @Bean + public RESTEndpoint getBffRtWebApiEndpoint(VMCodeGenController genService){ + return new RESTEndpoint( + "/runtime/lcm/v1.0/bff", + genService + ); + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMCodeGenController.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMCodeGenController.java new file mode 100644 index 0000000..6b30a13 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMCodeGenController.java @@ -0,0 +1,164 @@ +package com.inspur.edp.formserver.viewmodel.rtwebapi; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.bef.bizentity.GspBusinessEntity; +import com.inspur.edp.das.commonmodel.util.HandleAssemblyNameUtil; +import com.inspur.edp.cef.designtime.api.dtconsistencycheck.ConsistencyCheckEventMessage; +import com.inspur.edp.formserver.viewmodel.GspViewModel; +import com.inspur.edp.formserver.viewmodel.common.ConvertUtils; +import com.inspur.edp.formserver.viewmodel.common.ValueHelpConfig; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.actioneventargs.ChangingVoActionCodeEventArgs; +import com.inspur.edp.formserver.vmmanager.helpconfig.HelpConfigFilterSortHandler; +import com.inspur.edp.formserver.vmmanager.util.CheckInfoUtil; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.actioneventargs.*; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.entityeventargs.*; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.fieldeventargs.*; +import com.inspur.edp.formserver.vmmanager.validate.model.ViewModelChecker; +import com.inspur.edp.formserver.vmmanager.voguide.VoGuideUtil; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.metadata.businesstype.api.MdBizTypeMappingService; +import java.util.HashMap; + +import com.inspur.edp.formserver.vmmanager.vmdtconsistencycheckevent.VmDtConsistencyCheckEventBroker; +import com.inspur.lcm.metadata.logging.LoggerDisruptorQueue; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.util.List; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("") +@Produces(MediaType.APPLICATION_JSON) +public class VMCodeGenController { + + @Path("convertBizEntity") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBizEntity(String jsonObject) { + if (CheckInfoUtil.checkNull(jsonObject)) { + throw new RuntimeException("请传入有效Json对象."); + } + + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + JsonNode bizEntityJsonNode = jsonNode.get("bizEntityJson"); + CheckInfoUtil.checkNessaceryInfo("bizEntityJson", bizEntityJsonNode); + JsonNode bePkgNameJsonNode = jsonNode.get("bePkgName"); + CheckInfoUtil.checkNessaceryInfo("bePkgName", bePkgNameJsonNode); + JsonNode beIdJsonNode = jsonNode.get("beId"); + CheckInfoUtil.checkNessaceryInfo("beId", beIdJsonNode); + JsonNode voGeneratingAssemblyJsonNode = jsonNode.get("voGeneratingAssembly"); + CheckInfoUtil.checkNessaceryInfo("voGeneratingAssembly", voGeneratingAssemblyJsonNode); + + String bizEntityJson = bizEntityJsonNode.textValue(); + String bePkgName = bePkgNameJsonNode.textValue(); + String beId = beIdJsonNode.textValue(); + String voGeneratingAssembly = voGeneratingAssemblyJsonNode.textValue(); + + return convertBizEntityToViewModel(bizEntityJson, bePkgName, beId, voGeneratingAssembly); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + @Path("createVoRt") + @PUT + public String createVoRt(String jsonObject) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + + JsonNode basicInfoNode = jsonNode.get("basicInfo"); + CheckInfoUtil.checkNessaceryInfo("Vo基本信息", basicInfoNode); + String voCode = basicInfoNode.get("code").textValue(); + String voName = basicInfoNode.get("name").textValue(); + + JsonNode beNode = jsonNode.get("be"); + CheckInfoUtil.checkNessaceryInfo("源业务实体", beNode); + GspBusinessEntity be = mapper.readValue(beNode.toString(), GspBusinessEntity.class); + CheckInfoUtil.checkNessaceryInfo("源业务实体", be); + + GspMetadata beMetadata = VoGuideUtil.getInstance().getRtMetadata(be.getID()); + String beNameSpace = VoGuideUtil.getInstance().getVoMetaGeneratingAssembly(beMetadata); + String bizObjectId = beMetadata.getHeader().getBizobjectID(); + + JsonNode configsArrayNode = jsonNode.get("configs"); + HashMap configMap = new HashMap<>(); + if (configsArrayNode != null && configsArrayNode.size() != 0) { + for (JsonNode configNode : configsArrayNode) { + String key = configNode.get("key").textValue(); + String value = configNode.get("value").textValue(); + configMap.put(key, value); + } + } + + JsonNode billCategoryInfo = jsonNode.get("billCategoryId"); + CheckInfoUtil.checkNessaceryInfo("业务种类Id", billCategoryInfo); + String billCategoryId = billCategoryInfo.textValue(); + + GspViewModel vo = VoGuideUtil.getInstance() + .createVo(be, configMap, beNameSpace, HandleAssemblyNameUtil + .convertToJavaPackageName(beNameSpace)); + vo.setCode(voCode); + vo.setName(voName); + vo.setSource("Print"); + String voId = VoGuideUtil.getInstance().saveVoRt(vo, bizObjectId, beNameSpace); + MdBizTypeMappingService service=SpringBeanUtils.getBean(MdBizTypeMappingService.class); + service.save(billCategoryId,voId); + return new ObjectMapper().writeValueAsString(voId); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Path("checkVoConfigIdRt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void checkVoConfigIdRt(String jsonObject) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + JsonNode beIdNode = jsonNode.get("beId"); + CheckInfoUtil.checkNessaceryInfo("源业务实体元数据ID", beIdNode); + String beId = beIdNode.textValue(); + CheckInfoUtil.checkNessaceryInfo("源业务实体元数据ID", beId); + + JsonNode voCodeNode = jsonNode.get("voCode"); + CheckInfoUtil.checkNessaceryInfo("VO编号", voCodeNode); + String voCode = voCodeNode.textValue(); + CheckInfoUtil.checkNessaceryInfo("VO编号", voCode); + + GspMetadata beMetadata = VoGuideUtil.getInstance().getRtMetadata(beId); + String beNameSpace = VoGuideUtil.getInstance().getVoMetaGeneratingAssembly(beMetadata); + GspViewModel vo = ConvertUtils + .convertToViewModel((GspBusinessEntity) beMetadata.getContent(), beNameSpace, + beMetadata.getHeader().getId(), + HandleAssemblyNameUtil.convertToJavaPackageName(beNameSpace)); + vo.setCode(voCode); + VoGuideUtil.getInstance().checkBeforeSave(vo.getGeneratedConfigID(), vo.getId()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + private String convertBizEntityToViewModel(String bizEntityJson, String bePkgName, String beId, + String voGeneratingAssembly) { + GspBusinessEntity be = null; + try { + be = new ObjectMapper().readValue(bizEntityJson, GspBusinessEntity.class); + GspViewModel vm = ConvertUtils.convertToViewModel(be, bePkgName, beId, voGeneratingAssembly); + // 联动vo的关联带出字段枚举信息 +// LinkBeUtils linkBeUtils = new LinkBeUtils(); +// linkBeUtils.LinkBeRefElements(vm); + + return new ObjectMapper().writeValueAsString(vm); + } catch (JsonProcessingException e) { + throw new RuntimeException("元数据序列化失败", e); + } + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMMetadataController.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMMetadataController.java new file mode 100644 index 0000000..517a443 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/rtwebapi/VMMetadataController.java @@ -0,0 +1,161 @@ +package com.inspur.edp.formserver.viewmodel.rtwebapi; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.inspur.edp.bef.bizentity.GspBusinessEntity; +import com.inspur.edp.bef.bizentity.json.element.BizElementSerializer; +import com.inspur.edp.cef.designtime.api.element.GspAssociation; +import com.inspur.edp.cef.designtime.api.json.element.GspAssociationSerializer; +import com.inspur.edp.cef.designtime.api.util.MetadataUtil; +import com.inspur.edp.das.commonmodel.entity.element.GspCommonAssociation; +import com.inspur.edp.formserver.viewmodel.common.mapping.GspVoElementMapping; +import com.inspur.edp.formserver.viewmodel.util.ViewModelUtils; +import com.inspur.edp.formserver.vmmanager.exception.VmManagerException; +import com.inspur.edp.formserver.vmmanager.service.UpdateVirtualVoElementWithUdtService; +import com.inspur.edp.formserver.vmmanager.service.WebControllerService; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.entity.MetadataDto; +import com.inspur.edp.lcm.metadata.common.MetadataDtoConverter; +import com.inspur.edp.metadata.rtcustomization.api.CustomizationService; +import io.iec.edp.caf.commons.exception.ExceptionLevel; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +public class VMMetadataController { + private final String EXCEPTIONCODE="vmMetadataRtWebApi"; + + + @Path("getbizObject/{beid}/{objid}") + @GET + @Produces(MediaType.APPLICATION_JSON) + public String getBizObject(@PathParam("beid") String beid,@PathParam("objid") String objid,@QueryParam("path") String path,@QueryParam("bePkgName") String bePkgName) { + GspBusinessEntity be=getBizEntity(path,bePkgName,beid); + return WebControllerService.getInstance().getBizObject(be, objid); + } + + /** + * 保存运行时元数据 + * @param metadataDto + * @return + */ + @Path("saveMetadata") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public boolean saveMetadata(MetadataDto metadataDto) { + if(metadataDto == null) { + throw new VmManagerException("",EXCEPTIONCODE, "保存元数据DTO为空。",null, ExceptionLevel.Error,false); + } + GspMetadata metadata = MetadataDtoConverter.asMetadata(metadataDto); + SpringBeanUtils.getBean(CustomizationService.class).save(metadata); + return true; + } + + @Path("checkvo") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void checkKeywords(String jsonObject) { + WebControllerService.getInstance().checkKeywords(jsonObject); + } + + @Path("getVirtualVoAsso") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getVirtualVoAsso(String info) { + return WebControllerService.getInstance().getVirtualVoAsso(info, (String path, String bePkgName, String beId) -> getBizEntity(path,bePkgName,beId)); + } + + @Path("virtualVoChooseUdt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String updateVirtualVoUdtElementWhenChooseUdt(String info) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(info); + String refUdtId=node.get("refUdtId").textValue(); + String path=node.get("path").textValue(); + String beElementJson=node.get("udtElementJson").textValue(); + return UpdateVirtualVoElementWithUdtService + .getInstance().UpdateVariableWithRefUdtRT(refUdtId,path,beElementJson,true); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + /** + * + * @param path + * @param bePkgName + * @param beId + * @return + */ + private GspBusinessEntity getBizEntity(String path, String bePkgName, String beId) + { + + if (ViewModelUtils.checkNull(beId)) + { + throw new VmManagerException("",EXCEPTIONCODE, "待获取的业务实体元数据id不可为空。",null, ExceptionLevel.Error,false); + } + GspMetadata metadata = MetadataUtil.getCustomMetadata(beId); + if (!(metadata.getContent() instanceof GspBusinessEntity)) + { + throw new VmManagerException("",EXCEPTIONCODE, String.format("无法加载id='%1$s'的业务实体元数据。", beId),null,ExceptionLevel.Error,false); + } + return (GspBusinessEntity) metadata.getContent(); + } + + /** + * 转换BE字段 + * @param convertEleInfo + * @return + */ + @Path("convertBeElements") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBeElementIdsToVmElements(String convertEleInfo) { + return WebControllerService.getInstance().convertBeElementIdsToVmElements(convertEleInfo, + (String path, String bePkgName, String beId) -> getBizEntity(path, bePkgName, beId)); + } + + @Path("addObject") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String addBizObject(String addObjInfo) { + return WebControllerService.getInstance().addBizObject(addObjInfo, + (String path, String bePkgName, String beId) -> getBizEntity(path, bePkgName, beId)); + } + + + @Path("getBeAsso") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getBizAssoById(String info) { + ObjectMapper mapper=new ObjectMapper(); + SimpleModule module =new SimpleModule(); + BizElementSerializer bizElementSerializer=new BizElementSerializer(); + GspAssociationSerializer associationDeserializer=new GspAssociationSerializer(bizElementSerializer); + module.addSerializer(GspAssociation.class,associationDeserializer); + mapper.registerModule(module); + try { + JsonNode node= mapper.readTree(info); + String path = node.get("path").textValue(); + String voEleMappingJson = node.get("voEleMapping").textValue(); + String beAssoId = node.get("assoId").textValue(); + GspVoElementMapping voEleMapping = WebControllerService.getInstance().readVoEleMapping(voEleMappingJson); + GspCommonAssociation bizAsso = WebControllerService.getInstance().getBizAsso(path, voEleMapping, beAssoId, this::getBizEntity); + + String bizAssoJson=mapper.writeValueAsString(bizAsso); + return bizAssoJson; + } catch (JsonProcessingException e) { + throw new RuntimeException("GspAssociation序列化失败"+e); + } + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceAutoConfig.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceAutoConfig.java new file mode 100644 index 0000000..3cf4385 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceAutoConfig.java @@ -0,0 +1,21 @@ +package com.inspur.edp.formserver.viewmodel.webapi; + +import io.iec.edp.caf.rest.RESTEndpoint; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class BffWebApiServiceAutoConfig { + @Bean + public VMCodeGenController testBffWebApi() { + return new VMCodeGenController(); + } + + @Bean + public RESTEndpoint getBffWebApiEndpoint(VMCodeGenController genService){ + return new RESTEndpoint( + "/dev/main/v1.0/bff", + genService + ); + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceConfig.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceConfig.java new file mode 100644 index 0000000..79959fe --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/BffWebApiServiceConfig.java @@ -0,0 +1,21 @@ +package com.inspur.edp.formserver.viewmodel.webapi; + +import io.iec.edp.caf.rest.RESTEndpoint; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class BffWebApiServiceConfig { + @Bean + public ViewModelController getBffWebApi() { + return new ViewModelController(); + } + + @Bean + public RESTEndpoint getBffWebApiServiceEndpoint(ViewModelController genService){ + return new RESTEndpoint( + "/dev/main/v1.0/viewmodel", + genService + ); + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/VMCodeGenController.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/VMCodeGenController.java new file mode 100644 index 0000000..d87c8b9 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/VMCodeGenController.java @@ -0,0 +1,407 @@ +package com.inspur.edp.formserver.viewmodel.webapi; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.bef.bizentity.GspBusinessEntity; +import com.inspur.edp.das.commonmodel.util.HandleAssemblyNameUtil; +import com.inspur.edp.cef.designtime.api.dtconsistencycheck.ConsistencyCheckEventMessage; +import com.inspur.edp.formserver.viewmodel.GspViewModel; +import com.inspur.edp.formserver.viewmodel.common.ConvertUtils; +import com.inspur.edp.formserver.viewmodel.common.ValueHelpConfig; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.actioneventargs.ChangingVoActionCodeEventArgs; +import com.inspur.edp.formserver.vmmanager.helpconfig.HelpConfigFilterSortHandler; +import com.inspur.edp.formserver.vmmanager.service.WebControllerService; +import com.inspur.edp.formserver.vmmanager.util.CheckInfoUtil; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.actioneventargs.*; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.entityeventargs.*; +import com.inspur.edp.formserver.viewmodel.dtconsistencycheck.fieldeventargs.*; +import com.inspur.edp.formserver.vmmanager.validate.model.ViewModelChecker; +import com.inspur.edp.formserver.vmmanager.voguide.VoGuideUtil; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.metadata.businesstype.api.MdBizTypeMappingService; +import io.iec.edp.caf.boot.context.CAFContext; +import java.util.HashMap; + +import com.inspur.edp.formserver.vmmanager.vmdtconsistencycheckevent.VmDtConsistencyCheckEventBroker; +import com.inspur.lcm.metadata.logging.LoggerDisruptorQueue; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; +import java.util.List; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("") +@Produces(MediaType.APPLICATION_JSON) +public class VMCodeGenController { + @Path("checkvo") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void checkKeywords(String jsonObject) { + WebControllerService.getInstance().checkKeywords(jsonObject); + } + + @Path("convertBizEntity") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBizEntity(String jsonObject) { + if (CheckInfoUtil.checkNull(jsonObject)) { + throw new RuntimeException("请传入有效Json对象."); + } + + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + JsonNode bizEntityJsonNode = jsonNode.get("bizEntityJson"); + CheckInfoUtil.checkNessaceryInfo("bizEntityJson", bizEntityJsonNode); + JsonNode bePkgNameJsonNode = jsonNode.get("bePkgName"); + CheckInfoUtil.checkNessaceryInfo("bePkgName", bePkgNameJsonNode); + JsonNode beIdJsonNode = jsonNode.get("beId"); + CheckInfoUtil.checkNessaceryInfo("beId", beIdJsonNode); + JsonNode voGeneratingAssemblyJsonNode = jsonNode.get("voGeneratingAssembly"); + CheckInfoUtil.checkNessaceryInfo("voGeneratingAssembly", voGeneratingAssemblyJsonNode); + + String bizEntityJson = bizEntityJsonNode.textValue(); + String bePkgName = bePkgNameJsonNode.textValue(); + String beId = beIdJsonNode.textValue(); + String voGeneratingAssembly = voGeneratingAssemblyJsonNode.textValue(); + + return convertBizEntityToViewModel(bizEntityJson, bePkgName, beId, voGeneratingAssembly); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + @Path("createVoRt") + @PUT + public String createVoRt(String jsonObject) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + + JsonNode basicInfoNode = jsonNode.get("basicInfo"); + CheckInfoUtil.checkNessaceryInfo("Vo基本信息", basicInfoNode); + String voCode = basicInfoNode.get("code").textValue(); + String voName = basicInfoNode.get("name").textValue(); + + JsonNode beNode = jsonNode.get("be"); + CheckInfoUtil.checkNessaceryInfo("源业务实体", beNode); + GspBusinessEntity be = mapper.readValue(beNode.toString(), GspBusinessEntity.class); + CheckInfoUtil.checkNessaceryInfo("源业务实体", be); + + GspMetadata beMetadata = VoGuideUtil.getInstance().getRtMetadata(be.getID()); + String beNameSpace = VoGuideUtil.getInstance().getVoMetaGeneratingAssembly(beMetadata); + String bizObjectId = beMetadata.getHeader().getBizobjectID(); + + JsonNode configsArrayNode = jsonNode.get("configs"); + HashMap configMap = new HashMap<>(); + if (configsArrayNode != null && configsArrayNode.size() != 0) { + for (JsonNode configNode : configsArrayNode) { + String key = configNode.get("key").textValue(); + String value = configNode.get("value").textValue(); + configMap.put(key, value); + } + } + String billCategoryId = null; + JsonNode billCategoryInfo = jsonNode.get("billCategoryId"); + if(CheckInfoUtil.checkNull(billCategoryInfo)) { + billCategoryId = billCategoryInfo.textValue(); + } + + GspViewModel vo = VoGuideUtil.getInstance() + .createVo(be, configMap, beNameSpace, HandleAssemblyNameUtil + .convertToJavaPackageName(beNameSpace)); + vo.setCode(voCode); + vo.setName(voName); + String voId = VoGuideUtil.getInstance().saveVoRt(vo, bizObjectId, beNameSpace); + MdBizTypeMappingService service=SpringBeanUtils.getBean(MdBizTypeMappingService.class); + if(billCategoryId == null) + service.save(configMap.get("billCategoryId"),voId); + else + service.save(billCategoryId,voId); + + return new ObjectMapper().writeValueAsString(voId); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Path("checkVoConfigIdRt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void checkVoConfigIdRt(String jsonObject) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + JsonNode beIdNode = jsonNode.get("beId"); + CheckInfoUtil.checkNessaceryInfo("源业务实体元数据ID", beIdNode); + String beId = beIdNode.textValue(); + CheckInfoUtil.checkNessaceryInfo("源业务实体元数据ID", beId); + + JsonNode voCodeNode = jsonNode.get("voCode"); + CheckInfoUtil.checkNessaceryInfo("VO编号", voCodeNode); + String voCode = voCodeNode.textValue(); + CheckInfoUtil.checkNessaceryInfo("VO编号", voCode); + + GspMetadata beMetadata = VoGuideUtil.getInstance().getRtMetadata(beId); + String beNameSpace = VoGuideUtil.getInstance().getVoMetaGeneratingAssembly(beMetadata); + GspViewModel vo = ConvertUtils + .convertToViewModel((GspBusinessEntity) beMetadata.getContent(), beNameSpace, + beMetadata.getHeader().getId(), + HandleAssemblyNameUtil.convertToJavaPackageName(beNameSpace)); + vo.setCode(voCode); + VoGuideUtil.getInstance().checkBeforeSave(vo.getGeneratedConfigID(), vo.getId()); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Path("handleHelpConfigFilterSort") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ValueHelpConfig handleHelpConfigFilterSortCondition(String jsonObject) { + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode jsonNode = mapper.readTree(jsonObject); + JsonNode helpConfigNode = jsonNode.get("helpConfig"); + CheckInfoUtil.checkNessaceryInfo("helpConfig", helpConfigNode); + ValueHelpConfig config = mapper.readValue(helpConfigNode.textValue(), ValueHelpConfig.class); + JsonNode filterConditionNode = jsonNode.get("filterCondition"); + JsonNode sortConditionNode = jsonNode.get("sortCondition"); + JsonNode pathNode = jsonNode.get("path"); + HelpConfigFilterSortHandler.getInstance(config, pathNode.textValue()) + .handleConfigFilterAndSort( + filterConditionNode.textValue(), sortConditionNode.textValue()); + return config; + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + private String convertBizEntityToViewModel(String bizEntityJson, String bePkgName, String beId, + String voGeneratingAssembly) { + GspBusinessEntity be = null; + try { + be = new ObjectMapper().readValue(bizEntityJson, GspBusinessEntity.class); + GspViewModel vm = ConvertUtils.convertToViewModel(be, bePkgName, beId, voGeneratingAssembly); + // 联动vo的关联带出字段枚举信息 +// LinkBeUtils linkBeUtils = new LinkBeUtils(); +// linkBeUtils.LinkBeRefElements(vm); + + return new ObjectMapper().writeValueAsString(vm); + } catch (JsonProcessingException e) { + throw new RuntimeException("元数据序列化失败", e); + } + } + + + /** + * 删除Vo节点 + */ + @Path("vmDtConsistencyCheck/removingViewObject") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public RemovingViewObjectEventArgs removingViewObject(RemovingViewObjectEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireRemovingViewObject(args); + + if(args.getEventMessages().size() != 0){ + BefConsistencyCheckMessage(args.getEventMessages(),"请先解除该Vo节点的依赖和关联信息"); + } + return args; + } + + /** + * 修改BizEntityCode + * + * @return + */ + @Path("vmDtConsistencyCheck/changingViewObjectCode") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingViewObjectCodeEventArgs changingViewObjectCode(ChangingViewObjectCodeEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingViewObjectCode(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该Vo节点的依赖和关联信息"); + } + return args; + } + /** + * 删除Vo 字段 + * + * @return + */ + @Path("vmDtConsistencyCheck/removingVoField") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public RemovingVoFieldEventArgs removingVoField(RemovingVoFieldEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireRemovingVoField(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该Vo字段的依赖和关联信息"); + } + return args; + } + /** + * 修改Vo字段数据类型 + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoFieldDataType") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoFieldDataTypeEventArgs changingVoFieldDataType(ChangingVoFieldDataTypeEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoFieldDataType(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该Vo字段的依赖和关联信息"); + } + return args; + } + /** + * 修改Vo字段objectType + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoFieldObjectType") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoFieldObjectTypeEventArgs changingVoFieldObjectType(ChangingVoFieldObjectTypeEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoFieldObjectType(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该Vo字段的依赖和关联信息"); + } + return args; + } + /** + * 修改Vo字段标签 + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoFieldLabelId") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoFieldLabelIdEventArgs changingVoFieldLabelId(ChangingVoFieldLabelIdEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoFieldLabelId(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该Vo字段的依赖和关联信息"); + } + return args; + } + + /** + * 修改动作编号 + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoActionCode") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoActionCodeEventArgs changingVoActionCode(ChangingVoActionCodeEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoActionCode(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该动作的依赖和关联信息"); + } + return args; + } + /** + * 修改动作参数 + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoActionParams") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoActionParamsEventArgs changingVoActionParams(ChangingVoActionParamsEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoActionParams(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该动作的依赖和关联信息"); + } + return args; + } + /** + * 修改集合类型 + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoActionCollectType") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoActionCollectTypeEventArgs changingVoActionCollectType( + ChangingVoActionCollectTypeEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoActionCollectType(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该动作的依赖和关联信息"); + } + return args; + } + /** + * 修改动作参数 + * + * @return + */ + @Path("vmDtConsistencyCheck/changingVoActionReturn") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public ChangingVoActionReturnEventArgs changingVoActionReturn(ChangingVoActionReturnEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireChangingVoActionReturn(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该动作的依赖和关联信息"); + } + return args; + } + /** + * 修改动作参数 + * + * @return + */ + @Path("vmDtConsistencyCheck/deletingVoAction") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public DeletingVoActionEventArgs deletingVoAction(DeletingVoActionEventArgs args){ + VmDtConsistencyCheckEventBroker vmEventBroker = SpringBeanUtils.getBean(VmDtConsistencyCheckEventBroker.class); + vmEventBroker.fireDeletingVoAction(args); + + if(args.eventMessages.size() != 0){ + BefConsistencyCheckMessage(args.eventMessages, "请先解除该动作的依赖和关联信息"); + } + return args; + } + /** + * 控制台输出BEF Warnings + * + * @param messages + */ + public void BefConsistencyCheckMessage(List messages,String + suffix){ + StringBuilder befWarnings = new StringBuilder(); + if (messages.size() > 0) + messages.forEach(message->{ + befWarnings.append(message.getMessage()); + }); + befWarnings.append(suffix); + String currentUerId = CAFContext.current.getUserId(); + if (currentUerId == null || currentUerId.equals("")) { + throw new RuntimeException("获取当前用户ID为空"); + } + LoggerDisruptorQueue.publishEvent("[BEF Warning]:" + befWarnings.toString(),currentUerId); + } +} diff --git a/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/ViewModelController.java b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/ViewModelController.java new file mode 100644 index 0000000..6a64844 --- /dev/null +++ b/view-object-webapi/src/main/java/com/inspur/edp/formserver/viewmodel/webapi/ViewModelController.java @@ -0,0 +1,794 @@ +package com.inspur.edp.formserver.viewmodel.webapi; + +import static com.inspur.edp.formserver.viewmodel.common.ConvertUtils.toElement; +import static com.inspur.edp.formserver.viewmodel.common.ConvertUtils.toObject; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.inspur.edp.bef.bizentity.GspBizEntityElement; +import com.inspur.edp.bef.bizentity.GspBizEntityObject; +import com.inspur.edp.bef.bizentity.GspBusinessEntity; +import com.inspur.edp.bef.bizentity.json.element.BizElementDeserializer; +import com.inspur.edp.bef.bizentity.json.element.BizElementSerializer; +import com.inspur.edp.bef.bizentity.json.operation.BizMgrActionCollectionDeserializer; +import com.inspur.edp.bef.bizentity.operation.BizMgrAction; +import com.inspur.edp.bef.bizentity.operation.BizOperationCollection; +import com.inspur.edp.bef.bizentity.operation.collection.BizMgrActionCollection; +import com.inspur.edp.bef.bizentity.util.StringUtil; +import com.inspur.edp.cef.designtime.api.collection.GspFieldCollection; +import com.inspur.edp.cef.designtime.api.element.GspAssociation; +import com.inspur.edp.cef.designtime.api.json.element.GspAssociationSerializer; +import com.inspur.edp.das.commonmodel.IGspCommonElement; +import com.inspur.edp.das.commonmodel.IGspCommonModel; +import com.inspur.edp.das.commonmodel.IGspCommonObject; +import com.inspur.edp.das.commonmodel.collection.GspElementCollection; +import com.inspur.edp.das.commonmodel.entity.element.GspCommonAssociation; +import com.inspur.edp.das.commonmodel.entity.object.GspCommonObjectType; +import com.inspur.edp.formserver.viewmodel.GspViewModel; +import com.inspur.edp.formserver.viewmodel.GspViewModelElement; +import com.inspur.edp.formserver.viewmodel.GspViewObject; +import com.inspur.edp.formserver.viewmodel.action.ViewModelAction; +import com.inspur.edp.formserver.viewmodel.collection.VMActionCollection; +import com.inspur.edp.formserver.viewmodel.common.ConvertUtils; +import com.inspur.edp.formserver.viewmodel.common.InitVoUtil; +import com.inspur.edp.formserver.viewmodel.common.LinkBeUtils; +import com.inspur.edp.formserver.viewmodel.common.MappingType; +import com.inspur.edp.formserver.viewmodel.common.mapping.GspVoElementMapping; +import com.inspur.edp.formserver.viewmodel.common.mapping.GspVoElementSourceType; +import com.inspur.edp.formserver.viewmodel.common.mapping.GspVoObjectSourceType; +import com.inspur.edp.formserver.viewmodel.json.element.ViewElementDeserializer; +import com.inspur.edp.formserver.viewmodel.json.model.ViewModelDeserializer; +import com.inspur.edp.formserver.viewmodel.json.model.ViewModelSerializer; +import com.inspur.edp.formserver.viewmodel.json.operation.VmActionCollectionSerializer; +import com.inspur.edp.formserver.viewmodel.util.ViewModelUtils; +import com.inspur.edp.formserver.vmmanager.compcodebutton.CompButton; +import com.inspur.edp.formserver.vmmanager.exception.VmManagerException; +import com.inspur.edp.formserver.vmmanager.service.UpdateVariableWithUdtService; +import com.inspur.edp.formserver.vmmanager.service.UpdateVirtualVoElementWithUdtService; +import com.inspur.edp.formserver.vmmanager.service.VmManagerService; +import com.inspur.edp.formserver.vmmanager.service.WebControllerService; +import com.inspur.edp.formserver.vmmanager.util.CheckComUtil; +import com.inspur.edp.formserver.vmmanager.util.CheckInfoUtil; +import com.inspur.edp.formserver.vmmanager.util.SimplifyMetadataUtil; +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.service.FileService; +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.RefCommonService; +import com.inspur.edp.web.help.metadata.HelpMetadataContent; +import io.iec.edp.caf.commons.exception.ExceptionLevel; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.stream.Collectors; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import lombok.var; + +@Path("") +@Produces(MediaType.APPLICATION_JSON) +public class ViewModelController { + + private final String EXCEPTIONCODE="vmWebApi"; + + + + @Path("sysn") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void saveAndSysn(String metadataInfo){ + ObjectMapper mapper=getViewModelMapper(); + MetadataService service= SpringBeanUtils.getBean(MetadataService.class); + + try { + JsonNode node=mapper.readTree(metadataInfo); + isMetadataCodeExist(node); + String path=node.get("path").textValue(); + String metadataName=null; + if(!CheckInfoUtil.checkNull(node.get("name"))){ + metadataName=node.get("name").textValue(); + } + GspMetadata metadata=service.loadMetadata(metadataName,path); + //生成构件元数据 + ArrayList list= VmManagerService.generateComponent(metadata,path,true); + //构件代码模板 + VmManagerService.generateComponentCode(metadata,path,list); + //保存元数据 + VmManagerService.saveMetadata(metadata,path); + } catch (JsonProcessingException e) { + throw new RuntimeException("元数据信息读取异常"+e); + } + } + + @Path("isHelpComp") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public boolean isHelpComp(String info){ + return true; + } + + @Path("createVirtualVo") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String creataVirtualVo(String info){ + ObjectMapper mapper=getViewModelMapper(); + try { + JsonNode node=mapper.readTree(info); + String metadataID=node.get("metadataID").textValue(); + String metadataName=null; + if(!CheckInfoUtil.checkNull(node.get("metadataName"))){ + metadataName=node.get("metadataName").textValue(); + } + String metadataCode=node.get("metadataCode").textValue(); + String metadataAssembly=node.get("metadataAssembly").textValue(); + GspViewModel vm= InitVoUtil + .BuildVirtualVo(metadataID,metadataName,metadataCode,metadataAssembly); + String vmJson=mapper.writeValueAsString(vm); + return vmJson; + } catch (JsonProcessingException e) { + throw new RuntimeException("序列化异常"+e); + } + } + + @Path("convertBizEntity") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBizEntityToViewModel(String convertBeInfo) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(convertBeInfo); + String bizEntityJson=node.get("bizEntityJson").textValue(); + String bePkgName=null; + if(!CheckInfoUtil.checkNull(node.get("bePkgName"))){ + bePkgName=node.get("bePkgName").textValue(); + } + + String beId=node.get("beId").textValue(); + String voGeneratingAssembly=node.get("voGeneratingAssembly").textValue(); + return convertBizEntityToViewModel(bizEntityJson,bePkgName,beId,voGeneratingAssembly); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + @Path("chooseUdt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String updateUdtElementWhenChooseUdt(String info) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(info); + String refUdtId=node.get("refUdtId").textValue(); + String path=node.get("path").textValue(); + String beElementJson=node.get("udtElementJson").textValue(); + return UpdateVariableWithUdtService + .getInstance().updateVariableWithRefUdt(refUdtId,path,beElementJson,true); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + @Path("updateUdt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String updateUdtElementWhenLoading(String info) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(info); + String refUdtId=node.get("refUdtId").textValue(); + String path=node.get("path").textValue(); + String beElementJson=node.get("udtElementJson").textValue(); + return UpdateVariableWithUdtService.getInstance().updateVariableWithRefUdt(refUdtId,path,beElementJson,false); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + @Path("virtualVoChooseUdt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String updateVirtualVoUdtElementWhenChooseUdt(String info) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(info); + String refUdtId=node.get("refUdtId").textValue(); + String path=node.get("path").textValue(); + String beElementJson=node.get("udtElementJson").textValue(); + return UpdateVirtualVoElementWithUdtService + .getInstance().UpdateVariableWithRefUdt(refUdtId,path,beElementJson,true); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + @Path("virtualVoUpdateUdt") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String updateVirtualVoUdtElementWhenLoading(String info) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(info); + String refUdtId=node.get("refUdtId").textValue(); + String path=node.get("path").textValue(); + String beElementJson=node.get("udtElementJson").textValue(); + return UpdateVirtualVoElementWithUdtService + .getInstance().UpdateVariableWithRefUdt(refUdtId,path,beElementJson,false); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + } + + + @Path("changeMainObj") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String changeMainObj(String convertBeInfo) { + ObjectMapper mapper=getViewModelMapper(); + try { + JsonNode node= mapper.readTree(convertBeInfo); + String newObjId=node.get("newObjId").textValue(); + String bePkgName=null; + if(!CheckInfoUtil.checkNull(node.get("bePkgName"))){ + bePkgName=node.get("bePkgName").textValue(); + } + + String beId=node.get("beId").textValue(); + String voGeneratingAssembly=node.get("voGeneratingAssembly").textValue(); + GspBusinessEntity be=getBizEntity(null,bePkgName,beId); + GspBizEntityObject bizObj= (GspBizEntityObject) be.findObjectById(newObjId); + if (bizObj==null) + { + throw new VmManagerException("",EXCEPTIONCODE, "所选业务实体'{"+be.getName()+"}'中无选中的节点,业务实体id='{"+beId+"}', 节点id='{"+bizObj+"}'。",null, + ExceptionLevel.Error,false); + } + // 处理子节点 + if (bizObj.getObjectType() == GspCommonObjectType.ChildObject) + { + bizObj.setObjectType(GspCommonObjectType.MainObject); + bizObj.getKeys().clear(); + be.setMainObject(bizObj); + } + GspViewModel vm= ConvertUtils.convertToViewModel(be, bePkgName, beId, voGeneratingAssembly); + String vmJson=mapper.writeValueAsString(vm); + return vmJson; + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + + @Path("getHelpVoTargetBeId") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getHelpVoTargetBeId(String convertBeInfo) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(convertBeInfo); + String helperId=node.get("helperId").textValue(); + RefCommonService service=SpringBeanUtils.getBean(RefCommonService.class); + HelpMetadataContent helpMetadataContent= (HelpMetadataContent) service.getRefMetadata(helperId).getContent(); + String voId=helpMetadataContent.getDataSource().getVoSourceId(); + GspViewModel helpVo= (GspViewModel) service.getRefMetadata(voId).getContent(); + if(helpVo==null){ + throw new RuntimeException("当前帮助"+helpMetadataContent.getName()+"无对应的vo元数据,helpId="+"帮助来源类型为:"+helpMetadataContent.getDataSource().getSourceType()); + } + if (helpVo.getMapping() == null || helpVo.getMapping().getMapType() != MappingType.BizEntity) + { + throw new RuntimeException("当前帮助'"+helpMetadataContent.getName()+"'vo元数据非Be源。"); + } + return "\""+helpVo.getMapping().getTargetMetadataId()+"\""; + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + + + @Path("convertBeElements") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBeElementIdsToVmElements(String convertEleInfo) { + return WebControllerService.getInstance().convertBeElementIdsToVmElements(convertEleInfo,this::getBizEntity); + } + + @Path("getBeAsso") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getBizAssoById(String info) { + ObjectMapper mapper=new ObjectMapper(); + SimpleModule module =new SimpleModule(); + BizElementSerializer bizElementSerializer=new BizElementSerializer(); + GspAssociationSerializer associationDeserializer=new GspAssociationSerializer(bizElementSerializer); + module.addSerializer(GspAssociation.class,associationDeserializer); + mapper.registerModule(module); + try { + JsonNode node= mapper.readTree(info); + String path = node.get("path").textValue(); + String voEleMappingJson = node.get("voEleMapping").textValue(); + String beAssoId = node.get("assoId").textValue(); + GspVoElementMapping voEleMapping = WebControllerService.getInstance().readVoEleMapping(voEleMappingJson); + GspCommonAssociation bizAsso =WebControllerService.getInstance().getBizAsso(path, voEleMapping, beAssoId,this::getBizEntity); + + String bizAssoJson=mapper.writeValueAsString(bizAsso); + return bizAssoJson; + } catch (JsonProcessingException e) { + throw new RuntimeException("GspAssociation序列化失败"+e); + } + } + + @Path("getVoAsso") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getVoAsso(String info) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(info); + String path = node.get("path").textValue(); + String voEleMappingJson = node.get("voEleMapping").textValue(); + String beAssoJson = node.get("beAsso").textValue(); + String voAssoJson = node.get("voAsso").textValue(); + String refElementIdsJson = node.get("refElementIds").textValue(); + + + GspCommonAssociation beAsso = WebControllerService.getInstance().readAsso(beAssoJson,new BizElementDeserializer()); + GspCommonAssociation originVoAsso = WebControllerService.getInstance().readAsso(voAssoJson,new ViewElementDeserializer()); + var voEleMapping = WebControllerService.getInstance().readVoEleMapping(voEleMappingJson); + var refElementIds=WebControllerService.getInstance().readIdList(refElementIdsJson); + + if (refElementIds.size() == 0) + { + throw new VmManagerException("",EXCEPTIONCODE, "当前未选中关联带出字段。",null,ExceptionLevel.Error,false); + } + + GspFieldCollection bizRefElements = beAsso.getRefElementCollection(); + GspFieldCollection originVoRefElements = originVoAsso.getRefElementCollection(); + GspElementCollection refElements = new GspElementCollection(null); + + for (var refElementId : refElementIds) + { + IGspCommonElement voRefElement= (IGspCommonElement) originVoRefElements.stream().filter(item->item.getRefElementId().equals(refElementId)).findFirst().orElse(null); + if (!( voRefElement instanceof GspViewModelElement)) + { + IGspCommonElement beRefElement= (IGspCommonElement) bizRefElements.stream().filter(item->item.getRefElementId().equals(refElementId)).findFirst().orElse(null); + if (!(beRefElement instanceof GspBizEntityElement)) + { + throw new VmManagerException("",EXCEPTIONCODE, "be关联中无refElementId='{"+refElementId+"}'的关联带出字段。",null,ExceptionLevel.Error,false); + } + else + { + refElements.add(toElement((IGspCommonElement) beRefElement,voEleMapping.getTargetMetadataPkgName(),voEleMapping.getTargetMetadataId(),voEleMapping.getSourceType())); + } + } + else + { + refElements.add(voRefElement); + } + } + return WebControllerService.getInstance().writeViewElementsJson(refElements); + } catch (JsonProcessingException e) { + throw new RuntimeException("GspAssociation序列化失败"+e); + } + + } + + @Path("getVirtualVoAsso") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getVirtualVoAsso(String info) { + return WebControllerService.getInstance().getVirtualVoAsso(info, this::getBizEntity); + } + + @Path("convertActions") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBizActionsToVmActions(String convertActionInfo) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(convertActionInfo); + String bizActionsJson = node.get("bizActionsJson").textValue(); + String bePkgName=null; + if(!CheckInfoUtil.checkNull(node.get("bePkgName"))){ + bePkgName=node.get("bePkgName").textValue(); + } + String beId = node.get("beId").textValue(); + return convertBizActionsToVmActions(bizActionsJson, bePkgName, beId); + } catch (JsonProcessingException e) { + throw new RuntimeException("GspAssociation序列化失败"+e); + } + } + + @Path("convertElements") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String convertBizElementsToVmElements(String convertActionInfo) { + ObjectMapper mapper=new ObjectMapper(); + try { + JsonNode node= mapper.readTree(convertActionInfo); + String bizElementsJson = node.get("bizElementsJson").textValue(); + String bePkgName=null; + if(!CheckInfoUtil.checkNull(node.get("bePkgName"))){ + bePkgName=node.get("bePkgName").textValue(); + } + String beId = node.get("beId").textValue(); + return convertBizActionsToVmActions(bizElementsJson, bePkgName, beId); + } catch (JsonProcessingException e) { + throw new RuntimeException("GspAssociation序列化失败"+e); + } + } + + @Path("getbizObject/{beid}/{objid}") + @GET + @Produces(MediaType.APPLICATION_JSON) + public String getBizObject(@PathParam("beid") String beid,@PathParam("objid") String objid,@QueryParam("path") String path,@QueryParam("bePkgName") String bePkgName) { + GspBusinessEntity be=getBizEntity(path,bePkgName,beid); + return WebControllerService.getInstance().getBizObject(be, objid); + } + + @Path("addObjects") + @GET + @Produces(MediaType.APPLICATION_JSON) + public String addBizObjects(String convertActionInfo) { + ObjectMapper mapper=new ObjectMapper(); + SimpleModule module =new SimpleModule(); + module.addSerializer(IGspCommonModel.class,new ViewModelSerializer()); + module.addDeserializer(IGspCommonModel.class,new ViewModelDeserializer()); + mapper.registerModule(module); + try { + JsonNode node= mapper.readTree(convertActionInfo); + String vmJson = node.get("vmJson").textValue(); + String bizObjIdsJson = node.get("bizObjIds").textValue(); + String path = node.get("path").textValue(); + String bePkgName=null; + if(!CheckInfoUtil.checkNull(node.get("bePkgName"))){ + bePkgName=node.get("bePkgName").textValue(); + } + String beId = node.get("beId").textValue(); + + List bizObjIds = WebControllerService.getInstance().readIdList(bizObjIdsJson); + + GspBusinessEntity be = getBizEntity(path, bePkgName, beId); + GspViewModel vm =mapper.readValue(vmJson,GspViewModel.class); + List allBizObjIds = be.getAllObjectList().stream().map(item -> item.getID()).collect( + Collectors.toList());//.Select(item => item.ID).ToList(); + List vmObjMappingIds = vm.getAllObjectList().stream().map(item -> ((GspViewObject)item).getMapping().getTargetObjId()).collect( + Collectors.toList());//.Select(item => ((GspViewObject)item).Mapping.TargetObjId).ToList(); + + List newVmMappingObjIds = bizObjIds.stream().filter(item ->!vmObjMappingIds.contains(item)).collect(Collectors.toList());//.Where(item => !vmObjMappingIds.Contains(item)).ToList(); + if (newVmMappingObjIds.size()== 0) + { + return mapper.writeValueAsString(vm); + } + + // 删除未选中的be对象 + var redundantBizObjIds = allBizObjIds.stream().filter(item ->!vmObjMappingIds.contains(item)).collect(Collectors.toList());//.Where(item => !bizObjIds.Contains(item)).ToList(); + removeRedundantBizObj(be, redundantBizObjIds); + + // 添加新增的be对象 + addNewBizObject(vm, be, newVmMappingObjIds, vmObjMappingIds); + return mapper.writeValueAsString(vm); + } catch (JsonProcessingException e) { + throw new RuntimeException("GspAssociation序列化失败"+e); + } + } + + private void addNewBizObject(GspViewModel vm, GspBusinessEntity be,List newVmMappingObjIds, + List vmObjMappingIds) { + if (newVmMappingObjIds.size() != 0) + { + List ids = newVmMappingObjIds; + for(String id :ids){ + IGspCommonObject bizObj=getObjectById(be,id); + String parentObjId=bizObj.getParentObject().getID(); + if(vmObjMappingIds.contains(parentObjId)){ + IGspCommonObject parentObj=getMappedObjectById(vm,parentObjId); + if(parentObj==null) + parentObj.getContainChildObjects().add( + toObject(bizObj,vm.getMapping().getTargetMetadataPkgName(),vm.getMapping().getTargetMetadataId(),parentObj.getIDElement().getID(),GspVoObjectSourceType.BeObject)); + } + } + } + } + + private IGspCommonObject getObjectById(IGspCommonModel cm, String id) + { + return cm.getAllObjectList().stream().filter((item)->item.getID().equals(id)).findFirst().orElse(null);//;.Find(obj => obj.ID == id); + } + + private IGspCommonObject getMappedObjectById(GspViewModel vm, String id) + { + return vm.getAllObjectList().stream().filter((item)->((GspViewModel)item).getMapping().getTargetObjId().equals(id)).findFirst().orElse(null);//.Find(obj => ((GspViewObject)obj).Mapping.TargetObjId == id); + } + private void removeRedundantBizObj(GspBusinessEntity be, List redundantBizObjIds) { + if (redundantBizObjIds.size() != 0) + { + for (String id : redundantBizObjIds) + { + IGspCommonObject childObj = getObjectById(be, id); + if(childObj==null) + continue; + childObj.getParentObject().getContainChildObjects().remove(childObj); + } + } + } + + @Path("addObject") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String addBizObject(String addObjInfo) { + return WebControllerService.getInstance().addBizObject(addObjInfo,this::getBizEntity); + } + + @Path("batchSimplification") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public void SimplifyMetadata() { + SimplifyMetadataUtil util = new SimplifyMetadataUtil(); + util.Simplify(); + } + + + + private String convertBizActionsToVmActions(String bizActionsJson, String bePkgName, + String beId) { + VMActionCollection vmActions = new VMActionCollection(); + BizMgrActionCollection bizMgrActions = readBizMgrActions(bizActionsJson); + if (bizMgrActions.getCount() > 0) + { + bizMgrActions.forEach(mgrAction -> { var vmAction = ConvertUtils.toMappedAction((BizMgrAction)mgrAction, beId, bePkgName);vmActions.add(vmAction); + }); + } + return writeViewObjectsJson(vmActions); + } + + private String writeViewObjectsJson(VMActionCollection vmActions) { + ObjectMapper mapper=new ObjectMapper(); + SimpleModule module =new SimpleModule(); + module.addSerializer(VMActionCollection.class,new VmActionCollectionSerializer()); + mapper.registerModule(module); + try { + String vmActionsJson=mapper.writeValueAsString(vmActions); + return vmActionsJson; + } catch (JsonProcessingException e) { + throw new RuntimeException("VMActionCollection序列化失败"+e); + } + } + + private BizMgrActionCollection readBizMgrActions(String bizActionsJson) { + ObjectMapper mapper=new ObjectMapper(); + SimpleModule module =new SimpleModule(); + module.addDeserializer(BizOperationCollection.class,new BizMgrActionCollectionDeserializer()); + mapper.registerModule(module); + try { + BizMgrActionCollection bizOperations= (BizMgrActionCollection) mapper.readValue(bizActionsJson,BizOperationCollection.class); + return bizOperations; + } catch (JsonProcessingException e) { + throw new RuntimeException("BizMgrActionCollection反序列化失败"+e); + } + } + + +// private GspCommonAssociation getBizAsso(String path, GspVoElementMapping voEleMapping, +// String assoId) { +// GspBusinessEntity be = getBizEntity(path, voEleMapping.getTargetMetadataPkgName(), voEleMapping.getTargetMetadataId()); +// String bizEleId = voEleMapping.getTargetElementId(); +// GspBizEntityElement bizEle = (GspBizEntityElement) be.findElementById(bizEleId); +// if (bizEle == null) +// { +// throw new VmManagerException("",EXCEPTIONCODE, "找不到当前vo字段映射的be字段, 字段id={bizEleId}",null,ExceptionLevel.Error,false); +// } +// if (bizEle.getChildAssociations().getCount() == 0) +// { +// throw new VmManagerException("",EXCEPTIONCODE, "当前vo字段映射的be字段, 不是关联字段。",null,ExceptionLevel.Error,false); +// +// } +// GspAssociation association= bizEle.getChildAssociations().stream().filter(item->item.getId().equals(assoId)).findFirst().orElse(null); +// if (!(association instanceof GspCommonAssociation)) +// { +// throw new VmManagerException("",EXCEPTIONCODE, "找找不到当前vo关联映射的be关联, 关联id={assoId}。",null,ExceptionLevel.Error,false); +// } +// return (GspCommonAssociation) association; +// } + +// private GspVoElementMapping readVoEleMapping(String voEleMappingJson) { +// ObjectMapper mapper=new ObjectMapper(); +// SimpleModule module =new SimpleModule(); +// module.addSerializer(ViewModelMapping.class,new GspVoElementMappingSerializer()); +// module.addDeserializer(ViewModelMapping.class,new GspVoElementMappingDeserializer()); +// mapper.registerModule(module); +// try { +// GspVoElementMapping voElemapping= (GspVoElementMapping) mapper.readValue(voEleMappingJson,ViewModelMapping.class); +// if(voElemapping==null){ +// throw new VmManagerException("",EXCEPTIONCODE, "找不到当前vo字段映射的映射关系。",null,ExceptionLevel.Error,false); +// } +// return voElemapping; +// } catch (JsonProcessingException e) { +// throw new RuntimeException("VoElementMapping反序列化失败"+e); +// } +// } + + public static GspElementCollection convertPartialElementsToVoElements(IGspCommonObject co, List eleIdList, String pkgName, String metaId, GspVoElementSourceType sourceType ) + { + GspElementCollection voElements = new GspElementCollection(null); + if (eleIdList != null && eleIdList.size() > 0) + { + for (String eleId : eleIdList) + { + GspBizEntityElement bizElement = (GspBizEntityElement) co.findElement(eleId); + GspViewModelElement voElement = toElement(bizElement, pkgName, metaId, sourceType); + voElement.getMapping().setTargetObjectId(co.getID()); + voElements.add(voElement); + } + } + return voElements; + } + + private ObjectMapper getViewModelMapper(){ + ObjectMapper mapper=new ObjectMapper(); + SimpleModule module =new SimpleModule(); + module.addSerializer(IGspCommonModel.class,new ViewModelSerializer()); + module.addDeserializer(IGspCommonModel.class,new ViewModelDeserializer()); + mapper.registerModule(module); + return mapper; + } + private String convertBizEntityToViewModel(String bizEntityJson, String bePkgName, String beId, + String voGeneratingAssembly) { + GspBusinessEntity be = null; + try { + be = new ObjectMapper().readValue(bizEntityJson, GspBusinessEntity.class); + GspViewModel vm = ConvertUtils.convertToViewModel(be, bePkgName, beId, voGeneratingAssembly); +// 联动vo的关联带出字段枚举信息 + LinkBeUtils linkBeUtils = new LinkBeUtils(); + linkBeUtils.linkBeRefElements(vm); + + return new ObjectMapper().writeValueAsString(vm); + } catch (JsonProcessingException e) { + throw new RuntimeException("元数据序列化失败", e); + } + } + private GspBusinessEntity getBizEntity(String path, String bePkgName, String beId) + { + + if (ViewModelUtils.checkNull(beId)) + { + throw new VmManagerException("",EXCEPTIONCODE, "待获取的业务实体元数据id不可为空。",null, ExceptionLevel.Error,false); + } + GspMetadata metadata =SpringBeanUtils.getBean(RefCommonService.class).getRefMetadata(beId); + if (!(metadata.getContent() instanceof GspBusinessEntity)) + { + throw new VmManagerException("",EXCEPTIONCODE, String.format("无法加载id='%1$s'的业务实体元数据。", beId),null,ExceptionLevel.Error,false); + } + return (GspBusinessEntity) metadata.getContent(); + } + + /** + * 获取VO动作构件代码路径 + * @param info + * @return + */ + @Path("VOComponentCodePath") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getVOComponentCodePath(JsonNode info) { + String id = info.get("metadataId").textValue(); + String projectpath = info.get("metadataPath").textValue(); + String type = info.get("actionType").textValue(); + String action = info.get("actionCode").textValue(); + ArrayList actionList = new ArrayList<>(); + actionList.add(action); + GspMetadata metadata = SpringBeanUtils.getBean(MetadataService.class).loadMetadataByMetadataId(id, projectpath); + GspViewModel vo = (GspViewModel) metadata.getContent(); + String relativePath = metadata.getRelativePath(); + + GspProject metadataProj = SpringBeanUtils.getBean(MetadataService.class).getGspProjectInfo(relativePath); + String compAssemblyName = metadataProj.getProjectNameSpace(); + + CompButton button = new CompButton(); + String filePath =button.getCompPath(vo,type,relativePath,actionList,compAssemblyName); + filePath.replaceAll("\\\\", Matcher.quoteReplacement(File.separator)); + filePath.replaceAll("/", Matcher.quoteReplacement(File.separator)); + + return filePath; + } + + /** + * 获取VO动作构件代码 + * @param info + * @return + */ + @Path("VOComponentCode") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public String getVOComponentCode(JsonNode info) { + String id = info.get("metadataId").textValue(); + String projectpath = info.get("metadataPath").textValue(); + String type = info.get("actionType").textValue(); + String action = info.get("actionCode").textValue(); + ArrayList actionList = new ArrayList<>(); + actionList.add(action); + GspMetadata metadata = SpringBeanUtils.getBean(MetadataService.class).loadMetadataByMetadataId(id, projectpath); + GspViewModel vo = (GspViewModel) metadata.getContent(); + String relativePath = metadata.getRelativePath(); + GspProject metadataProj = SpringBeanUtils.getBean(MetadataService.class).getGspProjectInfo(relativePath); + String compAssemblyName = metadataProj.getProjectNameSpace(); + + CompButton button = new CompButton(); + String code =button.getCompCode(vo,type,relativePath,actionList,compAssemblyName); + + return code; + } + + /** + * 判断当前元数据是否在当前BO内 + * @param info + * @return + */ + @Path("isMetadataExist") + @PUT + @Produces(MediaType.APPLICATION_JSON) + public boolean isMetadataExist(JsonNode info) { + if(StringUtil.checkNull(info)) { + return false; + } + String path = info.get("path").textValue(); + String metadataFileName = info.get("metadataFileName").textValue(); + MetadataService service = SpringBeanUtils.getBean(com.inspur.edp.lcm.metadata.api.service.MetadataService.class); + return service.isMetadataExist(path, metadataFileName); + } + + private void isMetadataCodeExist(JsonNode info) { + if(StringUtil.checkNull(info)) { + return; + } + String metadataName = info.get("name").textValue(); + String projectPath = info.get("path").textValue(); + + GspMetadata metadata = SpringBeanUtils.getBean(MetadataService.class).loadMetadata(metadataName, projectPath); + GspViewModel vo = (GspViewModel) metadata.getContent(); + List checkInfo = new ArrayList<>(); + CompButton button = new CompButton(); + button.getNewActions(vo,checkInfo); + String relativePath = metadata.getRelativePath(); + MetadataProjectService service = SpringBeanUtils.getBean(MetadataProjectService.class); + String compModulePath = service.getJavaCompProjectPath(relativePath); + GspProject metadataProj = SpringBeanUtils.getBean(MetadataService.class).getGspProjectInfo(relativePath); + String compAssemblyName = metadataProj.getProjectNameSpace(); + if(checkInfo.size()<=0){ + return; + } + + for(CheckComUtil checkComUtil : checkInfo) { + ArrayList actionList = new ArrayList<>(); + actionList.add(checkComUtil.getAction()); + String filePath = button.getFilePath(vo, checkComUtil,compModulePath,compAssemblyName); + filePath.replaceAll("\\\\", Matcher.quoteReplacement(File.separator)); + filePath.replaceAll("/", Matcher.quoteReplacement(File.separator)); + FileService fsService = SpringBeanUtils.getBean(FileService.class); + if (fsService.isFileExist(filePath)) { + String fileName = ""; + if(!"VarDeterminations".equals(checkComUtil.getType())){ + fileName = checkComUtil.getAction()+"VOAction.java"; + }else { + fileName = vo.getName()+"Variable"+checkComUtil.getAction()+"VODtm.java"; + } + throw new RuntimeException("已存在名为"+fileName+"的构件代码文件,请修改编号为"+checkComUtil.getAction()+"、名称为"+checkComUtil.getActionName()+"的"+checkComUtil.getCheckInfo()+"的编号,再执行保存操作。"+"\r\n代码路径:"+filePath); + } + } + } + +} diff --git a/view-object-webapi/src/main/resources/META-INF/spring.factories b/view-object-webapi/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..a77ce4d --- /dev/null +++ b/view-object-webapi/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.inspur.edp.formserver.viewmodel.rtwebapi.BffRtWebApiServiceAutoConfig,com.inspur.edp.formserver.viewmodel.rtwebapi.BffMetadataRtWebApiServiceAutoConfig,com.inspur.edp.formserver.viewmodel.webapi.BffWebApiServiceAutoConfig,com.inspur.edp.formserver.viewmodel.webapi.BffWebApiServiceConfig -- Gitee From 9cf49566e2eed67c6f71c694df994332e745bc87 Mon Sep 17 00:00:00 2001 From: hanll02 Date: Fri, 9 Sep 2022 20:38:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=86=E5=9B=BE=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=B1=82=E6=8F=90=E4=BE=9B=E5=85=83=E6=95=B0=E6=8D=AE=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96=E5=85=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmmanager/ContentSerializer.java | 84 ++++++++++ .../vmmanager/TransferSerializer.java | 150 ++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/ContentSerializer.java create mode 100644 view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/TransferSerializer.java diff --git a/view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/ContentSerializer.java b/view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/ContentSerializer.java new file mode 100644 index 0000000..8b7eacd --- /dev/null +++ b/view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/ContentSerializer.java @@ -0,0 +1,84 @@ +/* + * 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.formserver.vmmanager; + + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.inspur.edp.formserver.viewmodel.Context; +import com.inspur.edp.formserver.viewmodel.GspViewModel; +import com.inspur.edp.formserver.viewmodel.VoThreadLoacl; +import com.inspur.edp.lcm.metadata.api.IMetadataContent; +import com.inspur.edp.lcm.metadata.spi.MetadataContentSerializer; + +import java.io.IOException; + +/** + * @author shksatrt + * @DATE 2019/7/29 - 10:12 + */ +public class ContentSerializer implements MetadataContentSerializer { + + @Override + public JsonNode Serialize(IMetadataContent iMetadataContent) { +// throw new RuntimeException("vo未实现序列化"); + Context context = new Context(); + context.setfull(false); + VoThreadLoacl.set(context); + try { + String json = new ObjectMapper().writeValueAsString(iMetadataContent); + JsonNode jsonNode = new ObjectMapper().readTree(json); + return jsonNode; + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (RuntimeException e) { + throw new RuntimeException(e + ((GspViewModel) iMetadataContent).getGeneratingAssembly()); + }finally { + VoThreadLoacl.unset(); + } + } + + @Override + public IMetadataContent DeSerialize(JsonNode jsonNode) { + ObjectMapper mapper = new ObjectMapper(); + try { + GspViewModel vm=mapper.readValue(handleJsonString(jsonNode.toString()), GspViewModel.class); +// if(RefCommonContext.isInvokeAtDesignTime()){ +// if (vm.getMainObject().getMapping() != null && vm.getMainObject().getMapping().getSourceType() == GspVoObjectSourceType.BeObject) { +// LinkBeUtils linkUtil = new LinkBeUtils(); +// linkUtil.linkWithBe(vm); +// } +// } + return vm; + } catch (IOException e) { + throw new RuntimeException("vo元数据反序列化失败"+e); + } + } + + private static String handleJsonString(String contentJson) { + if (contentJson.startsWith("\"")) { + contentJson = contentJson.replace("\\\"", "\""); + while (contentJson.startsWith("\"")) { + contentJson = contentJson.substring(1, contentJson.length() - 1); + } + } + return contentJson; + } +} diff --git a/view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/TransferSerializer.java b/view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/TransferSerializer.java new file mode 100644 index 0000000..0d30f8e --- /dev/null +++ b/view-object-manager/src/main/java/com/inspur/edp/formserver/vmmanager/TransferSerializer.java @@ -0,0 +1,150 @@ +/* + * 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.formserver.vmmanager; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.inspur.edp.bef.bizentity.GspBusinessEntity; +import com.inspur.edp.cef.designtime.api.IGspCommonField; +import com.inspur.edp.cef.designtime.api.collection.GspAssociationCollection; +import com.inspur.edp.cef.designtime.api.collection.GspFieldCollection; +import com.inspur.edp.cef.designtime.api.element.GspAssociation; +import com.inspur.edp.cef.designtime.api.element.GspElementObjectType; +import com.inspur.edp.das.commonmodel.IGspCommonElement; +import com.inspur.edp.das.commonmodel.IGspCommonModel; +import com.inspur.edp.das.commonmodel.IGspCommonObject; +import com.inspur.edp.formserver.viewmodel.GspViewModel; +import com.inspur.edp.formserver.viewmodel.GspViewObject; +import com.inspur.edp.formserver.viewmodel.collection.VMElementCollection; +import com.inspur.edp.formserver.viewmodel.collection.ViewObjectCollection; +import com.inspur.edp.formserver.viewmodel.json.model.ViewModelDeserializer; +import com.inspur.edp.formserver.viewmodel.json.model.ViewModelSerializer; +import com.inspur.edp.formserver.vmmanager.exception.VmManagerException; +import com.inspur.edp.lcm.metadata.api.IMetadataContent; +import com.inspur.edp.lcm.metadata.api.entity.GspMetadata; +import com.inspur.edp.lcm.metadata.api.service.RefCommonService; +import com.inspur.edp.lcm.metadata.spi.MetadataTransferSerializer; +import io.iec.edp.caf.commons.exception.ExceptionLevel; +import io.iec.edp.caf.commons.utils.SpringBeanUtils; + +public class TransferSerializer implements MetadataTransferSerializer { + + + //region getMapper + + private ObjectMapper getMapper() { + ObjectMapper mapper = new ObjectMapper(); + SimpleModule module = new SimpleModule(); + module.addDeserializer(IGspCommonModel.class, new ViewModelDeserializer()); + module.addSerializer(IGspCommonModel.class, new ViewModelSerializer()); + mapper.registerModule(module); + return mapper; + } + + //endregion + + //region 序列化 + public final String serialize(IMetadataContent metadataContent) { + GspViewModel viewModel = (GspViewModel) ((metadataContent instanceof GspViewModel) ? metadataContent : null); +// dealContent(viewModel); + String modelJson = null; + try { + modelJson = getMapper().writeValueAsString(viewModel); + } catch (JsonProcessingException e) { + throw new RuntimeException("ViewModel序列化失败!"); + } + return modelJson; + } + + private void dealContent(GspViewModel viewModel) { + dealObject(viewModel.getMainObject()); + } + + private void dealObject(GspViewObject viewObject){ + + ViewObjectCollection childObjs = viewObject.getContainChildObjects(); + if(childObjs != null && childObjs.size() > 0){ + childObjs.forEach((childObj) -> { + dealObject((GspViewObject)childObj); + }); + } + + VMElementCollection eles = viewObject.getContainElements(); + if(eles != null && eles.size() > 0){ + eles.forEach((ele) -> { + dealElement(ele); + }); + } + } + + private void dealElement(IGspCommonField element){ + if(element.getObjectType() != GspElementObjectType.Association) + return; + + GspAssociationCollection assos = element.getChildAssociations(); + if(assos != null && assos.size() > 0){ + assos.forEach((asso) -> { + dealAssociation(asso); + }); + } + } + + private void dealAssociation(GspAssociation association){ + + GspFieldCollection refEles = association.getRefElementCollection(); + if(refEles != null && refEles.size() > 0){ + refEles.forEach((refEle) -> { + dealRefElement(association, refEle); + }); + } + } + + private void dealRefElement(GspAssociation association, IGspCommonField refElement){ + if(refElement.getObjectType() != GspElementObjectType.Association) + return ; + RefCommonService service= SpringBeanUtils.getBean(RefCommonService.class); + GspMetadata refMetadata = service.getRefMetadata(association.getRefModelID()); + if(refMetadata == null) + throw new VmManagerException("","", "关联be["+association.getRefModelID()+"] ["+association.getRefModelCode()+"]没有获取到。",null, ExceptionLevel.Error,false); + GspBusinessEntity refBe= (GspBusinessEntity) refMetadata.getContent(); + IGspCommonObject refObj = refBe.findObjectById(association.getRefObjectID()); + if(refObj == null) + throw new VmManagerException("","", "关联be["+association.getRefModelCode()+"]中没有获取到节点["+association.getRefObjectID()+"] ["+association.getRefObjectCode()+"]。",null, ExceptionLevel.Error,false); + + IGspCommonElement element = refObj.findElement(refElement.getRefElementId()); + if(element == null) + throw new VmManagerException("","", "关联be["+association.getRefModelCode()+"]中没有获取到字段["+refElement.getRefElementId()+"] ["+refElement.getLabelID()+"]。",null, ExceptionLevel.Error,false); + + refElement.getChildAssociations().addAll(element.getChildAssociations().clone()); + + dealElement(refElement); + } + //endregion + + + public final IMetadataContent deserialize(String contentString) { + GspViewModel viewModel = new GspViewModel(); + try { + viewModel = getMapper().readValue(contentString, GspViewModel.class); + } catch (JsonProcessingException e) { + throw new VmManagerException("","", "vo反序列化失败" + contentString ,null, ExceptionLevel.Error,false); + + } + return viewModel; + } +} -- Gitee