Merge "Added API to get all schema sets for a given dataspace."
authorToine Siebelink <toine.siebelink@est.tech>
Fri, 9 Dec 2022 15:33:12 +0000 (15:33 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 9 Dec 2022 15:33:12 +0000 (15:33 +0000)
62 files changed:
checkstyle/pom.xml
cps-application/pom.xml
cps-bom/pom.xml
cps-dependencies/pom.xml
cps-events/pom.xml
cps-ncmp-events/pom.xml
cps-ncmp-rest-stub/pom.xml
cps-ncmp-rest/docs/openapi/ncmp-inventory.yml
cps-ncmp-rest/docs/openapi/openapi-inventory.yml
cps-ncmp-rest/pom.xml
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy
cps-ncmp-service/pom.xml
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java [new file with mode: 0644]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java [new file with mode: 0644]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/RestQueryParametersValidator.java [moved from cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java with 78% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/enums/PropertyType.java [moved from cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java with 74% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleQueryServiceParameters.java [moved from cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java with 94% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/CpsAsyncRequestResponseEventIntegrationSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisherSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy [new file with mode: 0644]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/DmiServiceUrlBuilderSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/utils/DmiServiceUrlBuilderSpec.groovy with 98% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditionsSpec.groovy [new file with mode: 0644]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/RestQueryParametersValidatorSpec.groovy [moved from cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy with 67% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/YangDataConverterSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/utils/YangDataConverterSpec.groovy with 95% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/kafka/MessagingBaseSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/utils/MessagingSpec.groovy with 97% similarity]
cps-parent/pom.xml
cps-path-parser/pom.xml
cps-rest/pom.xml
cps-ri/pom.xml
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsToDataNodePerfTest.groovy
cps-ri/src/test/resources/data/perf-test.sql [new file with mode: 0644]
cps-service/pom.xml
cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
csit/install-robotframework.sh
csit/prepare-csit.sh
csit/pylibs.txt
csit/run-csit.sh
docs/deployment.rst
docs/release-notes.rst
jacoco-report/pom.xml
pom.xml
spotbugs/pom.xml
version.properties

index dd308e2..ed065c4 100644 (file)
@@ -26,7 +26,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.onap.cps</groupId>
     <artifactId>checkstyle</artifactId>
-    <version>3.2.0-SNAPSHOT</version>
+    <version>3.2.1-SNAPSHOT</version>
 
     <profiles>
         <profile>
index a4d3cbd..9990cdd 100755 (executable)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index 004c31e..1193c60 100644 (file)
@@ -25,7 +25,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.onap.cps</groupId>
     <artifactId>cps-bom</artifactId>
-    <version>3.2.0-SNAPSHOT</version>
+    <version>3.2.1-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <description>This artifact contains dependencyManagement declarations of all published CPS components.</description>
index 18ed43c..5bdf793 100755 (executable)
@@ -27,7 +27,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.onap.cps</groupId>
     <artifactId>cps-dependencies</artifactId>
-    <version>3.2.0-SNAPSHOT</version>
+    <version>3.2.1-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <name>${project.groupId}:${project.artifactId}</name>
@@ -73,7 +73,7 @@
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-dependencies</artifactId>
-                <version>2.6.9</version>
+                <version>2.6.14</version>
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
@@ -87,7 +87,7 @@
             <dependency>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yangtools-artifacts</artifactId>
-                <version>6.0.1</version>
+                <version>8.0.6</version>
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
index 6cbb7eb..f940c82 100644 (file)
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index 193f5d0..8207fce 100644 (file)
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index a1711b5..93c73fc 100644 (file)
@@ -26,7 +26,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index 0c3dffd..16083bd 100755 (executable)
@@ -107,6 +107,35 @@ getAllCmHandleIdsForRegisteredDmi:
     operationId: getAllCmHandleIdsForRegisteredDmi
     parameters:
       - $ref: 'components.yaml#/components/parameters/dmiPluginIdentifierInQuery'
+    responses:
+      200:
+        description: OK
+        content:
+          application/json:
+            schema:
+              type: array
+              items:
+                type: string
+      401:
+        $ref: 'components.yaml#/components/responses/Unauthorized'
+      403:
+        $ref: 'components.yaml#/components/responses/Forbidden'
+      500:
+        $ref: 'components.yaml#/components/responses/InternalServerError'
+
+searchCmHandleIds:
+  post:
+    description: Query and get CMHandleIds for additional properties, public properties and registered DMI plugin (DMI plugin, DMI data plugin, DMI model plugin).
+    tags:
+      - network-cm-proxy-inventory
+    summary: Query for CM Handle IDs
+    operationId: searchCmHandleIds
+    requestBody:
+      required: true
+      content:
+        application/json:
+          schema:
+            $ref: 'components.yaml#/components/schemas/CmHandleQueryParameters'
     responses:
       200:
         description: OK
index 8f8dfe2..bd83dbf 100755 (executable)
@@ -35,5 +35,9 @@ paths:
 
   /v1/ch/cmHandles:
     $ref: 'ncmp-inventory.yml#/getAllCmHandleIdsForRegisteredDmi'
+
+  /v1/ch/searches:
+    $ref: 'ncmp-inventory.yml#/searchCmHandleIds'
+
 security:
   - basicAuth: []
\ No newline at end of file
index 8473674..a8544af 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index 118fa45..eb48754 100644 (file)
@@ -25,8 +25,10 @@ import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 import org.mapstruct.NullValueCheckStrategy;
 import org.mapstruct.NullValuePropertyMappingStrategy;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
 import org.onap.cps.ncmp.rest.model.RestInputCmHandle;
 import org.onap.cps.ncmp.rest.model.RestModuleDefinition;
@@ -59,4 +61,7 @@ public interface NcmpRestInputMapper {
     @InheritConfiguration(name = "toRestModuleReference")
     RestModuleDefinition toRestModuleDefinition(
             final ModuleDefinition moduleDefinition);
-}
\ No newline at end of file
+
+    CmHandleQueryServiceParameters toCmHandleQueryServiceParameters(
+            final CmHandleQueryParameters cmHandleQueryParameters);
+}
index 0c428e4..98da150 100755 (executable)
@@ -27,10 +27,12 @@ import java.util.stream.Collectors;
 import javax.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
 import org.onap.cps.ncmp.rest.api.NetworkCmProxyInventoryApi;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
 import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse;
 import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse;
 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
@@ -47,6 +49,16 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
     private final NetworkCmProxyDataService networkCmProxyDataService;
     private final NcmpRestInputMapper ncmpRestInputMapper;
 
+    @Override
+    public ResponseEntity<List<String>> searchCmHandleIds(final CmHandleQueryParameters cmHandleQueryParameters) {
+        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = ncmpRestInputMapper
+                .toCmHandleQueryServiceParameters(cmHandleQueryParameters);
+
+        final Set<String> cmHandleIds = networkCmProxyDataService
+                .executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters);
+        return ResponseEntity.ok(List.copyOf(cmHandleIds));
+    }
+
     /**
      * Get all cm-handle IDs under a registered DMI plugin.
      *
index cd3770e..dfe7bf3 100644 (file)
@@ -22,10 +22,13 @@ package org.onap.cps.ncmp.rest.controller
 
 import org.mapstruct.factory.Mappers
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters
+import org.onap.cps.ncmp.rest.model.ConditionProperties
 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
 import org.onap.cps.ncmp.rest.model.RestInputCmHandle
 import org.onap.cps.ncmp.rest.model.RestModuleDefinition
 import org.onap.cps.ncmp.rest.model.RestModuleReference
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ModuleDefinition
 import org.onap.cps.spi.model.ModuleReference
 import spock.lang.Specification
@@ -104,4 +107,22 @@ class NcmpRestInputMapperSpec extends Specification {
                     '    content: content\n' +
                     '}'
     }
+
+    def 'Convert a CmHandle REST query to CmHandle query service parameters.'() {
+        given: 'a CmHandle REST query with two conditions'
+            def conditionParameter1 = new ConditionProperties(conditionName: 'some condition', conditionParameters: [[p1:1]] )
+            def conditionParameter2 = new ConditionProperties(conditionName: 'other condition', conditionParameters: [[p2:2]] )
+            def cmHandleQuery = new CmHandleQueryParameters()
+            cmHandleQuery.cmHandleQueryParameters = [conditionParameter1, conditionParameter2]
+        when: 'it is converted into CmHandle query service parameters'
+            def result = objectUnderTest.toCmHandleQueryServiceParameters(cmHandleQuery)
+        then: 'the result is of the correct class'
+            assert result instanceof CmHandleQueryServiceParameters
+        and: 'the result has the same conditions'
+            assert result.cmHandleQueryParameters.size() == 2
+            assert result.cmHandleQueryParameters[0].conditionName == 'some condition'
+            assert result.cmHandleQueryParameters[0].conditionParameters == [[p1:1]]
+            assert result.cmHandleQueryParameters[1].conditionName == 'other condition'
+            assert result.cmHandleQueryParameters[1].conditionParameters == [[p2:2]]
+    }
 }
index b5a089b..88f496a 100644 (file)
@@ -27,10 +27,11 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters
 import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse
 import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse
 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.utils.JsonObjectMapper
 import org.spockframework.spring.SpringBean
 import org.springframework.beans.factory.annotation.Autowired
@@ -60,6 +61,9 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
 
     DmiPluginRegistration mockDmiPluginRegistration = Mock()
 
+    CmHandleQueryServiceParameters cmHandleQueryServiceParameters = Mock()
+
+    @SpringBean
     JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
 
     @Value('${rest.api.ncmp-inventory-base-path}/v1')
@@ -102,6 +106,29 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
             response.status == HttpStatus.BAD_REQUEST.value()
     }
 
+    def 'CmHandle search endpoint test #scenario.'() {
+        given: 'a query object'
+            def cmHandleQueryParameters = jsonObjectMapper.asJsonString(new CmHandleQueryParameters())
+        and: 'the mapper service returns a converted object'
+            ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters
+        and: 'the service returns the desired results'
+            mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse
+        when: 'post request is performed & search is called with the given request parameters'
+            def response = mvc.perform(
+                    post("$ncmpBasePathV1/ch/searches")
+                            .contentType(MediaType.APPLICATION_JSON)
+                            .content(cmHandleQueryParameters)
+            ).andReturn().response
+        then: 'response status is OK'
+            assert response.status == HttpStatus.OK.value()
+        and: 'the response data matches the service response.'
+            jsonObjectMapper.convertJsonString(response.getContentAsString(), List) == serviceMockResponse
+        where: 'the service respond with'
+            scenario             | serviceMockResponse
+            'empty response'     | []
+            'populates response' | ['cmHandle1', 'cmHandle2']
+    }
+
     def 'DMI Registration: All cm-handles operations processed successfully.'() {
         given: 'a dmi plugin registration'
             def dmiRegistrationRequest = '{}'
index 0f5a234..864ea0d 100644 (file)
@@ -27,7 +27,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index faf58b9..7322ebc 100644 (file)
@@ -21,8 +21,8 @@
 package org.onap.cps.ncmp.api;
 
 import java.util.Set;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 
 public interface NetworkCmProxyCmHandlerQueryService {
     /**
@@ -40,4 +40,12 @@ public interface NetworkCmProxyCmHandlerQueryService {
      * @return collection of cm handle ids
      */
     Set<String> queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+
+    /**
+     * Query and return cm handles that match the given query parameters.
+     *
+     * @param cmHandleQueryServiceParameters the cm handle query parameters
+     * @return collection of cm handle ids
+     */
+    Set<String> queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
 }
index 0ea0674..c9810e9 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Set;
 import org.onap.cps.ncmp.api.inventory.CompositeState;
 import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
@@ -183,4 +184,12 @@ public interface NetworkCmProxyDataService {
      * @return set of cm handle IDs
      */
     Set<String> getAllCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
+
+    /**
+     * Get all cm handle IDs by various search criteria.
+     *
+     * @param cmHandleQueryServiceParameters cm handle query parameters
+     * @return set of cm handle IDs
+     */
+    Set<String> executeCmHandleIdSearchForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
 }
index 1674c52..a8fc6d7 100644 (file)
 
 package org.onap.cps.ncmp.api.impl;
 
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCpsPathConditionProperties;
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateModuleNameConditionProperties;
 import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
 import static org.onap.cps.spi.FetchDescendantsOption.FETCH_DIRECT_CHILDREN_ONLY;
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties;
-import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -40,16 +40,18 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.cpspath.parser.PathParsingException;
 import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
+import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
 import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
 import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
+import org.onap.cps.ncmp.api.inventory.enums.PropertyType;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
 import org.onap.cps.spi.exceptions.DataValidationException;
 import org.onap.cps.spi.model.Anchor;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 import org.onap.cps.spi.model.ConditionProperties;
 import org.onap.cps.spi.model.DataNode;
-import org.onap.cps.utils.ValidQueryProperties;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -113,6 +115,92 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
         return moduleNameQueryResult;
     }
 
