use of alma.TMCDB.baci.ComponentData in project ACS by ACS-Community.
the class HibernateWDALImpl method getAlmaBranch.
protected Map<String, Object> getAlmaBranch() {
final Map<String, Object> almaRoot = new RootMap<String, Object>();
try {
Session session = hibernateUtil.getSession();
schemaResourceResolverLoader.setSession(session);
final Set<String> loadedComponents = new HashSet<String>();
//
if (plugin != null) {
final HibernateWDALPlugin.ControlDeviceBindCallback bindCallback = new HibernateWDALPlugin.ControlDeviceBindCallback() {
public void bindToComponentBranch(String name, String path, Object objectToBind) {
bindToAlmaBranch(almaRoot, name, path, objectToBind);
if (!loadedComponents.contains(path + "/" + name))
loadedComponents.add(path + "/" + name);
}
public void bindNonExpandedXMLToComponentBranch(Session session, Component component) {
alma.TMCDB.maci.Component comp = (alma.TMCDB.maci.Component) session.createCriteria(alma.TMCDB.maci.Component.class).add(Restrictions.eq("ComponentId", component.getComponentId())).uniqueResult();
if (comp == null)
throw new RuntimeException("Component with ID " + component.getComponentId() + " does not exist.");
bindNonExpandedComponentXMLToAlmaBranch(session, almaRoot, comp);
// TODO why do not add to already loaded components list??!!!
}
};
plugin.loadControlDevices(session, config, bindCallback);
}
//
// add devices
//
Iterator componentList = session.createCriteria(alma.TMCDB.maci.Component.class).add(Restrictions.eq("Control", false)).add(Restrictions.eq("ConfigurationId", configId)).list().iterator();
while (componentList.hasNext()) {
alma.TMCDB.maci.Component component = (alma.TMCDB.maci.Component) componentList.next();
// already loaded by plugins, skip
if (loadedComponents.contains(component.Path + "/" + component.getName()))
continue;
String query = "FROM alma.TMCDB.baci.BACIPropertyType WHERE ComponentId = " + component.ComponentId;
List propertyList = session.createQuery(query).list();
if (propertyList.size() > 0) {
ComponentData componentData = new ComponentData();
try {
componentData.setData(component.XMLDoc);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// add properties
for (Iterator iter = propertyList.iterator(); iter.hasNext(); ) {
BACIPropertyType baciProperty = (BACIPropertyType) iter.next();
//componentData._.put(baciProperty.PropertyName, baciProperty);
componentData._.put(baciProperty.PropertyName, new EmptyStringHandlerBACIPropertyType(baciProperty));
}
// bind object to map tree
bindToAlmaBranch(almaRoot, component.getName(), component.Path, componentData);
} else if (component.XMLDoc != null) {
bindNonExpandedComponentXMLToAlmaBranch(session, almaRoot, component);
}
}
} catch (Throwable th) {
th.printStackTrace();
}
return almaRoot;
}
use of alma.TMCDB.baci.ComponentData in project ACS by ACS-Community.
the class HibernateWDALImpl method updateAlmaBranch.
protected void updateAlmaBranch(String curl) {
m_logger.info("clear_cache(curl): AlmaBranch1");
Map<String, Object> rootMap = (Map<String, Object>) rootNode;
final Map<String, Object> almaRoot = (Map<String, Object>) rootMap.get(COMPONENT_TREE_NAME);
m_logger.info("clear_cache(curl): AlmaBranch2");
try {
Session session = hibernateUtil.getSession();
schemaResourceResolverLoader.setSession(session);
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): AlmaBranch3");
//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)));
//Remove the entries from existing maps.
System.out.println("\nChecking maps to remove");
m_logger.info("clear_cache(curl): AlmaBranch4");
Map rParentMap = almaRoot;
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 ComponentDAOImplSaver) {
System.out.println("Instance of ComponentDAOImplSaver (Component!).");
} else if (data instanceof ComponentData) {
System.out.println("Instance of ComponentData (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 = ((ComponentData) 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): AlmaBranch5");
final Set<String> loadedComponents = new HashSet<String>();
//
// add control devices
//
m_logger.info("clear_cache(curl): AlmaBranch6");
if (plugin != null) {
final HibernateWDALPlugin.ControlDeviceBindCallback bindCallback = new HibernateWDALPlugin.ControlDeviceBindCallback() {
public void bindToComponentBranch(String name, String path, Object objectToBind) {
bindToAlmaBranch(almaRoot, name, path, objectToBind);
if (!loadedComponents.contains(path + "/" + name))
loadedComponents.add(path + "/" + name);
}
public void bindNonExpandedXMLToComponentBranch(Session session, Component component) {
alma.TMCDB.maci.Component comp = (alma.TMCDB.maci.Component) session.createCriteria(alma.TMCDB.maci.Component.class).add(Restrictions.eq("ComponentId", component.getComponentId())).uniqueResult();
if (comp == null)
throw new RuntimeException("Component with ID " + component.getComponentId() + " does not exist.");
bindNonExpandedComponentXMLToAlmaBranch(session, almaRoot, comp);
}
};
plugin.updateControlDevices(session, config, bindCallback, curl);
}
m_logger.info("clear_cache(curl): AlmaBranch7");
//
// add devices
//
Iterator componentList = session.createCriteria(alma.TMCDB.maci.Component.class).add(Restrictions.eq("Control", false)).add(Restrictions.eq("ConfigurationId", configId)).add(cr).list().iterator();
System.out.println("\nFound the following Components");
m_logger.info("clear_cache(curl): AlmaBranch8");
while (componentList.hasNext()) {
alma.TMCDB.maci.Component component = (alma.TMCDB.maci.Component) componentList.next();
System.out.println(component.Path + "/" + component.getName());
// already loaded by plugins, skip
if (loadedComponents.contains(component.Path + "/" + component.getName()))
continue;
String query = "FROM alma.TMCDB.baci.BACIPropertyType WHERE ComponentId = " + component.ComponentId;
List propertyList = session.createQuery(query).list();
System.out.println("Size: " + propertyList.size());
if (propertyList.size() > 0) {
ComponentData componentData = new ComponentData();
try {
componentData.setData(component.XMLDoc);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// add properties
for (Iterator iter = propertyList.iterator(); iter.hasNext(); ) {
BACIPropertyType baciProperty = (BACIPropertyType) iter.next();
//componentData._.put(baciProperty.PropertyName, baciProperty);
componentData._.put(baciProperty.PropertyName, new EmptyStringHandlerBACIPropertyType(baciProperty));
}
// bind object to map tree
bindToAlmaBranch(almaRoot, component.getName(), component.Path, componentData);
} else if (component.XMLDoc != null) {
bindNonExpandedComponentXMLToAlmaBranch(session, almaRoot, component);
}
m_logger.info("clear_cache(curl): AlmaBranch9");
}
m_logger.info("clear_cache(curl): AlmaBranch10");
} catch (Throwable th) {
th.printStackTrace();
}
m_logger.info("clear_cache(curl): AlmaBranch11");
}
use of alma.TMCDB.baci.ComponentData in project ACS by ACS-Community.
the class HibernateWDALImpl method bindNonExpandedComponentXMLToAlmaBranch.
public void bindNonExpandedComponentXMLToAlmaBranch(Session session, Map<String, Object> parentMap, alma.TMCDB.maci.Component component) {
// from XMLDOC
if (component.URN != null) {
// now with XML create DAO object
// use CDB XML handler which does not creates strings...
XMLHandler xmlSolver = new XMLHandler(false, m_logger);
try {
synchronized (xmlNodeMonitor) {
saxParser.parse(new InputSource(new StringReader(component.XMLDoc)), xmlSolver);
}
} catch (Exception e) {
m_logger.log(AcsLogLevel.ERROR, "Failed to add component '" + component.Path + "/" + component.getName(), e);
return;
}
if (xmlSolver.m_errorString != null) {
m_logger.log(AcsLogLevel.ERROR, "Failed to add component '" + component.Path + "/" + component.getName() + "': XML parser error: " + xmlSolver.m_errorString);
return;
}
// create non-CORBA related, silent DAO
DAOImpl dao = new ComponentDAOImplSaver(component, xmlSolver.m_rootNode, null, m_logger, true);
// bind object to map tree
bindToAlmaBranch(parentMap, component.getName(), component.Path, dao);
} else {
m_logger.finer("No schema found for component " + component.Path + "/" + component.getName());
ComponentData componentData = new ComponentData();
try {
componentData.setData(component.XMLDoc);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// bind object to map tree
bindToAlmaBranch(parentMap, component.getName(), component.Path, componentData);
}
}
use of alma.TMCDB.baci.ComponentData in project ACS by ACS-Community.
the class HibernateWDALImpl method bindToAlmaBranch.
protected void bindToAlmaBranch(Map<String, Object> parentMap, String name, String path, Object objectToBind) {
// now find its submap
path = getNormalizedPath(path);
final String fullName = path + "/" + name;
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;
// hierarchical component (has it own XML) with children components
Object parentObj = parentMap.get(parentPath);
if (parentObj instanceof ComponentDAOImplSaver) {
m_logger.fine("Transforming non-hierachical to hierachical node for " + parentPath + " (of " + fullName + ")");
ComponentData cd = new ComponentData();
try {
cd.setData(((ComponentDAOImplSaver) parentObj).component.XMLDoc);
} catch (Throwable th) {
// should never happen, but still print it out
th.printStackTrace();
}
parentObj = cd;
parentMap.put(parentPath, parentObj);
}
ComponentData parentComponent = (ComponentData) parentObj;
if (parentComponent == null) {
parentComponent = new ComponentData();
parentMap.put(parentPath, parentComponent);
}
parentMap = parentComponent._;
path = subpath;
}
Object current = parentMap.get(name);
if (current != null) {
if (current instanceof ComponentData && objectToBind instanceof ComponentDAOImplSaver) {
m_logger.fine("Overriding XMLDoc of already bound node of " + fullName);
try {
((ComponentData) current).setData(((ComponentDAOImplSaver) objectToBind).component.XMLDoc);
} catch (Throwable th) {
// should never happen, but still print it out
th.printStackTrace();
}
} else if (current instanceof ComponentData && objectToBind instanceof ComponentData) {
m_logger.fine("Overriding XMLDoc of already bound node of " + fullName + ", but keeping its subnodes.");
((ComponentData) current).setData(((ComponentData) objectToBind).getExtraData());
} else {
// still override, but with warning
m_logger.warning("Overriding component node: " + fullName);
parentMap.put(name, objectToBind);
}
} else {
parentMap.put(name, objectToBind);
}
}
Aggregations