Example usage for org.hibernate.criterion Restrictions and

List of usage examples for org.hibernate.criterion Restrictions and

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions and.

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:com.cosylab.cdb.jdal.HibernateWDALImpl.java

License:Open Source License

protected void updateComponentsTableMap(String curl) {
    m_logger.info("clear_cache(curl): ComponentsTable1");
    final String keyField = "Name";
    final Class type = alma.TMCDB.maci.Component.class;
    Map<String, Object> rootMap = (Map<String, Object>) rootNode;
    Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) rootMap.get("MACI"))
            .get("Components");
    m_logger.info("clear_cache(curl): ComponentsTable2");
    try {// w  ww .  java  2  s.com
        Session session = hibernateUtil.getSession();

        Method accessor = DOMJavaClassIntrospector.getAccessorMethod(type, keyField);
        m_logger.info("clear_cache(curl): ComponentsTable3");
        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): ComponentsTable4");

        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): ComponentsTable5");

        //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): ComponentsTable6");
        List list = getListForConfiguration(session, type, cr);
        m_logger.info("clear_cache(curl): ComponentsTable7");

        System.out.println("\nFound the following Components");
        for (Object data : list) {
            System.out.println(((alma.TMCDB.maci.Component) data).Path + "/"
                    + ((alma.TMCDB.maci.Component) data).getName());
        }
        m_logger.info("clear_cache(curl): ComponentsTable8");

        //Remove the entries from existing maps.
        System.out.println("\nChecking maps to remove");
        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.Component) {
                    System.out.println("Instance of Component (Component!).");
                } else if (data instanceof alma.TMCDB.maci.ComponentNode) {
                    System.out.println("Instance of ComponentNode (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.ComponentNode) 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): ComponentsTable9");

        // Sort the list by path + component to ensure that parent components are added before their children
        Comparator<alma.TMCDB.maci.Component> comparator = new Comparator<alma.TMCDB.maci.Component>() {
            public int compare(alma.TMCDB.maci.Component o1, alma.TMCDB.maci.Component 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): ComponentsTable10");

        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.Component component = (alma.TMCDB.maci.Component) data;

            // some cleaning
            if (component.getComponentLogger().getMinLogLevel() == -1
                    && component.getComponentLogger().getMinLogLevelLocal() == -1)
                component.setComponentLogger(null);

            // now find its map
            String path = getNormalizedPath(component.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.ComponentNode parentComponent = (alma.TMCDB.maci.ComponentNode) parentMap
                        .get(parentPath);
                if (parentComponent == null) {
                    parentComponent = new alma.TMCDB.maci.ComponentNode();
                    parentMap.put(parentPath, parentComponent);
                }

                parentMap = parentComponent._;
                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.Component) {
                alma.TMCDB.maci.Component comp = (alma.TMCDB.maci.Component) data;
                m_logger.finer(
                        "Loaded component name=" + comp.Path + comp.getName() + ", type=" + comp.getType()
                                + ", container=" + comp.getContainer() + ", implLang=" + comp.getImplLang());
            } else {
                m_logger.warning("Bad component class '" + data.getClass().getName() + "' read from TMCDB.");
            }

            m_logger.info("clear_cache(curl): ComponentsTable11");
        }
        m_logger.info("clear_cache(curl): ComponentsTable12");

    } catch (Throwable th) {
        th.printStackTrace();
    }
    m_logger.info("clear_cache(curl): ComponentsTable13");
}

From source file:com.cosylab.cdb.jdal.HibernateWDALImpl.java

License:Open Source License

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 {/*w  w  w .  java  2 s .  c o  m*/
        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");
}

From source file:com.cosylab.cdb.jdal.HibernateWDALImpl.java

License:Open Source License

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 {/*www.j a va 2s.  c o  m*/
        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");
}

From source file:com.cosylab.cdb.jdal.HibernateWDALImpl.java

License:Open Source License

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 {//from w ww . j  a v  a  2  s  . c  om
        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()) {
        //   Object data = componentList.next();
        //   System.out.println(((alma.TMCDB.maci.Component)data).Path+"/"+((alma.TMCDB.maci.Component)data).getName());
        //}

        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");
}

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateEventDao.java

License:Mozilla Public License

