+
+ /**
+ * Get resource data from operational datastore.
+ *
+ * @param cmHandle cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @param acceptParamInHeader accept header parameter
+ * @param optionsParamInQuery options query parameter
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+ @Override
+ public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle,
+ final @NotNull @Valid String resourceIdentifier,
+ final String acceptParamInHeader,
+ final @Valid String optionsParamInQuery) {
+ final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle,
+ resourceIdentifier,
+ acceptParamInHeader,
+ optionsParamInQuery);
+ return ResponseEntity.ok(responseObject);
+ }
+
+ /**
+ * Get resource data from pass-through running datastore.
+ *
+ * @param cmHandle cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @param acceptParamInHeader accept header parameter
+ * @param optionsParamInQuery options query parameter
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+ @Override
+ public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandle,
+ final @NotNull @Valid String resourceIdentifier,
+ final String acceptParamInHeader,
+ final @Valid String optionsParamInQuery) {
+ final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
+ resourceIdentifier,
+ acceptParamInHeader,
+ optionsParamInQuery);
+ return ResponseEntity.ok(responseObject);
+ }
+
+ /**
+ * Create resource data in datastore pass through running
+ * for given cm-handle.
+ *
+ * @param resourceIdentifier resource identifier
+ * @param cmHandle cm handle identifier
+ * @param requestBody requestBody
+ * @param contentType content type of body
+ * @return {@code ResponseEntity} response from dmi plugi
+ */
+ @Override
+ public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier,
+ final String cmHandle,
+ final String requestBody,
+ final String contentType) {
+ networkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle(cmHandle,
+ resourceIdentifier, requestBody, contentType);
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
+ public ResponseEntity<CmHandles> executeCmHandleSearch(final Conditions conditions) {
+ final List<ConditionProperties> conditionProperties =
+ conditions.getConditions().stream().collect(Collectors.toList());
+ final CmHandles cmHandles = new CmHandles();
+ cmHandles.setCmHandles(toCmHandleProperties(processConditions(conditionProperties)));
+ return ResponseEntity.ok(cmHandles);
+ }
+
+ @Override
+ public ResponseEntity<Object> getModuleReferencesByCmHandle(final String cmHandle) {
+ final Collection<ModuleReference>
+ moduleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle);
+ return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK);
+ }
+
+ private Collection<String> processConditions(final List<ConditionProperties> conditionProperties) {
+ for (final ConditionProperties conditionProperty : conditionProperties) {
+ if (conditionProperty.getName().equals("hasAllModules")) {
+ return executeCmHandleSearchesForModuleNames(conditionProperty);
+ } else {
+ log.warn("Unrecognized condition name {}.", conditionProperty.getName());
+ }
+ }
+ log.warn("No valid conditions found {}.", conditionProperties);
+ return Collections.emptyList();
+ }
+
+ private Collection<String> executeCmHandleSearchesForModuleNames(final ConditionProperties conditionProperties) {
+ return networkCmProxyDataService
+ .executeCmHandleHasAllModulesSearch(getModuleNames(conditionProperties.getConditionParameters()));
+ }
+
+ private Collection<String> getModuleNames(final ModuleNamesAsJsonArray moduleNamesAsJsonArray) {
+ final Collection<String> moduleNames = new ArrayList<>(moduleNamesAsJsonArray.size());
+ for (final ModuleNameAsJsonObject moduleNameAsJsonObject : moduleNamesAsJsonArray) {
+ moduleNames.add(moduleNameAsJsonObject.getModuleName());
+ }
+ return moduleNames;
+ }
+
+ private CmHandleProperties toCmHandleProperties(final Collection<String> cmHandleIdentifiers) {
+ final CmHandleProperties cmHandleProperties = new CmHandleProperties();
+ for (final String cmHandleIdentifier : cmHandleIdentifiers) {
+ final CmHandleProperty cmHandleProperty = new CmHandleProperty();
+ cmHandleProperty.setCmHandleId(cmHandleIdentifier);
+ cmHandleProperties.add(cmHandleProperty);
+ }
+ return cmHandleProperties;
+ }
+
+