/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation
+ * Copyright (C) 2021-2024 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration;
+import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.models.YangResource;
*
* @param dmiRestClient {@code DmiRestClient}
*/
- public DmiModelOperations(final YangModelCmHandleRetriever dmiPropertiesRetriever,
+ public DmiModelOperations(final InventoryPersistence inventoryPersistence,
final JsonObjectMapper jsonObjectMapper,
final NcmpConfiguration.DmiProperties dmiProperties,
final DmiRestClient dmiRestClient, final DmiServiceUrlBuilder dmiServiceUrlBuilder) {
- super(dmiPropertiesRetriever, jsonObjectMapper, dmiProperties, dmiRestClient, dmiServiceUrlBuilder);
+ super(inventoryPersistence, jsonObjectMapper, dmiProperties, dmiRestClient, dmiServiceUrlBuilder);
}
/**
*/
public List<ModuleReference> getModuleReferences(final YangModelCmHandle yangModelCmHandle) {
final DmiRequestBody dmiRequestBody = DmiRequestBody.builder()
- .build();
+ .moduleSetTag(yangModelCmHandle.getModuleSetTag()).build();
dmiRequestBody.asDmiProperties(yangModelCmHandle.getDmiProperties());
final ResponseEntity<Object> dmiFetchModulesResponseEntity = getResourceFromDmiWithJsonData(
yangModelCmHandle.resolveDmiServiceName(MODEL),
*/
public Map<String, String> getNewYangResourcesFromDmi(final YangModelCmHandle yangModelCmHandle,
final Collection<ModuleReference> newModuleReferences) {
+ if (newModuleReferences.isEmpty()) {
+ return Collections.emptyMap();
+ }
final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources(
newModuleReferences, yangModelCmHandle.getDmiProperties());
final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData(
* Get resources from DMI for modules.
*
* @param dmiServiceName dmi service name
- * @param jsonData module names and revisions as JSON
+ * @param jsonRequestBody module names and revisions as JSON
* @param cmHandle cmHandle
* @param resourceName name of the resource(s)
* @return {@code ResponseEntity} response entity
*/
private ResponseEntity<Object> getResourceFromDmiWithJsonData(final String dmiServiceName,
- final String jsonData,
+ final String jsonRequestBody,
final String cmHandle,
final String resourceName) {
final String dmiResourceDataUrl = getDmiResourceUrl(dmiServiceName, cmHandle, resourceName);
- return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonData);
+ return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody,
+ OperationType.READ, null);
}
private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,