+    @Override
+    public Set<String> queryCmHandleIdsForInventory(
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+        if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
+            return getAllCmHandleIds();
+        }
+
+        final Map<String, NcmpServiceCmHandle> publicPropertiesQueryResult = queryCmHandlesByPublicProperties(
+                cmHandleQueryServiceParameters);
+        if (publicPropertiesQueryResult != null && publicPropertiesQueryResult.isEmpty()) {
+            return Collections.emptySet();
+        }
+
+        final Map<String, NcmpServiceCmHandle> privatePropertiesQueryResult = queryCmHandlesByPrivateProperties(
+                cmHandleQueryServiceParameters);
+        if (privatePropertiesQueryResult != null && privatePropertiesQueryResult.isEmpty()) {
+            return Collections.emptySet();
+        }
+
+        final Map<String, NcmpServiceCmHandle> dmiPropertiesQueryResult = queryCmHandlesByDmiPlugin(
+                cmHandleQueryServiceParameters);
+        if (dmiPropertiesQueryResult != null && dmiPropertiesQueryResult.isEmpty()) {
+            return Collections.emptySet();
+        }
+
+        final Map<String, NcmpServiceCmHandle> combinedResult =
+              combineQueryResults(publicPropertiesQueryResult, privatePropertiesQueryResult, dmiPropertiesQueryResult);
+
+        return combinedResult.keySet();
+    }
+
+    private Map<String, NcmpServiceCmHandle> queryCmHandlesByDmiPlugin(
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+        final Map<String, String> dmiPropertyQueryPairs =
+                getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+                        InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName());
+        if (dmiPropertyQueryPairs.isEmpty()) {
+            return NO_QUERY_TO_EXECUTE;
+        }
+
+        final String dmiPluginIdentifierValue = dmiPropertyQueryPairs.get(
+                PropertyType.DMI_PLUGIN.getYangContainerName());
+
+        final Set<NcmpServiceCmHandle> cmHandlesByDmiPluginIdentifier = cmHandleQueries
+                .getCmHandlesByDmiPluginIdentifier(dmiPluginIdentifierValue);
+
+        return cmHandlesByDmiPluginIdentifier.stream()
+                .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId, cmH -> cmH));
+    }
+
+    private Map<String, NcmpServiceCmHandle> queryCmHandlesByPrivateProperties(
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+        final Map<String, String> privatePropertyQueryPairs =
+                getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+                        InventoryQueryConditions.HAS_ALL_ADDITIONAL_PROPERTIES.getName());
+
+        return privatePropertyQueryPairs.isEmpty()
+                ? NO_QUERY_TO_EXECUTE
+                : cmHandleQueries.queryCmHandleAdditionalProperties(privatePropertyQueryPairs);
+    }
+
+    private Map<String, NcmpServiceCmHandle> queryCmHandlesByPublicProperties(
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+        final Map<String, String> publicPropertyQueryPairs =
+                getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+                        CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName());
+
+        return publicPropertyQueryPairs.isEmpty()
+                ? NO_QUERY_TO_EXECUTE
+                : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
+    }
+
+    private Map<String, NcmpServiceCmHandle> combineQueryResults(
+            final Map<String, NcmpServiceCmHandle> publicPropertiesQueryResult,
+            final Map<String, NcmpServiceCmHandle> privatePropertiesQueryResult,
+            final Map<String, NcmpServiceCmHandle> dmiPropertiesQueryResult) {
+
+        final Map<String, NcmpServiceCmHandle> propertiesCombinedResult = cmHandleQueries
+                .combineCmHandleQueries(publicPropertiesQueryResult, privatePropertiesQueryResult);
+        return cmHandleQueries
+                .combineCmHandleQueries(propertiesCombinedResult, dmiPropertiesQueryResult);
+    }
+
     private Map<String, NcmpServiceCmHandle> combineWithModuleNameQuery(
             final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
             final Map<String, NcmpServiceCmHandle> previousQueryResult) {
@@ -164,7 +252,8 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
         }
 
         final Map<String, String> publicPropertyQueryPairs =
-                getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+                getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+                        CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName());
         final Map<String, NcmpServiceCmHandle> propertiesQueryResult = publicPropertyQueryPairs.isEmpty()
                 ? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
 
