use of alma.TMCDB.maci.EventChannelNode in project ACS by ACS-Community.
the class HibernateWDALImpl method updateChannelsTableMap.
public void updateChannelsTableMap(String curl) {
m_logger.info("clear_cache(curl): ChannelsTable1");
final String keyField = "Name";
final Class type = alma.TMCDB.maci.EventChannel.class;
Map<String, Object> rootMap = (Map<String, Object>) rootNode;
Channels channels = (Channels) ((Map<String, Object>) rootMap.get("MACI")).get("Channels");
m_logger.info("clear_cache(curl): ChannelsTable2");
try {
Session session = hibernateUtil.getSession();
Method accessor = DOMJavaClassIntrospector.getAccessorMethod(type, keyField);
Field field = null;
if (accessor == null) {
try {
field = type.getField(keyField);
} catch (Throwable th) {
throw new IllegalStateException("failed to obtain key ");
}
}
if (channels == null)
channels = new Channels();
Map<String, EventChannelNode> map;
map = channels._;
m_logger.info("clear_cache(curl): ChannelsTable3");
alma.TMCDB.maci.NotificationServiceMapping mapping = (alma.TMCDB.maci.NotificationServiceMapping) session.createCriteria(alma.TMCDB.maci.NotificationServiceMapping.class).add(Restrictions.eq("ConfigurationId", configId)).uniqueResult();
m_logger.info("clear_cache(curl): ChannelsTable4");
if (mapping != null) {
channels.setNotificationServiceMapping(mapping);
}
m_logger.info("clear_cache(curl): ChannelsTable5");
String[] els = curl.split("/");
String rpath = "^/*";
String rsubpath = "^/*";
String rcpath = "^/*";
String rcname = els[els.length - 1];
for (int i = 0; i < els.length; i++) {
rpath += els[i];
rsubpath += els[i];
if (i < els.length - 1) {
rpath += "/+";
rsubpath += "/+";
rcpath += els[i];
if (i < els.length - 2)
rcpath += "/+";
}
}
rpath += "/*$";
rsubpath += "/+.*";
rcpath += "/*$";
System.out.println(rpath);
System.out.println(rsubpath);
System.out.println(rcpath + "|" + rcname);
m_logger.info("clear_cache(curl): ChannelsTable6");
//Consider the cases where the curl matches exactly the Path, where
//it is part of the path and when it matches exactly the path and
//the component name.
Criterion cr = Restrictions.disjunction().add(getRegularExpressionRestriction("Path", rpath)).add(getRegularExpressionRestriction("Path", rsubpath)).add(Restrictions.and(getRegularExpressionRestriction("Path", rcpath), Restrictions.eq("Name", rcname)));
List list = getListForConfiguration(session, type, cr);
m_logger.info("clear_cache(curl): ChannelsTable7");
System.out.println("\nFound the following Containers");
for (Object data : list) {
System.out.println(((alma.TMCDB.maci.Container) data).Path + "/" + ((alma.TMCDB.maci.Container) data).getName());
}
//Remove the entries from existing maps.
System.out.println("\nChecking maps to remove");
m_logger.info("clear_cache(curl): ChannelsTable8");
Map<String, EventChannelNode> rParentMap = map;
for (int i = 0; i < els.length; i++) {
System.out.println("Checking path " + els[i] + ".");
System.out.println("Parent keys: " + rParentMap.keySet().toString());
Object data = rParentMap.get(els[i]);
if (data == null) {
System.out.println("No element found with the given curl");
break;
} else {
if (data instanceof alma.TMCDB.maci.EventChannel) {
System.out.println("Instance of EventChannel (EventChannel!).");
} else if (data instanceof alma.TMCDB.maci.EventChannelNode) {
System.out.println("Instance of ContainerNode (Path!).");
} else {
System.out.println("Unknown type! Details: " + data.toString());
}
if (i < els.length - 1) {
System.out.println("There are elements remaining, so we proceed to next element in path.");
rParentMap = ((alma.TMCDB.maci.EventChannelNode) data)._;
} else {
System.out.println("There are no elements remaining, we remove all entries from this element in path and on.");
rParentMap.remove(els[i]);
}
}
}
m_logger.info("clear_cache(curl): ChannelsTable9");
for (Object data : list) {
String baseKey;
if (accessor != null)
baseKey = accessor.invoke(data, (Object[]) null).toString();
else
//if (field != null)
baseKey = field.get(data).toString();
// baseKey should not be null
Map parentMap = map;
alma.TMCDB.maci.EventChannel channel = (alma.TMCDB.maci.EventChannel) data;
// now find its map
String path = getNormalizedPath(channel.Path);
while (path != null && path.length() > 0) {
// remove trailing slashes, to have unique curl (used for key)
if (path.charAt(0) == '/') {
path = path.substring(1);
continue;
}
int pos = path.indexOf('/');
String parentPath = (pos > 0) ? path.substring(0, pos) : path;
String subpath = (pos > 0) ? path.substring(pos + 1, path.length()) : null;
alma.TMCDB.maci.EventChannelNode parentChannel = (alma.TMCDB.maci.EventChannelNode) parentMap.get(parentPath);
if (parentChannel == null) {
parentChannel = new alma.TMCDB.maci.EventChannelNode();
parentMap.put(parentPath, parentChannel);
}
parentMap = parentChannel._;
path = subpath;
}
// unique key generation
int count = 0;
String key = baseKey;
while (parentMap.containsKey(key)) key = baseKey + String.valueOf(++count);
parentMap.put(key, data);
m_logger.info("clear_cache(curl): ChannelsTable10");
}
m_logger.info("clear_cache(curl): ChannelsTable11");
} catch (Throwable th) {
th.printStackTrace();
}
m_logger.info("clear_cache(curl): ChannelsTable12");
}
use of alma.TMCDB.maci.EventChannelNode in project ACS by ACS-Community.
the class HibernateWDALImpl method getChannelsTableMap.
public Object getChannelsTableMap() {
final String keyField = "Name";
final Class type = alma.TMCDB.maci.EventChannel.class;
try {
Session session = hibernateUtil.getSession();
Method accessor = DOMJavaClassIntrospector.getAccessorMethod(type, keyField);
Field field = null;
if (accessor == null) {
try {
field = type.getField(keyField);
} catch (Throwable th) {
throw new IllegalStateException("failed to obtain key ");
}
}
boolean channelsExist = false;
Channels channels = new Channels();
alma.TMCDB.maci.NotificationServiceMapping mapping = (alma.TMCDB.maci.NotificationServiceMapping) session.createCriteria(alma.TMCDB.maci.NotificationServiceMapping.class).add(Restrictions.eq("ConfigurationId", configId)).uniqueResult();
if (mapping != null) {
channels.setNotificationServiceMapping(mapping);
channelsExist = true;
}
List list = getListForConfiguration(session, type);
if (list.size() > 0) {
channelsExist = true;
}
Map<String, EventChannelNode> map;
if (channelsExist) {
map = channels._;
} else {
//map = new RootMap<String, EventChannelNode>();
return null;
}
for (Object data : list) {
String baseKey;
if (accessor != null)
baseKey = accessor.invoke(data, (Object[]) null).toString();
else
//if (field != null)
baseKey = field.get(data).toString();
// baseKey should not be null
Map parentMap = map;
alma.TMCDB.maci.EventChannel channel = (alma.TMCDB.maci.EventChannel) data;
// now find its map
String path = getNormalizedPath(channel.Path);
while (path != null && path.length() > 0) {
// remove trailing slashes, to have unique curl (used for key)
if (path.charAt(0) == '/') {
path = path.substring(1);
continue;
}
int pos = path.indexOf('/');
String parentPath = (pos > 0) ? path.substring(0, pos) : path;
String subpath = (pos > 0) ? path.substring(pos + 1, path.length()) : null;
alma.TMCDB.maci.EventChannelNode parentChannel = (alma.TMCDB.maci.EventChannelNode) parentMap.get(parentPath);
if (parentChannel == null) {
parentChannel = new alma.TMCDB.maci.EventChannelNode();
parentMap.put(parentPath, parentChannel);
}
parentMap = parentChannel._;
path = subpath;
}
// unique key generation
int count = 0;
String key = baseKey;
while (parentMap.containsKey(key)) key = baseKey + String.valueOf(++count);
parentMap.put(key, data);
}
return channels;
} catch (Throwable th) {
th.printStackTrace();
}
return null;
}
Aggregations