Search in sources :

Example 1 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALImpl method updateContainersTableMap.

public void updateContainersTableMap(String curl) {
    m_logger.info("clear_cache(curl): ContainersTable1");
    final String keyField = "Name";
    final Class type = alma.TMCDB.maci.Container.class;
    Map<String, Object> rootMap = (Map<String, Object>) rootNode;
    Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) rootMap.get("MACI")).get("Containers");
    m_logger.info("clear_cache(curl): ContainersTable2");
    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 ");
            }
        }
        m_logger.info("clear_cache(curl): ContainersTable3");
        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): ContainersTable4");
        //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)));
        m_logger.info("clear_cache(curl): ContainersTable5");
        List list = getListForConfiguration(session, type, cr);
        m_logger.info("clear_cache(curl): ContainersTable6");
        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): ContainersTable7");
        Map 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.Container) {
                    System.out.println("Instance of Container (Container!).");
                } else if (data instanceof alma.TMCDB.maci.ContainerNode) {
                    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.ContainerNode) 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): ContainersTable8");
        // Sort the list by path + component to ensure that parent containers are added before their children
        Comparator<alma.TMCDB.maci.Container> comparator = new Comparator<alma.TMCDB.maci.Container>() {

            public int compare(alma.TMCDB.maci.Container o1, alma.TMCDB.maci.Container o2) {
                String fullName1 = ((o1.Path == null ? "" : o1.Path) + "/") + o1.getName();
                String fullName2 = ((o2.Path == null ? "" : o2.Path) + "/") + o2.getName();
                return fullName1.compareTo(fullName2);
            }
        };
        Collections.sort(list, comparator);
        m_logger.info("clear_cache(curl): ContainersTable9");
        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.Container container = (alma.TMCDB.maci.Container) data;
            // do not include this
            if (DUMMY_CONTAINER_FLAG.equals(container.getDeployInfo().getTypeModifiers()))
                continue;
            // some cleaning
            if (container.getDeployInfo() != null && container.getDeployInfo().getHost() == null)
                container.setDeployInfo(null);
            // now find its map
            String path = getNormalizedPath(container.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.ContainerNode parentContainer = (alma.TMCDB.maci.ContainerNode) parentMap.get(parentPath);
                if (parentContainer == null) {
                    parentContainer = new alma.TMCDB.maci.ContainerNode();
                    parentMap.put(parentPath, parentContainer);
                }
                parentMap = parentContainer._;
                path = subpath;
            }
            // unique key generation
            int count = 0;
            String key = baseKey;
            while (parentMap.containsKey(key)) key = baseKey + String.valueOf(++count);
            parentMap.put(key, data);
            if (data instanceof alma.TMCDB.maci.Container) {
                alma.TMCDB.maci.Container cont = (alma.TMCDB.maci.Container) data;
                m_logger.finer("Loaded container name=" + cont.Path + cont.getName() + ", implLang=" + cont.getImplLang());
            } else {
                m_logger.warning("Bad container class '" + data.getClass().getName() + "' read from TMCDB.");
            }
            m_logger.info("clear_cache(curl): ContainersTable10");
        }
        m_logger.info("clear_cache(curl): ContainersTable11");
    } catch (Throwable th) {
        th.printStackTrace();
    }
    m_logger.info("clear_cache(curl): ContainersTable12");
}
Also used : Method(java.lang.reflect.Method) Comparator(java.util.Comparator) Field(java.lang.reflect.Field) Container(alma.acs.tmcdb.Container) Criterion(org.hibernate.criterion.Criterion) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Session(org.hibernate.Session)

Example 2 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap 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");
}
Also used : Channels(alma.TMCDB.maci.Channels) EventChannel(alma.acs.tmcdb.EventChannel) Field(java.lang.reflect.Field) Container(alma.acs.tmcdb.Container) Criterion(org.hibernate.criterion.Criterion) EventChannelNode(alma.TMCDB.maci.EventChannelNode) NotificationServiceMapping(alma.acs.tmcdb.NotificationServiceMapping) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) EventChannelNode(alma.TMCDB.maci.EventChannelNode) Map(java.util.Map) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Session(org.hibernate.Session)

Example 3 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap 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;
}
Also used : RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) ComponentData(alma.TMCDB.baci.ComponentData) EmptyStringHandlerBACIPropertyType(alma.TMCDB.baci.EmptyStringHandlerBACIPropertyType) BACIPropertyType(alma.TMCDB.baci.BACIPropertyType) HibernateWDALPlugin(com.cosylab.cdb.jdal.hibernate.plugin.HibernateWDALPlugin) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Component(alma.acs.tmcdb.Component) EmptyStringHandlerBACIPropertyType(alma.TMCDB.baci.EmptyStringHandlerBACIPropertyType) Session(org.hibernate.Session) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 4 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap in project ACS by ACS-Community.

the class HibernateWDALImpl method clear_cache.

