diff options
author | Lee Anjella Macabuhay <lee.anjella.macabuhay@est.tech> | 2024-08-14 13:01:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-08-14 13:01:18 +0000 |
commit | ae80bb42d8b41f280fb52cac70f974067ce31c68 (patch) | |
tree | 87a9d2685da0ae8f3c604c2d9df8e4de7e8f445f /cps-ncmp-service/src/main | |
parent | 1de8a6e451c47c66a6d0ecc7a5585e2f3e8420b5 (diff) | |
parent | 117dcc8b8e0a7aa36c6f9f125d37381dabd2ad93 (diff) |
Merge "Support alternate Id interface for CPS-E-05 #2"
Diffstat (limited to 'cps-ncmp-service/src/main')
7 files changed, 71 insertions, 22 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java index e93aa4c603..98a343b92e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/data/models/CmResourceAddress.java @@ -20,6 +20,22 @@ package org.onap.cps.ncmp.api.data.models; -public record CmResourceAddress(String datastoreName, String cmHandleId, String resourceIdentifier) { +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.onap.cps.ncmp.config.CpsApplicationContext; +import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; +@Getter +@RequiredArgsConstructor +public class CmResourceAddress { + + private final String datastoreName; + @Getter(AccessLevel.NONE) + private final String cmHandleReference; + private final String resourceIdentifier; + + public String getResolvedCmHandleId() { + return CpsApplicationContext.getCpsBean(AlternateIdMatcher.class).getCmHandleId(cmHandleReference); + } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java index 4cbf9d4b3b..90783a829a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/DmiDataOperations.java @@ -92,12 +92,12 @@ public class DmiDataOperations { final String topic, final String requestId, final String authorization) { - final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.cmHandleId()); + final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.getResolvedCmHandleId()); final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState(); validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState); final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle); final UrlTemplateParameters urlTemplateParameters = getUrlTemplateParameters(cmResourceAddress - .datastoreName(), yangModelCmHandle, cmResourceAddress.resourceIdentifier(), options, topic); + .getDatastoreName(), yangModelCmHandle, cmResourceAddress.getResourceIdentifier(), options, topic); return dmiRestClient.asynchronousPostOperationWithJsonData(DATA, urlTemplateParameters, jsonRequestBody, READ, authorization); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java index bff2f6390c..01022cc03e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NcmpCachedResourceRequestHandler.java @@ -61,9 +61,9 @@ public class NcmpCachedResourceRequestHandler extends NcmpDatastoreRequestHandle final String authorization) { final FetchDescendantsOption fetchDescendantsOption = getFetchDescendantsOption(includeDescendants); - final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.datastoreName(), - cmResourceAddress.cmHandleId(), - cmResourceAddress.resourceIdentifier(), + final DataNode dataNode = cpsDataService.getDataNodes(cmResourceAddress.getDatastoreName(), + cmResourceAddress.getResolvedCmHandleId(), + cmResourceAddress.getResourceIdentifier(), fetchDescendantsOption).iterator().next(); return Mono.justOrEmpty(dataNode); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java index 503915716e..b97088a5e0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/data/NetworkCmProxyFacade.java @@ -33,6 +33,7 @@ import org.onap.cps.ncmp.api.data.models.CmResourceAddress; import org.onap.cps.ncmp.api.data.models.DataOperationRequest; import org.onap.cps.ncmp.api.data.models.DatastoreType; import org.onap.cps.ncmp.api.data.models.OperationType; +import org.onap.cps.ncmp.impl.utils.AlternateIdMatcher; import org.onap.cps.spi.model.DataNode; import org.springframework.stereotype.Service; @@ -44,34 +45,35 @@ public class NetworkCmProxyFacade { private final NcmpCachedResourceRequestHandler ncmpCachedResourceRequestHandler; private final NcmpPassthroughResourceRequestHandler ncmpPassthroughResourceRequestHandler; private final DmiDataOperations dmiDataOperations; + private final AlternateIdMatcher alternateIdMatcher; /** * Fetches resource data for a given data store using DMI (Data Management Interface). * This method retrieves data based on the provided CmResourceAddress and additional query parameters. * It supports asynchronous processing and handles authorization if required. * - * @param cmResourceAddress The target data store, including the CM handle and resource identifier. - * This parameter must not be null. - * @param options Additional query parameters that may influence the data retrieval process, - * such as filters or limits. This parameter can be null. - * @param topic The topic name for triggering asynchronous responses. If specified, - * the response will be sent to this topic. This parameter can be null. - * @param includeDescendants include (all) descendants or not - * @param authorization The contents of the Authorization header. This parameter can be null - * if authorization is not required. + * @param cmResourceAddress The target data store, including the CM handle and resource identifier. + * This parameter must not be null. + * @param optionsParamInQuery Additional query parameters that may influence the data retrieval process, + * such as filters or limits. This parameter can be null. + * @param topicParamInQuery The topic name for triggering asynchronous responses. If specified, + * the response will be sent to this topic. This parameter can be null. + * @param includeDescendants include (all) descendants or not + * @param authorization The contents of the Authorization header. This parameter can be null + * if authorization is not required. * @return the result object, depends on use op topic. With topic a map object with request id is returned * otherwise the result of the request. */ public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress, - final String options, - final String topic, + final String optionsParamInQuery, + final String topicParamInQuery, final Boolean includeDescendants, final String authorization) { - final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler - = getNcmpDatastoreRequestHandler(cmResourceAddress.datastoreName()); - return ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, options, topic, includeDescendants, - authorization); + final NcmpDatastoreRequestHandler ncmpDatastoreRequestHandler + = getNcmpDatastoreRequestHandler(cmResourceAddress.getDatastoreName()); + return ncmpDatastoreRequestHandler.executeRequest(cmResourceAddress, optionsParamInQuery, + topicParamInQuery, includeDescendants, authorization); } /** @@ -117,7 +119,6 @@ public class NetworkCmProxyFacade { operationType, requestData, dataType, authorization); } - private NcmpDatastoreRequestHandler getNcmpDatastoreRequestHandler(final String datastoreName) { if (OPERATIONAL.equals(DatastoreType.fromDatastoreName(datastoreName))) { return ncmpCachedResourceRequestHandler; diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java index cb4b04e4a0..beef752ef1 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistence.java @@ -144,4 +144,12 @@ public interface InventoryPersistence extends NcmpPersistence { * @return Collection of CM handle Ids */ Collection<String> getCmHandleIdsWithGivenModules(Collection<String> moduleNamesForQuery); + + /** + * Check database if cm handle id exists if not return false. + * + * @param cmHandleId cmHandle Id + * @return Boolean + */ + boolean isExistingCmHandleId(String cmHandleId); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java index 0ca2cd3407..083b25db3d 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImpl.java @@ -195,6 +195,15 @@ public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements Inv return cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery); } + @Override + public boolean isExistingCmHandleId(final String cmHandleId) { + try { + return getCmHandleDataNodeByCmHandleId(cmHandleId).size() > 0; + } catch (final DataNodeNotFoundException exception) { + return false; + } + } + private static String getXPathForCmHandleById(final String cmHandleId) { return NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']"; } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java index 832e576d55..c408ff9b13 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/AlternateIdMatcher.java @@ -56,6 +56,21 @@ public class AlternateIdMatcher { throw new NoAlternateIdMatchFoundException(alternateId); } + /** + * Get cm handle Id from given cmHandleReference. + * + * @param cmHandleReference alternate ID + * @return cm handle id string + */ + public String getCmHandleId(final String cmHandleReference) { + if (inventoryPersistence.isExistingCmHandleId(cmHandleReference)) { + return cmHandleReference; + } else { + return inventoryPersistence.getCmHandleDataNodeByAlternateId(cmHandleReference) + .getLeaves().get("id").toString(); + } + } + private String getParentPath(final String path, final String separator) { final int lastSeparatorIndex = path.lastIndexOf(separator); return lastSeparatorIndex < 0 ? "" : path.substring(0, lastSeparatorIndex); |