@@ -178,7 +267,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
 
     private Collection<String> getModuleNamesForQuery(final List<ConditionProperties> conditionProperties) {
         final List<String> result = new ArrayList<>();
-        getConditions(conditionProperties, ValidQueryProperties.HAS_ALL_MODULES.getQueryProperty())
+        getConditions(conditionProperties, CmHandleQueryConditions.HAS_ALL_MODULES.getConditionName())
             .parallelStream().forEach(
                 conditionProperty -> {
                     validateModuleNameConditionProperties(conditionProperty);
@@ -190,15 +279,15 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
 
     private Map<String, String> getCpsPath(final List<ConditionProperties> conditionProperties) {
         final Map<String, String> result = new HashMap<>();
-        getConditions(conditionProperties, ValidQueryProperties.WITH_CPS_PATH.getQueryProperty()).forEach(
+        getConditions(conditionProperties, CmHandleQueryConditions.WITH_CPS_PATH.getConditionName()).forEach(
                 result::putAll);
         return result;
     }
 
-    private Map<String, String> getPublicPropertyPairs(final List<ConditionProperties> conditionProperties) {
+    private Map<String, String> getPropertyPairs(final List<ConditionProperties> conditionProperties,
+                                                       final String queryProperty) {
         final Map<String, String> result = new HashMap<>();
-        getConditions(conditionProperties,
-                ValidQueryProperties.HAS_ALL_PROPERTIES.getQueryProperty()).forEach(result::putAll);
+        getConditions(conditionProperties, queryProperty).forEach(result::putAll);
         return result;
     }
 
index 27c3646..d00d211 100755 (executable)
@@ -25,7 +25,7 @@ package org.onap.cps.ncmp.api.impl;
 
 import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum;
-import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters;
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
 
 import com.hazelcast.map.IMap;
 import java.time.OffsetDateTime;
@@ -45,6 +45,8 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
 import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler;
 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
 import org.onap.cps.ncmp.api.impl.operations.DmiOperations;
+import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
 import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
@@ -54,6 +56,7 @@ import org.onap.cps.ncmp.api.inventory.CompositeStateUtils;
 import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
 import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
 import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError;
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
@@ -64,7 +67,6 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
 import org.onap.cps.spi.exceptions.CpsException;
 import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
 import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 import org.onap.cps.spi.model.ModuleDefinition;
 import org.onap.cps.spi.model.ModuleReference;
 import org.onap.cps.utils.JsonObjectMapper;
@@ -171,9 +173,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     public Set<NcmpServiceCmHandle> executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
         final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
                 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
-
-        validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
-
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
         return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters);
     }
 
@@ -187,9 +187,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     public Set<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
         final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
                 cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
-
-        validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
-
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
         return networkCmProxyCmHandlerQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
     }
 
@@ -237,6 +235,19 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         return cmHandleIds;
     }
 
+    /**
+     * Get all cm handle IDs by various properties.
+     *
+     * @param cmHandleQueryServiceParameters cm handle query parameters
+     * @return set of cm handle IDs
+     */
+    @Override
+    public Set<String> executeCmHandleIdSearchForInventory(
+            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+        validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
+        return networkCmProxyCmHandlerQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
+    }
+
     /**
      * Retrieve cm handle details for a given cm handle.
      *
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java
new file mode 100644 (file)
index 0000000..b1bb7f7
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.utils;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.stream.Collectors;
+import lombok.Getter;
+
+@Getter
+public enum CmHandleQueryConditions {
+    HAS_ALL_PROPERTIES("hasAllProperties"),
+    HAS_ALL_MODULES("hasAllModules"),
+    WITH_CPS_PATH("cmHandleWithCpsPath");
+
+    public static final Collection<String> ALL_CONDITION_NAMES = Arrays.stream(CmHandleQueryConditions.values())
+        .map(CmHandleQueryConditions::getConditionName).collect(Collectors.toList());
+
+    private final String conditionName;
+
+    CmHandleQueryConditions(final String conditionName) {
+        this.conditionName = conditionName;
+    }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java
new file mode 100644 (file)
index 0000000..9437cf0
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.utils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum InventoryQueryConditions {
+
+    HAS_ALL_PROPERTIES("hasAllProperties"),
+    HAS_ALL_ADDITIONAL_PROPERTIES("hasAllAdditionalProperties"),
+    CM_HANDLE_WITH_DMI_PLUGIN("cmHandleWithDmiPlugin");
+
+    public static final List<String> ALL_CONDITION_NAMES = Arrays.stream(InventoryQueryConditions.values())
+        .map(InventoryQueryConditions::getName).collect(Collectors.toList());
+
+    private final String name;
+
+}
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.utils;
+package org.onap.cps.ncmp.api.impl.utils;
 
 import com.google.common.base.Strings;
-import java.util.Arrays;
+import java.util.Collection;
 import java.util.Map;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
 import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
 
 @Slf4j
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class CmHandleQueryRestParametersValidator {
+public class RestQueryParametersValidator {
 
     /**
-     * Validate cm handle query parameters.
+     * Validate query parameters.
+     *
      * @param cmHandleQueryServiceParameters name of data to be validated
+     * @param validConditionNames valid condition names
      */
     public static void validateCmHandleQueryParameters(
-            final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+        final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+        final Collection<String> validConditionNames) {
         cmHandleQueryServiceParameters.getCmHandleQueryParameters().forEach(
-                conditionApiProperty -> {
-                    if (Strings.isNullOrEmpty(conditionApiProperty.getConditionName())) {
-                        throw createDataValidationException("Missing 'conditionName' - please supply a valid name.");
-                    }
-                    if (Arrays.stream(ValidQueryProperties.values()).noneMatch(validQueryProperty ->
-                        validQueryProperty.getQueryProperty().equals(conditionApiProperty.getConditionName()))) {
+                cmHandleQueryParameter -> {
+                    if (validConditionNames.stream().noneMatch(validConditionName ->
+                        validConditionName.equals(cmHandleQueryParameter.getConditionName()))) {
                         throw createDataValidationException(
                                 String.format("Wrong 'conditionName': %s - please supply a valid name.",
-                                conditionApiProperty.getConditionName()));
+                                cmHandleQueryParameter.getConditionName()));
                     }
-                    if (conditionApiProperty.getConditionParameters().isEmpty()) {
+                    if (cmHandleQueryParameter.getConditionParameters().isEmpty()) {
                         throw createDataValidationException(
                                 "Empty 'conditionsParameters' - please supply a valid condition parameter.");
                     }
-                    conditionApiProperty.getConditionParameters().forEach(
-                            CmHandleQueryRestParametersValidator::validateConditionParameter
+                    cmHandleQueryParameter.getConditionParameters().forEach(
+                            RestQueryParametersValidator::validateConditionParameter
                     );
                 }
         );
@@ -67,7 +67,7 @@ public class CmHandleQueryRestParametersValidator {
                     "Empty 'conditionsParameter' - please supply a valid condition parameter.");
         }
         if (conditionParameter.size() > 1) {
-            throw createDataValidationException("Too many name in one 'conditionsParameter' -"
+            throw createDataValidationException("Too many names in one 'conditionsParameter' -"
                     + " please supply one name in one condition parameter.");
         }
         conditionParameter.forEach((key, value) -> {
index daabbb5..bae0262 100644 (file)
@@ -30,12 +30,22 @@ import org.onap.cps.spi.model.DataNode;
 public interface CmHandleQueries {
 
     /**
-     * Query CmHandles based on PublicProperties.
+     * Query CmHandles based on additional (private) properties.
+     *
+     * @param additionalPropertyQueryPairs private properties for query
+     * @return CmHandles which have these private properties
+     */
+    Map<String, NcmpServiceCmHandle> queryCmHandleAdditionalProperties(
+            Map<String, String> additionalPropertyQueryPairs);
+
+    /**
+     * Query CmHandles based on public properties.
      *
      * @param publicPropertyQueryPairs public properties for query
      * @return CmHandles which have these public properties
      */
-    Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs);
+    Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
+            Map<String, String> publicPropertyQueryPairs);
 
     /**
      * Combine Maps of CmHandles.
index e9e2fca..1a54a82 100644 (file)
@@ -34,6 +34,7 @@ import java.util.Set;
 import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.inventory.enums.PropertyType;
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
 import org.onap.cps.spi.CpsDataPersistenceService;
 import org.onap.cps.spi.FetchDescendantsOption;
@@ -51,16 +52,28 @@ public class CmHandleQueriesImpl implements CmHandleQueries {
     private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
     private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
 
+    @Override
+    public Map<String, NcmpServiceCmHandle> queryCmHandleAdditionalProperties(
+            final Map<String, String> privatePropertyQueryPairs) {
+        return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL);
+    }
 
     @Override
     public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
             final Map<String, String> publicPropertyQueryPairs) {
-        if (publicPropertyQueryPairs.isEmpty()) {
+        return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC);
+    }
+
+    private  Map<String, NcmpServiceCmHandle> queryCmHandleAnyProperties(
+            final Map<String, String> propertyQueryPairs,
+            final PropertyType propertyType) {
+        if (propertyQueryPairs.isEmpty()) {
             return Collections.emptyMap();
         }
         Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
-        for (final Map.Entry<String, String> publicPropertyQueryPair : publicPropertyQueryPairs.entrySet()) {
-            final String cpsPath = "//public-properties[@name=\"" + publicPropertyQueryPair.getKey()
+        for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
+            final String cpsPath = "//" + propertyType.getYangContainerName() + "[@name=\""
+                    + publicPropertyQueryPair.getKey()
                     + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
 
             final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.utils;
+package org.onap.cps.ncmp.api.inventory.enums;
 
+import lombok.AllArgsConstructor;
 import lombok.Getter;
 
 @Getter
-public enum ValidQueryProperties {
-    HAS_ALL_PROPERTIES("hasAllProperties"),
-    HAS_ALL_MODULES("hasAllModules"),
-    WITH_CPS_PATH("cmHandleWithCpsPath");
+@AllArgsConstructor
+public enum PropertyType {
+    ADDITIONAL("additional-properties"),
+    PUBLIC("public-properties"),
+    DMI_PLUGIN("dmiPluginName");
 
-    private final String queryProperty;
-
-    ValidQueryProperties(final String queryProperty) {
-        this.queryProperty = queryProperty;
-    }
+    private final String yangContainerName;
 }
@@ -18,7 +18,7 @@
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.spi.model;
+package org.onap.cps.ncmp.api.models;
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -29,6 +29,7 @@ import javax.validation.Valid;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
+import org.onap.cps.spi.model.ConditionProperties;
 
 @Setter
 @Getter
index eea53e8..201f6af 100644 (file)
@@ -22,13 +22,14 @@ package org.onap.cps.ncmp.api.impl
 
 import org.onap.cps.cpspath.parser.PathParsingException
 import org.onap.cps.ncmp.api.inventory.CmHandleQueries
+import org.onap.cps.ncmp.api.inventory.CmHandleQueriesImpl
 import org.onap.cps.ncmp.api.inventory.InventoryPersistence
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import org.onap.cps.spi.FetchDescendantsOption
 import org.onap.cps.spi.exceptions.DataInUseException
 import org.onap.cps.spi.exceptions.DataValidationException
 import org.onap.cps.spi.model.Anchor
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ConditionProperties
 import org.onap.cps.spi.model.DataNode
 import spock.lang.Specification
@@ -38,12 +39,16 @@ import java.util.stream.Collectors
 class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
 
     def cmHandleQueries = Mock(CmHandleQueries)
-    def inventoryPersistence = Mock(InventoryPersistence)
+    def partiallyMockedCmHandleQueries = Spy(CmHandleQueriesImpl)
+    def mockInventoryPersistence = Mock(InventoryPersistence)
 
     def static someCmHandleDataNode = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'some-cmhandle-id\']', leaves: ['id':'some-cmhandle-id'])
     def dmiRegistry = new DataNode(xpath: '/dmi-registry', childDataNodes: createDataNodeList(['PNFDemo1', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4']))
 
-    def objectUnderTest = new NetworkCmProxyCmHandlerQueryServiceImpl(cmHandleQueries, inventoryPersistence)
+    static def queryResultCmHandleMap = createCmHandleMap(['H1', 'H2'])
+
+    def objectUnderTest = new NetworkCmProxyCmHandlerQueryServiceImpl(cmHandleQueries, mockInventoryPersistence)
+    def objectUnderTestSpy = new NetworkCmProxyCmHandlerQueryServiceImpl(partiallyMockedCmHandleQueries, mockInventoryPersistence)
 
     def 'Retrieve cm handles with cpsPath when combined with no Module Query.'() {
         given: 'a cmHandleWithCpsPath condition property'
@@ -105,9 +110,9 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         and: 'null is returned from the state and public property queries'
             cmHandleQueries.combineCmHandleQueries(*_) >> null
         and: '#scenario from the modules query'
-            inventoryPersistence.queryAnchors(*_) >> returnedAnchors
+            mockInventoryPersistence.queryAnchors(*_) >> returnedAnchors
         and: 'the same cmHandles are returned from the persistence service layer'
-            returnedAnchors.size() * inventoryPersistence.getDataNode(*_) >> returnedCmHandles
+            returnedAnchors.size() * mockInventoryPersistence.getDataNode(*_) >> returnedCmHandles
         when: 'the query is executed for both cm handle ids and details'
             def returnedCmHandlesJustIds = objectUnderTest.queryCmHandleIds(cmHandleQueryParameters)
             def returnedCmHandlesWithData = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
@@ -131,7 +136,7 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         and: 'cmHandles are returned from the state and public property combined queries'
             cmHandleQueries.combineCmHandleQueries(*_) >> combinedQueryMap
         and: 'cmHandles are returned from the module names query'
-            inventoryPersistence.queryAnchors(['some-module-name']) >> anchorsForModuleQuery
+            mockInventoryPersistence.queryAnchors(['some-module-name']) >> anchorsForModuleQuery
         and: 'cmHandleQueries returns a datanode result'
             2 * cmHandleQueries.queryCmHandleDataNodesByCpsPath(*_) >> [someCmHandleDataNode]
         when: 'the query is executed for both cm handle ids and details'
@@ -154,9 +159,9 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
         given: 'We use an empty query'
             def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
         and: 'the inventory persistence returns the dmi registry datanode with just ids'
-            inventoryPersistence.getDataNode("/dmi-registry", FetchDescendantsOption.FETCH_DIRECT_CHILDREN_ONLY) >> dmiRegistry
+            mockInventoryPersistence.getDataNode("/dmi-registry", FetchDescendantsOption.FETCH_DIRECT_CHILDREN_ONLY) >> dmiRegistry
         and: 'the inventory persistence returns the dmi registry datanode with data'
-            inventoryPersistence.getDataNode("/dmi-registry") >> dmiRegistry
+            mockInventoryPersistence.getDataNode("/dmi-registry") >> dmiRegistry
         when: 'the query is executed for both cm handle ids and details'
             def returnedCmHandlesJustIds = objectUnderTest.queryCmHandleIds(cmHandleQueryParameters)
             def returnedCmHandlesWithData = objectUnderTest.queryCmHandles(cmHandleQueryParameters)
@@ -165,13 +170,68 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
             returnedCmHandlesWithData.stream().map(d -> d.cmHandleId).collect(Collectors.toSet()) == ['PNFDemo1', 'PNFDemo2', 'PNFDemo3', 'PNFDemo4'] as Set
     }
 
+
+    def 'Retrieve all CMHandleIds for empty query parameters' () {
+        given: 'We query without any parameters'
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
+        and: 'the inventoryPersistence returns all four CmHandleIds'
+            mockInventoryPersistence.getDataNode(*_) >> dmiRegistry
+        when: 'the query executed'
+            def resultSet = objectUnderTest.queryCmHandleIdsForInventory(cmHandleQueryParameters)
+        then: 'the size of the result list equals the size of all cmHandleIds.'
+            resultSet.size() == 4
+    }
+
+    def 'Retrieve CMHandleIds when #scenario.' () {
+        given: 'a query object created with #condition'
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
+            def conditionProperties = createConditionProperties(conditionName, [['some-key': 'some-value']])
+            cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
+        and: 'the inventoryPersistence returns different CmHandleIds'
+            partiallyMockedCmHandleQueries.queryCmHandlePublicProperties(*_) >> cmHandlesWithMatchingPublicProperties
+            partiallyMockedCmHandleQueries.queryCmHandleAdditionalProperties(*_) >> cmHandlesWithMatchingPrivateProperties
+        when: 'the query executed'
+            def result = objectUnderTestSpy.queryCmHandleIdsForInventory(cmHandleQueryParameters)
+        then: 'the expected number of results are returned.'
+            assert result.size() == expectedCmHandleIdsSize
+        where: 'the following data is used'
+            scenario                                          | conditionName                | cmHandlesWithMatchingPublicProperties | cmHandlesWithMatchingPrivateProperties || expectedCmHandleIdsSize
+            'all properties, only public matching'            | 'hasAllProperties'           | queryResultCmHandleMap                |  null                                  || 2
+            'all properties, no matching cm handles'          | 'hasAllProperties'           | [:]                                   |  [:]                                   || 0
+            'additional properties, some matching cm handles' | 'hasAllAdditionalProperties' | [:]                                   | queryResultCmHandleMap                 || 2
+            'additional properties, no matching cm handles'   | 'hasAllAdditionalProperties' | null                                  |  [:]                                   || 0
+    }
+
+    def 'Retrieve CMHandleIds by different DMI properties with #scenario.' () {
+        given: 'a query object created with dmi plugin as condition'
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
+            def conditionProperties = createConditionProperties('cmHandleWithDmiPlugin', [['some-key': 'some-value']])
+            cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
+        and: 'the inventoryPersistence returns different CmHandleIds'
+            partiallyMockedCmHandleQueries.getCmHandlesByDmiPluginIdentifier(*_) >> cmHandleQueryResult
+        when: 'the query executed'
+            def result = objectUnderTestSpy.queryCmHandleIdsForInventory(cmHandleQueryParameters)
+        then: 'the expected number of results are returned.'
+            assert result.size() == expectedCmHandleIdsSize
+        where: 'the following data is used'
+            scenario       | cmHandleQueryResult             || expectedCmHandleIdsSize
+            'some matches' | queryResultCmHandleMap.values() || 2
+            'no matches'   | []                              || 0
+    }
+
+    static def createCmHandleMap(cmHandleIds) {
+        def cmHandleMap = [:]
+        cmHandleIds.each{ cmHandleMap[it] = new NcmpServiceCmHandle(cmHandleId : it) }
+        return cmHandleMap
+    }
+
     def createConditionProperties(String conditionName, List<Map<String, String>> conditionParameters) {
         return new ConditionProperties(conditionName : conditionName, conditionParameters : conditionParameters)
     }
 
     def static createDataNodeList(dataNodeIds) {
         def dataNodes =[]
-        dataNodeIds.forEach(id -> {dataNodes.add(new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'' + id + '\']', leaves: ['id':id]))})
+        dataNodeIds.each{ dataNodes << new DataNode(xpath: "/dmi-registry/cm-handles[@id='${it}']", leaves: ['id':it]) }
         return dataNodes
     }
 }
index 58ca06b..578f7f3 100644 (file)
@@ -33,14 +33,12 @@ import org.onap.cps.ncmp.api.inventory.InventoryPersistence
 import org.onap.cps.ncmp.api.inventory.LockReasonCategory
 import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
 import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters
-import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.ncmp.api.models.ConditionApiProperties
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import org.onap.cps.spi.exceptions.CpsException
-import org.onap.cps.spi.exceptions.DataNodeNotFoundException
-import org.onap.cps.spi.exceptions.DataValidationException
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters
+import org.onap.cps.spi.model.ConditionProperties
 import spock.lang.Shared
 import java.util.stream.Collectors
 import org.onap.cps.utils.JsonObjectMapper
@@ -57,10 +55,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.
 import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.PASSTHROUGH_RUNNING
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE
-import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError.CM_HANDLE_DOES_NOT_EXIST
-import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError.CM_HANDLE_INVALID_ID
-import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError.UNKNOWN_ERROR
-
 
 class NetworkCmProxyDataServiceImplSpec extends Specification {
 
@@ -202,6 +196,23 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             result == [ 'public prop' : 'some public prop' ]
     }
 
+    def 'Execute cm handle id search for inventory'() {
+        given: 'a ConditionApiProperties object'
+            def conditionProperties = new ConditionProperties()
+            conditionProperties.conditionName = 'hasAllProperties'
+            conditionProperties.conditionParameters = [ [ 'some-key' : 'some-value' ] ]
+            def conditionServiceProps = new CmHandleQueryServiceParameters()
+            conditionServiceProps.cmHandleQueryParameters = [conditionProperties] as List<ConditionProperties>
+        and: 'the system returns an set of cmHandle ids'
+            mockCpsCmHandlerQueryService.queryCmHandleIdsForInventory(*_) >> [ 'cmHandle1', 'cmHandle2' ]
+        when: 'getting cm handle id set for a given dmi property'
+            def result = objectUnderTest.executeCmHandleIdSearchForInventory(conditionServiceProps)
+        then: 'the result returns the correct 2 elements'
+            assert result.size() == 2
+            assert result.contains('cmHandle1')
+            assert result.contains('cmHandle2')
+    }
+
     def 'Get cm handle composite state'() {
         given: 'a yang modelled cm handle'
             def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
index 31f179a..51162c7 100644 (file)
@@ -23,7 +23,7 @@ package org.onap.cps.ncmp.api.impl.async
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.apache.kafka.clients.consumer.KafkaConsumer
 import org.mapstruct.factory.Mappers
-import org.onap.cps.ncmp.api.utils.MessagingSpec
+import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
 import org.onap.cps.ncmp.event.model.DmiAsyncRequestResponseEvent
 import org.onap.cps.ncmp.event.model.NcmpAsyncRequestResponseEvent
 import org.onap.cps.ncmp.utils.TestUtils
@@ -39,7 +39,7 @@ import java.time.Duration
 @SpringBootTest(classes = [NcmpAsyncRequestResponseEventProducer, NcmpAsyncRequestResponseEventConsumer, ObjectMapper, JsonObjectMapper])
 @Testcontainers
 @DirtiesContext
-class NcmpAsyncRequestResponseEventProducerIntegrationSpec extends MessagingSpec {
+class NcmpAsyncRequestResponseEventProducerIntegrationSpec extends MessagingBaseSpec {
 
     @SpringBean
     NcmpAsyncRequestResponseEventProducer cpsAsyncRequestResponseEventProducerService =
index c7e6b6d..61bf33d 100644 (file)
@@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl.event.lcm
 
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.apache.kafka.clients.consumer.KafkaConsumer
-import org.onap.cps.ncmp.api.utils.MessagingSpec
+import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
 import org.onap.cps.ncmp.utils.TestUtils
 import org.onap.cps.utils.JsonObjectMapper
 import org.onap.ncmp.cmhandle.event.lcm.Event
@@ -38,7 +38,7 @@ import java.time.Duration
 @SpringBootTest(classes = [LcmEventsPublisher, ObjectMapper, JsonObjectMapper])
 @Testcontainers
 @DirtiesContext
-class LcmEventsPublisherSpec extends MessagingSpec {
+class LcmEventsPublisherSpec extends MessagingBaseSpec {
 
     def kafkaConsumer = new KafkaConsumer<>(consumerConfigProperties('ncmp-group'))
 
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditionsSpec.groovy
new file mode 100644 (file)
index 0000000..f0e2d9f
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START========================================================
+ * Copyright (c) 2022 Nordix Foundation.
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an 'AS IS' BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.utils
+
+import spock.lang.Specification
+
+class CmHandleQueryConditionsSpec extends Specification {
+
+    def 'CmHandle query condition names.'() {
+        expect: '3 conditions with the correct names'
+            assert CmHandleQueryConditions.ALL_CONDITION_NAMES.size() == 3
+            assert CmHandleQueryConditions.ALL_CONDITION_NAMES.containsAll('hasAllProperties',
+                                                                           'hasAllModules',
+                                                                           'cmHandleWithCpsPath')
+    }
+
+}
@@ -18,7 +18,7 @@
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.utils
+package org.onap.cps.ncmp.api.impl.utils
 
 import org.onap.cps.spi.utils.CpsValidator
 
@@ -26,7 +26,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiOperations.DataStoreEnum.
 
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
-import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder
 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import spock.lang.Shared
 import spock.lang.Specification
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditionsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditionsSpec.groovy
new file mode 100644 (file)
index 0000000..00edb8d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START========================================================
+ * Copyright (c) 2022 Nordix Foundation.
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an 'AS IS' BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.utils
+
+import spock.lang.Specification
+
+class InventoryQueryConditionsSpec extends Specification {
+
+    def 'Inventory query condition names.'() {
+        expect: '3 conditions with the correct names'
+            assert InventoryQueryConditions.ALL_CONDITION_NAMES.size() == 3
+            assert InventoryQueryConditions.ALL_CONDITION_NAMES.containsAll('hasAllProperties',
+                                                                            'hasAllAdditionalProperties',
+                                                                            'cmHandleWithDmiPlugin')
+    }
+
+
+}
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.utils
+package org.onap.cps.ncmp.api.impl.utils
 
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
 import org.onap.cps.spi.exceptions.DataValidationException
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ConditionProperties
 import spock.lang.Specification
 
-class CmHandleQueryRestParametersValidatorSpec extends Specification {
+class RestQueryParametersValidatorSpec extends Specification {
+
+
     def 'CM Handle Query validation: empty query.'() {
         given: 'a cm handle query'
             def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
         when: 'validator is invoked'
-            CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters)
+            RestQueryParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters, [])
         then: 'data validation exception is not thrown'
             noExceptionThrown()
     }
@@ -39,11 +41,11 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
         given: 'a cm handle query'
             def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def condition = new ConditionProperties()
-            condition.conditionName = 'hasAllProperties'
-            condition.conditionParameters = [[key1:'value1'],[key2:'value2']]
-            cmHandleQueryParameters.cmHandleQueryParameters = [condition]
+            condition.conditionName = 'validConditionName'
+            condition.conditionParameters = [['key':'value']]
+        cmHandleQueryParameters.cmHandleQueryParameters = [condition]
         when: 'validator is invoked'
-            CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters)
+            RestQueryParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters, ['validConditionName'])
         then: 'data validation exception is not thrown'
             noExceptionThrown()
     }
@@ -56,31 +58,33 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
             condition.conditionParameters = conditionParameters
             cmHandleQueryParameters.cmHandleQueryParameters = [condition]
         when: 'validator is invoked'
-            CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters)
+            RestQueryParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters, ['validConditionName'])
         then: 'a data validation exception is thrown'
-            thrown(DataValidationException)
+            def thrown = thrown(DataValidationException)
+        and: 'the exception details contain the correct significant term '
+            thrown.details.contains(expectedWordInDetails)
         where:
-            scenario               | conditionName      | conditionParameters
-            'empty properties'     | 'hasAllProperties' | [[ : ]]
-            'empty conditions'     | 'hasAllProperties' | []
-            'wrong condition name' | 'wrong'            | []
-            'no condition name'    | ''                 | []
-            'too many properties'  | 'hasAllProperties' | [[key1:'value1', key2:'value2']]
-            'wrong properties'     | 'hasAllProperties' | [['':'wrong']]
+            scenario                 | conditionName        | conditionParameters              || expectedWordInDetails
+            'unknown condition name' | 'unknownCondition'   | [['key':'value']]                  || 'conditionName'
+            'no condition name'      | ''                   | [['key':'value']]                  || 'conditionName'
+            'empty properties'       | 'validConditionName' | [[ : ]]                          || 'conditionsParameter'
+            'empty conditions'       | 'validConditionName' | [[:]]                               || 'conditionsParameter'
+            'too many properties'    | 'validConditionName' | [[key1:'value1', key2:'value2']] || 'conditionsParameter'
+            'empty key'              | 'validConditionName' | [['':'wrong']]                   || 'conditionsParameter'
     }
 
     def 'CM Handle Query validation: validate module name condition properties - valid query.'() {
         given: 'a condition property'
             def conditionProperty = [moduleName: 'value']
         when: 'validator is invoked'
-            CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties(conditionProperty)
+            RestQueryParametersValidator.validateModuleNameConditionProperties(conditionProperty)
         then: 'data validation exception is not thrown'
             noExceptionThrown()
     }
 
     def 'CM Handle Query validation: validate module name condition properties - #scenario.'() {
         when: 'validator is invoked'
-            CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties(conditionProperty)
+            RestQueryParametersValidator.validateModuleNameConditionProperties(conditionProperty)
         then: 'a data validation exception is thrown'
             thrown(DataValidationException)
         where:
@@ -91,7 +95,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
 
     def 'Validate CmHandle where an exception is thrown due to #scenario.'() {
         when: 'the validator is called on a cps path condition property'
-            CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties(conditionProperty)
+            RestQueryParametersValidator.validateCpsPathConditionProperties(conditionProperty)
         then: 'a data validation exception is thrown'
             def e = thrown(DataValidationException)
         and: 'exception message matches the expected message'
@@ -105,12 +109,12 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
 
     def 'No conditions.'() {
         expect: 'no conditions always returns true'
-            CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties([:]) == true
+            RestQueryParametersValidator.validateCpsPathConditionProperties([:]) == true
     }
 
     def 'Validate CmHandle where #scenario.'() {
         when: 'the validator is called on a cps path condition property'
-            def result = CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties(['cpsPath':cpsPath])
+            def result = RestQueryParametersValidator.validateCpsPathConditionProperties(['cpsPath':cpsPath])
         then: 'the expected boolean value is returned'
             result == expectedBoolean
         where:
@@ -18,9 +18,8 @@
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.utils
+package org.onap.cps.ncmp.api.impl.utils
 
-import org.onap.cps.ncmp.api.impl.utils.YangDataConverter
 import org.onap.cps.spi.model.DataNode
 import spock.lang.Specification
 
index 752b9f3..2800f5c 100644 (file)
@@ -37,10 +37,13 @@ class CmHandleQueriesImplSpec extends Specification {
     @Shared
     def static sampleDataNodes = [new DataNode()]
 
+    def dataNodeWithPrivateField = '//additional-properties[@name=\"Contact3\" and @value=\"newemailforstore3@bookstore.com\"]/ancestor::cm-handles'
+
     def static pnfDemo = createDataNode('PNFDemo')
     def static pnfDemo2 = createDataNode('PNFDemo2')
     def static pnfDemo3 = createDataNode('PNFDemo3')
     def static pnfDemo4 = createDataNode('PNFDemo4')
+    def static pnfDemo5 = createDataNode('PNFDemo5')
 
     def static pnfDemoCmHandle = new NcmpServiceCmHandle(cmHandleId: 'PNFDemo')
     def static pnfDemo2CmHandle = new NcmpServiceCmHandle(cmHandleId: 'PNFDemo2')
@@ -69,6 +72,22 @@ class CmHandleQueriesImplSpec extends Specification {
             returnedCmHandlesWithData.keySet().size() == 0
     }
 
+    def 'Query CmHandles using empty private properties query pair.'() {
+        when: 'a query on CmHandle private properties is executed using an empty map'
+            def returnedCmHandlesWithData = objectUnderTest.queryCmHandleAdditionalProperties([:])
+        then: 'no cm handles are returned'
+            returnedCmHandlesWithData.keySet().size() == 0
+    }
+
+    def 'Query CmHandles by a private field\'s value.'() {
+        given: 'a data node exists with a certain additional-property'
+            cpsDataPersistenceService.queryDataNodes(_, _, dataNodeWithPrivateField, _) >> [pnfDemo5]
+        when: 'a query on CmHandle private properties is executed using a map'
+            def returnedCmHandlesWithData = objectUnderTest.queryCmHandleAdditionalProperties(['Contact3': 'newemailforstore3@bookstore.com'])
+        then: 'one cm handle is returned'
+            returnedCmHandlesWithData.keySet().size() == 1
+    }
+
     def 'Combine two query results where #scenario.'() {
         when: 'two query results in the form of a map of NcmpServiceCmHandles are combined into a single query result'
             def result = objectUnderTest.combineCmHandleQueries(firstQuery, secondQuery)
@@ -85,7 +104,7 @@ class CmHandleQueriesImplSpec extends Specification {
             'both queries are null'                                      | null                                                       | null                                                       || null
     }
 
-    def 'Get Cm Handles By State'() {
+    def 'Get CmHandles by it\'s state.'() {
         given: 'a cm handle state to query'
             def cmHandleState = CmHandleState.ADVISED
         and: 'the persistence service returns a list of data nodes'
@@ -97,6 +116,22 @@ class CmHandleQueriesImplSpec extends Specification {
             assert result == sampleDataNodes
     }
 
+    def 'Check the state of a cmHandle when #scenario.'() {
+        given: 'a cm handle state to compare'
+            def cmHandleState = state
+        and: 'the persistence service returns a list of data nodes'
+            cpsDataPersistenceService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+                    '/dmi-registry/cm-handles[@id=\'some-cm-handle\']/state', OMIT_DESCENDANTS) >> new DataNode(leaves: ['cm-handle-state': 'READY'])
+        when: 'cm handles are compared by state'
+            def result = objectUnderTest.cmHandleHasState('some-cm-handle', cmHandleState)
+        then: 'the returned result matches the expected result from the persistence service'
+            result == expectedResult
+        where:
+            scenario                           | state                 || expectedResult
+            'the provided state matches'       | CmHandleState.READY   || true
+            'the provided state does not match'| CmHandleState.DELETED || false
+    }
+
     def 'Get Cm Handles state by Cm-Handle Id'() {
         given: 'a cm handle state to query'
             def cmHandleState = CmHandleState.READY
@@ -18,7 +18,7 @@
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.utils
+package org.onap.cps.ncmp.api.kafka
 
 import org.apache.kafka.common.serialization.StringDeserializer
 import org.apache.kafka.common.serialization.StringSerializer
@@ -31,7 +31,7 @@ import org.testcontainers.containers.KafkaContainer
 import org.testcontainers.utility.DockerImageName
 import spock.lang.Specification
 
-class MessagingSpec extends Specification {
+class MessagingBaseSpec extends Specification {
 
     static {
         Runtime.getRuntime().addShutdownHook(new Thread(kafkaTestContainer::stop))
index a29d624..d3fe0f3 100755 (executable)
 
     <groupId>org.onap.cps</groupId>
     <artifactId>cps-parent</artifactId>
-    <version>3.2.0-SNAPSHOT</version>
+    <version>3.2.1-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <properties>
         <app>org.onap.cps.Application</app>
         <java.version>11</java.version>
         <minimum-coverage>0.97</minimum-coverage>
+        <postgres.version>42.5.0</postgres.version>
 
         <jacoco.reportDirectory.aggregate>${project.reporting.outputDirectory}/jacoco-aggregate</jacoco.reportDirectory.aggregate>
         <sonar.coverage.jacoco.xmlReportPaths>
index dce9ace..d9c1508 100644 (file)
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index f42aaaa..da41340 100755 (executable)
@@ -28,7 +28,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
 
index a1cc20c..b6fe284 100644 (file)
@@ -26,7 +26,7 @@
     <parent>\r
         <groupId>org.onap.cps</groupId>\r
         <artifactId>cps-parent</artifactId>\r
-        <version>3.2.0-SNAPSHOT</version>\r
+        <version>3.2.1-SNAPSHOT</version>\r
         <relativePath>../cps-parent/pom.xml</relativePath>\r
     </parent>\r
 \r
@@ -61,6 +61,7 @@
         <dependency>\r
             <groupId>org.postgresql</groupId>\r
             <artifactId>postgresql</artifactId>\r
+            <version>${postgres.version}</version>\r
         </dependency>\r
         <!-- Add Hibernate support for Postgres datatype JSONB -->\r
         <dependency>\r
index ac1be1c..b22f171 100644 (file)
@@ -232,9 +232,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         if (isRootXpath(xpath)) {
             final List<FragmentExtract> fragmentExtracts = fragmentRepository.getTopLevelFragments(dataspaceEntity,
                     anchorEntity);
-            final FragmentEntity fragmentEntity = FragmentEntityArranger.toFragmentEntityTree(anchorEntity,
+            return FragmentEntityArranger.toFragmentEntityTree(anchorEntity,
                     fragmentExtracts);
-            return fragmentEntity;
         } else {
             final String normalizedXpath = getNormalizedXpath(xpath);
             final FragmentEntity fragmentEntity;
index fdb1442..03f021e 100755 (executable)
@@ -62,9 +62,9 @@ import org.onap.cps.spi.repository.ModuleReferenceRepository;
 import org.onap.cps.spi.repository.SchemaSetRepository;
 import org.onap.cps.spi.repository.YangResourceRepository;
 import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangModelDependencyInfo;
 import org.springframework.dao.DataIntegrityViolationException;
 import org.springframework.retry.annotation.Backoff;
@@ -261,6 +261,11 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
                 createIdentifierFromSourceName(checkNotNull(sourceName));
 
         final var tempYangTextSchemaSource = new YangTextSchemaSource(revisionSourceIdentifier) {
+            @Override
+            public Optional<String> getSymbolicName() {
+                return Optional.empty();
+            }
+
             @Override
             protected MoreObjects.ToStringHelper addToStringAttributes(
                     final MoreObjects.ToStringHelper toStringHelper) {
index 781d4cb..fb6749c 100644 (file)
@@ -28,18 +28,19 @@ import org.onap.cps.spi.model.DataNodeBuilder
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.jdbc.Sql
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
-import static org.onap.cps.spi.impl.CpsPersistenceSpecBase.CLEAR_DATA
 
 class CpsToDataNodePerfTest extends CpsPersistenceSpecBase {
 
-    static final String SET_DATA = '/data/fragment.sql'
+    static final String PERF_TEST_DATA = '/data/perf-test.sql'
 
     @Autowired
     CpsDataPersistenceService objectUnderTest
 
-    def XPATH_DATA_NODE_WITH_DESCENDANTS = '/parent-1'
+    def PERF_TEST_PARENT = '/perf-parent-1'
 
-    @Sql([CLEAR_DATA, SET_DATA])
+    def EXPECTED_NUMBER_OF_NODES = 10051  //  1 Parent + 50 Children + 10000 Grand-children
+
+    @Sql([CLEAR_DATA, PERF_TEST_DATA])
     def 'Get data node by xpath with all descendants with many children'() {
         given: 'nodes and grandchildren have been persisted'
             def setupStopWatch = new StopWatch()
@@ -47,43 +48,65 @@ class CpsToDataNodePerfTest extends CpsPersistenceSpecBase {
             createLineage()
             setupStopWatch.stop()
             def setupDurationInMillis = setupStopWatch.getTime()
-        when: 'data node is requested with all descendants'
+        and: 'setup duration is under 8000 milliseconds'
+            assert setupDurationInMillis < 8000
+        when: 'get parent is executed with all descendants'
             def readStopWatch = new StopWatch()
             readStopWatch.start()
-            def result = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_NAME1, XPATH_DATA_NODE_WITH_DESCENDANTS, INCLUDE_ALL_DESCENDANTS)
+            def result = objectUnderTest.getDataNode('PERF-DATASPACE', 'PERF-ANCHOR', PERF_TEST_PARENT, INCLUDE_ALL_DESCENDANTS)
             readStopWatch.stop()
             def readDurationInMillis = readStopWatch.getTime()
-        then: 'setup duration is under 2500 milliseconds'
-            assert setupDurationInMillis < 2500
-        and: 'read duration is under 180 milliseconds'
-            assert readDurationInMillis < 180
+        then: 'read duration is under 450 milliseconds'
+            assert readDurationInMillis < 450
+        and: 'data node is returned with all the descendants populated'
+            assert countDataNodes(result) == EXPECTED_NUMBER_OF_NODES
+        when: 'get root is executed with all descendants'
+            readStopWatch.reset()
+            readStopWatch.start()
+            result = objectUnderTest.getDataNode('PERF-DATASPACE', 'PERF-ANCHOR', '', INCLUDE_ALL_DESCENDANTS)
+            readStopWatch.stop()
+            readDurationInMillis = readStopWatch.getTime()
+        then: 'read duration is under 450 milliseconds'
+            assert readDurationInMillis < 450
+        and: 'data node is returned with all the descendants populated'
+            assert countDataNodes(result) == EXPECTED_NUMBER_OF_NODES
+        when: 'query is executed with all descendants'
+            readStopWatch.reset()
+            readStopWatch.start()
+            result = objectUnderTest.queryDataNodes('PERF-DATASPACE', 'PERF-ANCHOR', '//perf-parent-1', INCLUDE_ALL_DESCENDANTS)
+            readStopWatch.stop()
+            readDurationInMillis = readStopWatch.getTime()
+        then: 'read duration is under 450 milliseconds'
+            assert readDurationInMillis < 450
         and: 'data node is returned with all the descendants populated'
-            assert countDataNodes(result) == 1533
+            assert countDataNodes(result) == EXPECTED_NUMBER_OF_NODES
     }
 
     def createLineage() {
-        def numOfChildren = 30
-        def numOfGrandChildren = 50
+        def numOfChildren = 50
+        def numOfGrandChildren = 200
         (1..numOfChildren).each {
             def childName = "perf-test-child-${it}".toString()
-            def newChild = goForthAndMultiply(XPATH_DATA_NODE_WITH_DESCENDANTS, childName, numOfGrandChildren)
-            objectUnderTest.addChildDataNode(DATASPACE_NAME, ANCHOR_NAME1, XPATH_DATA_NODE_WITH_DESCENDANTS, newChild)
+            def newChild = goForthAndMultiply(PERF_TEST_PARENT, childName, numOfGrandChildren)
+            objectUnderTest.addChildDataNode('PERF-DATASPACE', 'PERF-ANCHOR', PERF_TEST_PARENT, newChild)
         }
     }
 
     def goForthAndMultiply(parentXpath, childName, numOfGrandChildren) {
         def children = []
         (1..numOfGrandChildren).each {
-            def child = new DataNodeBuilder().withXpath("${parentXpath}/${childName}/${it}-grand-child").build()
+            def child = new DataNodeBuilder().withXpath("${parentXpath}/${childName}/${it}perf-test-grand-child").build()
             children.add(child)
         }
         return new DataNodeBuilder().withXpath("${parentXpath}/${childName}").withChildDataNodes(children).build()
     }
 
-    def countDataNodes(DataNode dataNode) {
+    def countDataNodes(dataNodes) {
         int nodeCount = 1
-        for (DataNode child : dataNode.childDataNodes) {
-            nodeCount = nodeCount + (countDataNodes(child))
+        for (DataNode parent : dataNodes) {
+            for (DataNode child : parent.childDataNodes) {
+                nodeCount = nodeCount + (countDataNodes(child))
+            }
         }
         return nodeCount
     }
diff --git a/cps-ri/src/test/resources/data/perf-test.sql b/cps-ri/src/test/resources/data/perf-test.sql
new file mode 100644 (file)
index 0000000..5119f26
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+   ============LICENSE_START=======================================================
+    Copyright (C) 2022 Nordix Foundation.
+   ================================================================================
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+   SPDX-License-Identifier: Apache-2.0
+   ============LICENSE_END=========================================================
+*/
+
+INSERT INTO DATASPACE (ID, NAME) VALUES (9001, 'PERF-DATASPACE');
+
+INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES  (9002, 'PERF-SCHEMA-SET', 9001);
+
+INSERT INTO ANCHOR (ID, NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES (9003, 'PERF-ANCHOR', 9001, 9002);
+
+INSERT INTO FRAGMENT (ID, DATASPACE_ID, ANCHOR_ID, PARENT_ID, XPATH) VALUES  (0, 9001, 9003, null, '/perf-parent-1');
+
index 4a98cc2..77f262c 100644 (file)
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.onap.cps</groupId>
     <artifactId>cps-parent</artifactId>
-    <version>3.2.0-SNAPSHOT</version>
+    <version>3.2.1-SNAPSHOT</version>
     <relativePath>../cps-parent/pom.xml</relativePath>
   </parent>
 
index 88ebe3b..b08d8c1 100755 (executable)
@@ -226,11 +226,11 @@ public class CpsDataServiceImpl implements CpsDataService {
         final SchemaContext schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
 
         if (ROOT_NODE_XPATH.equals(parentNodeXpath)) {
-            final NormalizedNode<?, ?> normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext);
+            final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext);
             return new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build();
         }
 
-        final NormalizedNode<?, ?> normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
+        final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
         return new DataNodeBuilder()
             .withParentNodeXpath(parentNodeXpath)
             .withNormalizedNodeTree(normalizedNode)
@@ -252,7 +252,7 @@ public class CpsDataServiceImpl implements CpsDataService {
         final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
         final SchemaContext schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
 
-        final NormalizedNode<?, ?> normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
+        final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
         final Collection<DataNode> dataNodes = new DataNodeBuilder()
             .withParentNodeXpath(parentNodeXpath)
             .withNormalizedNodeTree(normalizedNode)
index f2bde03..eaa2d77 100644 (file)
@@ -44,7 +44,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.ValueNode;
 @Slf4j
 public class DataNodeBuilder {
 
-    private NormalizedNode<?, ?> normalizedNodeTree;
+    private NormalizedNode normalizedNodeTree;
     private String xpath;
     private String moduleNamePrefix;
     private String parentNodeXpath = "";
@@ -69,7 +69,7 @@ public class DataNodeBuilder {
      * @param normalizedNodeTree used for creating the Data Node
      * @return this {@link DataNodeBuilder} object
      */
-    public DataNodeBuilder withNormalizedNodeTree(final NormalizedNode<?, ?> normalizedNodeTree) {
+    public DataNodeBuilder withNormalizedNodeTree(final NormalizedNode normalizedNodeTree) {
         this.normalizedNodeTree = normalizedNodeTree;
         return this;
     }
@@ -171,15 +171,16 @@ public class DataNodeBuilder {
     }
 
     private static void addDataNodeFromNormalizedNode(final DataNode currentDataNode,
-        final NormalizedNode<?, ?> normalizedNode) {
+        final NormalizedNode normalizedNode) {
 
         if (normalizedNode instanceof DataContainerNode) {
-            addYangContainer(currentDataNode, (DataContainerNode<?>) normalizedNode);
+            addYangContainer(currentDataNode, (DataContainerNode) normalizedNode);
         } else if (normalizedNode instanceof MapNode) {
             addDataNodeForEachListElement(currentDataNode, (MapNode) normalizedNode);
         } else if (normalizedNode instanceof ValueNode) {
-            final ValueNode<?, ?> valuesNode = (ValueNode<?, ?>) normalizedNode;
-            addYangLeaf(currentDataNode, valuesNode.getNodeType().getLocalName(), valuesNode.getValue());
+            final ValueNode<NormalizedNode> valuesNode = (ValueNode) normalizedNode;
+            addYangLeaf(currentDataNode, valuesNode.getIdentifier().getNodeType().getLocalName(),
+                    valuesNode.body());
         } else if (normalizedNode instanceof LeafSetNode) {
             addYangLeafList(currentDataNode, (LeafSetNode<?>) normalizedNode);
         } else {
@@ -187,13 +188,13 @@ public class DataNodeBuilder {
         }
     }
 
-    private static void addYangContainer(final DataNode currentDataNode, final DataContainerNode<?> dataContainerNode) {
+    private static void addYangContainer(final DataNode currentDataNode, final DataContainerNode dataContainerNode) {
         final DataNode dataContainerDataNode =
             (dataContainerNode.getIdentifier() instanceof YangInstanceIdentifier.AugmentationIdentifier)
                 ? currentDataNode
                 : createAndAddChildDataNode(currentDataNode, YangUtils.buildXpath(dataContainerNode.getIdentifier()));
-        final Collection<DataContainerChild<?, ?>> normalizedChildNodes = dataContainerNode.getValue();
-        for (final NormalizedNode<?, ?> normalizedNode : normalizedChildNodes) {
+        final Collection<DataContainerChild> normalizedChildNodes = dataContainerNode.body();
+        for (final NormalizedNode normalizedNode : normalizedChildNodes) {
             addDataNodeFromNormalizedNode(dataContainerDataNode, normalizedNode);
         }
     }
@@ -207,16 +208,16 @@ public class DataNodeBuilder {
     }
 
     private static void addYangLeafList(final DataNode currentDataNode, final LeafSetNode<?> leafSetNode) {
-        final String leafListName = leafSetNode.getNodeType().getLocalName();
-        final List<?> leafListValues = ((Collection<? extends NormalizedNode<?, ?>>) leafSetNode.getValue())
-            .stream()
-            .map(normalizedNode -> ((ValueNode<?, ?>) normalizedNode).getValue())
-            .collect(Collectors.toUnmodifiableList());
+        final String leafListName = leafSetNode.getIdentifier().getNodeType().getLocalName();
+        final List<?> leafListValues = ((Collection<? extends NormalizedNode>) leafSetNode.body())
+                .stream()
+                .map(normalizedNode -> (normalizedNode).body())
+                .collect(Collectors.toUnmodifiableList());
         addYangLeaf(currentDataNode, leafListName, leafListValues);
     }
 
     private static void addDataNodeForEachListElement(final DataNode currentDataNode, final MapNode mapNode) {
-        final Collection<MapEntryNode> mapEntryNodes = mapNode.getValue();
+        final Collection<MapEntryNode> mapEntryNodes = mapNode.body();
         for (final MapEntryNode mapEntryNode : mapEntryNodes) {
             addDataNodeFromNormalizedNode(currentDataNode, mapEntryNode);
         }
index 8fcdc4e..48241ed 100644 (file)
@@ -26,6 +26,7 @@ import com.google.gson.JsonSyntaxException;
 import com.google.gson.stream.JsonReader;
 import java.io.IOException;
 import java.io.StringReader;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -36,8 +37,11 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.spi.exceptions.DataValidationException;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory;
 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
@@ -45,7 +49,10 @@ import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
 
 @Slf4j
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
@@ -61,8 +68,7 @@ public class YangUtils {
      * @param schemaContext schema context describing associated data model
      * @return the NormalizedNode object
      */
-    @SuppressWarnings("squid:S1452")  // Generic type <? ,?> is returned by external librray, opendaylight.yangtools
-    public static NormalizedNode<?, ?> parseJsonData(final String jsonData, final SchemaContext schemaContext) {
+    public static NormalizedNode parseJsonData(final String jsonData, final SchemaContext schemaContext) {
         return parseJsonData(jsonData, schemaContext, Optional.empty());
     }
 
@@ -74,32 +80,41 @@ public class YangUtils {
      * @param parentNodeXpath the xpath referencing the parent node current data fragment belong to
      * @return the NormalizedNode object
      */
-    @SuppressWarnings("squid:S1452")  // Generic type <? ,?> is returned by external librray, opendaylight.yangtools
-    public static NormalizedNode<?, ?> parseJsonData(final String jsonData, final SchemaContext schemaContext,
+    public static NormalizedNode parseJsonData(final String jsonData, final SchemaContext schemaContext,
         final String parentNodeXpath) {
-        final var parentSchemaNode = getDataSchemaNodeByXpath(parentNodeXpath, schemaContext);
-        return parseJsonData(jsonData, schemaContext, Optional.of(parentSchemaNode));
+        final Collection<QName> dataSchemaNodeIdentifiers =
+                getDataSchemaNodeIdentifiersByXpath(parentNodeXpath, schemaContext);
+        return parseJsonData(jsonData, schemaContext, Optional.of(dataSchemaNodeIdentifiers));
     }
 
-    private static NormalizedNode<?, ?> parseJsonData(final String jsonData, final SchemaContext schemaContext,
-        final Optional<DataSchemaNode> optionalParentSchemaNode) {
-        final var jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02
+    private static NormalizedNode parseJsonData(final String jsonData, final SchemaContext schemaContext,
+        final Optional<Collection<QName>> dataSchemaNodeIdentifiers) {
+        final JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02
             .getShared((EffectiveModelContext) schemaContext);
-        final var normalizedNodeResult = new NormalizedNodeResult();
-        final var normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter
+        final NormalizedNodeResult normalizedNodeResult = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter
             .from(normalizedNodeResult);
+        final JsonReader jsonReader = new JsonReader(new StringReader(jsonData));
+        final JsonParserStream jsonParserStream;
+
+        if (dataSchemaNodeIdentifiers.isPresent()) {
+            final EffectiveModelContext effectiveModelContext = ((EffectiveModelContext) schemaContext);
+            final EffectiveStatementInference effectiveStatementInference =
+                    SchemaInferenceStack.of(effectiveModelContext,
+                    SchemaNodeIdentifier.Absolute.of(dataSchemaNodeIdentifiers.get())).toInference();
+            jsonParserStream =
+                    JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory, effectiveStatementInference);
+        } else {
+            jsonParserStream = JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory);
+        }
 
-        try (final JsonParserStream jsonParserStream = optionalParentSchemaNode.isPresent()
-            ? JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory, optionalParentSchemaNode.get())
-            : JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory)
-        ) {
-            final var jsonReader = new JsonReader(new StringReader(jsonData));
+        try {
             jsonParserStream.parse(jsonReader);
-
-        } catch (final IOException | JsonSyntaxException exception) {
+            jsonParserStream.close();
+        } catch (final JsonSyntaxException exception) {
             throw new DataValidationException(
                 "Failed to parse json data: " + jsonData, exception.getMessage(), exception);
-        } catch (final IllegalStateException illegalStateException) {
+        } catch (final IOException | IllegalStateException illegalStateException) {
             throw new DataValidationException(
                 "Failed to parse json data. Unsupported xpath or json data:" + jsonData, illegalStateException
                 .getMessage(), illegalStateException);
@@ -114,7 +129,7 @@ public class YangUtils {
      * @return an xpath
      */
     public static String buildXpath(final YangInstanceIdentifier.PathArgument nodeIdentifier) {
-        final var xpathBuilder = new StringBuilder();
+        final StringBuilder xpathBuilder = new StringBuilder();
         xpathBuilder.append("/").append(nodeIdentifier.getNodeType().getLocalName());
 
         if (nodeIdentifier instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
@@ -143,10 +158,11 @@ public class YangUtils {
         }
     }
 
-    private static DataSchemaNode getDataSchemaNodeByXpath(final String parentNodeXpath,
-        final SchemaContext schemaContext) {
+    private static Collection<QName> getDataSchemaNodeIdentifiersByXpath(final String parentNodeXpath,
+                                                                      final SchemaContext schemaContext) {
         final String[] xpathNodeIdSequence = xpathToNodeIdSequence(parentNodeXpath);
-        return findDataSchemaNodeByXpathNodeIdSequence(xpathNodeIdSequence, schemaContext.getChildNodes());
+        return findDataSchemaNodeIdentifiersByXpathNodeIdSequence(xpathNodeIdSequence, schemaContext.getChildNodes(),
+                new ArrayList<>());
     }
 
     private static String[] xpathToNodeIdSequence(final String xpath) {
@@ -161,25 +177,29 @@ public class YangUtils {
         return xpathNodeIdSequence;
     }
 
-    private static DataSchemaNode findDataSchemaNodeByXpathNodeIdSequence(final String[] xpathNodeIdSequence,
-        final Collection<? extends DataSchemaNode> dataSchemaNodes) {
+    private static Collection<QName> findDataSchemaNodeIdentifiersByXpathNodeIdSequence(
+            final String[] xpathNodeIdSequence,
+            final Collection<? extends DataSchemaNode> dataSchemaNodes,
+            final Collection<QName> dataSchemaNodeIdentifiers) {
         final String currentXpathNodeId = xpathNodeIdSequence[0];
         final DataSchemaNode currentDataSchemaNode = dataSchemaNodes.stream()
             .filter(dataSchemaNode -> currentXpathNodeId.equals(dataSchemaNode.getQName().getLocalName()))
             .findFirst().orElseThrow(() -> schemaNodeNotFoundException(currentXpathNodeId));
+        dataSchemaNodeIdentifiers.add(currentDataSchemaNode.getQName());
         if (xpathNodeIdSequence.length <= 1) {
-            return currentDataSchemaNode;
+            return dataSchemaNodeIdentifiers;
         }
         if (currentDataSchemaNode instanceof DataNodeContainer) {
-            return findDataSchemaNodeByXpathNodeIdSequence(
+            return findDataSchemaNodeIdentifiersByXpathNodeIdSequence(
                 getNextLevelXpathNodeIdSequence(xpathNodeIdSequence),
-                ((DataNodeContainer) currentDataSchemaNode).getChildNodes());
+                    ((DataNodeContainer) currentDataSchemaNode).getChildNodes(),
+                    dataSchemaNodeIdentifiers);
         }
         throw schemaNodeNotFoundException(xpathNodeIdSequence[1]);
     }
 
     private static String[] getNextLevelXpathNodeIdSequence(final String[] xpathNodeIdSequence) {
-        final var nextXpathNodeIdSequence = new String[xpathNodeIdSequence.length - 1];
+        final String[] nextXpathNodeIdSequence = new String[xpathNodeIdSequence.length - 1];
         System.arraycopy(xpathNodeIdSequence, 1, nextXpathNodeIdSequence, 0, nextXpathNodeIdSequence.length);
         return nextXpathNodeIdSequence;
     }
index fd53497..e0f24f3 100644 (file)
@@ -32,6 +32,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import lombok.NoArgsConstructor;
@@ -41,9 +42,9 @@ import org.onap.cps.spi.model.ModuleReference;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
@@ -154,6 +155,11 @@ public final class YangTextSchemaSourceSetBuilder {
             createIdentifierFromSourceName(checkNotNull(sourceName));
 
         return new YangTextSchemaSource(revisionSourceIdentifier) {
+            @Override
+            public Optional<String> getSymbolicName() {
+                return Optional.empty();
+            }
+
             @Override
             protected MoreObjects.ToStringHelper addToStringAttributes(
                 final MoreObjects.ToStringHelper toStringHelper) {
index 68f9251..40f0e0a 100644 (file)
@@ -10,7 +10,7 @@ import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier
 import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import spock.lang.Specification
 import org.onap.cps.TestUtils
@@ -38,10 +38,10 @@ class JsonParserStreamSpec extends Specification{
         then: 'result is the correct size'
             result.size() == 2
         then: 'data container child is a type of normalized node'
-            def dataContainerChild = result.getValue()[index]
+            def dataContainerChild = result.body().getAt(index)
             dataContainerChild instanceof NormalizedNode == true
         then: 'qualified name created is as expected'
-            dataContainerChild.nodeType == QName.create('org:onap:ccsdk:multiDataTree', '2020-09-15', nodeName)
+            dataContainerChild.identifier.nodeType == QName.create('org:onap:ccsdk:multiDataTree', '2020-09-15', nodeName)
         where:
             index   | nodeName
             0       | 'first-container'
index 3f19091..65aa3af 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Nordix Foundation
+ *  Copyright (C) 2020-2022 Nordix Foundation
  *  Modifications Copyright (C) 2021 Pantheon.tech
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,9 +36,9 @@ class YangUtilsSpec extends Specification {
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
             def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
         when: 'the json data is parsed'
-            NormalizedNode<?, ?> result = YangUtils.parseJsonData(jsonData, schemaContext)
+            NormalizedNode result = YangUtils.parseJsonData(jsonData, schemaContext)
         then: 'the result is a normalized node of the correct type'
-            result.nodeType == QName.create('org:onap:ccsdk:sample', '2020-09-15', 'bookstore')
+            result.getIdentifier().nodeType == QName.create('org:onap:ccsdk:sample', '2020-09-15', 'bookstore')
     }
 
     def 'Parsing invalid data: #description.'() {
@@ -63,7 +63,7 @@ class YangUtilsSpec extends Specification {
         when: 'json string is parsed'
             def result = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
         then: 'result represents a node of expected type'
-            result.nodeType == QName.create('org:onap:cps:test:test-tree', '2020-02-02', nodeName)
+            result.getIdentifier().nodeType == QName.create('org:onap:cps:test:test-tree', '2020-02-02', nodeName)
         where:
             scenario                    | jsonData                                                                      | parentNodeXpath                       || nodeName
             'list element as container' | '{ "branch": { "name": "B", "nest": { "name": "N", "birds": ["bird"] } } }'   | '/test-tree'                          || 'branch'
index dada622..54dbce4 100644 (file)
@@ -1,12 +1,13 @@
-ROBOT_VENV=$(mktemp -d --suffix=robot_venv)
-echo "ROBOT_VENV=${ROBOT_VENV}" >> "${WORKSPACE}/env.properties"
+set -exu
+
+ROBOT3_VENV=$(mktemp -d --suffix=robot_venv)
+echo "ROBOT3_VENV=${ROBOT3_VENV}" >> "${WORKSPACE}/env.properties"
 
 echo "Python version is: $(python3 --version)"
 
-python3 -m venv "${ROBOT_VENV}"
-source "${ROBOT_VENV}/bin/activate"
+python3 -m venv "${ROBOT3_VENV}"
+source "${ROBOT3_VENV}/bin/activate"
 
-set -exu
 
 # Make sure pip3 itself us up-to-date.
 python3 -m pip install --upgrade pip
index b56c385..67412f3 100755 (executable)
@@ -20,6 +20,8 @@
 # Branched from ccsdk/distribution to this repository Feb 23, 2021
 #
 
+echo "---> prepare-csit.sh"
+
 if [ -z "$WORKSPACE" ]; then
     export WORKSPACE=`git rev-parse --show-toplevel`
 fi
@@ -35,11 +37,12 @@ if [ -f ${WORKSPACE}/env.properties ]; then
 fi
 if [ -f ${ROBOT3_VENV}/bin/activate ]; then
    source ${ROBOT3_VENV}/bin/activate
-#else
-#    rm -rf /tmp/ci-management
-#    rm -f ${WORKSPACE}/env.properties
-#    cd /tmp
-#    source ${WORKSPACE}/install-robotframework.sh
+else
+    rm -rf /tmp/ci-management
+    rm -f ${WORKSPACE}/env.properties
+    cd /tmp
+    git clone "https://gerrit.onap.org/r/ci-management"
+    source /tmp/ci-management/jjb/integration/include-raw-integration-install-robotframework-py3.sh
 fi
 
 # install eteutils
index d6250db..4952616 100644 (file)
@@ -5,7 +5,7 @@ netifaces
 pyhocon
 requests
 robotframework-httplibrary
-robotframework-requests
+robotframework-requests==0.9.3
 robotframework-selenium2library
 robotframework-extendedselenium2library
 robotframework-sshlibrary
index 25f5f6a..6703160 100755 (executable)
@@ -26,6 +26,8 @@ WORKDIR=$(mktemp -d --suffix=-robot-workdir)
 # functions
 #
 
+echo "---> run-csit.sh"
+
 # wrapper for sourcing a file
 function source_safely() {
     [ -z "$1" ] && return 1
index 59ff946..c7504e2 100644 (file)
@@ -246,8 +246,8 @@ Any spring supported property can be configured by providing in ``config.additio
 | config.additional.                    | Kafka topic to publish to cps-temporal                                                                  | ``cps.data-updated-events``   |
 | notification.data-updated.topic       |                                                                                                         |                               |
 +---------------------------------------+---------------------------------------------------------------------------------------------------------+-------------------------------+
-| config.additional.                    | Dataspaces to be enabled for publishing events to cps-temporal                                          |                               |
-| notification.data-updated.filters.    |                                                                                                         |                               |
+| config.additional.                    | Array of dataspaces to be enabled for publishing events to cps-temporal                                 | []                            |
+| notification.data-updated.filters.    | If left blank CPS-Temporal notification will be sent for all dataspaces                                  |                               |
 | enabled-dataspaces                    |                                                                                                         |                               |
 +---------------------------------------+---------------------------------------------------------------------------------------------------------+-------------------------------+
 | config.additional.                    | If asynchronous messaging, user notifications, and updated event persistence should be enabled          | ``true``                      |
index b757f19..6e6236b 100755 (executable)
@@ -16,8 +16,8 @@ CPS Release Notes
 ..      * * *   LONDON   * * *
 ..      ======================
 
-Version: 3.2.0 (not yet released)
-=================================
+Version: 3.2.1
+==============
 
 Release Data
 ------------
@@ -26,25 +26,26 @@ Release Data
 | **CPS Project**                      |                                                        |
 |                                      |                                                        |
 +--------------------------------------+--------------------------------------------------------+
-| **Docker images**                    | onap/cps-and-ncmp:3.2.0                                |
+| **Docker images**                    | (not yet released)                                     |
 |                                      |                                                        |
 +--------------------------------------+--------------------------------------------------------+
-| **Release designation**              | 3.2.0 London                                           |
+| **Release designation**              | 3.2.1 London                                           |
 |                                      |                                                        |
 +--------------------------------------+--------------------------------------------------------+
-| **Release date**                     | (not yet released)                                     |
+| **Release date**                     |                                                        |
 |                                      |                                                        |
 +--------------------------------------+--------------------------------------------------------+
 Features
 --------
-   - `CPS-1002 <https://jira.onap.org/browse/CPS-1002>`_  Query data NCMP-Operational with CPSpath
+3.2.1
+   - `CPS-1236 <https://jira.onap.org/browse/CPS-1236>`_  DMI audit support for NCMP: Filter on any properties of CM Handles
+3.2.0
    - `CPS-1185 <https://jira.onap.org/browse/CPS-1185>`_  Get all dataspaces
-   - `CPS-1186 <https://jira.onap.org/browse/CPS-1186>`_  Get all schema sets for a dataspace
    - `CPS-1187 <https://jira.onap.org/browse/CPS-1187>`_  Get single dataspace
-   - `CPS-1189 <https://jira.onap.org/browse/CPS-1189>`_  Various create endpoints should return 201 response with empty body
 
 Bug Fixes
 ---------
+3.2.0
    - `CPS-1312 <https://jira.onap.org/browse/CPS-1312>`_  CPS(/NCMP) does not have version control
    - `CPS-1350 <https://jira.onap.org/browse/CPS-1350>`_  [CPS/NCMP] Add Basic Auth to CPS/NCMP OpenAPI Definitions
 
index 3e7af63..5318c98 100644 (file)
@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.onap.cps</groupId>
         <artifactId>cps-parent</artifactId>
-        <version>3.2.0-SNAPSHOT</version>
+        <version>3.2.1-SNAPSHOT</version>
         <relativePath>../cps-parent/pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
diff --git a/pom.xml b/pom.xml
index 2f7c157..501861c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -32,7 +32,7 @@
 \r
     <groupId>org.onap.cps</groupId>\r
     <artifactId>cps-aggregator</artifactId>\r
-    <version>3.2.0-SNAPSHOT</version>\r
+    <version>3.2.1-SNAPSHOT</version>\r
     <packaging>pom</packaging>\r
 \r
     <name>cps</name>\r
index 306bdff..d63259e 100644 (file)
@@ -25,7 +25,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.onap.cps</groupId>
     <artifactId>spotbugs</artifactId>
-    <version>3.2.0-SNAPSHOT</version>
+    <version>3.2.1-SNAPSHOT</version>
 
     <properties>
         <nexusproxy>https://nexus.onap.org</nexusproxy>
index 0a0cb6c..5830e54 100755 (executable)
@@ -22,7 +22,7 @@
 
 major=3
 minor=2
-patch=0
+patch=1
 
 base_version=${major}.${minor}.${patch}