@Test public void retrieveStateAttributesDeviceAdaptersWithoutFilter() throws Exception { prepareDevicesForAdapterInUseTest(); Map<ModelNodeId, Pair<List<QName>, List<FilterNode>>> mapAttributes = new HashMap<>(); Document filterDeviceAdapterWithType = DocumentUtils.loadXmlDocument(DeviceManagementSubsystemTest.class.getResourceAsStream("/filter-device-adapter.xml")); mapAttributes.put(NETWORK_MANAGER_ID_TEMPLATE, new Pair<>(Collections.emptyList(), Arrays.asList(getFilterNode(filterDeviceAdapterWithType)))); Map<ModelNodeId, List<Element>> stateInfo = m_deviceManagementSubsystem.retrieveStateAttributes(mapAttributes); assertEquals(1, stateInfo.size()); List<Element> deviceAdapter = stateInfo.get(NETWORK_MANAGER_ID_TEMPLATE); assertEquals(1, deviceAdapter.size()); TestUtil.assertXMLEquals(DocumentUtils.loadXmlDocument(DeviceManagementSubsystemTest.class.getResourceAsStream("/filter-device-adapter-response.xml")).getDocumentElement(), deviceAdapter.get(0)); }
@Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class, Exception.class}) protected Map<ModelNodeId, List<Element>> retrieveStateAttributes(Map<ModelNodeId, Pair<List<QName>, List<FilterNode>>> mapAttributes) throws GetAttributeException { Map<ModelNodeId, List<Element>> stateInfo = new HashMap<>(); try { Document document = DocumentUtils.createDocument(); for (Map.Entry<ModelNodeId, Pair<List<QName>, List<FilterNode>>> entry : mapAttributes.entrySet()) { List<Element> stateElements = new ArrayList<>(); ModelNodeId nodeId = entry.getKey(); List<FilterNode> filters = entry.getValue().getSecond(); Element deviceStateElement = null; Element newDevicesElement = null; Element deviceAdapterElement = null; if (nodeId.matchesTemplate(DEVICE_ID_TEMPLATE)) { Device device = getDevice(nodeId.getRdnValue("name")); if (device != null) { deviceStateElement = buildDeviceStateElement(document, device); } } else if (nodeId.matchesTemplate(NETWORK_MANAGER_ID_TEMPLATE)) { List<NewDeviceInfo> newDeviceInfos = m_connectionManager.getNewDevices(); List<DeviceAdapter> adapters = new ArrayList<>(m_adapterManager.getAllDeviceAdapters()); if (!newDeviceInfos.isEmpty()) { newDevicesElement = buildNewDeviceStateElement(document, newDeviceInfos); } deviceAdapterElement = buildAdaptersStateElement(document, adapters); } for (FilterNode filter : filters) { if (DEVICE_STATE.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceStateElement = document.createElementNS(NS, DEVICE_STATE); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(MANAGED_DEVICES_SP), deviceStateElement, filteredDeviceStateElement); deviceStateElement = filteredDeviceStateElement; if (deviceStateElement != null) { stateElements.add(deviceStateElement); } } else if (NEW_DEVICES.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredNewDevicesElement = document.createElementNS(NS, NEW_DEVICES); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(NEW_DEVICES_SP), newDevicesElement, filteredNewDevicesElement); newDevicesElement = filteredNewDevicesElement; if (newDevicesElement != null) { stateElements.add(newDevicesElement); } } else if (DEVICE_ADAPTERS.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceAdaptersElement = document.createElementNS(NS, DEVICE_ADAPTERS); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(DEVICE_ADAPTERS_SP), deviceAdapterElement, filteredDeviceAdaptersElement); deviceAdapterElement = filteredDeviceAdaptersElement; if (deviceAdapterElement != null) { stateElements.add(deviceAdapterElement); } } stateInfo.put(nodeId, stateElements); } } } catch (Exception e) { LOGGER.error("Error in retrieveStateAttributes: ", e); throw e; } return stateInfo; }
DeviceManagementSubsystem extends AbstractSubSystem { @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class, Exception.class}) protected Map<ModelNodeId, List<Element>> retrieveStateAttributes(Map<ModelNodeId, Pair<List<QName>, List<FilterNode>>> mapAttributes) throws GetAttributeException { Map<ModelNodeId, List<Element>> stateInfo = new HashMap<>(); try { Document document = DocumentUtils.createDocument(); for (Map.Entry<ModelNodeId, Pair<List<QName>, List<FilterNode>>> entry : mapAttributes.entrySet()) { List<Element> stateElements = new ArrayList<>(); ModelNodeId nodeId = entry.getKey(); List<FilterNode> filters = entry.getValue().getSecond(); Element deviceStateElement = null; Element newDevicesElement = null; Element deviceAdapterElement = null; if (nodeId.matchesTemplate(DEVICE_ID_TEMPLATE)) { Device device = getDevice(nodeId.getRdnValue("name")); if (device != null) { deviceStateElement = buildDeviceStateElement(document, device); } } else if (nodeId.matchesTemplate(NETWORK_MANAGER_ID_TEMPLATE)) { List<NewDeviceInfo> newDeviceInfos = m_connectionManager.getNewDevices(); List<DeviceAdapter> adapters = new ArrayList<>(m_adapterManager.getAllDeviceAdapters()); if (!newDeviceInfos.isEmpty()) { newDevicesElement = buildNewDeviceStateElement(document, newDeviceInfos); } deviceAdapterElement = buildAdaptersStateElement(document, adapters); } for (FilterNode filter : filters) { if (DEVICE_STATE.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceStateElement = document.createElementNS(NS, DEVICE_STATE); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(MANAGED_DEVICES_SP), deviceStateElement, filteredDeviceStateElement); deviceStateElement = filteredDeviceStateElement; if (deviceStateElement != null) { stateElements.add(deviceStateElement); } } else if (NEW_DEVICES.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredNewDevicesElement = document.createElementNS(NS, NEW_DEVICES); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(NEW_DEVICES_SP), newDevicesElement, filteredNewDevicesElement); newDevicesElement = filteredNewDevicesElement; if (newDevicesElement != null) { stateElements.add(newDevicesElement); } } else if (DEVICE_ADAPTERS.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceAdaptersElement = document.createElementNS(NS, DEVICE_ADAPTERS); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(DEVICE_ADAPTERS_SP), deviceAdapterElement, filteredDeviceAdaptersElement); deviceAdapterElement = filteredDeviceAdaptersElement; if (deviceAdapterElement != null) { stateElements.add(deviceAdapterElement); } } stateInfo.put(nodeId, stateElements); } } } catch (Exception e) { LOGGER.error("Error in retrieveStateAttributes: ", e); throw e; } return stateInfo; } }
DeviceManagementSubsystem extends AbstractSubSystem { @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class, Exception.class}) protected Map<ModelNodeId, List<Element>> retrieveStateAttributes(Map<ModelNodeId, Pair<List<QName>, List<FilterNode>>> mapAttributes) throws GetAttributeException { Map<ModelNodeId, List<Element>> stateInfo = new HashMap<>(); try { Document document = DocumentUtils.createDocument(); for (Map.Entry<ModelNodeId, Pair<List<QName>, List<FilterNode>>> entry : mapAttributes.entrySet()) { List<Element> stateElements = new ArrayList<>(); ModelNodeId nodeId = entry.getKey(); List<FilterNode> filters = entry.getValue().getSecond(); Element deviceStateElement = null; Element newDevicesElement = null; Element deviceAdapterElement = null; if (nodeId.matchesTemplate(DEVICE_ID_TEMPLATE)) { Device device = getDevice(nodeId.getRdnValue("name")); if (device != null) { deviceStateElement = buildDeviceStateElement(document, device); } } else if (nodeId.matchesTemplate(NETWORK_MANAGER_ID_TEMPLATE)) { List<NewDeviceInfo> newDeviceInfos = m_connectionManager.getNewDevices(); List<DeviceAdapter> adapters = new ArrayList<>(m_adapterManager.getAllDeviceAdapters()); if (!newDeviceInfos.isEmpty()) { newDevicesElement = buildNewDeviceStateElement(document, newDeviceInfos); } deviceAdapterElement = buildAdaptersStateElement(document, adapters); } for (FilterNode filter : filters) { if (DEVICE_STATE.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceStateElement = document.createElementNS(NS, DEVICE_STATE); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(MANAGED_DEVICES_SP), deviceStateElement, filteredDeviceStateElement); deviceStateElement = filteredDeviceStateElement; if (deviceStateElement != null) { stateElements.add(deviceStateElement); } } else if (NEW_DEVICES.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredNewDevicesElement = document.createElementNS(NS, NEW_DEVICES); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(NEW_DEVICES_SP), newDevicesElement, filteredNewDevicesElement); newDevicesElement = filteredNewDevicesElement; if (newDevicesElement != null) { stateElements.add(newDevicesElement); } } else if (DEVICE_ADAPTERS.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceAdaptersElement = document.createElementNS(NS, DEVICE_ADAPTERS); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(DEVICE_ADAPTERS_SP), deviceAdapterElement, filteredDeviceAdaptersElement); deviceAdapterElement = filteredDeviceAdaptersElement; if (deviceAdapterElement != null) { stateElements.add(deviceAdapterElement); } } stateInfo.put(nodeId, stateElements); } } } catch (Exception e) { LOGGER.error("Error in retrieveStateAttributes: ", e); throw e; } return stateInfo; } DeviceManagementSubsystem(SchemaRegistry schemaRegistry, AdapterManager adapterManager); }
DeviceManagementSubsystem extends AbstractSubSystem { @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class, Exception.class}) protected Map<ModelNodeId, List<Element>> retrieveStateAttributes(Map<ModelNodeId, Pair<List<QName>, List<FilterNode>>> mapAttributes) throws GetAttributeException { Map<ModelNodeId, List<Element>> stateInfo = new HashMap<>(); try { Document document = DocumentUtils.createDocument(); for (Map.Entry<ModelNodeId, Pair<List<QName>, List<FilterNode>>> entry : mapAttributes.entrySet()) { List<Element> stateElements = new ArrayList<>(); ModelNodeId nodeId = entry.getKey(); List<FilterNode> filters = entry.getValue().getSecond(); Element deviceStateElement = null; Element newDevicesElement = null; Element deviceAdapterElement = null; if (nodeId.matchesTemplate(DEVICE_ID_TEMPLATE)) { Device device = getDevice(nodeId.getRdnValue("name")); if (device != null) { deviceStateElement = buildDeviceStateElement(document, device); } } else if (nodeId.matchesTemplate(NETWORK_MANAGER_ID_TEMPLATE)) { List<NewDeviceInfo> newDeviceInfos = m_connectionManager.getNewDevices(); List<DeviceAdapter> adapters = new ArrayList<>(m_adapterManager.getAllDeviceAdapters()); if (!newDeviceInfos.isEmpty()) { newDevicesElement = buildNewDeviceStateElement(document, newDeviceInfos); } deviceAdapterElement = buildAdaptersStateElement(document, adapters); } for (FilterNode filter : filters) { if (DEVICE_STATE.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceStateElement = document.createElementNS(NS, DEVICE_STATE); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(MANAGED_DEVICES_SP), deviceStateElement, filteredDeviceStateElement); deviceStateElement = filteredDeviceStateElement; if (deviceStateElement != null) { stateElements.add(deviceStateElement); } } else if (NEW_DEVICES.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredNewDevicesElement = document.createElementNS(NS, NEW_DEVICES); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(NEW_DEVICES_SP), newDevicesElement, filteredNewDevicesElement); newDevicesElement = filteredNewDevicesElement; if (newDevicesElement != null) { stateElements.add(newDevicesElement); } } else if (DEVICE_ADAPTERS.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceAdaptersElement = document.createElementNS(NS, DEVICE_ADAPTERS); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(DEVICE_ADAPTERS_SP), deviceAdapterElement, filteredDeviceAdaptersElement); deviceAdapterElement = filteredDeviceAdaptersElement; if (deviceAdapterElement != null) { stateElements.add(deviceAdapterElement); } } stateInfo.put(nodeId, stateElements); } } } catch (Exception e) { LOGGER.error("Error in retrieveStateAttributes: ", e); throw e; } return stateInfo; } DeviceManagementSubsystem(SchemaRegistry schemaRegistry, AdapterManager adapterManager); DeviceManager getDeviceManager(); void setDeviceManager(DeviceManager deviceManager); NetconfConnectionManager getConnectionManager(); void setConnectionManager(NetconfConnectionManager connectionManager); @Override void notifyChanged(List<ChangeNotification> changeNotificationList); }
DeviceManagementSubsystem extends AbstractSubSystem { @Override @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {RuntimeException.class, Exception.class}) protected Map<ModelNodeId, List<Element>> retrieveStateAttributes(Map<ModelNodeId, Pair<List<QName>, List<FilterNode>>> mapAttributes) throws GetAttributeException { Map<ModelNodeId, List<Element>> stateInfo = new HashMap<>(); try { Document document = DocumentUtils.createDocument(); for (Map.Entry<ModelNodeId, Pair<List<QName>, List<FilterNode>>> entry : mapAttributes.entrySet()) { List<Element> stateElements = new ArrayList<>(); ModelNodeId nodeId = entry.getKey(); List<FilterNode> filters = entry.getValue().getSecond(); Element deviceStateElement = null; Element newDevicesElement = null; Element deviceAdapterElement = null; if (nodeId.matchesTemplate(DEVICE_ID_TEMPLATE)) { Device device = getDevice(nodeId.getRdnValue("name")); if (device != null) { deviceStateElement = buildDeviceStateElement(document, device); } } else if (nodeId.matchesTemplate(NETWORK_MANAGER_ID_TEMPLATE)) { List<NewDeviceInfo> newDeviceInfos = m_connectionManager.getNewDevices(); List<DeviceAdapter> adapters = new ArrayList<>(m_adapterManager.getAllDeviceAdapters()); if (!newDeviceInfos.isEmpty()) { newDevicesElement = buildNewDeviceStateElement(document, newDeviceInfos); } deviceAdapterElement = buildAdaptersStateElement(document, adapters); } for (FilterNode filter : filters) { if (DEVICE_STATE.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceStateElement = document.createElementNS(NS, DEVICE_STATE); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(MANAGED_DEVICES_SP), deviceStateElement, filteredDeviceStateElement); deviceStateElement = filteredDeviceStateElement; if (deviceStateElement != null) { stateElements.add(deviceStateElement); } } else if (NEW_DEVICES.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredNewDevicesElement = document.createElementNS(NS, NEW_DEVICES); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(NEW_DEVICES_SP), newDevicesElement, filteredNewDevicesElement); newDevicesElement = filteredNewDevicesElement; if (newDevicesElement != null) { stateElements.add(newDevicesElement); } } else if (DEVICE_ADAPTERS.equals(filter.getNodeName()) && NS.equals(filter.getNamespace())) { Element filteredDeviceAdaptersElement = document.createElementNS(NS, DEVICE_ADAPTERS); m_subtreeFilterUtil.doFilter(document, filter, m_schemaRegistry.getDataSchemaNode(DEVICE_ADAPTERS_SP), deviceAdapterElement, filteredDeviceAdaptersElement); deviceAdapterElement = filteredDeviceAdaptersElement; if (deviceAdapterElement != null) { stateElements.add(deviceAdapterElement); } } stateInfo.put(nodeId, stateElements); } } } catch (Exception e) { LOGGER.error("Error in retrieveStateAttributes: ", e); throw e; } return stateInfo; } DeviceManagementSubsystem(SchemaRegistry schemaRegistry, AdapterManager adapterManager); DeviceManager getDeviceManager(); void setDeviceManager(DeviceManager deviceManager); NetconfConnectionManager getConnectionManager(); void setConnectionManager(NetconfConnectionManager connectionManager); @Override void notifyChanged(List<ChangeNotification> changeNotificationList);  }