summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-02-27 20:16:47 -0500
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-03-11 09:13:22 -0400
commita5130dcf4e70f394c1432baefffc198882f04dc1 (patch)
treed0eaa477c7795db5066726def23aa6bc2cd4e363 /ms/controllerblueprints/modules/service
parentfc3e34836f7be8eda28a8f996d733e8dfca01450 (diff)
Add blueprint runtime validator
Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java60
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java147
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt12
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt22
4 files changed, 17 insertions, 224 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java
deleted file mode 100644
index 57330d90f..000000000
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2018 IBM.
- *
- * 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.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints.service.validator;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
-
-/**
- * ResourceDictionaryValidator.java Purpose: Provide Validation Service for Model Type Resource
- * Dictionary Validator
- *
- * @author Brinda Santh
- * @version 1.0
- */
-public class ResourceDictionaryValidator {
-
- private ResourceDictionaryValidator() {}
-
- /**
- * This is a validateResourceDictionary method
- *
- * @param resourceDictionary
- * @return boolean
- *
- */
- public static boolean validateResourceDictionary(ResourceDictionary resourceDictionary) {
-
- Preconditions.checkNotNull(resourceDictionary,"ResourceDictionary Information is missing." );
-
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()),
- "DataDictionary Alias Name Information is missing.");
- Preconditions.checkNotNull( resourceDictionary.getDefinition(),
- "DataDictionary Definition Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()),
- "DataDictionary Description Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getTags()),
- "DataDictionary Tags Information is missing.");
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getUpdatedBy()),
- "DataDictionary Updated By Information is missing.");
- return true;
-
- }
-
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
deleted file mode 100644
index 5d15e0876..000000000
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property.
- *
- * 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.
- */
-
-package org.onap.ccsdk.apps.controllerblueprints.service.validator;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
-import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintValidatorDefaultService;
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService;
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * ServiceTemplateValidator.java Purpose: Provide Configuration Generator ServiceTemplateValidator
- *
- * @author Brinda Santh
- * @version 1.0
- */
-
-public class ServiceTemplateValidator extends BluePrintValidatorDefaultService {
-
- StringBuilder message = new StringBuilder();
- private Map<String, String> metaData = new HashMap<>();
-
- /**
- * This is a validateServiceTemplate
- *
- * @param serviceTemplateContent serviceTemplateContent
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException {
- if (StringUtils.isNotBlank(serviceTemplateContent)) {
- ServiceTemplate serviceTemplate =
- JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class);
- return validateServiceTemplate(serviceTemplate);
- } else {
- throw new BluePrintException(
- "Service Template Content is (" + serviceTemplateContent + ") not Defined.");
- }
- }
-
- /**
- * This is a validateServiceTemplate
- *
- * @param serviceTemplate serviceTemplate
- * @return boolean
- * @throws BluePrintException BluePrintException
- */
- @SuppressWarnings("squid:S00112")
- public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {
- Map<String, Object> properties = new HashMap<>();
- super.validateBlueprint(serviceTemplate, properties);
- return true;
- }
-
- /**
- * This is a getMetaData to get the key information during the
- *
- * @return Map<String , String>
- */
- public Map<String, String> getMetaData() {
- return metaData;
- }
-
- @Override
- public void validateMetadata(@NotNull Map<String, String> metaDataMap) throws BluePrintException {
-
- Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing.");
- super.validateMetadata(metaDataMap);
-
- this.metaData.putAll(serviceTemplate.getMetadata());
- }
-
-
- @Override
- public void validateNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- super.validateNodeTemplate(nodeTemplateName, nodeTemplate);
- validateNodeTemplateCustom(nodeTemplateName, nodeTemplate);
-
- }
-
- @Deprecated()
- private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate)
- throws BluePrintException {
- String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom();
-
- if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) {
- List<ResourceAssignment> resourceAssignment = getResourceAssignments(nodeTemplate);
- ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl();
- resourceAssignmentValidationService.validate(resourceAssignment);
- }
- }
-
- private List<ResourceAssignment> getResourceAssignments(@NotNull NodeTemplate nodeTemplate) {
-
- List<ResourceAssignment> resourceAssignment = null;
-
- if (MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) {
-
- CapabilityAssignment capabilityAssignment =
- nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (capabilityAssignment != null && capabilityAssignment.getProperties() != null) {
- Object mappingObject =
- capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING);
- if (mappingObject != null) {
- String mappingContent = JacksonUtils.Companion.getJson(mappingObject);
- Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent),
- String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING));
-
- resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class);
-
- Preconditions.checkNotNull(resourceAssignment,
- String.format("Failed to get resource assignment info from the content (%s) ", mappingContent));
- }
- }
- }
- return resourceAssignment;
- }
-}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt
index f856b9efe..88589eb7d 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,21 +25,10 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.*
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationServiceImpl
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository
import org.springframework.stereotype.Service
-// Resource Dictionary Validation Services
-
-@Service
-class DefaultResourceAssignmentValidationService : ResourceAssignmentValidationServiceImpl()
-
-@Service
-class DefalutResourceDefinitionValidationService(bluePrintRepoService: BluePrintRepoService)
- : ResourceDefinitionValidationServiceImpl(bluePrintRepoService)
-
interface ResourceDefinitionRepoService : BluePrintRepoService {
@Throws(BluePrintException::class)
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
index c24931484..ec7d8aebc 100644
--- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt
@@ -1,5 +1,6 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +21,15 @@ import com.google.common.base.Preconditions
import org.apache.commons.collections.CollectionUtils
import org.apache.commons.lang3.StringUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
-import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionValidationService
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository
-import org.onap.ccsdk.apps.controllerblueprints.service.validator.ResourceDictionaryValidator
import org.springframework.stereotype.Service
@Service
-class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository,
- private val resourceDictionaryValidationService: ResourceDefinitionValidationService) {
+class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) {
/**
@@ -86,7 +85,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
val resourceDefinition = resourceDictionary.definition
Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content")
// Validate the Resource Definitions
- resourceDictionaryValidationService.validate(resourceDefinition)
+ //TODO( Save Validator)
+ //validate(resourceDefinition)
resourceDictionary.tags = resourceDefinition.tags
resourceDefinition.updatedBy = resourceDictionary.updatedBy
@@ -98,7 +98,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type
}
- ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary)
+ validateResourceDictionary(resourceDictionary)
val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name)
if (dbResourceDictionaryData.isPresent) {
@@ -135,4 +135,14 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour
fun getResourceSourceMapping(): ResourceSourceMapping {
return ResourceSourceMappingFactory.getRegisterSourceMapping()
}
+
+ private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean {
+ checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.")
+ checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." }
+ checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.")
+ checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.")
+ checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.")
+ return true
+
+ }
} \ No newline at end of file