From ee9f2dd72054056547ce7e9e96e8e9fb0eef4902 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 26 Aug 2018 22:10:50 -0400 Subject: Controller Blueprints Microservice Add resource dictionary validation implementation services, validation repository services and Junit Test cases. Change-Id: Ia746b86b7d9098eabe5e643dcba558ef9aa7160f Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh --- .../service/BluePrintEnhancerRepoDBService.java | 100 -------------------- .../service/BluePrintEnhancerService.java | 5 +- .../service/BluePrintRepoDBService.java | 101 +++++++++++++++++++++ .../service/ResourceDictionaryService.java | 26 ++++-- .../ResourceDictionaryValidationService.java | 31 +++++++ .../service/validator/ModelTypeValidator.java | 52 +---------- 6 files changed, 152 insertions(+), 163 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java (limited to 'ms/controllerblueprints/modules/service') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java deleted file mode 100644 index a2e5b104c..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java +++ /dev/null @@ -1,100 +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; - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.*; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerRepoService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; -import org.springframework.stereotype.Service; - -import java.util.Optional; - -/** - * BluePrintEnhancerRepoDBService - * - * @author Brinda Santh - */ -@Service -public class BluePrintEnhancerRepoDBService implements BluePrintEnhancerRepoService { - - private ModelTypeRepository modelTypeRepository; - - public BluePrintEnhancerRepoDBService(ModelTypeRepository modelTypeRepository) { - this.modelTypeRepository = modelTypeRepository; - } - - - @Override - public NodeType getNodeType(String nodeTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing"); - String content = getModelDefinitions(nodeTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing"); - return JacksonUtils.readValue(content, NodeType.class); - } - - - @Override - public DataType getDataType(String dataTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing"); - String content = getModelDefinitions(dataTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing"); - return JacksonUtils.readValue(content, DataType.class); - } - - - @Override - public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing"); - String content = getModelDefinitions(artifactTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing"); - return JacksonUtils.readValue(content, ArtifactType.class); - } - - - @Override - public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing"); - String content = getModelDefinitions(relationshipTypeName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing"); - return JacksonUtils.readValue(content, RelationshipType.class); - } - - - @Override - public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing"); - String content = getModelDefinitions(capabilityDefinitionName); - Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing"); - return JacksonUtils.readValue(content, CapabilityDefinition.class); - } - - private String getModelDefinitions(String modelName) throws BluePrintException { - String modelDefinition = null; - Optional modelTypedb = modelTypeRepository.findByModelName(modelName); - if (modelTypedb.isPresent()) { - modelDefinition = modelTypedb.get().getDefinition(); - } else { - throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); - } - return modelDefinition; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java index afd12f219..0cf846c7a 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java @@ -1,5 +1,6 @@ /* * 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. @@ -24,7 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.*; import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDefaultService; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerRepoService; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; import org.slf4j.Logger; @@ -48,7 +49,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private HashMap recipeDataTypes = new HashMap<>(); - public BluePrintEnhancerService(BluePrintEnhancerRepoService bluePrintEnhancerRepoDBService) { + public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) { super(bluePrintEnhancerRepoDBService); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java new file mode 100644 index 000000000..4a26119c0 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java @@ -0,0 +1,101 @@ +/* + * 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; + +import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.*; +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +/** + * BluePrintRepoDBService + * + * @author Brinda Santh + */ +@Service +public class BluePrintRepoDBService implements BluePrintRepoService { + + private ModelTypeRepository modelTypeRepository; + + public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { + this.modelTypeRepository = modelTypeRepository; + } + + + @Override + public NodeType getNodeType(String nodeTypeName) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing"); + String content = getModelDefinitions(nodeTypeName); + Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing"); + return JacksonUtils.readValue(content, NodeType.class); + } + + + @Override + public DataType getDataType(String dataTypeName) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing"); + String content = getModelDefinitions(dataTypeName); + Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing"); + return JacksonUtils.readValue(content, DataType.class); + } + + + @Override + public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing"); + String content = getModelDefinitions(artifactTypeName); + Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing"); + return JacksonUtils.readValue(content, ArtifactType.class); + } + + + @Override + public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing"); + String content = getModelDefinitions(relationshipTypeName); + Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing"); + return JacksonUtils.readValue(content, RelationshipType.class); + } + + + @Override + public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing"); + String content = getModelDefinitions(capabilityDefinitionName); + Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing"); + return JacksonUtils.readValue(content, CapabilityDefinition.class); + } + + private String getModelDefinitions(String modelName) throws BluePrintException { + String modelDefinition = null; + Optional modelTypedb = modelTypeRepository.findByModelName(modelName); + if (modelTypedb.isPresent()) { + modelDefinition = modelTypedb.get().getDefinition(); + } else { + throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); + } + return modelDefinition; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index 4bb87d7fc..5420dd390 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -43,19 +43,23 @@ public class ResourceDictionaryService { private ResourceDictionaryRepository resourceDictionaryRepository; + private ResourceDictionaryValidationService resourceDictionaryValidationService; + /** * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database - * + * * @param dataDictionaryRepository - * + * @param resourceDictionaryValidationService */ - public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository) { + public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository, + ResourceDictionaryValidationService resourceDictionaryValidationService) { this.resourceDictionaryRepository = dataDictionaryRepository; + this.resourceDictionaryValidationService = resourceDictionaryValidationService; } /** * This is a getDataDictionaryByName service - * + * * @param name * @return DataDictionary * @throws BluePrintException @@ -70,7 +74,7 @@ public class ResourceDictionaryService { /** * This is a searchResourceDictionaryByNames service - * + * * @param names * @return List * @throws BluePrintException @@ -86,7 +90,7 @@ public class ResourceDictionaryService { /** * This is a searchResourceDictionaryByTags service - * + * * @param tags * @return List * @throws BluePrintException @@ -101,7 +105,7 @@ public class ResourceDictionaryService { /** * This is a saveDataDictionary service - * + * * @param resourceDictionary * @return DataDictionary * @throws BluePrintException @@ -113,6 +117,8 @@ public class ResourceDictionaryService { ResourceDefinition resourceDefinition = JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + // Check the Source already Present + resourceDictionaryValidationService.validate(resourceDefinition); if (resourceDefinition == null) { throw new BluePrintException( @@ -126,11 +132,11 @@ public class ResourceDictionaryService { PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType(resourceDictionary.getDataType()); propertyDefinition.setDescription(resourceDictionary.getDescription()); - if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){ + if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) { EntrySchema entrySchema = new EntrySchema(); entrySchema.setType(resourceDictionary.getEntrySchema()); propertyDefinition.setEntrySchema(entrySchema); - }else{ + } else { propertyDefinition.setEntrySchema(null); } resourceDefinition.setTags(resourceDictionary.getTags()); @@ -165,7 +171,7 @@ public class ResourceDictionaryService { /** * This is a deleteResourceDictionary service - * + * * @param name * @throws BluePrintException */ diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java new file mode 100644 index 000000000..7de7fc4c3 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java @@ -0,0 +1,31 @@ +/* + * 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; + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDictionaryDefaultValidationService; +import org.springframework.stereotype.Service; + +@Service +public class ResourceDictionaryValidationService extends ResourceDictionaryDefaultValidationService { + + private BluePrintRepoService bluePrintRepoService; + + public ResourceDictionaryValidationService(BluePrintRepoService bluePrintRepoService) { + super(bluePrintRepoService); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java index 85f256ea7..1201f6b49 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java @@ -1,5 +1,6 @@ /* * 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. @@ -19,7 +20,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import org.apache.commons.lang3.StringUtils; 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.ArtifactType; import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; @@ -53,54 +53,6 @@ public class ModelTypeValidator { return validTypes; } - @Deprecated - private static List getValidModelDerivedFrom(String definitionType) { - List validTypes = new ArrayList<>(); - if (StringUtils.isNotBlank(definitionType)) { - if (BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE.equalsIgnoreCase(definitionType)) { - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_DG); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_VNF); - validTypes.add(ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT); - } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE.equalsIgnoreCase(definitionType)) { - validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_NETCONF); - validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_SSH); - validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_SFTP); - validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_CHEF); - validTypes.add(ConfigModelConstant.MODEL_TYPE_CAPABILITY_ANSIBLEF); - } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE.equalsIgnoreCase(definitionType)) { - validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_DEPENDS_ON); - validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_HOSTED_ON); - validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO); - validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ATTACH_TO); - validTypes.add(BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_ROUTES_TO); - } - - } - return validTypes; - } - - /** - * This is a validateNodeType - * - * @param definitionType - * @param derivedFrom - * @return boolean - * @throws BluePrintException - */ - public static boolean validateNodeType(String definitionType, String derivedFrom) throws BluePrintException { - boolean valid = true; - if (!BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType) - && !BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE.equalsIgnoreCase(definitionType)) { - List validTypes = getValidModelDerivedFrom(definitionType); - if (!validTypes.contains(derivedFrom)) { - throw new BluePrintException( - "Not Valid Model Type (" + derivedFrom + "), It sould be " + validTypes); - } - } - return valid; - } - /** * This is a validateModelTypeDefinition * @@ -187,8 +139,6 @@ public class ModelTypeValidator { validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition()); - validateNodeType(modelType.getDefinitionType(), modelType.getDerivedFrom()); - } else { throw new BluePrintException("Model Type Information is missing."); } -- cgit 1.2.3-korg