VoHelper
VoHelper
package com.isoftstone.pcis.policy.core.helper;
import com.isoftstone.fwk.dao.CommonDao;
import com.isoftstone.fwk.service.BusinessServiceException;
import com.isoftstone.fwk.util.BeanTool;
import com.isoftstone.fwk.util.SpringUtils;
import com.isoftstone.pcis.policy.core.exception.VoManipulateException;
import com.isoftstone.pcis.policy.vo.AbstractCvrgVO;
import com.isoftstone.pcis.prod.exception.ProductDefinitionException;
import com.isoftstone.pcis.prod.service.ProdService;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class VoHelper
{
public static String VO_TYPE_APP = "App";
public static String VO_TYPE_PLY = "Ply";
public static String ELEMENT_NAME = "Name";
public static String ELEMENT_CAPTION = "Caption";
public static String ELEMENT_NAME_PRODEF = "CNmeEn";
public static String ELEMENT_CAPTION_PRODEF = "CNmeCn";
private static final Log logger = LogFactory.getLog(VoHelper.class);
private static String voPkg = "com.isoftstone.pcis.policy.vo";
private static String voUdrPkg = "com.isoftstone.pcis.policy.app.underwrite.vo";
public static Class getVoClass(String componentName, String voType) {
String className = voPkg + "." + getVoClassName(componentName, voType);
try {
return Class.forName(className);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}return null;
}
public static Class getAppVoClass(String componentName)
{
String className = voPkg + "." + getAppVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Class getPlyVoClass(String componentName)
{
String className = voPkg + "." + getPlyVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Class getUdrVoClass(String componentName)
{
String className = voUdrPkg + "." + getUdrVoClassName(componentName);
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
logger.error("Class.forName(" + className + ") 出现异常。");
}return null;
}
public static Object createAppEntryVo(String componentName)
{
Class c = getAppVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static Object createPlyEntryVo(String componentName)
{
Class c = getPlyVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static Object createUdrEntryVo(String componentName)
{
Class c = getUdrVoClass(componentName);
try {
if (c != null) {
return c.newInstance();
}
return null;
} catch (InstantiationException e) {
logger.error(e.getMessage());
return null;
} catch (IllegalAccessException e) {
logger.error(e.getMessage());
}return null;
}
public static String getVoClassName(String componentName, String voType)
{
return voType + componentName + "VO";
}
public static String getAppVoClassName(String componentName)
{
return "App" + componentName + "VO";
}
public static String getPlyVoClassName(String componentName)
{
return "Ply" + componentName + "VO";
}
public static String getUdrVoClassName(String componentName)
{
return "Undr" + componentName + "VO";
}
public static String getComponentNameOfVo(Object entry)
{
String[] pathArray = entry.getClass().getName().split("\\.");
String voName = pathArray[(pathArray.length - 1)];
String featureName = null;
if ((voName.matches("^App")) || (!voName.matches("VO$")))
featureName = voName.replaceAll("^App", "").replaceAll("VO$", "");
else if ((voName.matches("^Ply")) || (!voName.matches("VO$"))) {
featureName = voName.replaceAll("^Ply", "").replaceAll("VO$", "");
}
return featureName;
}
public static void serializePlyVo() {
CommonDao dao = (CommonDao)SpringUtils.getSpringBean("commonDao");
}
public static boolean hasPkId(Object vo) throws VoManipulateException
{
try {
Map propertyMap = BeanUtils.describe(vo);
if (propertyMap.containsKey("CPkId")) {
return true;
}
return false;
}
catch (Exception e) {
throw new VoManipulateException("判断vo是否有CPkId字段时出错", e);
}
}
public static String getOrigPkId(Object vo)
throws VoManipulateException
{
try
{
String origRowId = BeanUtils.getProperty(vo, "CRowId");
if (origRowId != null) {
return origRowId;
}
return BeanUtils.getProperty(vo, "CPkId");
}
catch (Exception e)
{
throw new VoManipulateException("获得vo[" + vo.getClass().getName() + "]原始id时出错", e);
}
}
public static Long getSeqNoIgnoreException(Object vo) {
try {
return (Long)PropertyUtils.getProperty(vo, "NSeqNo");
} catch (Exception e) {
logger.warn("忽略获得seqno时出错");
}return null;
}
public static Map<String, Map<String, Object>> compareEntry(Object oldEntry, Object newEntry, Set<String> propSet)
throws VoManipulateException
{
try
{
propSet.remove("class");
Map diffMap = new HashMap();
for (String propName : propSet) {
Object oldValue = PropertyUtils.getProperty(oldEntry, propName);
Object newValue = PropertyUtils.getProperty(newEntry, propName);
if ((oldValue != null) || (newValue != null))
{
if ((oldValue != null) && (newValue != null))
{
if ((oldValue instanceof Date)) {
if (DateUtils.isSameDay((Date)oldValue, (Date)newValue)) {
continue;
}
}
else {
if ((oldValue instanceof Double) ?
Double.compare(((Double)oldValue).doubleValue(), ((Double)newValue).doubleValue()) == 0 :
oldValue.equals(newValue))
{
continue;
}
}
}
Map diff = new HashMap();
diff.put("old", oldValue);
diff.put("new", newValue);
diffMap.put(propName, diff);
}
}
return diffMap;
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static Map<String, Map<String, Object>> compareEntryEx(Object oldEntry, Object newEntry, Set<String> excludePropSet)
throws VoManipulateException
{
try
{
Map propMap = BeanUtils.describe(oldEntry);
Set propSet = new HashSet();
propSet.addAll((Collection)propMap.keySet());
propSet.removeAll(excludePropSet);
return compareEntry(oldEntry, newEntry, propSet);
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static Map<String, Map<String, Object>> compareEntry(Object oldEntry, Object newEntry)
throws VoManipulateException
{
try
{
Map propMap = BeanUtils.describe(oldEntry);
Set propSet = new HashSet();
propSet.addAll((Collection)propMap.keySet());
return compareEntry(oldEntry, newEntry, propSet);
} catch (Exception e) {
throw new VoManipulateException("比较失败", e);
}
}
public static List<String> getKeyNameList(String prodNo, String componentName)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
return prodService.getProdEleNmeEn(prodNo, componentName);
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<String> getCoverageKeyNameList(String prodNo, String cvrgNo)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
return prodService.getProdEleNmeEn(prodNo, "Cvrg",
cvrgNo);
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<Map<String, String>> getKeyNameCaptionMapList(String prodNo, String componentName)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
List elemNameMapList = prodService.getProdEleNme(prodNo, componentName, null);
List nameLabelMapList = new ArrayList();
for (Map elemNameMap : elemNameMapList) {
String complexName = (String)elemNameMap.get("CNmeEn");
String[] nameSects = complexName.split("\\.");
Map nameLabelMap = new HashMap();
nameLabelMap.put(ELEMENT_NAME_PRODEF, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION_PRODEF, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMap.put(ELEMENT_NAME, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMapList.add(nameLabelMap);
}
return nameLabelMapList;
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static List<Map<String, String>> getCoverageKeyNameCaptionMapList(String prodNo, String cvrgNo)
throws ProductDefinitionException
{
try
{
ProdService prodService = (ProdService)SpringUtils.getSpringBean("prodService");
List elemNameMapList = prodService.getProdEleNme(prodNo,
"Cvrg", cvrgNo);
List nameLabelMapList = new ArrayList();
for (Map elemNameMap : elemNameMapList) {
String complexName = (String)elemNameMap.get("CNmeEn");
String[] nameSects = complexName.split("\\.");
Map nameLabelMap = new HashMap();
nameLabelMap.put(ELEMENT_NAME_PRODEF, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION_PRODEF, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMap.put(ELEMENT_NAME, nameSects[1]);
nameLabelMap.put(ELEMENT_CAPTION, (String)elemNameMap.get(ELEMENT_CAPTION_PRODEF));
nameLabelMapList.add(nameLabelMap);
}
return nameLabelMapList;
} catch (BusinessServiceException e) {
throw new ProductDefinitionException("获得保单要素分类关键字异常", e);
}
}
public static String getKeyValueAsStr(Object entry, List<String> keyNameList)
throws VoManipulateException
{
try
{
if ((keyNameList != null) && (!keyNameList.isEmpty())) {
String[] elemValues = new String[keyNameList.size()];
for (int i = 0; i < keyNameList.size(); i++) {
String attrName = ((String)keyNameList.get(i)).substring(
((String)keyNameList.get(i)).indexOf(".") + 1);
String aValue = BeanTool.getAttributeValueAsString(entry, attrName);
elemValues[i] = aValue;
}
return StringUtils.join(elemValues, "-%-");
}
if ((entry instanceof AbstractCvrgVO)) {
return ((AbstractCvrgVO)entry).getCCvrgNo();
}
Long seqNo = getSeqNoIgnoreException(entry);
if (seqNo != null) {
return seqNo.toString();
}
return null;
}
catch (Exception e)
{
throw new VoManipulateException("生成要素关键标识描述时异常", e);
}
}
}
VoHelper的更多相关文章
随机推荐
- 如何使页面滚动条移动到指定元素element的位置处?
如何使页面滚动条移动到指定元素element的位置处? 在用selenium做测试时,会遇到需要操作的元素不在当前可视页面中的情况,如果是手工测试,自然很简单,手动拖拽滚动条到目标元素处即可. 那么, ...
- 51nod1349 最大值
还是傻叉单调栈 #include<cstdio> #include<cstring> #include<cctype> #include<algorithm& ...
- Flume环境部署和配置详解及案例大全
flume是一个分布式.可靠.和高可用的海量日志采集.聚合和传输的系统.支持在日志系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(比如文本.HDF ...
- Jqgrid入门-Jqgrid格式化数据(九)
上一章已经说明了在Jqgrid中如何对数据分组,这一章主要探讨如何格式化Jqgrid中的数据.何谓格式化呢?举个例子,比如对时间格式化处理,去掉后面的时分秒:对数字进行处理,加上千分位分隔符,小数的保 ...
- mysql大数据导出导入
1)导出 select * from users into outfile '/tmp/users.txt';或 select * from users where sex=1 into outfil ...
- 信息熵 Information Theory
信息论(Information Theory)是概率论与数理统计的一个分枝.用于信息处理.信息熵.通信系统.数据传输.率失真理论.密码学.信噪比.数据压缩和相关课题.本文主要罗列一些基于熵的概念及其意 ...
- HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6
现在有一个字符串"MI",这个字符串可以遵循以下规则进行转换: 1.Mx 可以转换成 Mxx ,即 M 之后的所有字符全部复制一遍(MUI –> MUIUI) 2.III 可 ...
- 【原创】搭建Nginx(负载均衡)+Redis(Session共享)+Tomcat集群
为什么移除首页?哪里不符合要求?倒是回我邮件啊! 一.环境搭建 Linux下Vagrant搭建Tomcat7.Java7 二.Nginx的安装配置与测试 *虚拟机下转至root sudo -i 1)下 ...
- RDoc
RDoc - Ruby Documentation System home github.com/rdoc/rdoc rdoc docs.seattlerb.org/rdoc bugs github. ...
- 恢复SD卡错删数据
对于众多米粉来说,手机里存储的很多资料都非常宝贵,如果不小心删除了,想要重新收集这些资料就显得非常困难.有道是千金易得,数据无价,特别是一些珍贵照片之类的充满回忆的数据,丢失了甚至会抱憾 ...