package com.vci.server.cache;
|
|
import java.util.List;
|
import java.util.ArrayList;
|
import java.util.Comparator;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.corba.omd.btm.BtmItem;
|
import com.vci.corba.omd.etm.EnumItem;
|
import com.vci.corba.omd.lcm.LifeCycle;
|
import com.vci.corba.omd.ltm.LinkType;
|
import com.vci.corba.omd.stm.StatePool;
|
import com.vci.corba.omd.vrm.VersionRule;
|
import com.vci.server.cache.redis.RedisUtil;
|
|
public final class OMCacheProvider {
|
|
public static AttribItem getAttribute(String name) {
|
String attrObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, name);
|
if (StringUtils.isBlank(attrObj))
|
return null;
|
|
return JSONObject.parseObject(attrObj, AttribItem.class);
|
}
|
|
public static AttribItem[] getAttributes(String[] names) {
|
List<AttribItem> lstAI = new ArrayList<AttribItem>();
|
for (int i = 0; i < names.length; i++) {
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, names[i]);
|
if (StringUtils.isBlank(jsonObj))
|
continue;
|
|
lstAI.add(JSONObject.parseObject(jsonObj, AttribItem.class));
|
}
|
|
lstAI.sort(new Comparator<AttribItem>() {//使用List接口的方法排序
|
@Override
|
public int compare(AttribItem o1, AttribItem o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstAI.toArray(new AttribItem[0]);
|
}
|
|
public static AttribItem[] getAttributes() {
|
List<AttribItem> lstAI = new ArrayList<AttribItem>();
|
|
Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.ATTRITEMS);
|
String[] jsons = map.values().toArray(new String[0]);
|
for (int i = 0; i < jsons.length; i++) {
|
if (StringUtils.isBlank(jsons[i]))
|
continue;
|
|
lstAI.add(JSONObject.parseObject(jsons[i], AttribItem.class));
|
}
|
|
lstAI.sort(new Comparator<AttribItem>() {//使用List接口的方法排序
|
@Override
|
public int compare(AttribItem o1, AttribItem o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstAI.toArray(new AttribItem[0]);
|
}
|
|
public static boolean existAttribute(String name) {
|
if (StringUtils.isBlank(name))
|
return false;
|
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return false;
|
|
return true;
|
}
|
|
public static EnumItem getEnumType(String name) {
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.ENUMTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return null;
|
|
return JSONObject.parseObject(jsonObj, EnumItem.class);
|
}
|
|
public static boolean existEnumType(String name) {
|
if (StringUtils.isBlank(name))
|
return false;
|
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.ENUMTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return false;
|
|
return true;
|
}
|
|
public static EnumItem[] getEnumTypeByFilter(String filter) {
|
|
Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.ENUMTYPES);
|
|
boolean isFilter = !StringUtils.isBlank(filter);
|
|
List<EnumItem> lstET = new ArrayList<EnumItem>();
|
String[] jsons = map.values().toArray(new String[0]);
|
for (String json : jsons) {
|
if (StringUtils.isBlank(json))
|
continue;
|
|
EnumItem item = JSONObject.parseObject(json, EnumItem.class);
|
if (isFilter) {
|
if (item.name.contains(filter))
|
lstET.add(item);
|
} else {
|
lstET.add(item);
|
}
|
}
|
|
lstET.sort(new Comparator<EnumItem>() {//使用List接口的方法排序
|
@Override
|
public int compare(EnumItem o1, EnumItem o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstET.toArray(new EnumItem[0]);
|
}
|
|
public static StatePool getLifeState(String name) {
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.LIFESTATES, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return null;
|
|
return JSONObject.parseObject(jsonObj, StatePool.class);
|
}
|
|
public static StatePool[] getLifeStates() {
|
List<StatePool> lstState = new ArrayList<StatePool>();
|
|
Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.LIFESTATES);
|
String[] jsons = map.values().toArray(new String[0]);
|
for (int i = 0; i < jsons.length; i++) {
|
if (StringUtils.isBlank(jsons[i]))
|
continue;
|
|
lstState.add(JSONObject.parseObject(jsons[i], StatePool.class));
|
}
|
|
lstState.sort(new Comparator<StatePool>() {//使用List接口的方法排序
|
@Override
|
public int compare(StatePool o1, StatePool o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstState.toArray(new StatePool[0]);
|
}
|
|
|
public static LifeCycle getLifeCycle(String name) {
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.LIFECYCLES, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return null;
|
|
return JSONObject.parseObject(jsonObj, LifeCycle.class);
|
}
|
|
public static LifeCycle[] getLifeCycles() {
|
List<LifeCycle> lstLC = new ArrayList<LifeCycle>();
|
|
Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.LIFECYCLES);
|
String[] jsons = map.values().toArray(new String[0]);
|
for (int i = 0; i < jsons.length; i++) {
|
if (StringUtils.isBlank(jsons[i]))
|
continue;
|
|
lstLC.add(JSONObject.parseObject(jsons[i], LifeCycle.class));
|
}
|
|
lstLC.sort(new Comparator<LifeCycle>() {//使用List接口的方法排序
|
@Override
|
public int compare(LifeCycle o1, LifeCycle o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstLC.toArray(new LifeCycle[0]);
|
}
|
|
/**
|
* 获取事件key
|
*
|
* @throws Throwable
|
*/
|
public static String[] getLCEventKeys() {
|
Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.LCEVENTS);
|
|
return map.keySet().toArray(new String[0]);
|
}
|
|
/**
|
* 获取事件value
|
*
|
* @throws Throwable
|
*/
|
|
public static String getLCEventValue(String key) throws Throwable {
|
return RedisUtil.getInstance().hget(CacheNames.LCEVENTS, key);
|
}
|
|
public static VersionRule getVersionRule(String name) {
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.VERRULES, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return null;
|
|
return JSONObject.parseObject(jsonObj, VersionRule.class);
|
}
|
|
public static VersionRule[] getVersionRules() {
|
List<VersionRule> lstVR = new ArrayList<VersionRule>();
|
|
Map<String, String> map = RedisUtil.getInstance().hgetAll(CacheNames.VERRULES);
|
String[] jsons = map.values().toArray(new String[0]);
|
for (int i = 0; i < jsons.length; i++) {
|
if (StringUtils.isBlank(jsons[i]))
|
continue;
|
|
lstVR.add(JSONObject.parseObject(jsons[i], VersionRule.class));
|
}
|
|
lstVR.sort(new Comparator<VersionRule>() {//使用List接口的方法排序
|
@Override
|
public int compare(VersionRule o1, VersionRule o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstVR.toArray(new VersionRule[0]);
|
}
|
|
|
public static BtmItem getBizType(String name) {
|
String btObj = RedisUtil.getInstance().hget(CacheNames.BIZTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(btObj))
|
return null;
|
|
return JSONObject.parseObject(btObj, BtmItem.class);
|
}
|
|
public static BtmItem[] getBizTypes() {
|
Map<String, String> allBTs = RedisUtil.getInstance().hgetAll(CacheNames.BIZTYPES);
|
|
List<BtmItem> lstObj = new ArrayList<BtmItem>();
|
String[] items = allBTs.values().toArray(new String[0]);
|
for (int i = 0; i < items.length; i++) {
|
lstObj.add(JSONObject.parseObject(items[i], BtmItem.class));
|
}
|
|
lstObj.sort(new Comparator<BtmItem>() {//使用List接口的方法排序
|
@Override
|
public int compare(BtmItem o1, BtmItem o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstObj.toArray(new BtmItem[0]);
|
}
|
|
public static BtmItem[] getChildrenBizTypes(String btName) {
|
Map<String, String> allBTs = RedisUtil.getInstance().hgetAll(CacheNames.BIZTYPES);
|
|
List<BtmItem> lstBT = new ArrayList<BtmItem>();
|
String[] items = allBTs.values().toArray(new String[0]);
|
for (int i = 0; i < items.length; i++) {
|
BtmItem bt = JSONObject.parseObject(items[i], BtmItem.class);
|
if (bt.fName.equals(btName))
|
lstBT.add(bt);
|
}
|
|
lstBT.sort(new Comparator<BtmItem>() {//使用List接口的方法排序
|
@Override
|
public int compare(BtmItem o1, BtmItem o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstBT.toArray(new BtmItem[0]);
|
}
|
|
public static String[] getBTAttributes(String name) {
|
String btObj = RedisUtil.getInstance().hget(CacheNames.BIZTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(btObj))
|
return new String[0];
|
|
BtmItem bt = JSONObject.parseObject(btObj, BtmItem.class);
|
if (bt != null)
|
return bt.apNameArray;
|
|
return new String[0];
|
}
|
|
|
public static AttribItem[] getAttribItemsByBizType(String name) {
|
String btObj = RedisUtil.getInstance().hget(CacheNames.BIZTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(btObj))
|
return new AttribItem[0];
|
|
BtmItem bt = JSONObject.parseObject(btObj, BtmItem.class);
|
if (bt == null)
|
return new AttribItem[0];
|
|
List<AttribItem> lstAI = new ArrayList<AttribItem>();
|
for (int i = 0; i < bt.apNameArray.length; i++) {
|
String attrObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, bt.apNameArray[i]);
|
if (StringUtils.isBlank(attrObj))
|
continue;
|
|
lstAI.add(JSONObject.parseObject(attrObj, AttribItem.class));
|
}
|
|
return lstAI.toArray(new AttribItem[0]);
|
}
|
|
|
public static LinkType getLinkType(String name) {
|
String attrObj = RedisUtil.getInstance().hget(CacheNames.LINKTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(attrObj))
|
return null;
|
|
return JSONObject.parseObject(attrObj, LinkType.class);
|
}
|
|
public static LinkType[] getLinkTypes() {
|
Map<String, String> allLTs = RedisUtil.getInstance().hgetAll(CacheNames.LINKTYPES);
|
|
List<LinkType> lstObj = new ArrayList<LinkType>();
|
String[] items = allLTs.values().toArray(new String[0]);
|
for (int i = 0; i < items.length; i++) {
|
lstObj.add(JSONObject.parseObject(items[i], LinkType.class));
|
}
|
|
lstObj.sort(new Comparator<LinkType>() {//使用List接口的方法排序
|
@Override
|
public int compare(LinkType o1, LinkType o2) {
|
return o1.name.toLowerCase().compareTo(o2.name.toLowerCase());
|
}
|
});
|
|
return lstObj.toArray(new LinkType[0]);
|
}
|
|
|
public static String[] getLTAttributes(String name) {
|
String jsonObj = RedisUtil.getInstance().hget(CacheNames.LINKTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(jsonObj))
|
return new String[0];
|
|
LinkType lt = JSONObject.parseObject(jsonObj, LinkType.class);
|
if (lt != null)
|
return lt.attributes;
|
|
return new String[0];
|
}
|
|
|
public static AttribItem[] getAttribItemsByLinkType(String name) {
|
String btObj = RedisUtil.getInstance().hget(CacheNames.LINKTYPES, name.toLowerCase());
|
if (StringUtils.isBlank(btObj))
|
return new AttribItem[0];
|
|
BtmItem bt = JSONObject.parseObject(btObj, BtmItem.class);
|
if (bt == null)
|
return new AttribItem[0];
|
|
List<AttribItem> lstAI = new ArrayList<AttribItem>();
|
for (int i = 0; i < bt.apNameArray.length; i++) {
|
String attrObj = RedisUtil.getInstance().hget(CacheNames.ATTRITEMS, bt.apNameArray[i]);
|
if (StringUtils.isBlank(attrObj))
|
continue;
|
|
lstAI.add(JSONObject.parseObject(attrObj, AttribItem.class));
|
}
|
|
return lstAI.toArray(new AttribItem[0]);
|
}
|
|
}
|