diff options
Diffstat (limited to 'cps-service')
10 files changed, 85 insertions, 46 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index 79d6e03d4..5e8eb9f6c 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Map; import org.onap.cps.spi.CascadeDeleteAllowed; import org.onap.cps.spi.exceptions.DataInUseException; +import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.spi.model.SchemaSet; @@ -94,6 +95,15 @@ public interface CpsModuleService { Collection<ModuleReference> getYangResourcesModuleReferences(String dataspaceName, String anchorName); /** + * Retrieve module definitions for the given dataspace name and anchor name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return a collection of module definitions (moduleName, revision, yang resource content) + */ + Collection<ModuleDefinition> getModuleDefinitionsByAnchorName(String dataspaceName, String anchorName); + + /** * Identify previously unknown Yang Resource module references. * The system will ignore the namespace of all module references. * diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index db8a81f27..ff725a617 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -31,6 +31,7 @@ import org.onap.cps.spi.CascadeDeleteAllowed; import org.onap.cps.spi.CpsModulePersistenceService; import org.onap.cps.spi.exceptions.SchemaSetInUseException; import org.onap.cps.spi.model.Anchor; +import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.spi.model.SchemaSet; import org.onap.cps.utils.CpsValidator; @@ -106,6 +107,13 @@ public class CpsModuleServiceImpl implements CpsModuleService { } @Override + public Collection<ModuleDefinition> getModuleDefinitionsByAnchorName(final String dataspaceName, + final String anchorName) { + CpsValidator.validateNameCharacters(dataspaceName, anchorName); + return cpsModulePersistenceService.getYangResourceDefinitions(dataspaceName, anchorName); + } + + @Override public Collection<ModuleReference> identifyNewModuleReferences( final Collection<ModuleReference> moduleReferencesToCheck) { return cpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck); diff --git a/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java b/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java index 2667ef490..2d8f7fb08 100644 --- a/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java +++ b/cps-service/src/main/java/org/onap/cps/config/AsyncConfig.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (c) 2021 Bell Canada. + * Modifications 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. @@ -33,7 +34,7 @@ import org.springframework.validation.annotation.Validated; @EnableAsync @Configuration -@ConditionalOnProperty(name = "notification.async.enabled", havingValue = "true", matchIfMissing = false) +@ConditionalOnProperty(name = "notification.enabled", havingValue = "true", matchIfMissing = true) @ConfigurationProperties("notification.async.executor") @Validated @Setter diff --git a/cps-service/src/main/java/org/onap/cps/notification/NotificationProperties.java b/cps-service/src/main/java/org/onap/cps/notification/NotificationProperties.java index eb75e3f75..3776a93d9 100644 --- a/cps-service/src/main/java/org/onap/cps/notification/NotificationProperties.java +++ b/cps-service/src/main/java/org/onap/cps/notification/NotificationProperties.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Map; import javax.validation.constraints.NotNull; import lombok.Data; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.validation.annotation.Validated; @@ -36,6 +37,7 @@ public class NotificationProperties { @NotNull private String topic; private Map<String, String> filters = Collections.emptyMap(); - @NotNull - private boolean enabled = false; + + @Value("${notification.enabled:true}") + private boolean enabled; } diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java index 0e90e84f1..db2cb60f3 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -23,6 +23,7 @@ package org.onap.cps.spi; import java.util.Collection; import java.util.Map; +import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; /** @@ -89,11 +90,20 @@ public interface CpsModulePersistenceService { * * @param dataspaceName dataspace name * @param anchorName anchor name - * @return a collection of module names and revisions + * @return a collection of module reference (moduleName and revision) */ Collection<ModuleReference> getYangResourceModuleReferences(String dataspaceName, String anchorName); /** + * Get YANG resource definitions for the given anchor name and dataspace name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return a collection of module definitions (moduleName, revision and yang resource content) + */ + Collection<ModuleDefinition> getYangResourceDefinitions(String dataspaceName, String anchorName); + + /** * Remove unused Yang Resource Modules. */ void deleteUnusedYangResourceModules(); diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeIdentifier.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeIdentifier.java deleted file mode 100644 index 2bd2b774d..000000000 --- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeIdentifier.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ============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.spi.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -@EqualsAndHashCode -@JsonIgnoreProperties(ignoreUnknown = true) -public class DataNodeIdentifier { - private String dataspace; - private String schemaSetName; - private String anchorName; - private String xpath; -} diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java new file mode 100644 index 000000000..d7a5b38dc --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java @@ -0,0 +1,37 @@ +/* + * ============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.spi.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ModuleDefinition extends ModuleReference { + + private static final long serialVersionUID = -6591435720836327732L; + private final String content; + + public ModuleDefinition(final String moduleName, final String revision, final String content) { + super(moduleName, revision); + this.content = content; + } +}
\ No newline at end of file diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index 95d731478..429de7d51 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -24,7 +24,6 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils import org.onap.cps.api.CpsAdminService -import org.onap.cps.spi.CascadeDeleteAllowed import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.exceptions.ModelValidationException @@ -243,4 +242,11 @@ class CpsModuleServiceImplSpec extends Specification { then: 'cps module persistence service is called with module references to check' 1 * mockCpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck); } + + def 'Getting module definitions.'() { + when: 'get module definitions method is called with a valid dataspace and anchor name' + objectUnderTest.getModuleDefinitionsByAnchorName('some-dataspace-name', 'some-anchor-name') + then: 'CPS module persistence service is invoked the correct number of times' + 1 * mockCpsModulePersistenceService.getYangResourceDefinitions('some-dataspace-name', 'some-anchor-name') + } } diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy index acb52413f..461014418 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy @@ -22,6 +22,7 @@ package org.onap.cps.utils import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationFeature import groovy.json.JsonSlurper import org.onap.cps.TestUtils import org.onap.cps.spi.exceptions.DataValidationException @@ -79,10 +80,12 @@ class JsonObjectMapperSpec extends Specification { def 'Map a unstructured object to json String.'() { given: 'Unstructured object' def object = new Object() + and: 'disable serialization failure on empty bean' + spiedObjectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); when: 'the object is mapped to string' jsonObjectMapper.asJsonString(object); - then: 'an exception is thrown' - thrown(DataValidationException) + then: 'no exception is thrown' + noExceptionThrown() } def 'Map a structurally compatible json String to JsonNode.'() { diff --git a/cps-service/src/test/resources/application.yml b/cps-service/src/test/resources/application.yml index a28b40083..04295eb74 100644 --- a/cps-service/src/test/resources/application.yml +++ b/cps-service/src/test/resources/application.yml @@ -18,13 +18,12 @@ # ============LICENSE_END========================================================= notification: + enabled: true data-updated: filters: enabled-dataspaces: ".*-published,.*-important" - enabled: true topic: cps-event async: - enabled: true executor: core-pool-size: 2 max-pool-size: 10 |