欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

SiebelAdapter--具体干事的类,

发布时间:2023/12/16 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 SiebelAdapter--具体干事的类, 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

继承关系
OrderEntryServiceImpl extends AbstractBase implements OrderEntryService
AbstractBase implements AdapterConfig :内部获取Aapter,调用各种方法。
interface Adapter
SiebelAdapter implements Adapter
具体请看:
SiebelAdapter.java —适配器实现类
联动 ExceptionWithCode, JDBFactory

public class SiebelAdapter<Z extends BaseModel> implements Adapter<Z>{public static final Logger logger = LoggerFactory.getLogger(SiebelAdapter.class);protected AdapterConfig<Z> config;public AdapterConfig<Z> getConfig(){return config;}public void setConfig( AdapterConfig<Z> config){this.config = config;}//1;获取适配器配置public Z getConfigByModel(Z model){return fillProperties(getConfig(),model);}public Z fillProperties(AdapterConfig<Z> adapter, Z model){if(StringUtils.isBlank(model.getBusinessComponeseName())){ model.setBusinessComponeseName(adapter.getBCName())}//BC,BO,IC,IO,PBC一样,我就不写了.基本就是在各个实现类中 重写AdapterConfig接口的方法.return model;}//2:getMappingfinal private Map<String ,String> getMapping(){Map<String ,String> mapping = new LinkedHashMap<>();if(mapping.isEmpty() ){Map<String ,String> map = getConfig().getRawMapping();if( map != null ){map.put("Id","rowId");map.put("Created","createTime");map.put("Created By","creatorId");mapping.putAll(map);}}return mapping;}//3,4 getExpress/getOrExpress 条件拼接。public final String getExpress (List<String> exprList){StringBuffer expr = new String Buffer();for(String e : exprList){if( expr.length() > 0 ) expr.append(" and ");expr.append(e);}return expr.toString();}public final String getOrExpress (List<String> exprList){StringBuffer expr = new String Buffer();for(String e : exprList){if( expr.length() > 0 ) expr.append(" or");expr.append(e);}return expr.toString();}//5通过查询 取得数据的列表public List<Z> getList(Z model) throws Exception{return getList( model, getConfig().getListExpress(model) );}public List<Z> getListByBs(Z model) throws Exception{return getListByBs( model,getConfig().getListExpress(model) );}//--通过查询 取得数据的列表public List<Z> getList(Z model,String expr) throws Exception{Z modelconfig = getConfigByModel(model);//得到具体有Bo,BC,IC,IO配置的模型if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");} --BO未指定if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}--BC未指定/从这里可以看出来,在具体的实现类中必须 重写BO,BC方法,指明其名字,否则将报错。List<Z> retlist = new LinkedList<Z>();//获取siebel--数据对象SiebelDataBean sdb = JDBFactory.getSiebelDataBean(); try{ getConfigInfo(sdb);//获取siebel--BO对象SiebelBusObject busObject = sdb.getBusObject(modelconfig.getBusinessObjectNameI());//获取siebel--BC对象,及其父BC对象 try{ SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName()); try{ SiebelBusComp pc = busComp.parentBusComp();//激活BC字段activateField( getFieldOpt(busComp),model );if(expr != null && expr.length() > 0){//条件表达式,传进来的busComp.clearToQuery();busComp.setSearchExpr(expr); }logger.info(String.format("ViewMode : [%s] ,BO : [%s], BC : [%s], SearchExpr : {%s}",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCName(),expr) );//BC设置排序配置 if(StringUtils.isNotNullOrEmptyStr(getConfig().getSortSpec(model))){ busComp.setSortSpec( getConfig().getSortSpec(model) );}busComp.setViewModel( model.getViewType);//bc设置视图busComp.executeQuery2(false,false);//执行查询?//busComp.executeQuery(true);int count = 0;//啥意思?妈的,查列表 都这么复杂的吗?if( busComp.firstRecord() ){Z m = convert(model.getFieldOpt(busComp));count++;m.setPageRowNo(count);retlist.add(m);while(busComp.nextRecord()){retlist.add(convert(model,getFieldOpt(busComp)));}}return retlist;}finally{busComp.release();}//首先释放BC}finally{busObject.release();}//再次释放BO}finally{JDBFactory.freeSiebelDataBean(sdb);}//最后释放Siebel数据模型 } //**6**.getListByBS 通过BS 获取列表 public List<Z> getListByBs(Z model ,String expr) throws Exception{Z modelconfig = getConfigByModel(model);//得到具体有Bo,BC,IC,IO配置的模型if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//1:获取siebel--数据对象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{getConfigInfo(sdb);//2:创建输入,出Siebel属性集合SiebelPropertySet inpPS = sdb.newPropertySet(); SiebelPropertySet outPS = sdb.newPropertySet(); SiebelService oBS = sdb.getService("SHYY Upload Attachment Service Test");//3:给输入Siebel集合设值inpPS .setProperty("BusObject",modelconfig.getBOName()); //给集合设值inpPS .setProperty("BusComp",modelconfig.getBCName()); inpPS .setProperty("ViewMode",String.format(%d"",model.getViewType())); if(expr != null && expr.legnth() > 0 ){ inpPS.setProperty("SearchExpr",expr); }if(StringUtils.isNotNullOrEmptyStr(getConfig().getSortSpec())){inpPS.setProperty("SortSpec",getConfig().getSortSpec());} //4:创建输入Siebel参数集合SiebelPropertySet inpPS_PARAMS = sdb.newPropertySet();//5:得到实现类中的参数映射Map<String ,String > map = getMapping();for(String key : map){inpPS_PARAMS .setProperty(key,key); //把实现类中的key(BC字段),作为参数.}inpPS.addChild(inpPS_PARAMS ); //子BC?//控制台打印日志:logger.info(String.format("ViewMode : [%s] ,BO : [%s], BC : [%s], SearchExpr : {%s}",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCName(),expr) );//调用BS方法oBS.invokeMethod("Action",inpPS,outPS);List<Z> retlist = new LinkedList<>();for( int i = 0; i < outPS.getChildCount(); i++){SiebelPropertySet childPS = outPS.getChild(i);//得到每一个子属性集合Z m = convert(model,childPS);String rowId = m.getRowId();boolean found = false;for(Z z : retlist){if(rowId.equals(z.getRowId())){found = true;break;}} if(!fount){retlist.add(m);}return retlist; }finally{JDBFactory.freeSiebelDateBean(sdb);}} } //**7**添加数据 public void add(Z model) throws Exception{addAndGetRowId(model); } public String addAndGetRowId(Z model) throws Exception{//1:得到具体有Bo,BC,IC,IO配置的模型Z modelconfig = getConfigByModel(model);if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//2:获取siebel--数据对象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{ getConfigInfo(sdb);//3:获取siebel--BO对象SiebelBusObject busObj = sdb.getBusObject(modelconfig.getBusinessObjectName());try{Map<String, String > map = getConfig().getParentList(model);if(map != null ){for(String bcName : map.KeySet()){String rowId = map.get(bcName);if(StringUtils.isNotNullOrEmptyStr(rowId)){SiebelBusComp parentbusComp = busObject.getBusComp(bcname);parentbusComp.setViewMode(3);parentbusComp.setSearchExpr("[Id] = '"+rowId+"'");parentbusComp.executeQuery2(true,true);if( !parentbusComp.firstRecord()){throw new Exception("父BC中,查不到相关记录")}}}}SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());try{if(model.isAdminModel()){busComp.invokeMethod("SetAdminMode",new String[] {"TRUE"});logger.info("SetAdminMode TRUE");}activateField(getFieldOpt(busComp),model);busComp.setViewMode(model.getViewMode());busComp.setSearchExpr("1<>1");busComp.executeQuery2(true,true);busComp.newRecord(true);setFieldValue(busComp,getFieldOpt(busComp),model);busComp.writeRecord();logger.info(String.format( "ViewMode: [%s], BO :[%s] , BC : [%s] ,[Id] : %s ",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCNaem(), busComp.getFieldValue("Id")));String id = busComp.getFieldValue("Id");model.setRowId(id);return id; }finally{if(model.isAdminMode()){busComp.invokeMethod("SetAdminMode",new String[] {"FALSE"});logger.info("SetAdminMode false");}busComp.release();} }finally{busObject.release(); } }finally{JDBFactory.freeSiebelDataBean(); } //还有批量添加. //**8** 批量添加 public List<String> batAddAndGetRowIds(List<Z> list) throws Exception{if( list == null || list.isEmpty() ) throws new Exception("没有数据需要添加");if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//1:获取siebel--数据对象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{getConfigInfo(sdb);//3:获取siebel--BO对象SiebelBusObject busObj = sdb.getBusObject(modelconfig.getBusinessObjectName());try{Map<String, String > map = getConfig().getParentList( list.get(0) );if(map != null ){for(String bcName : map.KeySet()){String rowId = map.get(bcName);if(StringUtils.isNotNullOrEmptyStr(rowId)){SiebelBusComp parentbusComp = busObject.getBusComp(bcname);parentbusComp.setViewMode(3);parentbusComp.setSearchExpr("[Id] = '"+rowId+"'");parentbusComp.executeQuery2(true,true);if( !parentbusComp.firstRecord()){throw new Exception("父BC中,查不到相关记录")}}}} SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());activateField(getFieldOpt(busComp),list.get(0));busComp.setViewMode(model.getViewMode());busComp.setSearchExpr("1<>1");busComp.executeQuery2(true,true);List<String> retlist = new LinkedList<>();for(Z model : retlist){busComp.newRecord(true);setFieldValue( busComp,getFieldOpt(busComp ),model );busComp.writeRecord();String id = busComp.getFieldValue("id");model.setRowId(id);retlist.add(id);} logger.info(String.format( "ViewMode: [%s], BO :[%s] , BC : [%s] ,[Id] : %s ",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCNaem(), busComp.getFieldValue("Id"))); return retlist; }finally{busComp.release();} }finally{busObject.release();} }finally{JDBFactory.freeSiebelDataBean(sdb);} } //**9** 更新数据 public void update(Z model) throws Exception{if( StringUtils.isBlank( model.getRowId()) ){throw new Exception("未指定对应的RowId ,操作无法继续");}//1:得到具体有Bo,BC,IC,IO配置的模型Z modelconfig = getConfigByModel(model);if(StringUtils.isBlank(modelconfig.getBOName())){ throw new ExceptionWithCode("0010");}if(StringUtils.isBlank(modelconfig.getBCName())){ throw new ExceptionWithCode("0011");}//2:获取siebel--数据对象SiebelDataBean sdb = JDBFactory.getSiebelDataBean();try{ getConfigInfo(sdb);//3:获取siebel--BO对象SiebelBusObject busObj = sdb.getBusObject(modelconfig.getBusinessObjectName());try{Map<String, String > map = getConfig().getParentList(model);if(map != null ){for(String bcName : map.KeySet()){String rowId = map.get(bcName);if(StringUtils.isNotNullOrEmptyStr(rowId)){SiebelBusComp parentbusComp = busObject.getBusComp(bcname);parentbusComp.setViewMode(3);parentbusComp.setSearchExpr("[Id] = '"+rowId+"'");parentbusComp.executeQuery2(true,true);if( !parentbusComp.firstRecord()){throw new Exception("父BC中,查不到相关记录")}}}}SiebelBusComp busComp = busObject.getBusComp(modelconfig.getBusinessComponeseName());try{if(model.isAdminModel()){busComp.invokeMethod("SetAdminMode",new String[] {"TRUE"});logger.info("SetAdminMode TRUE");}activateField(getFieldOpt(busComp),model);busComp.setViewMode(model.getViewMode());busComp.cleatToQuery();logger.info(String.format( "ViewMode: [%s], BO :[%s] , BC : [%s] ,[Id] : %s ",model.getViewType(),modelconfig.getBOName(),modelconfig.getBCNaem(), busComp.getFieldValue("Id")));busComp.setSearchSpec( "Id",model.getRowId() );busComp.executeQuery2(true,true);if( busComp.firstRecord() ){setFieldValue(busComp,getFiledOpt(busComp), model);busComp.writeRecord();return;}throw new Exception("记录没有找到");}finally{if(model.isAdminModel()){busComp.invokeMethod("SetAdminMode",new String[] {"TRUE"});logger.info("SetAdminMode TRUE");}busComp.release();}finally{busObject.release();}}finally{JDBFactory.freeSiebelDataBean(sdb);}} //增删改查基本都是这样,批量的情况下把model 换成list.get(0) }//转换参数 String[] ------ String :{"a","b","c"}---a,b,c private static final String convert(String[] param ){ if(param ==null){ return "";} StringBuffer sb = new StringBuffer();for(String p : param){if( sb.length()>0 ) sb.append(',');sb.append(p);} return sb.toString(); } //还有好多,太他妈多了,日乐购了。 final private void activateField(SiebelBusComp pickBusComp,MVGBaseModel model ) throws Exception{Map<String ,String > map = model.getMapping();for(String key : map.keySet()){if(StringUtils.isBlank(key)) continue;pickBusComp.activateField(key);} } //设置全局变量:就是新建一个map 放一个自定义变量进去,在放入参数 public Map<String,String> profileAttrs(List<String> attrList) throws Exception{SiebelDataBean sdb = JDBFactory.getSiebelDataBean();//这里有日志打印,校验siebel连接的try{getConfigInfo(sdb);//这里有日志打印,---设置用户信息到CurrentConfigModel的。Map<String,String> retmap = new LinkedHashMap<String,String>();for(String key : attrList){retMap.put(key,sdb.getProfileAttr(key));//Siebel那边的方法}logger.info(String.format("profileAttrs:[%s]",retmap.toString()));return retmap; }finally{JDBFactory.freeSiebelDataBean();} } public void profileSetAttrs( Map<String,String> attrList )throws Exception{SiebelDataBean sdb = JDBFactory.getSiebelDataBean();//这里有日志打印,校验siebel连接的try{getConfigInfo(sdb);//这里有日志打印,---设置用户信息到CurrentConfigModel的。Map<String,String> retmap = new LinkedHashMap<String,String>();for(String key : attrList){sdb.setProfileAttr(key,attrList.get(key));logger.info(String.format("profileAttrs:[%s = %s]",key,attrList.get(key)));}}finally{JDBFactory.freeSiebelDataBean();}} //忘记了一个很重要的方法,这个可以解释为什么CurrentConfigModel 有值。就是登录接口中的。 private static final void getConfigInfo(SiebelDataBean sdb){CurrentConfigModel = null ;try{config = SystemUtils.getCurrentConfigModel(); //这一步不要忘记了,同步副本信息。这样可以拿到同一个。不然//副本中的还是空的。下面就可以 设值了。}catch(Exception e){e.printStackTrace();}if( config == null ) return ; //其实第一次登录这个绝对是空的。if( sdb.positionId().equals(config.getPositionId()) ) return;//把siebel数据模型的数据 设置到CurrentConfigModel中。但是我不明白,为什么sdb中有值?、config.setPositionId(sdb.positionId());config.setPositinName(sdb.positionName());config.setLoginId(sdb.loginId());config.setLoginName(sdb.loginName()); try{config.setOrganizationLoc(sdb.getProfileAttr("Organization Loc")); }catch(SiebelException e){e.printStackTrace();}logger.info(String.format("用户配置信息被设置!")); }}//类尾

总结

以上是生活随笔为你收集整理的SiebelAdapter--具体干事的类,的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。