AlarmUtil { public static String toDbId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, ModelNodeId modelNodeId, Map<String, Pair<String, SchemaRegistry>> prefixToNsMap) { String nodeId = AlarmUtil.xPathAlarmString(prefixToNsMap, modelNodeId); List<String> moduleNamesList = new ArrayList<String>(); StringBuilder dbId = new StringBuilder(); LocationPath jxPath = AlarmUtil.buildLocationPath(nodeId); Step[] splitSteps = jxPath.getSteps(); if (splitSteps != null && splitSteps.length > 0) { dbId.append(SLASH); for (Step stepNode : splitSteps) { SchemaRegistry mountRegistry = buildDbId(stepNode, schemaRegistry, prefixToNsMap, moduleNamesList, dbId); if (mountRegistry != null) { schemaRegistry = mountRegistry; } Expression[] predicates = stepNode.getPredicates(); if (predicates != null && predicates.length > 0) { for (int predicateCount = 0; predicateCount < predicates.length; predicateCount++) { buildDbId(predicates[predicateCount], schemaRegistry, prefixToNsMap, moduleNamesList, dbId); } } dbId.append(SLASH); } } dbId = dbId.deleteCharAt(dbId.length() - 1); return dbId.toString(); } private  AlarmUtil(); static Step[] splitXpathByJXPath(String xPath); static Map<String, Pair<String, SchemaRegistry>> getPrefixToNsMap(ModelNodeId modelNodeId, ModelNodeDataStoreManager dsm,
                                                                             SchemaRegistry schemaRegistry, String mountKey); static ModelNodeId toNodeIdUsingNodeElement(String dbId, Element element); static ModelNodeId toNodeIdUsingRegistry(String dbId, SchemaRegistry registry); static Alarm convertToAlarmEntity(AlarmInfo alarmInfo, String dbId); static List<AlarmInfo> convertAlarmToAlarmInfoList(List<Alarm> existingBaaAlarms, SchemaRegistry schemaRegistry,
                                                              ModelNodeDataStoreManager dsm); static String xPathAlarmString(Map<String, Pair<String, SchemaRegistry>> prefixToNsMap, ModelNodeId modelNodeId); static String toDbId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, ModelNodeId modelNodeId,
                                Map<String, Pair<String, SchemaRegistry>> prefixToNsMap); static QName getNodeName(Step stepNode); static ModelNodeId toNodeId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, String dbId,
                                       String mountRegistryKey); static ModelNodeId toNodeId(SchemaRegistry schemaRegistry, ModelNodeDataStoreManager dsm, String dbId); static String xPathString(Map<String, Pair<String, SchemaRegistry>> prefixToNsMap, NamespaceContext nsContext,
                                     ModelNodeId modelNodeId);  }
@Test public void testToDbId() { String actualDbId = AlarmUtil.toDbId(m_schemaRegistry, m_dsm, MODEL_NODE_ID, AlarmUtil.getPrefixToNsMap(MODEL_NODE_ID, m_dsm, m_schemaRegistry, null)); assertEquals(DB_ID, actualDbId); actualDbId = AlarmUtil.toDbId(m_schemaRegistry, m_dsm, YET_ANOTHER_MODEL_NODE_ID, AlarmUtil.getPrefixToNsMap(YET_ANOTHER_MODEL_NODE_ID, m_dsm, m_schemaRegistry, null)); assertEquals(YET_ANOTHER_DB_ID, actualDbId); actualDbId = AlarmUtil.toDbId(m_schemaRegistry, m_dsm, INTF_MODEL_NODE_ID, AlarmUtil.getPrefixToNsMap(INTF_MODEL_NODE_ID, m_dsm, m_schemaRegistry, null)); assertEquals(DB_ID_FOR_INTF, actualDbId); Map<String, Pair<String, SchemaRegistry>> prefixToNsMap = new HashMap<>(); Pair<String, SchemaRegistry> pair = new Pair<String, SchemaRegistry>(AlarmTestConstants.BAA_NAMESPACE, m_schemaRegistry); prefixToNsMap.put("baa", pair); pair = new Pair<String, SchemaRegistry>(AlarmTestConstants.NETWORK_MANAGER_NAMESPACE, m_schemaRegistry); prefixToNsMap.put("adh", pair); pair = new Pair<String, SchemaRegistry>(IF_INTF_NS, m_mountRegistry); prefixToNsMap.put("if", pair); String actualString = AlarmUtil.xPathString(prefixToNsMap, m_schemaRegistry, INTF_MODEL_NODE_ID); assertEquals(DB_ID_WITH_INTF, actualString); }