diff options
10 files changed, 70 insertions, 33 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DmiWriteOperation.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DmiWriteOperation.java index 7e9ca7988b..2119f817e7 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DmiWriteOperation.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/datajobs/models/DmiWriteOperation.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. + * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ package org.onap.cps.ncmp.api.datajobs.models; -import java.util.Map; - /** * Describes the write data job operation to be forwarded to dmi. * @@ -32,12 +30,10 @@ import java.util.Map; * @param moduleSetTag The module set tag of the CM Handle. * @param value The value to be written depends on the type of operation. * @param operationId Unique identifier of the operation within the request. - * @param privateProperties Contains the private properties of a Cm Handle. */ public record DmiWriteOperation( String path, String op, String moduleSetTag, Object value, - String operationId, - Map<String, String> privateProperties) {} + String operationId) {} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java index f200aa2ad7..f189edc89a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/WriteRequestExaminer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024-2025 Nordix Foundation + * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ package org.onap.cps.ncmp.impl.datajobs; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -107,7 +106,6 @@ public class WriteRequestExaminer { writeOperation.op(), ncmpServiceCmHandle.getModuleSetTag(), writeOperation.value(), - writeOperation.operationId(), - Collections.emptyMap()); // TODO: Private properties will be removed as part of CPS-2693. + writeOperation.operationId()); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java index d6b947697e..15aa1213aa 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 Nordix Foundation + * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -130,4 +130,13 @@ public interface CmHandleQueryService { */ Collection<String> getAllCmHandleReferences(boolean outputAlternateId); + /** + * Retrieves all Cm handle references by cps path. + * + * @param cpsPath cps path for which the cmHandle is requested + * @param outputAlternateId If {@code true}, returns alternate ids; if {@code false}, returns standard cm handle ids + * @return collection of cm handle references. Returns an empty collection if no references are found. + */ + Collection<String> getCmHandleReferencesByCpsPath(String cpsPath, boolean outputAlternateId); + } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java index 4a753bd8f4..bdf3785a7a 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 Nordix Foundation + * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -152,6 +152,25 @@ public class CmHandleQueryServiceImpl implements CmHandleQueryService { return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cpsPath, String.class); } + @Override + public Collection<String> getCmHandleReferencesByCpsPath(final String cpsPath, final boolean outputAlternateId) { + final String cpsPathInQuery; + final String cpsPathInQueryWithAttribute; + if (CpsPathUtil.getCpsPathQuery(cpsPath).getXpathPrefix().endsWith("/cm-handles")) { + cpsPathInQuery = cpsPath; + } else { + cpsPathInQuery = cpsPath + ANCESTOR_CM_HANDLES; + } + + if (outputAlternateId) { + cpsPathInQueryWithAttribute = cpsPathInQuery + "/@alternate-id"; + } else { + cpsPathInQueryWithAttribute = cpsPathInQuery + "/@id"; + } + return cpsQueryService.queryDataLeaf(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + cpsPathInQueryWithAttribute, String.class); + } + private Collection<String> getCmHandleReferencesByTrustLevel(final TrustLevel targetTrustLevel, final boolean outputAlternateId) { final Collection<String> selectedCmHandleReferences = new HashSet<>(); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java index 49b7726d08..6076895f0f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceImpl.java @@ -21,7 +21,6 @@ package org.onap.cps.ncmp.impl.inventory; import static org.onap.cps.api.parameters.FetchDescendantsOption.DIRECT_CHILDREN_ONLY; -import static org.onap.cps.api.parameters.FetchDescendantsOption.OMIT_DESCENDANTS; import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.validateCpsPathConditionProperties; import static org.onap.cps.ncmp.impl.inventory.CmHandleQueryParametersValidator.validateModuleNameConditionProperties; import static org.onap.cps.ncmp.impl.inventory.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT; @@ -181,9 +180,8 @@ public class ParameterizedCmHandleQueryServiceImpl implements ParameterizedCmHan return NO_QUERY_TO_EXECUTE; } try { - cpsPathQueryResult = collectCmHandleReferencesFromDataNodes( - cmHandleQueryService.queryCmHandleAncestorsByCpsPath(cpsPathCondition.get("cpsPath"), - OMIT_DESCENDANTS), outputAlternateId); + cpsPathQueryResult = cmHandleQueryService.getCmHandleReferencesByCpsPath(cpsPathCondition.get("cpsPath"), + outputAlternateId); } catch (final PathParsingException pathParsingException) { throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(), pathParsingException); diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducerSpec.groovy index 3bf4c2c160..49e43f9067 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiInEventProducerSpec.groovy @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi import com.fasterxml.jackson.databind.ObjectMapper import io.cloudevents.CloudEvent +import io.cloudevents.core.v1.CloudEventBuilder import org.onap.cps.events.EventsPublisher import org.onap.cps.ncmp.config.CpsApplicationContext import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.CmHandle @@ -33,7 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ContextConfiguration import spock.lang.Specification -@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper]) +@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper, CloudEventBuilder]) @ContextConfiguration(classes = [CpsApplicationContext]) class DmiInEventProducerSpec extends Specification { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy index fde7e182d0..d8adde261c 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducerSpec.groovy @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp import com.fasterxml.jackson.databind.ObjectMapper import io.cloudevents.CloudEvent +import io.cloudevents.core.v1.CloudEventBuilder import org.onap.cps.events.EventsPublisher import org.onap.cps.ncmp.config.CpsApplicationContext import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler @@ -33,7 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ContextConfiguration import spock.lang.Specification -@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper]) +@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper, CloudEventBuilder]) @ContextConfiguration(classes = [CpsApplicationContext]) class NcmpOutEventProducerSpec extends Specification { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy index 93362f23be..175fb1877b 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy @@ -25,13 +25,13 @@ class DmiSubJobRequestHandlerSpec extends Specification { given: 'a data job id, metadata and a map of producer keys and write operations to create a request' def dataJobId = 'some-job-id' def dataJobMetadata = new DataJobMetadata('d1', 't1', 't2') - def dmiWriteOperation = new DmiWriteOperation('p', 'operation', 'tag', null, 'o1', [:]) - def dmiWriteOperationsPerProducerKey = [new ProducerKey('dmi1', 'prod1'): [dmiWriteOperation]] + def dmiWriteOperation = new DmiWriteOperation('p', 'operation', 'tag', null, 'o1') + def dmiWriteOperationsPerProducerKey = [(new ProducerKey('dmi1', 'prod1')): [dmiWriteOperation]] def authorization = 'my authorization header' and: 'the dmi rest client will return a response (for the correct parameters)' def responseAsKeyValuePairs = [subJobId:'my-sub-job-id'] def responseEntity = new ResponseEntity<>(responseAsKeyValuePairs, HttpStatus.OK) - def expectedJson = '{"destination":"d1","dataAcceptType":"t1","dataContentType":"t2","dataProducerId":"prod1","dataJobId":"some-job-id","data":[{"path":"p","op":"operation","moduleSetTag":"tag","value":null,"operationId":"o1","privateProperties":{}}]}' + def expectedJson = '{"destination":"d1","dataAcceptType":"t1","dataContentType":"t2","dataProducerId":"prod1","dataJobId":"some-job-id","data":[{"path":"p","op":"operation","moduleSetTag":"tag","value":null,"operationId":"o1"}]}' mockDmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, _, expectedJson, OperationType.CREATE, authorization) >> responseEntity when: 'sending request to DMI invoked' objectUnderTest.sendRequestsToDmi(authorization, dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy index 57210c5e50..e978121644 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/CmHandleQueryServiceImplSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 Nordix Foundation + * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -234,6 +234,20 @@ class CmHandleQueryServiceImplSpec extends Specification { 'output is cm handle ids' | false || ['PNFDemo', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4', 'PNFDemo5'] } + def 'Get all cm handle references by cps path'() { + when: 'the all cm handle references is retrieved via cps path' + objectUnderTest.getCmHandleReferencesByCpsPath(sampleCpsPath, outputAlternateId) + then: 'query service to query data leaf is called once with the correct cps path as parameter' + 1 * mockCpsQueryService.queryDataLeaf(_, _, expectedCpsPathForQuery,_) + where: + scenario | sampleCpsPath | outputAlternateId || expectedCpsPathForQuery + 'cps path suffixes with cm-handles and outputs alternateId' | '/some/path/ending/in/cm-handles' | true || '/some/path/ending/in/cm-handles/@alternate-id' + 'cps path suffixes without cm-handles and outputs alternateId'| '/some/path/NotEnding/incmhandles'| true || '/some/path/NotEnding/incmhandles/ancestor::cm-handles/@alternate-id' + 'cps path suffixes with cm-handles and outputs cmHandleId' | '/some/path/ending/in/cm-handles' | false || '/some/path/ending/in/cm-handles/@id' + 'cps path suffixes without cm-handles and outputs cmhandleId' | '/some/path/NotEnding/incmhandles'| false || '/some/path/NotEnding/incmhandles/ancestor::cm-handles/@id' + + } + void mockResponses() { mockCpsQueryService.queryDataLeaf(_, _, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles/@id', _) >> [pnfDemo.getLeaves().get('id'), pnfDemo2.getLeaves().get('id'), pnfDemo4.getLeaves().get('id')] @@ -261,6 +275,7 @@ class CmHandleQueryServiceImplSpec extends Specification { mockCpsQueryService.queryDataLeaf(_, _, '/dmi-registry/cm-handles/@alternate-id', _) >> getAllCmHandleReferences(true) mockCpsQueryService.queryDataLeaf(_, _, '/dmi-registry/cm-handles/@id', _) >> getAllCmHandleReferences(false) + } def static createDataNode(dataNodeId) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy index b2e08afc71..594d7fb31d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/ParameterizedCmHandleQueryServiceSpec.groovy @@ -51,16 +51,16 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification { def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']]) cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties]) - and: 'the query get the cm handle datanodes excluding all descendants returns a datanode' - cmHandleQueries.queryCmHandleAncestorsByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(leaves: ['id':'some-cmhandle-id', 'alternate-id':'some-alternate-id'])] + and: 'the query get the cm handle references' + cmHandleQueries.getCmHandleReferencesByCpsPath('/some/cps/path', outputAlternateId) >> cmHandleReferences.asCollection() when: 'the query is executed for cm handle ids' def result = objectUnderTest.queryCmHandleReferenceIds(cmHandleQueryParameters, outputAlternateId) then: 'the correct expected cm handles ids are returned' assert result == expectedCmhandleReference where: 'the following data is used' - senario | outputAlternateId || expectedCmhandleReference - 'output CmHandle Ids' | false || ['some-cmhandle-id'] as Set - 'output Alternate Ids' | true || ['some-alternate-id'] as Set + senario | outputAlternateId | cmHandleReferences || expectedCmhandleReference + 'output CmHandle Ids' | false | ['some-cmhandle-id'] as Set || ['some-cmhandle-id'] as Set + 'output Alternate Ids' | true | ['some-alternate-id'] as Set || ['some-alternate-id'] as Set } def 'Query cm handle where cps path itself is ancestor axis.'() { @@ -68,16 +68,16 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification { def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']]) cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties]) - and: 'the query get the cm handle data nodes excluding all descendants returns a datanode' - cmHandleQueries.queryCmHandleAncestorsByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(leaves: ['id':'some-cmhandle-id', 'alternate-id':'some-alternate-id'])] + and: 'the query get the cm handle references' + cmHandleQueries.getCmHandleReferencesByCpsPath('/some/cps/path', outputAlternateId) >> cmHandleReferences.asCollection() when: 'the query is executed for cm handle ids' def result = objectUnderTest.queryCmHandleIdsForInventory(cmHandleQueryParameters, outputAlternateId) then: 'the correct expected cm handles ids are returned' assert result == expectedCmhandleReference where: 'the following data is used' - senario | outputAlternateId || expectedCmhandleReference - 'outputAlternate is false' | false || ['some-cmhandle-id'] as Set - 'outputAlternate is true' | true || ['some-alternate-id'] as Set + senario | outputAlternateId | cmHandleReferences || expectedCmhandleReference + 'outputAlternate is false' | false | ['some-cmhandle-id'] as Set || ['some-cmhandle-id'] as Set + 'outputAlternate is true' | true | ['some-alternate-id'] as Set|| ['some-alternate-id'] as Set } def 'Cm handle ids query with error: #scenario.'() { @@ -86,7 +86,7 @@ class ParameterizedCmHandleQueryServiceSpec extends Specification { def conditionProperties = createConditionProperties('cmHandleWithCpsPath', [['cpsPath' : '/some/cps/path']]) cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties]) and: 'cmHandleQueries throws a path parsing exception' - cmHandleQueries.queryCmHandleAncestorsByCpsPath('/some/cps/path', FetchDescendantsOption.OMIT_DESCENDANTS) >> { throw thrownException } + cmHandleQueries.getCmHandleReferencesByCpsPath('/some/cps/path', _) >> { throw thrownException } when: 'the query is executed for cm handle ids' objectUnderTest.queryCmHandleReferenceIds(cmHandleQueryParameters, false) then: 'a data validation exception is thrown' |