public void clear_cache(String curl) {
    System.out.println("clear_cache(curl)");
    if (loadInProgress.get()) {
        m_logger.warning("Incoming Corba call denied (NO_RESOURCES) because data is being loaded.");
        throw new NO_RESOURCES("load in progress");
    }
    curl = curl.replaceAll("/+", "/");
    //Reload curl data from DB
    if (curl.matches("/")) {
        System.out.println("clear_cache_all()");
        clear_cache_all();
        return;
    } else {
        loadInProgress.set(true);
        m_logger.info("clear_cache(curl): Main1");
        try {
            hibernateUtil.getSession().clear();
        } catch (Throwable th) {
            th.printStackTrace();
        }
        m_logger.info("clear_cache(curl): Main2");
        String c = curl.replaceFirst("^/", "");
        c = curl.replaceFirst("/$", "");
        if (plugin != null) {
            try {
                Map<String, Object> rootMap = (Map<String, Object>) rootNode;
                Session session = hibernateUtil.getSession();
                plugin.updatePrologue(session, config, rootMap, c);
            } catch (Throwable th) {
                this.m_logger.log(Level.SEVERE, "Failure in plugin " + plugin.getClass().getName(), th);
                th.printStackTrace();
            }
        }
        m_logger.info("clear_cache(curl): Main3");
        if (c.startsWith("MACI")) {
            loadMACI(c, true);
        //} else if (c.startsWith("Alarms"){
        //	loadAlarms(c);
        } else if (c.startsWith(COMPONENT_TREE_NAME)) {
            loadComponentsTree(c, true);
        } else {
            System.out.println("Unsupported curl: " + curl);
        }
        m_logger.info("clear_cache(curl): Main4");
        if (plugin != null) {
            try {
                Map<String, Object> rootMap = (Map<String, Object>) rootNode;
                Session session = hibernateUtil.getSession();
                plugin.updateEpilogue(session, config, rootMap, c);
            } catch (Throwable th) {
                this.m_logger.log(Level.SEVERE, "Failure in plugin " + plugin.getClass().getName(), th);
                th.printStackTrace();
            }
        }
        m_logger.info("clear_cache(curl): Main5");
        loadInProgress.set(false);
    }
    //Set<String> curls = new HashSet<String>();
    //curls.add(curl);
    //synchronized (daoMap) {
    //	Iterator iter = daoMap.keySet().iterator();
    //	while (iter.hasNext()) {
    //		String c = (String) iter.next();
    //		if(c.startsWith(curl))
    //			curls.add(c);
    //	}
    //}
    //synchronized (wdaoMap) {
    //	Iterator iter = wdaoMap.keySet().iterator();
    //	while (iter.hasNext()) {
    //		String c = (String) iter.next();
    //		if(c.startsWith(curl))
    //			curls.add(c);
    //	}
    //}
    //
    //synchronized (listenedCurls) {
    //	Iterator iter = listenedCurls.keySet().iterator();
    //	while (iter.hasNext()) {
    //		String c = (String) iter.next();
    //		if(c.startsWith(curl))
    //			curls.add(c);
    //	}
    //}
    Set<String> curls = new HashSet<String>();
    synchronized (daoMap) {
        curls.addAll(daoMap.keySet());
    }
    m_logger.info("clear_cache(curl): Main6");
    synchronized (wdaoMap) {
        curls.addAll(wdaoMap.keySet());
    }
    m_logger.info("clear_cache(curl): Main7");
    synchronized (listenedCurls) {
        Iterator iter = listenedCurls.keySet().iterator();
        while (iter.hasNext()) {
            String c = (String) iter.next();
            curls.add(c);
        }
    }
    m_logger.info("clear_cache(curl): Main8");
    for (String c : curls) clearCache(c);
    m_logger.info("clear_cache(curl): Main9");
}
Also used : Iterator(java.util.Iterator) Map(java.util.Map) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES) Session(org.hibernate.Session) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 5 with RootMap

use of com.cosylab.cdb.jdal.hibernate.RootMap 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");
}
Also used : EmptyStringHandlerBACIPropertyType(alma.TMCDB.baci.EmptyStringHandlerBACIPropertyType) BACIPropertyType(alma.TMCDB.baci.BACIPropertyType) Criterion(org.hibernate.criterion.Criterion) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Component(alma.acs.tmcdb.Component) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ComponentData(alma.TMCDB.baci.ComponentData) HibernateWDALPlugin(com.cosylab.cdb.jdal.hibernate.plugin.HibernateWDALPlugin) Map(java.util.Map) RootMap(com.cosylab.cdb.jdal.hibernate.RootMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) EmptyStringHandlerBACIPropertyType(alma.TMCDB.baci.EmptyStringHandlerBACIPropertyType) Session(org.hibernate.Session)

Aggregations

RootMap (com.cosylab.cdb.jdal.hibernate.RootMap)14 ArrayList (java.util.ArrayList)13 LinkedList (java.util.LinkedList)11 List (java.util.List)11 Session (org.hibernate.Session)11 HashMap (java.util.HashMap)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 Field (java.lang.reflect.Field)6 Method (java.lang.reflect.Method)6 Criterion (org.hibernate.criterion.Criterion)5 ClientLogManager (alma.acs.logging.ClientLogManager)3 Component (alma.acs.tmcdb.Component)3 Container (alma.acs.tmcdb.Container)3 Comparator (java.util.Comparator)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 LinkedHashSet (java.util.LinkedHashSet)3 AlarmDefinition (alma.TMCDB.alarm.AlarmDefinition)2 AlarmSystemConfiguration (alma.TMCDB.alarm.AlarmSystemConfiguration)2