解析型支持传入对象名称,当获取对象展示名称时,若根据资源元数据获取不到则使用指定的对象名称
+ * @param entityCode 实体对象编码 + * @param displayValueKey 实体展示名称资源项Key + * @param modelResInfo 模型对象信息 + * @param entityId 实体对象Id + * @param entityName 对象名称 + */ + public CefEntityResInfoImpl(String entityCode, String displayValueKey, + CefModelResInfoImpl modelResInfo, String entityId, String entityName) { this.entityId = entityId; - entityTypeInfo = new CefEntityTypeInfo(entityCode, displayValueKey); + entityTypeInfo = new CefEntityTypeInfo(entityCode, entityName, displayValueKey); this.modelResInfo = modelResInfo; initColumns(); initUQConstraintInfos(); @@ -188,13 +202,13 @@ public abstract class CefEntityResInfoImpl extends EntityResInfo { @Override public final String getUniqueConstraintMessage(String uniqueConCode) { - return modelResInfo.getResourceItemValue( - entityTypeInfo.getUniqueConstraintInfos().get(uniqueConCode).getDisplayValueKey()); + UniqueConstraintInfo uniqueConstraintInfo = entityTypeInfo.getUniqueConstraintInfos().get(uniqueConCode); + return modelResInfo.getResourceItemValue(uniqueConstraintInfo.getDisplayValueKey(), uniqueConstraintInfo.getDefaultDisplayName()); } @Override - public final String getDisplayName() { - return modelResInfo.getResourceItemValue(entityTypeInfo.getDisplayValueKey()); + public String getDisplayName() { + return modelResInfo.getResourceItemValue(entityTypeInfo.getDisplayValueKey(), entityTypeInfo.getEntityName()); } public final String getI18nPrefix() { @@ -204,8 +218,9 @@ public abstract class CefEntityResInfoImpl extends EntityResInfo { @Override public String getPropertyDispalyName(String labelId) { - String resourceKey = entityTypeInfo.getPropertyInfos().get(labelId).getDisplayValueKey(); - return modelResInfo.getResourceItemValue(resourceKey); + DataTypePropertyInfo propertyInfo = entityTypeInfo.getPropertyInfos().get(labelId); + String resourceKey = propertyInfo.getDisplayValueKey(); + return modelResInfo.getResourceItemValue(resourceKey, propertyInfo.getDefaultDisplayName()); } @Override @@ -213,37 +228,29 @@ public abstract class CefEntityResInfoImpl extends EntityResInfo { DataTypePropertyInfo info = entityTypeInfo.getPropertyInfos().get(labelId); if (info != null) { if (info.getObjectType() == ObjectType.Enum) { - return modelResInfo.getResourceItemValue( - ((EnumPropertyInfo) info.getObjectInfo()).getEnumValueInfo(enumKey) - .getDisplayValueKey()); + EnumValueInfo enumValueInfo = ((EnumPropertyInfo) info.getObjectInfo()).getEnumValueInfo(enumKey); + return modelResInfo.getResourceItemValue(enumValueInfo.getDisplayValueKey(), enumValueInfo.getDefaultName()); } else if (info.getObjectInfo() instanceof SimpleEnumUdtPropertyInfo) { - return modelResInfo.getResourceItemValue( - (((SimpleEnumUdtPropertyInfo) info.getObjectInfo()).getEnumInfo()) - .getEnumValueInfo(enumKey) - .getDisplayValueKey()); + EnumValueInfo enumValueInfo = (((SimpleEnumUdtPropertyInfo) info.getObjectInfo()).getEnumInfo()) + .getEnumValueInfo(enumKey); + return modelResInfo.getResourceItemValue(enumValueInfo.getDisplayValueKey(), enumValueInfo.getDefaultName()); } } throw new CefRuntimeBaseException(ExceptionCode.CEF_RUNTIME_3014, labelId); } @Override - public String getAssoRefEnumPropertyDisplayValue(String labelId, String refEleCode, - String enumKey) { + public String getAssoRefEnumPropertyDisplayValue(String labelId, String refEleCode, String enumKey) { DataTypePropertyInfo dataTypePropertyInfo = entityTypeInfo.getPropertyInfo(labelId); - AssocationPropertyInfo associationPropertyInfo = (AssocationPropertyInfo) dataTypePropertyInfo - .getObjectInfo(); - DataTypePropertyInfo info = associationPropertyInfo.getAssociationInfo().getRefPropInfos() - .get(refEleCode); + AssocationPropertyInfo associationPropertyInfo = (AssocationPropertyInfo) dataTypePropertyInfo.getObjectInfo(); + DataTypePropertyInfo info = associationPropertyInfo.getAssociationInfo().getRefPropInfos().get(refEleCode); if (info.getObjectType() == ObjectType.Enum) { - return modelResInfo.getResourceItemValue( - ((EnumPropertyInfo) info.getObjectInfo()).getEnumValueInfo(enumKey) - .getDisplayValueKey()); + EnumValueInfo enumValueInfo = ((EnumPropertyInfo) info.getObjectInfo()).getEnumValueInfo(enumKey); + return modelResInfo.getResourceItemValue(enumValueInfo.getDisplayValueKey(), enumValueInfo.getDefaultName()); } else if (info.getObjectInfo() instanceof SimpleEnumUdtPropertyInfo) { - return modelResInfo.getResourceItemValue( - (((SimpleEnumUdtPropertyInfo) info.getObjectInfo()).getEnumInfo()) - .getEnumValueInfo(enumKey) - .getDisplayValueKey()); + EnumValueInfo enumValueInfo = (((SimpleEnumUdtPropertyInfo) info.getObjectInfo()).getEnumInfo()).getEnumValueInfo(enumKey); + return modelResInfo.getResourceItemValue(enumValueInfo.getDisplayValueKey(), enumValueInfo.getDefaultName()); } throw new CefRuntimeBaseException(ExceptionCode.CEF_RUNTIME_3014, labelId); } @@ -269,11 +276,10 @@ public abstract class CefEntityResInfoImpl extends EntityResInfo { @Override public String getAssoRefPropertyDisplay(String labelId, String refEleCode) { DataTypePropertyInfo dataTypePropertyInfo = entityTypeInfo.getPropertyInfo(labelId); -// AssocationPropertyInfo associationPropertyInfo = (AssocationPropertyInfo) dataTypePropertyInfo -// .getObjectInfo(); + AssocationPropertyInfo associationPropertyInfo = (AssocationPropertyInfo) dataTypePropertyInfo.getObjectInfo(); + DataTypePropertyInfo refPropertyInfo = associationPropertyInfo.getAssociationInfo().getRefPropertyInfo(refEleCode); //关联带出字段 - String displayKey = this.getDisplayPrefix() + "." + labelId + "." + refEleCode + ".Name"; - return this.modelResInfo.getResourceItemValue(displayKey); + return this.modelResInfo.getResourceItemValue(refPropertyInfo.getDisplayValueKey(), refPropertyInfo.getDefaultDisplayName()); } protected final void addChildEntityResInfo(EntityResInfo info) { diff --git a/common-entity-framework-spi/src/main/java/com/inspur/edp/cef/spi/entity/resourceInfo/builinImpls/CefModelResInfoImpl.java b/common-entity-framework-spi/src/main/java/com/inspur/edp/cef/spi/entity/resourceInfo/builinImpls/CefModelResInfoImpl.java index 16ac43ebfd68e61fc4304f00223fcb075e00925d..0476a5f78e55e8ed20eb9d0cdc74840155075b5e 100644 --- a/common-entity-framework-spi/src/main/java/com/inspur/edp/cef/spi/entity/resourceInfo/builinImpls/CefModelResInfoImpl.java +++ b/common-entity-framework-spi/src/main/java/com/inspur/edp/cef/spi/entity/resourceInfo/builinImpls/CefModelResInfoImpl.java @@ -17,11 +17,13 @@ package com.inspur.edp.cef.spi.entity.resourceInfo.builinImpls; import com.inspur.edp.cef.api.CefRtBeanUtil; -import com.inspur.edp.cef.api.message.CefException; import com.inspur.edp.cef.entity.exception.CefRuntimeBaseException; import com.inspur.edp.cef.spi.entity.resourceInfo.EntityResInfo; import com.inspur.edp.cef.spi.entity.resourceInfo.ModelResInfo; import com.inspur.edp.cef.spi.exception.ExceptionCode; +import io.iec.edp.caf.commons.utils.StringUtils; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import java.util.HashMap; import java.util.Map; @@ -30,6 +32,7 @@ import java.util.Stack; /** * 模型通用信息 */ +@Slf4j public abstract class CefModelResInfoImpl extends ModelResInfo { /** @@ -54,16 +57,36 @@ public abstract class CefModelResInfoImpl extends ModelResInfo { private EntityResInfo rootEntityResInfo; private Map根据资源项获取,若资源项中未找到,则使用默认元数据模型名称
+ * @return 模型名称 */ @Override public String getModelDispalyName() { - return getResourceItemValue(displayKey); + return getResourceItemValue(displayKey, metadataName); } /** @@ -120,14 +143,35 @@ public abstract class CefModelResInfoImpl extends ModelResInfo { } public final String getResourceItemValue(String resourceKey) { - String resValue = ""; try { - resValue = CefRtBeanUtil.getResourceItemValue(currentSu, resMetadataId, resourceKey); + return CefRtBeanUtil.getResourceItemValue(currentSu, resMetadataId, resourceKey); } catch (Exception ex) { String[] params = new String[]{currentSu, metaDataId, resMetadataId, resourceKey}; throw new CefRuntimeBaseException(ExceptionCode.CEF_RUNTIME_3032, ex, params); } - return resValue; + } + + /** + * 获取资源项值,若未获取到,则返回默认值 + * @param resourceKey 资源项key + * @param defaultValue 默认值 + * @return 获取资源项值,若未获取到,则返回默认值 + */ + public final String getResourceItemValue(String resourceKey, String defaultValue) { + try { + String resValue = getResourceItemValue(resourceKey); + if (!StringUtils.isEmpty(resValue)) { + return resValue; + } + } catch (Exception ex) { + log.error("根据[{}]未查询到对应的资源内容,使用默认值[{}]", resourceKey, defaultValue, ex); + return defaultValue == null? "" : defaultValue; + } + if (log.isDebugEnabled()) { + // 输出日志, newException以获取堆栈 + log.debug("根据[{}]未查询到对应的资源内容,使用默认值[{}]", resourceKey, defaultValue, new Exception()); + } + return defaultValue == null? "" : defaultValue; } /** diff --git a/common-entity-framework-variable-api/pom.xml b/common-entity-framework-variable-api/pom.xml index 641bff8e8632e1b95b2d7e1f6c056d3a231c3902..11c188e2d4e77fe382743b4795e7762290266804 100644 --- a/common-entity-framework-variable-api/pom.xml +++ b/common-entity-framework-variable-api/pom.xml @@ -22,7 +22,7 @@