private Criteria getEventCriteria(List<String> eventActions, User user, Date startTime, Date stopTime,
        Set<Integer> appIds, Set<Integer> teamIds, Set<Integer> vulnIds, Set<Integer> defectIds) {
    Criteria criteria = getSession().createCriteria(getClassReference()).add(Restrictions.eq("active", true));

    criteria.createAlias("scan", "scan", Criteria.LEFT_JOIN);
    criteria.createAlias("application", "application", Criteria.LEFT_JOIN);
    criteria.createAlias("application.organization", "application.organization", Criteria.LEFT_JOIN);
    criteria.createAlias("vulnerability", "vulnerability", Criteria.LEFT_JOIN);
    criteria.createAlias("defect", "defect", Criteria.LEFT_JOIN);

    if ((eventActions != null) && (!eventActions.isEmpty())) {
        criteria.add(Restrictions.in("eventAction", eventActions));
    }/*from  ww  w . j  a v a2 s .c  o m*/

    if (user != null) {
        criteria.add(Restrictions.eq("user", user));
    }

    if (startTime != null) {
        criteria.add(Restrictions.ge("date", startTime));
    }
    if (stopTime != null) {
        criteria.add(Restrictions.lt("date", stopTime));
    }

    Criterion associationRestrictions = null;
    if ((appIds != null) && (!appIds.isEmpty())) {
        associationRestrictions = disjoinRestrictions(associationRestrictions,
                Restrictions.in("application.id", appIds));
    }
    if ((teamIds != null) && (!teamIds.isEmpty())) {
        associationRestrictions = disjoinRestrictions(associationRestrictions,
                Restrictions.in("application.organization.id", teamIds));
    }
    if ((vulnIds != null) && (!vulnIds.isEmpty())) {
        associationRestrictions = disjoinRestrictions(associationRestrictions,
                Restrictions.in("vulnerability.id", vulnIds));
        if ((defectIds != null) && (!defectIds.isEmpty())) {
            associationRestrictions = disjoinRestrictions(associationRestrictions, Restrictions
                    .and(Restrictions.in("defect.id", defectIds), Restrictions.isNull("vulnerability.id")));
        }
    } else if ((defectIds != null) && (!defectIds.isEmpty())) {
        associationRestrictions = disjoinRestrictions(associationRestrictions,
                Restrictions.in("defect.id", defectIds));
    }
    if (associationRestrictions != null) {
        criteria.add(associationRestrictions);
    }

    Order order = getOrder();
    if (order != null) {
        criteria.addOrder(order);
    }

    return criteria;
}

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateUserDao.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override/*from   w  w  w  .jav  a 2s  .c  om*/
public List<User> retrieveAppPermissibleUsers(Integer orgId, Integer appId) {

    List<User> globalUserList = getActiveUserCriteria().add(Restrictions.eq("hasGlobalGroupAccess", true))
            .addOrder(Order.asc("name")).list();
    List<User> appAllUserList = getActiveUserCriteria().add(Restrictions.eq("hasGlobalGroupAccess", false))
            .createAlias("accessControlTeamMaps", "teamMap")
            .add(Restrictions.and(Restrictions.eq("teamMap.allApps", true),
                    Restrictions.eq("teamMap.organization.id", orgId)))
            .addOrder(Order.asc("name")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
    List<User> appUserList = getActiveUserCriteria().add(Restrictions.eq("hasGlobalGroupAccess", false))
            .createAlias("accessControlTeamMaps", "teamMap")
            .createAlias("teamMap.accessControlApplicationMaps", "appMap")
            .add(Restrictions.and(Restrictions.eq("teamMap.allApps", false),
                    Restrictions.eq("appMap.application.id", appId)))
            .addOrder(Order.asc("name")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
    globalUserList.addAll(appUserList);
    for (User u : appAllUserList)
        if (!globalUserList.contains(u))
            globalUserList.add(u);

    return globalUserList;
}

From source file:com.ephesoft.dcma.da.dao.hibernate.ServiceStatusDaoImpl.java

License:Open Source License

@Override
public List<ServiceStatus> getServiceStatusListForServer(final ServerRegistry serverRegistry,
        final ServiceType serviceType) {
    LOGGER.debug(EphesoftStringUtil.concatenate("Getting status of service: ", serviceType.toString(),
            "for Server: ", serverRegistry.getIpAddress()));
    final DetachedCriteria detachedCriteria = criteria();
    detachedCriteria.add(Restrictions.and(Restrictions.eq(SERVER_REGISTRY, serverRegistry),
            Restrictions.eq(SERVICE_TYPE, serviceType)));
    final List<ServiceStatus> serviceStatusList = find(detachedCriteria);
    if (!CollectionUtil.isEmpty(serviceStatusList)) {
        LOGGER.debug(EphesoftStringUtil.concatenate("Status of service list", serviceType.toString(),
                "is under: ", serverRegistry.getIpAddress()));
    } else {/*from w  w  w.  j  a  va  2  s.c  o m*/
        LOGGER.debug(EphesoftStringUtil.concatenate("Status of service list", serviceType.toString(),
                "is not under given server"));
    }
    return serviceStatusList;
}

From source file:com.esp.dao.GenericDAO.java

@Override
public List<T> findUniqueMultiple(Class<T> entity, String property1, String Property2, Object value1,
        Object value2) {//from   w  w w.ja  va2  s  . co m

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(entity);
    Criterion condition1 = Restrictions.eq(property1, value1);
    Criterion condition2 = Restrictions.eq(Property2, value2);
    LogicalExpression andExp = Restrictions.and(condition1, condition2);
    System.out.println("\n " + andExp);
    //criteria.add(andExp);
    criteria.addOrder(Order.asc("id"));
    System.out.println("\n " + criteria.add(andExp));
    return criteria.list();
}

From source file:com.eucalyptus.auth.DatabaseAccountProxy.java

License:Open Source License

@Override
public List<Authorization> lookupAccountGlobalAuthorizations(String resourceType) throws AuthException {
    String accountId = this.delegate.getAccountNumber();
    if (resourceType == null) {
        throw new AuthException("Empty resource type");
    }//from  ww w.  java2  s.  com
    EntityWrapper<AuthorizationEntity> db = EntityWrapper.get(AuthorizationEntity.class);
    try {
        @SuppressWarnings("unchecked")
        List<AuthorizationEntity> authorizations = (List<AuthorizationEntity>) db
                .createCriteria(AuthorizationEntity.class).setCacheable(true)
                .add(Restrictions.and(Restrictions.eq("type", resourceType),
                        Restrictions.or(Restrictions.eq("effect", EffectType.Allow),
                                Restrictions.eq("effect", EffectType.Deny))))
                .createCriteria("statement").setCacheable(true).createCriteria("policy").setCacheable(true)
                .createCriteria("group").setCacheable(true)
                .add(Restrictions.eq("name", DatabaseAuthUtils.getUserGroupName(User.ACCOUNT_ADMIN)))
                .createCriteria("account").setCacheable(true).add(Restrictions.eq("accountNumber", accountId))
                .list();
        db.commit();
        List<Authorization> results = Lists.newArrayList();
        for (AuthorizationEntity auth : authorizations) {
            results.add(new DatabaseAuthorizationProxy(auth));
        }
        return results;
    } catch (Exception e) {
        db.rollback();
        Debugging.logError(LOG, e,
                "Failed to lookup global authorization for account " + accountId + ", type=" + resourceType);
        throw new AuthException("Failed to lookup account global auth", e);
    }
}

From source file:com.eucalyptus.auth.DatabaseAccountProxy.java

License:Open Source License

@Override
public List<Authorization> lookupAccountGlobalQuotas(String resourceType) throws AuthException {
    String accountId = this.delegate.getAccountNumber();
    if (resourceType == null) {
        throw new AuthException("Empty resource type");
    }/*w ww . j  a  v a 2 s .  c o m*/
    EntityWrapper<AuthorizationEntity> db = EntityWrapper.get(AuthorizationEntity.class);
    try {
        @SuppressWarnings("unchecked")
        List<AuthorizationEntity> authorizations = (List<AuthorizationEntity>) db
                .createCriteria(AuthorizationEntity.class).setCacheable(true)
                .add(Restrictions.and(Restrictions.eq("type", resourceType),
                        Restrictions.eq("effect", EffectType.Limit)))
                .createCriteria("statement").setCacheable(true).createCriteria("policy").setCacheable(true)
                .createCriteria("group").setCacheable(true)
                .add(Restrictions.eq("name", DatabaseAuthUtils.getUserGroupName(User.ACCOUNT_ADMIN)))
                .createCriteria("account").setCacheable(true).add(Restrictions.eq("accountNumber", accountId))
                .list();
        db.commit();
        List<Authorization> results = Lists.newArrayList();
        for (AuthorizationEntity auth : authorizations) {
            results.add(new DatabaseAuthorizationProxy(auth));
        }
        return results;
    } catch (Exception e) {
        db.rollback();
        Debugging.logError(LOG, e,
                "Failed to lookup global quota for account " + accountId + ", type=" + resourceType);
        throw new AuthException("Failed to lookup account global quota", e);
    }
}