+ public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
+ final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
+ final YangModelCmHandle yangModelCmHandle =
+ yangModelCmHandleRetriever.getDmiServiceNamesAndProperties(cmHandleId);
+ final List<YangModelCmHandle.Property> dmiProperties = yangModelCmHandle.getDmiProperties();
+ final List<YangModelCmHandle.Property> publicProperties = yangModelCmHandle.getPublicProperties();
+ ncmpServiceCmHandle.setCmHandleID(yangModelCmHandle.getId());
+ setDmiProperties(dmiProperties, ncmpServiceCmHandle);
+ setPublicProperties(publicProperties, ncmpServiceCmHandle);
+ return ncmpServiceCmHandle;
+ }
+
+ private void setDmiProperties(final List<YangModelCmHandle.Property> dmiProperties,
+ final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ final Map<String, String> dmiPropertiesMap = new LinkedHashMap<>(dmiProperties.size());
+ asPropertiesMap(dmiProperties, dmiPropertiesMap);
+ ncmpServiceCmHandle.setDmiProperties(dmiPropertiesMap);
+ }
+
+ private void setPublicProperties(final List<YangModelCmHandle.Property> publicProperties,
+ final NcmpServiceCmHandle ncmpServiceCmHandle) {
+ final Map<String, String> publicPropertiesMap = new LinkedHashMap<>();
+ asPropertiesMap(publicProperties, publicPropertiesMap);
+ ncmpServiceCmHandle.setPublicProperties(publicPropertiesMap);
+ }
+
+ private void asPropertiesMap(final List<YangModelCmHandle.Property> properties,
+ final Map<String, String> propertiesMap) {
+ for (final YangModelCmHandle.Property property: properties) {
+ propertiesMap.put(property.getName(), property.getValue());
+ }
+ }
+
+ /**
+ * THis method registers a cm handle and initiates modules sync.
+ *
+ * @param dmiPluginRegistration dmi plugin registration information.
+ * @throws JsonProcessingException thrown if json is malformed or missing.
+ */
+ public void parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(
+ final DmiPluginRegistration dmiPluginRegistration) throws JsonProcessingException {
+ final YangModelCmHandlesList createdYangModelCmHandlesList =
+ getUpdatedYangModelCmHandlesList(dmiPluginRegistration,
+ dmiPluginRegistration.getCreatedCmHandles());
+ registerAndSyncNewCmHandles(createdYangModelCmHandlesList);
+ }
+
+ private static Object handleResponse(final ResponseEntity<?> responseEntity,
+ final String exceptionMessage) {
+ if (responseEntity.getStatusCode().is2xxSuccessful()) {
+ return responseEntity.getBody();
+ } else {
+ throw new ServerNcmpException(exceptionMessage,
+ "DMI status code: " + responseEntity.getStatusCodeValue()
+ + ", DMI response body: " + responseEntity.getBody());
+ }
+ }
+
+ private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
+ networkCmProxyDataServicePropertyHandler.updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles());
+ }
+
+ private YangModelCmHandlesList getUpdatedYangModelCmHandlesList(
+ final DmiPluginRegistration dmiPluginRegistration,
+ final List<NcmpServiceCmHandle> updatedCmHandles) {
+ return YangModelCmHandlesList.toYangModelCmHandlesList(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ updatedCmHandles);
+ }
+
+ private void registerAndSyncNewCmHandles(final YangModelCmHandlesList yangModelCmHandlesList) {
+ final String cmHandleJsonData = jsonObjectMapper.asJsonString(yangModelCmHandlesList);
+ cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
+ cmHandleJsonData, NO_TIMESTAMP);
+
+ for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandlesList.getYangModelCmHandles()) {
+ syncModulesAndCreateAnchor(yangModelCmHandle);
+ }
+ }
+
+ protected void syncModulesAndCreateAnchor(final YangModelCmHandle yangModelCmHandle) {
+ syncAndCreateSchemaSet(yangModelCmHandle);
+ createAnchor(yangModelCmHandle);
+ }
+
+ private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
+ for (final String cmHandle : dmiPluginRegistration.getRemovedCmHandles()) {
+ try {
+ attemptToDeleteSchemaSetWithCascade(cmHandle);
+ cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+ "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
+ } catch (final DataNodeNotFoundException e) {
+ log.warn("Datanode {} not deleted message {}", cmHandle, e.getMessage());