From b35d55e3f57630551f0b773674bd1f5c44585ede Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Thu, 9 Aug 2018 20:47:29 +0000 Subject: Controller Blueprints MS Creating the base directory structure for Controller Blueprints MicroService Change-Id: I1ccf7fc76446048af3b2822f9155bb634657aee3 Issue-ID: CCSDK-410 Signed-off-by: Singal, Kapil (ks220y) --- .../service/AutoResourceMappingService.java | 211 +++++++++++++ .../service/BluePrintEnhancerRepoDBService.java | 100 ++++++ .../service/BluePrintEnhancerService.java | 207 +++++++++++++ .../service/ConfigModelCreateService.java | 339 +++++++++++++++++++++ .../service/ConfigModelService.java | 247 +++++++++++++++ .../service/ConfigModelValidatorService.java | 67 ++++ .../service/DataBaseInitService.java | 325 ++++++++++++++++++++ .../service/ModelTypeService.java | 178 +++++++++++ .../service/ResourceDictionaryService.java | 169 ++++++++++ .../service/SchemaGeneratorService.java | 116 +++++++ .../service/ServiceTemplateService.java | 140 +++++++++ .../service/common/ApplicationConstants.java | 33 ++ .../service/common/ErrorMessage.java | 63 ++++ .../service/common/ServiceExceptionMapper.java | 42 +++ .../service/common/SwaggerGenerator.java | 187 ++++++++++++ .../service/domain/ConfigModel.java | 291 ++++++++++++++++++ .../service/domain/ConfigModelContent.java | 175 +++++++++++ .../service/domain/ConfigModelSearch.java | 171 +++++++++++ .../service/domain/ModelType.java | 170 +++++++++++ .../service/domain/ResourceDictionary.java | 207 +++++++++++++ .../service/model/AutoMapResponse.java | 53 ++++ .../repository/ConfigModelContentRepository.java | 95 ++++++ .../service/repository/ConfigModelRepository.java | 90 ++++++ .../repository/ConfigModelSearchRepository.java | 43 +++ .../service/repository/ModelTypeRepository.java | 98 ++++++ .../repository/ResourceDictionaryRepository.java | 68 +++++ .../service/rs/ConfigModelRest.java | 179 +++++++++++ .../service/rs/ConfigModelRestImpl.java | 116 +++++++ .../service/rs/ModelTypeRest.java | 125 ++++++++ .../service/rs/ModelTypeRestImpl.java | 87 ++++++ .../service/rs/ResourceDictionaryRest.java | 126 ++++++++ .../service/rs/ResourceDictionaryRestImpl.java | 91 ++++++ .../service/rs/ServiceTemplateRest.java | 134 ++++++++ .../service/rs/ServiceTemplateRestImpl.java | 94 ++++++ .../service/utils/ConfigModelUtils.java | 124 ++++++++ .../service/validator/ModelTypeValidator.java | 200 ++++++++++++ .../validator/ResourceDictionaryValidator.java | 88 ++++++ .../validator/ServiceTemplateValidator.java | 123 ++++++++ 38 files changed, 5372 insertions(+) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java create 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/BluePrintEnhancerService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java new file mode 100644 index 000000000..6b09c81ff --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -0,0 +1,211 @@ +/* + * 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 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.data.PropertyDefinition; +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.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * AutoResourceMappingService.java Purpose: Provide Automapping of Resource Assignments AutoResourceMappingService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class AutoResourceMappingService { + + private static Logger log = LoggerFactory.getLogger(AutoResourceMappingService.class); + + private ResourceDictionaryRepository dataDictionaryRepository; + + /** + * This is a AutoResourceMappingService constructor + * + * @param dataDictionaryRepository + * + */ + public AutoResourceMappingService(ResourceDictionaryRepository dataDictionaryRepository) { + this.dataDictionaryRepository = dataDictionaryRepository; + } + + /** + * This is a autoMap service to map the template keys automatically to Dictionary fields. + * + * @param resourceAssignments + * @return AutoMapResponse + */ + public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { + AutoMapResponse autoMapResponse = new AutoMapResponse(); + try { + if (CollectionUtils.isNotEmpty(resourceAssignments)) { + + // Create the Dictionary definitions for the ResourceAssignment Names + Map dictionaryMap = getDictionaryDefinitions(resourceAssignments); + + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) + && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { + + populateDictionaryMapping(dictionaryMap, resourceAssignment); + + log.info("Mapped Resource : {}", resourceAssignment); + + } else { + // Do nothins + } + } + } + List dictionaries = getDictionaryDefinitionsList(resourceAssignments); + List resourceAssignmentsFinal = getAllAutomapResourceAssignments(resourceAssignments); + autoMapResponse.setDataDictionaries(dictionaries); + autoMapResponse.setResourceAssignments(resourceAssignmentsFinal); + } catch (Exception e) { + log.error(String.format("Failed in auto process %s", e.getMessage())); + throw new BluePrintException(e.getMessage(), e); + } + return autoMapResponse; + } + + private void populateDictionaryMapping(Map dictionaryMap, ResourceAssignment resourceAssignment) { + ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); + if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) { + + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), DictionaryDefinition.class); + + if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) + && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { + + resourceAssignment.setDictionaryName(dbDataDictionary.getName()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + } + } + } + + private Map getDictionaryDefinitions(List resourceAssignments) { + Map dictionaryMap = new HashMap<>(); + List names = new ArrayList<>(); + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName())) { + names.add(resourceAssignment.getName()); + } + } + if (CollectionUtils.isNotEmpty(names)) { + + List dictionaries = dataDictionaryRepository.findByNameIn(names); + if (CollectionUtils.isNotEmpty( dictionaries)) { + for (ResourceDictionary dataDictionary : dictionaries) { + if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName())) { + dictionaryMap.put(dataDictionary.getName(), dataDictionary); + } + } + } + } + return dictionaryMap; + + } + + private List getDictionaryDefinitionsList(List resourceAssignments) { + List dictionaries = null; + List names = new ArrayList<>(); + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { + + if (!names.contains(resourceAssignment.getDictionaryName())) { + names.add(resourceAssignment.getDictionaryName()); + } + + if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { + List dependencyNames = resourceAssignment.getDependencies(); + for (String dependencyName : dependencyNames) { + if (StringUtils.isNotBlank(dependencyName) && !names.contains(dependencyName)) { + names.add(dependencyName); + } + } + } + } + } + if (CollectionUtils.isNotEmpty(names)) { + dictionaries = dataDictionaryRepository.findByNameIn(names); + } + return dictionaries; + + } + + private List getAllAutomapResourceAssignments(List resourceAssignments) { + List dictionaries = null; + List names = new ArrayList<>(); + List resourceAssignmentsWithDepencies = resourceAssignments; + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { + if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { + List dependencieNames = resourceAssignment.getDependencies(); + for (String dependencieName : dependencieNames) { + if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName) + && !checkAssignmentsExists(resourceAssignmentsWithDepencies, dependencieName)) { + names.add(dependencieName); + } + } + } + } + } + + if (!names.isEmpty()) { + dictionaries = dataDictionaryRepository.findByNameIn(names); + } + if (dictionaries != null) { + for (ResourceDictionary resourcedictionary : dictionaries) { + DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), DictionaryDefinition.class); + PropertyDefinition property = new PropertyDefinition(); + property.setRequired(true); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(resourcedictionary.getName()); + resourceAssignment.setDictionaryName(resourcedictionary + .getName()); + resourceAssignment.setVersion(0); + resourceAssignment.setProperty(property); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + resourceAssignmentsWithDepencies.add(resourceAssignment); + } + } + return resourceAssignmentsWithDepencies; + + } + + + public boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { + return resourceAssignmentsWithDepencies.stream().anyMatch(names -> names.getName().equalsIgnoreCase(resourceName)); + } + +} 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 new file mode 100644 index 000000000..a2e5b104c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerRepoDBService.java @@ -0,0 +1,100 @@ +/* + * 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 new file mode 100644 index 000000000..afd12f219 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java @@ -0,0 +1,207 @@ +/* + * 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.fasterxml.jackson.databind.JsonNode; +import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +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.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * BluePrintEnhancerService + * + * @author Brinda Santh DATE : 8/8/2018 + */ + +@Service +public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { + + private static Logger log = LoggerFactory.getLogger(BluePrintEnhancerService.class); + + private HashMap recipeDataTypes = new HashMap<>(); + + public BluePrintEnhancerService(BluePrintEnhancerRepoService bluePrintEnhancerRepoDBService) { + super(bluePrintEnhancerRepoDBService); + } + + @Override + public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) { + super.enrichTopologyTemplate(serviceTemplate); + + // Update the Recipe Inputs and DataTypes + populateRecipeInputs(serviceTemplate); + } + + + @Override + public void enrichNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) throws BluePrintException { + super.enrichNodeTemplate(nodeTemplateName, nodeTemplate); + + String nodeTypeName = nodeTemplate.getType(); + log.info("*** Enriching NodeType: {}", nodeTypeName); + // Get NodeType from Repo and Update Service Template + NodeType nodeType = super.populateNodeType(nodeTypeName); + + // Enrich NodeType + super.enrichNodeType(nodeTypeName, nodeType); + + // Custom for Artifact Population + if (StringUtils.isNotBlank(nodeType.getDerivedFrom()) + && ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT.equalsIgnoreCase(nodeType.getDerivedFrom())) { + populateArtifactTemplateMappingDataType(nodeTemplateName, nodeTemplate); + } + + //Enrich Node Template Artifacts + super.enrichNodeTemplateArtifactDefinition(nodeTemplateName, nodeTemplate); + + } + + + private void populateArtifactTemplateMappingDataType(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) + throws BluePrintException { + log.info("****** Processing Artifact Node Template : {}", nodeTemplateName); + + if (nodeTemplate.getProperties() != null) { + + if (!nodeTemplate.getProperties().containsKey(ConfigModelConstant.PROPERTY_RECIPE_NAMES)) { + throw new BluePrintException("Node Template (" + nodeTemplateName + ") doesn't have " + + ConfigModelConstant.PROPERTY_RECIPE_NAMES + " property."); + } + + // Modified for ONAP converted Object to JsonNode + JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES); + + log.info("Processing Receipe Names : {} ", recipeNames); + + if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) { + + Map mappingProperties = + getCapabilityMappingProperties(nodeTemplateName, nodeTemplate); + + for (JsonNode recipeNameNode : recipeNames) { + String recipeName = recipeNameNode.textValue(); + processRecipe(nodeTemplateName, mappingProperties, recipeName); + } + } + } + } + + private void processRecipe(@NotNull String nodeTemplateName, Map mappingProperties, String recipeName) { + if (StringUtils.isNotBlank(recipeName)) { + DataType recipeDataType = this.recipeDataTypes.get(recipeName); + if (recipeDataType == null) { + log.info("DataType not present for the recipe({})" , recipeName); + recipeDataType = new DataType(); + recipeDataType.setVersion("1.0.0"); + recipeDataType.setDescription( + "This is Dynamic Data type definition generated from resource mapping for the config template name " + + nodeTemplateName + "."); + recipeDataType.setDerivedFrom(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); + Map dataTypeProperties = new HashMap<>(); + recipeDataType.setProperties(dataTypeProperties); + } else { + log.info("DataType Already present for the recipe({})" , recipeName); + } + + // Merge all the Recipe Properties + mergeDataTypeProperties(recipeDataType, mappingProperties); + + // Overwrite Recipe DataType + this.recipeDataTypes.put(recipeName, recipeDataType); + + } + } + + private Map getCapabilityMappingProperties(String nodeTemplateName, + NodeTemplate nodeTemplate) { + + Map dataTypeProperties = null; + if (nodeTemplate != null) { + CapabilityAssignment capability = + nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); + + if (capability != null && capability.getProperties() != null) { + + String resourceAssignmentContent = JacksonUtils + .getJson(capability.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); + + List resourceAssignments = + JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); + + Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); + dataTypeProperties = new HashMap<>(); + + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null + // && Boolean.valueOf(resourceAssignment.getInputParameter()) + && resourceAssignment.getProperty() != null + && StringUtils.isNotBlank(resourceAssignment.getName())) { + + // Enrich the Property Definition + super.enrichPropertyDefinition(resourceAssignment.getName(), resourceAssignment.getProperty()); + + dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty()); + + } + } + + } + } + return dataTypeProperties; + } + + private void mergeDataTypeProperties(DataType dataType, Map mergeProperties) { + if (dataType != null && dataType.getProperties() != null && mergeProperties != null) { + // Add the Other Template Properties + mergeProperties.forEach((mappingKey, propertyDefinition) -> { + dataType.getProperties().put(mappingKey, propertyDefinition); + }); + } + } + + private void populateRecipeInputs(ServiceTemplate serviceTemplate) { + if (this.recipeDataTypes != null && !this.recipeDataTypes.isEmpty()) { + this.recipeDataTypes.forEach((recipeName, recipeDataType) -> { + String dataTypePrifix = recipeName.replace("-action", "") + "-request"; + String dataTypeName = "dt-" + dataTypePrifix; + + serviceTemplate.getDataTypes().put(dataTypeName, recipeDataType); + + PropertyDefinition customInputProperty = new PropertyDefinition(); + customInputProperty.setDescription("This is Dynamic Data type for the receipe " + recipeName + "."); + customInputProperty.setRequired(Boolean.FALSE); + customInputProperty.setType(dataTypeName); + serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrifix, customInputProperty); + + }); + } + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java new file mode 100644 index 000000000..7e96f2f89 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -0,0 +1,339 @@ +/* + * 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.collections.CollectionUtils; +import org.apache.commons.io.IOUtils; +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.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * ServiceTemplateCreateService.java Purpose: Provide Service Template Create Service processing + * ServiceTemplateCreateService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class ConfigModelCreateService { + + private static Logger log = LoggerFactory.getLogger(ConfigModelCreateService.class); + + private ConfigModelRepository configModelRepository; + private ConfigModelValidatorService configModelValidatorService; + + /** + * This is a ConfigModelCreateService + * + * @param configModelRepository ConfigModelRepository + * @param configModelValidatorService ConfigModelValidatorService + */ + public ConfigModelCreateService(ConfigModelRepository configModelRepository, + ConfigModelValidatorService configModelValidatorService) { + this.configModelRepository = configModelRepository; + this.configModelValidatorService = configModelValidatorService; + } + + /** + * This is a createInitialServiceTemplateContent method + * + * @param templateName templateName + * @return String + * @throws BluePrintException BluePrintException + */ + public String createInitialServiceTemplateContent(String templateName) throws BluePrintException { + String serviceTemplateContent = null; + if (StringUtils.isNotBlank(templateName)) { + try { + serviceTemplateContent = IOUtils.toString(ConfigModelCreateService.class.getClassLoader() + .getResourceAsStream("service_template/" + templateName + ".json"), Charset.defaultCharset()); + } catch (IOException e) { + throw new BluePrintException(e.getMessage(), e); + } + + } + return serviceTemplateContent; + } + + /** + * This is a createInitialServiceTemplate method + * + * @param templateName templateName + * @return ServiceTemplate + * @throws BluePrintException BluePrintException + */ + public ServiceTemplate createInitialServiceTemplate(String templateName) throws BluePrintException { + ServiceTemplate serviceTemplate = null; + if (StringUtils.isNotBlank(templateName)) { + try { + String serviceTemplateContent = IOUtils.toString(ConfigModelCreateService.class.getClassLoader() + .getResourceAsStream("service_template/" + templateName + ".json"), Charset.defaultCharset()); + if (StringUtils.isNotBlank(serviceTemplateContent)) { + serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + } + } catch (IOException e) { + throw new BluePrintException(e.getMessage(), e); + } + + } + return serviceTemplate; + } + + /** + * This is a saveConfigModel method + * + * @param configModel configModel + * @return ConfigModel + * @throws BluePrintException BluePrintException + */ + public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { + + if (configModel != null) { + String artifactName = configModel.getArtifactName(); + String artifactVersion = configModel.getArtifactVersion(); + String author = configModel.getUpdatedBy(); + // configModel.setTags(artifactName); + + if (StringUtils.isBlank(author)) { + throw new BluePrintException("Artifact Author is missing in the Service Template"); + } + + if (StringUtils.isBlank(artifactName)) { + throw new BluePrintException("Artifact Name is missing in the Service Template"); + } + + if (StringUtils.isBlank(artifactVersion)) { + throw new BluePrintException("Artifact Version is missing in the Service Template"); + } + ConfigModel updateConfigModel = null; + + Optional dbConfigModelOptional = Optional.empty(); + + if (configModel.getId() != null) { + log.info("Searching for config model id : {}", configModel.getId()); + dbConfigModelOptional = configModelRepository.findById(configModel.getId()); + } + + if (!dbConfigModelOptional.isPresent()) { + log.info("Searching for config model name :" + + configModel.getArtifactName() + ", version " + configModel.getArtifactVersion()); + dbConfigModelOptional = configModelRepository.findByArtifactNameAndArtifactVersion( + configModel.getArtifactName(), configModel.getArtifactVersion()); + } + + if (dbConfigModelOptional.isPresent()) { + updateConfigModel = dbConfigModelOptional.get(); + log.info("Processing for config model id : {} with config model content count : {}" + , updateConfigModel.getId(), updateConfigModel.getConfigModelContents().size()); + } else { + ConfigModel tempConfigModel = new ConfigModel(); + tempConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); + tempConfigModel.setArtifactName(artifactName); + tempConfigModel.setArtifactVersion(artifactVersion); + tempConfigModel.setUpdatedBy(author); + tempConfigModel.setPublished(ApplicationConstants.ACTIVE_N); + tempConfigModel.setTags(artifactName); + configModelRepository.saveAndFlush(tempConfigModel); + updateConfigModel = tempConfigModel; + } + + Long dbConfigModelId = updateConfigModel.getId(); + + if (dbConfigModelId == null) { + throw new BluePrintException("failed to get the initial saved config model id."); + } + + log.info("Processing for config model id : {}", dbConfigModelId); + + deleteConfigModelContent(dbConfigModelId); + + addConfigModelContent(dbConfigModelId, configModel); + + // Populate Content model types + updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author); + + + return updateConfigModel; + } else { + throw new BluePrintException("Config model information is missing"); + } + + } + + private void deleteConfigModelContent(Long dbConfigModelId) { + if (dbConfigModelId != null) { + ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); + if (dbConfigModel != null && CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { + dbConfigModel.getConfigModelContents().clear(); + log.debug("Configuration Model content deleting : {}", dbConfigModel.getConfigModelContents()); + configModelRepository.saveAndFlush(dbConfigModel); + } + + } + } + + private void addConfigModelContent(Long dbConfigModelId, ConfigModel configModel) { + if (dbConfigModelId != null && configModel != null + && CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { + ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); + if (dbConfigModel != null) { + for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { + if (configModelContent != null) { + configModelContent.setId(null); + configModelContent.setConfigModel(dbConfigModel); + dbConfigModel.getConfigModelContents().add(configModelContent); + log.debug("Configuration Model content adding : {}", configModelContent); + } + } + configModelRepository.saveAndFlush(dbConfigModel); + } + + } + } + + private ConfigModel updateConfigModel(Long dbConfigModelId, String artifactName, String artifactVersion, + String author) throws BluePrintException { + + ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); + if (dbConfigModel != null) { + // Populate tags from metadata + String tags = getConfigModelTags(dbConfigModel); + if (StringUtils.isBlank(tags)) { + throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); + } + dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); + dbConfigModel.setArtifactName(artifactName); + dbConfigModel.setArtifactVersion(artifactVersion); + dbConfigModel.setUpdatedBy(author); + dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); + dbConfigModel.setTags(tags); + configModelRepository.saveAndFlush(dbConfigModel); + + log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); + } + return dbConfigModel; + } + + private List getValidContentTypes() { + List valids = new ArrayList<>(); + valids.add(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); + valids.add(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); + return valids; + + } + + private String getConfigModelTags(ConfigModel configModel) throws BluePrintException { + String tags = null; + if (CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { + + for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { + if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { + + if (!getValidContentTypes().contains(configModelContent.getContentType())) { + throw new BluePrintException(configModelContent.getContentType() + + " is not a valid content type, It should be any one of this " + + getValidContentTypes()); + } + + if (configModelContent.getContentType().equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { + ServiceTemplate serviceTemplate = + JacksonUtils.readValue(configModelContent.getContent(), ServiceTemplate.class); + Preconditions.checkNotNull(serviceTemplate, "failed to transform service template content"); + if (serviceTemplate.getMetadata() != null) { + serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, + configModel.getUpdatedBy()); + serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_VERSION, + configModel.getArtifactVersion()); + serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_NAME, + configModel.getArtifactName()); + } + tags = String.valueOf(serviceTemplate.getMetadata()); + } else { + // Do Nothing + } + } + } + } + return tags; + } + + /** + * This is a publishConfigModel method + * + * @param id id + * @return ConfigModel + * @throws BluePrintException BluePrintException + */ + public ConfigModel publishConfigModel(Long id) throws BluePrintException { + ConfigModel dbConfigModel = null; + if (id != null) { + Optional dbConfigModelOptional = configModelRepository.findById(id); + if (dbConfigModelOptional.isPresent()) { + dbConfigModel = dbConfigModelOptional.get(); + List configModelContents = dbConfigModel.getConfigModelContents(); + if (configModelContents != null && !configModelContents.isEmpty()) { + for (ConfigModelContent configModelContent : configModelContents) { + if (configModelContent.getContentType() + .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { + ServiceTemplate serviceTemplate = JacksonUtils + .readValue(configModelContent.getContent(), ServiceTemplate.class); + if (serviceTemplate != null) { + validateServiceTemplate(serviceTemplate); + } + } + } + } + dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); + configModelRepository.save(dbConfigModel); + log.info("Config model ({}) published successfully.", id); + + } + + } + return dbConfigModel; + } + + /** + * This is a validateServiceTemplate method + * + * @param serviceTemplate Service Template + * @return ServiceTemplate + * @throws BluePrintException BluePrintException + */ + public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + return this.configModelValidatorService.validateServiceTemplate(serviceTemplate); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java new file mode 100644 index 000000000..feee3a3ea --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java @@ -0,0 +1,247 @@ +/* + * 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 org.apache.commons.collections.CollectionUtils; +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.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Optional; + +/** + * ConfigModelService.java Purpose: Provide Service Template Service processing ConfigModelService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class ConfigModelService { + + private static Logger log = LoggerFactory.getLogger(ConfigModelService.class); + + private ConfigModelRepository configModelRepository; + private ConfigModelContentRepository configModelContentRepository; + private ConfigModelCreateService configModelCreateService; + + /** + * This is a ConfigModelService constructor. + * + * @param configModelRepository + * @param configModelContentRepository + * @param configModelCreateService + */ + public ConfigModelService(ConfigModelRepository configModelRepository, + ConfigModelContentRepository configModelContentRepository, + ConfigModelCreateService configModelCreateService) { + this.configModelRepository = configModelRepository; + this.configModelContentRepository = configModelContentRepository; + this.configModelCreateService = configModelCreateService; + } + + /** + * This is a getInitialConfigModel method + * + * @param templateName + * @return ConfigModel + * @throws BluePrintException + */ + public ConfigModel getInitialConfigModel(String templateName) throws BluePrintException { + ConfigModel configModel = null; + if (StringUtils.isNotBlank(templateName)) { + configModel = new ConfigModel(); + configModel.setArtifactName(templateName); + configModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); + configModel.setUpdatedBy("xxxxx@xxx.com"); + ConfigModelContent configModelContent = new ConfigModelContent(); + configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); + configModelContent.setName(templateName); + String content = this.configModelCreateService.createInitialServiceTemplateContent(templateName); + configModelContent.setContent(content); + + List configModelContents = new ArrayList<>(); + configModelContents.add(configModelContent); + + configModel.setConfigModelContents(configModelContents); + } + return configModel; + } + + /** + * This is a saveConfigModel method + * + * @param configModel + * @return ConfigModel + * @throws BluePrintException + */ + public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { + return this.configModelCreateService.saveConfigModel(configModel); + } + + /** + * This is a publishConfigModel method + * + * @param id + * @return ConfigModel + * @throws BluePrintException + */ + public ConfigModel publishConfigModel(Long id) throws BluePrintException { + return this.configModelCreateService.publishConfigModel(id); + } + + /** + * This is a searchConfigModels method + * + * @param tags + * @return ConfigModel + */ + public List searchConfigModels(String tags) { + List models = configModelRepository.findByTagsContainingIgnoreCase(tags); + if (models != null) { + for (ConfigModel configModel : models) { + configModel.setConfigModelContents(null); + } + } + return models; + } + + /** + * This is a getConfigModelByNameAndVersion method + * + * @param name + * @param version + * @return ConfigModel + */ + public ConfigModel getConfigModelByNameAndVersion(String name, String version) { + ConfigModel configModel = null; + Optional dbConfigModel = null; + if (StringUtils.isNotBlank(version)) { + dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version); + } else { + dbConfigModel = configModelRepository.findTopByArtifactNameOrderByArtifactVersionDesc(name); + } + if (dbConfigModel.isPresent()) { + configModel = dbConfigModel.get(); + } + return configModel; + } + + /** + * This is a getConfigModel method + * + * @param id + * @return ConfigModel + */ + public ConfigModel getConfigModel(Long id) { + ConfigModel configModel = null; + if (id != null) { + Optional dbConfigModel = configModelRepository.findById(id); + if (dbConfigModel.isPresent()) { + configModel = dbConfigModel.get(); + } + } + return configModel; + } + + /** + * This method returns clone of the given model id, by masking the other unrelated fields + * + * @param id + * @return + */ + + public ConfigModel getCloneConfigModel(Long id) { + + ConfigModel configModel = null; + ConfigModel cloneConfigModel = null; + if (id != null) { + Optional dbConfigModel = configModelRepository.findById(id); + if (dbConfigModel.isPresent()) { + configModel = dbConfigModel.get(); + cloneConfigModel = configModel; + cloneConfigModel.setUpdatedBy("xxxxx@xxx.com"); + cloneConfigModel.setArtifactName("XXXX"); + cloneConfigModel.setPublished("XXXX"); + cloneConfigModel.setPublished("XXXX"); + cloneConfigModel.setUpdatedBy("XXXX"); + cloneConfigModel.setId(null); + cloneConfigModel.setTags(null); + cloneConfigModel.setCreatedDate(new Date()); + List configModelContents = cloneConfigModel.getConfigModelContents(); + + if (CollectionUtils.isNotEmpty(configModelContents)) { + for (ConfigModelContent configModelContent : configModelContents) { + if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { + configModelContent.setId(null); + configModelContent.setCreationDate(new Date()); + + if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON + .equalsIgnoreCase(configModelContent.getContentType())) { + ServiceTemplate serviceTemplate = JacksonUtils + .readValue(configModelContent.getContent(), ServiceTemplate.class); + if (serviceTemplate != null && serviceTemplate.getMetadata() != null) { + serviceTemplate.getMetadata() + .put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, "XXXX"); + serviceTemplate.getMetadata() + .put(BluePrintConstants.METADATA_TEMPLATE_VERSION, "1.0.0"); + serviceTemplate.getMetadata() + .put(BluePrintConstants.METADATA_TEMPLATE_NAME, "XXXXXX"); + + configModelContent.setContent(JacksonUtils.getJson(serviceTemplate)); + } + } + } + + } + } + } + } + return cloneConfigModel; + } + + /** + * This is a deleteConfigModel method + * + * @param id + */ + + @Transactional + public void deleteConfigModel(Long id) { + Optional dbConfigModel = configModelRepository.findById(id); + if (dbConfigModel.isPresent()) { + configModelContentRepository.deleteByConfigModel(dbConfigModel.get()); + configModelRepository.delete(dbConfigModel.get()); + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java new file mode 100644 index 000000000..21b00f8c2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java @@ -0,0 +1,67 @@ +/* + * 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.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator; +import org.springframework.stereotype.Service; + +/** + * ServiceTemplateValidatorService.java Purpose: Provide Service to Validate Service Model Template + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class ConfigModelValidatorService { + + /** + * This is a validateServiceTemplate + * + * @param serviceTemplateContent + * @return ServiceTemplate + * @throws BluePrintException + */ + public ServiceTemplate validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateContent), "Service Template Content is (" + serviceTemplateContent + ") not Defined."); + ServiceTemplate serviceTemplate = + JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + return validateServiceTemplate(serviceTemplate); + } + + /** + * This is a enhanceServiceTemplate + * + * @param serviceTemplate + * @return ServiceTemplate + * @throws BluePrintException + */ + @SuppressWarnings("squid:S00112") + public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined."); + ServiceTemplateValidator validator = new ServiceTemplateValidator(); + validator.validateServiceTemplate(serviceTemplate); + return serviceTemplate; + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java new file mode 100644 index 000000000..9ab319cb7 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -0,0 +1,325 @@ +/* + * 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 org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.text.StrBuilder; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType; +import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; + +/** + * DataBaseInitService.java Purpose: Provide DataBaseInitService Service + * + * @author Brinda Santh + * @version 1.0 + */ + +@Component +@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true", matchIfMissing = false) +public class DataBaseInitService { + + private static Logger log = LoggerFactory.getLogger(DataBaseInitService.class); + @Value("${blueprints.load.path}") + private String modelLoadPath; + private ModelTypeService modelTypeService; + private ResourceDictionaryService resourceDictionaryService; + private ConfigModelService configModelService; + + private String dataTypePath; + private String nodeTypePath; + private String artifactTypePath; + private String resourceDictionaryPath; + private String bluePrintsPath; + + @Autowired + private ResourcePatternResolver resourceLoader; + + /** + * This is a DataBaseInitService, used to load the initial data + * + * @param modelTypeService + * @param resourceDictionaryService + * @param configModelService + */ + public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService, + ConfigModelService configModelService) { + this.modelTypeService = modelTypeService; + this.resourceDictionaryService = resourceDictionaryService; + this.configModelService = configModelService; + log.info("DataBaseInitService started..."); + + } + + @PostConstruct + private void initDatabase() { + log.info("loading Blueprints from DIR : {}", modelLoadPath); + dataTypePath = modelLoadPath + "/model_type/data_type"; + nodeTypePath = modelLoadPath + "/model_type/node_type"; + artifactTypePath = modelLoadPath + "/model_type/artifact_type"; + resourceDictionaryPath = modelLoadPath + "/resource_dictionary"; + bluePrintsPath = modelLoadPath + "/blueprints"; + + log.info("loading dataTypePath from DIR : {}", dataTypePath); + log.info("loading nodeTypePath from DIR : {}", nodeTypePath); + log.info("loading artifactTypePath from DIR : {}", artifactTypePath); + log.info("loading resourceDictionaryPath from DIR : {}", resourceDictionaryPath); + log.info("loading bluePrintsPath from DIR : {}", bluePrintsPath); + + loadModelType(); + loadResourceDictionary(); + loadBlueprints(); + } + + private void loadModelType() { + log.info(" *************************** loadModelType **********************"); + try { + Resource[] dataTypefiles = getPathResources(dataTypePath, ".json"); + StrBuilder errorBuilder = new StrBuilder(); + if (dataTypefiles != null) { + for (Resource file : dataTypefiles) { + if (file != null) { + loadDataType(file, errorBuilder); + } + } + } + + Resource[] nodeTypefiles = getPathResources(nodeTypePath, ".json"); + if (nodeTypefiles != null) { + for (Resource file : nodeTypefiles) { + if (file != null) { + loadNodeType(file, errorBuilder); + } + } + } + + Resource[] artifactTypefiles = getPathResources(artifactTypePath, ".json"); + if (artifactTypefiles != null) { + for (Resource file : artifactTypefiles) { + if (file != null) { + loadArtifactType(file, errorBuilder); + } + } + } + + if (!errorBuilder.isEmpty()) { + log.error(errorBuilder.toString()); + } + } catch (Exception e) { + log.error("Failed in Data type loading", e); + } + } + + private void loadResourceDictionary() { + log.info( + " *************************** loadResourceDictionary **********************"); + try { + Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, ".json"); + if (dataTypefiles != null) { + StrBuilder errorBuilder = new StrBuilder(); + String fileName = null; + for (Resource file : dataTypefiles) { + try { + fileName = file.getFilename(); + log.trace("Loading : {}", fileName); + String definitionContent = getResourceContent(file); + DictionaryDefinition dictionaryDefinition = + JacksonUtils.readValue(definitionContent, DictionaryDefinition.class); + if (dictionaryDefinition != null) { + ResourceDictionary resourceDictionary = new ResourceDictionary(); + resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); + resourceDictionary.setName(dictionaryDefinition.getName()); + resourceDictionary.setDefinition(definitionContent); + + if (dictionaryDefinition.getValidValues() != null) + resourceDictionary + .setValidValues(String.valueOf(dictionaryDefinition.getValidValues())); + + if (dictionaryDefinition.getSampleValue() != null) + resourceDictionary + .setValidValues(String.valueOf(dictionaryDefinition.getSampleValue())); + + resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); + resourceDictionary.setDataType(dictionaryDefinition.getDataType()); + resourceDictionary.setEntrySchema(dictionaryDefinition.getEntrySchema()); + resourceDictionary.setDescription(dictionaryDefinition.getDescription()); + resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy()); + if (StringUtils.isBlank(dictionaryDefinition.getTags())) { + resourceDictionary.setTags( + dictionaryDefinition.getName() + ", " + dictionaryDefinition.getUpdatedBy() + + ", " + dictionaryDefinition.getResourceType() + ", " + + dictionaryDefinition.getUpdatedBy()); + + } else { + resourceDictionary.setTags(dictionaryDefinition.getTags()); + } + resourceDictionaryService.saveResourceDictionary(resourceDictionary); + + log.trace(" Loaded successfully : {}", file.getFilename()); + } else { + throw new BluePrintException("couldn't get dictionary from content information"); + } + } catch (Exception e) { + errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage()); + } + } + if (!errorBuilder.isEmpty()) { + log.error(errorBuilder.toString()); + } + + } + } catch (Exception e) { + log.error( + "Failed in Resource dictionary loading", e); + } + } + + private void loadBlueprints() { + log.info("*************************** loadServiceTemplate **********************"); + try { + List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(bluePrintsPath); + if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { + StrBuilder errorBuilder = new StrBuilder(); + for (String fileName : serviceTemplateDirs) { + try { + String bluePrintPath = this.bluePrintsPath.concat("/").concat(fileName); + log.debug("***** Loading service template : {}", bluePrintPath); + ConfigModel configModel = ConfigModelUtils.getConfigModel(bluePrintPath); + + configModel = this.configModelService.saveConfigModel(configModel); + + log.info("Publishing : {}", configModel.getId()); + + this.configModelService.publishConfigModel(configModel.getId()); + + log.info("Loaded service template successfully: {}", fileName); + + } catch (Exception e) { + errorBuilder.appendln("load config model " + fileName + " error : " + e.getMessage()); + } + } + + if (!errorBuilder.isEmpty()) { + log.error(errorBuilder.toString()); + } + } + } catch (Exception e) { + log.error("Failed in Service Template loading", e); + } + } + + private void loadNodeType(Resource file, StrBuilder errorBuilder) { + try { + log.trace("Loading Node Type : {}", file.getFilename()); + String nodeKey = file.getFilename().replace(".json", ""); + String definitionContent = getResourceContent(file); + NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); + modelType.setDerivedFrom(nodeType.getDerivedFrom()); + modelType.setDescription(nodeType.getDescription()); + modelType.setDefinition(definitionContent); + modelType.setModelName(nodeKey); + modelType.setVersion(nodeType.getVersion()); + modelType.setUpdatedBy("System"); + modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + "," + + nodeType.getDerivedFrom()); + modelTypeService.saveModel(modelType); + log.trace("Loaded Node Type successfully : {}", file.getFilename()); + } catch (Exception e) { + errorBuilder.appendln("Node type loading error : " + file.getFilename() + ":" + e.getMessage()); + } + } + + private void loadDataType(Resource file, StrBuilder errorBuilder) { + try { + log.trace("Loading Data Type: {}", file.getFilename()); + String dataKey = file.getFilename().replace(".json", ""); + String definitionContent = getResourceContent(file); + DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(dataType.getDerivedFrom()); + modelType.setDescription(dataType.getDescription()); + modelType.setDefinition(definitionContent); + modelType.setModelName(dataKey); + modelType.setVersion(dataType.getVersion()); + modelType.setUpdatedBy("System"); + modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelTypeService.saveModel(modelType); + log.trace(" Loaded Data Type successfully : {}", file.getFilename()); + } catch (Exception e) { + errorBuilder.appendln("Data type loading error : " + file.getFilename() + ":" + e.getMessage()); + } + } + + private void loadArtifactType(Resource file, StrBuilder errorBuilder) { + try { + log.trace("Loading Artifact Type: {}", file.getFilename()); + String dataKey = file.getFilename().replace(".json", ""); + String definitionContent = getResourceContent(file); + ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); + modelType.setDerivedFrom(artifactType.getDerivedFrom()); + modelType.setDescription(artifactType.getDescription()); + modelType.setDefinition(definitionContent); + modelType.setModelName(dataKey); + modelType.setVersion(artifactType.getVersion()); + modelType.setUpdatedBy("System"); + modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); + modelTypeService.saveModel(modelType); + log.trace("Loaded Artifact Type successfully : {}", file.getFilename()); + } catch (Exception e) { + errorBuilder.appendln("Artifact type loading error : " + file.getFilename() + ":" + e.getMessage()); + } + } + + private Resource[] getPathResources(String path, String extension) throws IOException { + return resourceLoader.getResources("file:" + path + "/*" + extension); + } + + private String getResourceContent(Resource resource) throws IOException { + return IOUtils.toString(resource.getInputStream(), Charset.defaultCharset()); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java new file mode 100644 index 000000000..2bc2963b6 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java @@ -0,0 +1,178 @@ +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.validator.ModelTypeValidator; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; + +/** + * ModelTypeService.java Purpose: Provide ModelTypeService Service ModelTypeService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +@Transactional +public class ModelTypeService { + + private ModelTypeRepository modelTypeRepository; + + /** + * This is a ModelTypeService, used to save and get the model types stored in database + * + * @param modelTypeRepository + */ + public ModelTypeService(ModelTypeRepository modelTypeRepository) { + this.modelTypeRepository = modelTypeRepository; + } + + + /** + * This is a getModelTypeByName service + * + * @param modelTypeName + * @return ModelType + * @throws BluePrintException + */ + public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException { + ModelType modelType = null; + if (StringUtils.isNotBlank(modelTypeName)) { + Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); + if (modelTypeOption.isPresent()) { + modelType = modelTypeOption.get(); + } + } else { + throw new BluePrintException("Model Name Information is missing."); + } + return modelType; + } + + + /** + * This is a searchModelTypes service + * + * @param tags + * @return List + * @throws BluePrintException + */ + public List searchModelTypes(String tags) throws BluePrintException { + if (tags != null) { + return modelTypeRepository.findByTagsContainingIgnoreCase(tags); + } else { + throw new BluePrintException("No Search Information provide"); + } + } + + /** + * This is a saveModel service + * + * @param modelType + * @return ModelType + * @throws BluePrintException + */ + public ModelType saveModel(ModelType modelType) throws BluePrintException { + + ModelTypeValidator.validateModelType(modelType); + + Optional dbModelType = modelTypeRepository.findByModelName(modelType.getModelName()); + if (dbModelType.isPresent()) { + ModelType dbModel = dbModelType.get(); + dbModel.setDescription(modelType.getDescription()); + dbModel.setDefinition(modelType.getDefinition()); + dbModel.setDefinitionType(modelType.getDefinitionType()); + dbModel.setDerivedFrom(modelType.getDerivedFrom()); + dbModel.setTags(modelType.getTags()); + dbModel.setVersion(modelType.getVersion()); + dbModel.setUpdatedBy(modelType.getUpdatedBy()); + modelType = modelTypeRepository.save(dbModel); + } else { + modelType = modelTypeRepository.save(modelType); + } + return modelType; + } + + + /** + * This is a deleteByModelName service + * + * @param modelName + * @throws BluePrintException + */ + public void deleteByModelName(String modelName) throws BluePrintException { + if (modelName != null) { + modelTypeRepository.deleteByModelName(modelName); + } else { + throw new BluePrintException("Model Name Information is missing."); + } + } + + /** + * This is a getModelTypeByTags service + * + * @param tags + * @return List + * @throws BluePrintException + */ + public List getModelTypeByTags(String tags) throws BluePrintException { + if (StringUtils.isNotBlank(tags)) { + return modelTypeRepository.findByTagsContainingIgnoreCase(tags); + } else { + throw new BluePrintException("Model Tag Information is missing."); + } + } + + /** + * This is a getModelTypeByDefinitionType service + * + * @param definitionType + * @return List + * @throws BluePrintException + */ + public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { + if (StringUtils.isNotBlank(definitionType)) { + return modelTypeRepository.findByDefinitionType(definitionType); + } else { + throw new BluePrintException("Model definitionType Information is missing."); + } + } + + /** + * This is a getModelTypeByDerivedFrom service + * + * @param derivedFrom + * @return List + * @throws BluePrintException + */ + public List getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException { + if (StringUtils.isNotBlank(derivedFrom)) { + return modelTypeRepository.findByDerivedFrom(derivedFrom); + } else { + throw new BluePrintException("Model derivedFrom Information is missing."); + } + } + + +} 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 new file mode 100644 index 000000000..b9567db13 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -0,0 +1,169 @@ +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +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; + +import java.util.List; +import java.util.Optional; + +/** + * ResourceDictionaryService.java Purpose: Provide DataDictionaryService Service + * DataDictionaryService + * + * @author Brinda Santh + * @version 1.0 + */ +@Service +public class ResourceDictionaryService { + + private ResourceDictionaryRepository resourceDictionaryRepository; + + /** + * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database + * + * @param dataDictionaryRepository + * + */ + public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository) { + this.resourceDictionaryRepository = dataDictionaryRepository; + } + + /** + * This is a getDataDictionaryByName service + * + * @param name + * @return DataDictionary + * @throws BluePrintException + */ + public ResourceDictionary getResourceDictionaryByName(String name) throws BluePrintException { + if (StringUtils.isNotBlank(name)) { + return resourceDictionaryRepository.findByName(name).get(); + } else { + throw new BluePrintException("Resource Mapping Name Information is missing."); + } + } + + /** + * This is a searchResourceDictionaryByNames service + * + * @param names + * @return List + * @throws BluePrintException + */ + public List searchResourceDictionaryByNames(List names) + throws BluePrintException { + if (names != null && !names.isEmpty()) { + return resourceDictionaryRepository.findByNameIn(names); + } else { + throw new BluePrintException("No Search Information provide"); + } + } + + /** + * This is a searchResourceDictionaryByTags service + * + * @param tags + * @return List + * @throws BluePrintException + */ + public List searchResourceDictionaryByTags(String tags) throws BluePrintException { + if (StringUtils.isNotBlank(tags)) { + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); + } else { + throw new BluePrintException("No Search Information provide"); + } + } + + /** + * This is a saveDataDictionary service + * + * @param resourceDictionary + * @return DataDictionary + * @throws BluePrintException + */ + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) + throws BluePrintException { + if (resourceDictionary != null) { + ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); + + DictionaryDefinition dictionaryDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class); + + if (dictionaryDefinition == null) { + throw new BluePrintException( + "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); + } + + dictionaryDefinition.setName(resourceDictionary.getName()); + dictionaryDefinition.setResourcePath(resourceDictionary.getResourcePath()); + dictionaryDefinition.setResourceType(resourceDictionary.getResourceType()); + dictionaryDefinition.setDataType(resourceDictionary.getDataType()); + dictionaryDefinition.setEntrySchema(resourceDictionary.getEntrySchema()); + dictionaryDefinition.setTags(resourceDictionary.getTags()); + dictionaryDefinition.setDescription(resourceDictionary.getDescription()); + dictionaryDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + + String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true); + resourceDictionary.setDefinition(definitionContent); + + Optional dbResourceDictionaryData = + resourceDictionaryRepository.findByName(resourceDictionary.getName()); + if (dbResourceDictionaryData.isPresent()) { + ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); + + dbResourceDictionary.setName(resourceDictionary.getName()); + dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); + dbResourceDictionary.setDescription(resourceDictionary.getDescription()); + dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); + dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); + dbResourceDictionary.setDataType(resourceDictionary.getDataType()); + dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); + dbResourceDictionary.setTags(resourceDictionary.getTags()); + dbResourceDictionary.setValidValues(resourceDictionary.getValidValues()); + resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); + } else { + resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); + } + } else { + throw new BluePrintException("Resource Dictionary information is missing"); + } + return resourceDictionary; + } + + /** + * This is a deleteResourceDictionary service + * + * @param name + * @throws BluePrintException + */ + public void deleteResourceDictionary(String name) throws BluePrintException { + if (name != null) { + resourceDictionaryRepository.deleteByName(name); + } else { + throw new BluePrintException("Resource Mapping Id Information is missing."); + } + + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java new file mode 100644 index 000000000..a75651f19 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -0,0 +1,116 @@ +/* + * 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.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.common.SwaggerGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +/** + * SchemaGeneratorService.java Purpose: Provide Service to generate service template input schema definition and Sample + * Json generation. + * + * @author Brinda Santh + * @version 1.0 + */ + +public class SchemaGeneratorService { + private static Logger log = LoggerFactory.getLogger(SchemaGeneratorService.class); + + private Map dataTypes; + + /** + * This is a SchemaGeneratorService constructor + */ + public SchemaGeneratorService() { + dataTypes = new HashMap<>(); + } + + /** + * This is a generateSchema + * + * @param serviceTemplateContent service template content + * @return String + * @throws BluePrintException Blueprint Exception + */ + public String generateSchema(String serviceTemplateContent) throws BluePrintException { + if (StringUtils.isNotBlank(serviceTemplateContent)) { + ServiceTemplate serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, + ServiceTemplate.class); + return generateSchema(serviceTemplate); + } else { + throw new BluePrintException( + "Service Template Content is (" + serviceTemplateContent + ") not Defined."); + } + } + + /** + * This is a generateSchema + * + * @param serviceTemplate service template content + * @return String + * @throws BluePrintException Blueprint Exception + */ + public String generateSchema(ServiceTemplate serviceTemplate) throws BluePrintException { + String schemaContent = null; + Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined."); + try { + if (serviceTemplate.getTopologyTemplate() != null + && serviceTemplate.getTopologyTemplate().getInputs() != null) { + SwaggerGenerator swaggerGenerator = new SwaggerGenerator(serviceTemplate); + schemaContent = swaggerGenerator.generateSwagger(); + } + } catch (Exception e) { + throw new BluePrintException(e.getMessage(), e); + } + + return schemaContent; + } + + private void manageServiceTemplateActions(ServiceTemplate serviceTemplate, String actionName) { + if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null + && StringUtils.isNotBlank(actionName)) { + + if (MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs())) { + + serviceTemplate.getTopologyTemplate().getInputs().entrySet().removeIf(entity -> { + String keyName = entity.getKey(); + String replacedAction = actionName.replace("-action", "-request"); + log.debug("Key name : " + keyName + ", actionName " + + actionName + ", replacedAction :" + replacedAction); + if (keyName.endsWith("-request") && !keyName.equals(replacedAction)) { + log.info("deleting input property {} ", keyName); + return true; + } + return false; + }); + } + + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java new file mode 100644 index 000000000..70b7917a4 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -0,0 +1,140 @@ +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * ServiceTemplateService.java Purpose: Provide Service Template Create Service processing ServiceTemplateService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class ServiceTemplateService { + + private ResourceDictionaryRepository dataDictionaryRepository; + + private ConfigModelCreateService configModelCreateService; + private BluePrintEnhancerService bluePrintEnhancerService; + + /** + * This is a SchemaGeneratorService constructor + * + * @param dataDictionaryRepository + * @param configModelCreateService + * @param bluePrintEnhancerService + */ + public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, + ConfigModelCreateService configModelCreateService, + BluePrintEnhancerService bluePrintEnhancerService) { + this.dataDictionaryRepository = dataDictionaryRepository; + this.configModelCreateService = configModelCreateService; + this.bluePrintEnhancerService = bluePrintEnhancerService; + + } + + /** + * This is a validateServiceTemplate method + * + * @param serviceTemplate + * @return ServiceTemplate + * @throws BluePrintException + */ + public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + return this.configModelCreateService.validateServiceTemplate(serviceTemplate); + } + + /** + * This is a enrichServiceTemplate method + * + * @param serviceTemplate + * @return ServiceTemplate + * @throws BluePrintException + */ + public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + this.bluePrintEnhancerService.enhance(serviceTemplate); + return serviceTemplate; + } + + /** + * This is a autoMap method to map the template keys + * + * @param resourceAssignments + * @return AutoMapResponse + * @throws BluePrintException + */ + public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { + AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository); + AutoMapResponse autoMapResponse = autoMappingService.autoMap(resourceAssignments); + return autoMapResponse; + } + + /** + * This is a validateResourceAssignments method + * + * @param resourceAssignments + * @return List + * @throws BluePrintException + */ + public List validateResourceAssignments(List resourceAssignments) + throws BluePrintException { + try { + ResourceAssignmentValidator resourceAssignmentValidator = + new ResourceAssignmentValidator(resourceAssignments); + resourceAssignmentValidator.validateResourceAssignment(); + } catch (BluePrintException e) { + throw new BluePrintException(e.getMessage(), e); + } + return resourceAssignments; + } + + /** + * This is a generateResourceAssignments method + * + * @param templateContent + * @return List + */ + public List generateResourceAssignments(ConfigModelContent templateContent) { + List resourceAssignments = new ArrayList<>(); + if (templateContent != null && StringUtils.isNotBlank(templateContent.getContent())) { + Pattern p = Pattern.compile("(?<=\\$\\{)([^\\}]+)(?=\\})"); + Matcher m = p.matcher(templateContent.getContent()); + while (m.find()) { + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(m.group()); + resourceAssignments.add(resourceAssignment); + } + } + return resourceAssignments; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java new file mode 100644 index 000000000..8dd748404 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java @@ -0,0 +1,33 @@ +/* + * 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.common; + +/** + * ApplicationConstants.java Purpose: Provide ControllerBluprintsApplication Constant Information + * + * @author Brinda Santh + * @version 1.0 + */ +public final class ApplicationConstants { + private ApplicationConstants() { + + } + public static final String ACTIVE_Y = "Y"; + public static final String ACTIVE_N = "N"; + public static final String ASDC_ARTIFACT_TYPE_SDNC_MODEL = "SDNC_MODEL"; + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java new file mode 100644 index 000000000..f7a802e46 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java @@ -0,0 +1,63 @@ +/* + * 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.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import java.io.Serializable; + +@JsonInclude(Include.NON_NULL) +public class ErrorMessage implements Serializable { + private Integer httpStatus; + private String message; + private Integer code; + private String developerMessage; + + public Integer getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(Integer httpStatus) { + this.httpStatus = httpStatus; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDeveloperMessage() { + return developerMessage; + } + + public void setDeveloperMessage(String developerMessage) { + this.developerMessage = developerMessage; + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java new file mode 100644 index 000000000..f223dccb2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java @@ -0,0 +1,42 @@ +/* + * 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.common; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; +import java.io.PrintWriter; +import java.io.StringWriter; + +@Provider +public class ServiceExceptionMapper implements ExceptionMapper { + + @Override + public Response toResponse(BluePrintException ex) { + ErrorMessage errorMessage = new ErrorMessage(); + errorMessage.setCode(ex.getCode()); + errorMessage.setMessage(ex.getMessage()); + StringWriter errorStackTrace = new StringWriter(); + ex.printStackTrace(new PrintWriter(errorStackTrace)); + errorMessage.setDeveloperMessage(ex.toString()); + return Response.status(500).entity(errorMessage).type(MediaType.APPLICATION_JSON).build(); + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java new file mode 100644 index 000000000..e90807633 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java @@ -0,0 +1,187 @@ +/* + * 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.common; + +import io.swagger.models.*; +import io.swagger.models.parameters.BodyParameter; +import io.swagger.models.parameters.Parameter; +import io.swagger.models.properties.*; +import io.swagger.util.Json; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes; +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; + +import java.util.*; + +/** + * SwaggerGenerator.java Purpose: Provide Service to generate service template input schema definition and Sample Json + * generation. + * + * @author Brinda Santh + * @version 1.0 + */ +@Deprecated +public class SwaggerGenerator { + + private ServiceTemplate serviceTemplate; + + /** + * This is a SwaggerGenerator constructor + */ + public SwaggerGenerator(ServiceTemplate serviceTemplate) { + this.serviceTemplate = serviceTemplate; + } + + /** + * This is a generateSwagger + * + * @return String + */ + public String generateSwagger() { + String swaggerContent = null; + + Swagger swagger = new Swagger().info(getInfo()); + + swagger.setPaths(getPaths()); + swagger.setDefinitions(getDefinition()); + + + swaggerContent = Json.pretty(swagger); + return swaggerContent; + } + + private Info getInfo() { + Info info = new Info(); + Contact contact = new Contact(); + contact.setName(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR)); + info.setContact(contact); + info.setTitle(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME)); + info.setDescription(serviceTemplate.getDescription()); + info.setVersion(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION)); + return info; + } + + private Map getPaths() { + Map paths = new HashMap<>(); + Path path = new Path(); + Operation post = new Operation(); + post.setOperationId("configure"); + post.setConsumes(Arrays.asList("application/json", "application/xml")); + post.setProduces(Arrays.asList("application/json", "application/xml")); + List parameters = new ArrayList<>(); + Parameter in = new BodyParameter().schema(new RefModel("#/definitions/inputs")); + in.setRequired(true); + in.setName("inputs"); + parameters.add(in); + post.setParameters(parameters); + + Map responses = new HashMap<>(); + Response response = new Response().description("Success"); + responses.put("200", response); + + Response failureResponse = new Response().description("Failure"); + responses.put("400", failureResponse); + post.setResponses(responses); + + path.setPost(post); + paths.put("/operations/config-selfservice-api:configure", path); + return paths; + } + + private Map getDefinition() { + Map models = new HashMap<>(); + + ModelImpl inputmodel = new ModelImpl(); + inputmodel.setTitle("inputs"); + serviceTemplate.getTopologyTemplate().getInputs().forEach((propertyName, property) -> { + Property defProperty = getPropery(propertyName, property); + inputmodel.property(propertyName, defProperty); + }); + models.put("inputs", inputmodel); + + if (MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { + serviceTemplate.getDataTypes().forEach((name, dataType) -> { + ModelImpl model = new ModelImpl(); + model.setDescription(dataType.getDescription()); + // model.setType("object"); + if (dataType != null && MapUtils.isNotEmpty(dataType.getProperties())) { + + dataType.getProperties().forEach((propertyName, property) -> { + Property defProperty = getPropery(propertyName, property); + model.addProperty(propertyName, defProperty); + }); + } + models.put(name, model); + }); + } + return models; + + } + + private Property getPropery(String name, PropertyDefinition propertyDefinition) { + Property defProperty = null; + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyDefinition.getType())) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN.equals(propertyDefinition.getType())) { + defProperty = new BooleanProperty(); + } else if (BluePrintConstants.DATA_TYPE_INTEGER.equals(propertyDefinition.getType())) { + StringProperty stringProperty = new StringProperty(); + stringProperty.setType("integer"); + defProperty = stringProperty; + } else if (BluePrintConstants.DATA_TYPE_FLOAT.equals(propertyDefinition.getType())) { + StringProperty stringProperty = new StringProperty(); + stringProperty.setFormat("float"); + defProperty = stringProperty; + } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP.equals(propertyDefinition.getType())) { + DateTimeProperty dateTimeProperty = new DateTimeProperty(); + dateTimeProperty.setFormat("date-time"); + defProperty = dateTimeProperty; + } else { + defProperty = new StringProperty(); + } + } else if (BluePrintTypes.validCollectionTypes().contains(propertyDefinition.getType())) { + ArrayProperty arrayProperty = new ArrayProperty(); + if (propertyDefinition.getEntrySchema() != null) { + String entrySchema = propertyDefinition.getEntrySchema().getType(); + if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema)) { + Property innerType = new RefProperty("#/definitions/" + entrySchema); + arrayProperty.setItems(innerType); + } else { + Property innerType = new StringProperty(); + arrayProperty.setItems(innerType); + } + defProperty = arrayProperty; + } + + } else { + defProperty = new RefProperty("#/definitions/" + propertyDefinition.getType()); + } + defProperty.setName(name); + if (propertyDefinition.getDefaultValue() != null) { + defProperty.setDefault(String.valueOf(propertyDefinition.getDefaultValue())); + } + + defProperty.setRequired(BooleanUtils.isTrue(propertyDefinition.getRequired())); + defProperty.setDescription(propertyDefinition.getDescription()); + return defProperty; + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java new file mode 100644 index 000000000..224960fa5 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java @@ -0,0 +1,291 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonManagedReference; +import org.hibernate.annotations.Proxy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * ConfigModel.java Purpose: Provide Configuration Generator ConfigModel Entity + * + * @author Brinda Santh + * @version 1.0 + */ + +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL") +@Proxy(lazy=false) +public class ConfigModel implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "config_model_id") + private Long id; + + @Column(name = "service_uuid") + private String serviceUUID; + + @Column(name = "distribution_id") + private String distributionId; + + @Column(name = "service_name") + private String serviceName; + + @Column(name = "service_description") + private String serviceDescription; + + @Column(name = "resource_uuid") + private String resourceUUID; + + @Column(name = "resource_instance_name") + private String resourceInstanceName; + + @Column(name = "resource_name") + private String resourceName; + + @Column(name = "resource_version") + private String resourceVersion; + + @Column(name = "resource_type") + private String resourceType; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @NotNull + @Column(name = "artifact_version") + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @NotNull + @Column(name = "artifact_name") + private String artifactName; + + @NotNull + @Column(name = "published") + private String published; + + @NotNull + @Column(name = "updated_by") + private String updatedBy; + + @NotNull + @Lob + @Column(name = "tags") + private String tags; + + + @OneToMany(mappedBy = "configModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) + @Column(nullable = true) + @JsonManagedReference + private List configModelContents = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceDescription() { + return serviceDescription; + } + + public void setServiceDescription(String serviceDescription) { + this.serviceDescription = serviceDescription; + } + + public String getResourceUUID() { + return resourceUUID; + } + + public void setResourceUUID(String resourceUUID) { + this.resourceUUID = resourceUUID; + } + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public List getConfigModelContents() { + return configModelContents; + } + + public void setConfigModelContents(List configModelContents) { + this.configModelContents = configModelContents; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java new file mode 100644 index 000000000..f7bd554df --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -0,0 +1,175 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.util.Date; +import java.util.Objects; + +/** + * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL_CONTENT") +public class ConfigModelContent { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "config_model_content_id") + private Long id; + + @NotNull + @Column(name = "name") + private String name; + + @NotNull + @Column(name = "content_type") + private String contentType; + + + @ManyToOne + @JoinColumn(name = "config_model_id") + @JsonBackReference + private ConfigModel configModel; + + @Lob + @Column(name = "description") + private String description; + + @NotNull + @Lob + @Column(name = "content") + private String content; + + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "updated_date") + private Date creationDate; + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("["); + builder.append("id = " + id); + builder.append(", name = " + name); + builder.append(", contentType = " + contentType); + builder.append("]"); + return builder.toString(); + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + if (!(o instanceof ConfigModelContent)) { + return false; + } + ConfigModelContent configModelContent = (ConfigModelContent) o; + return Objects.equals(id, configModelContent.id) && Objects.equals(name, configModelContent.name) + && Objects.equals(contentType, configModelContent.contentType); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, contentType); + } + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getContentType() { + return contentType; + } + + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + + public ConfigModel getConfigModel() { + return configModel; + } + + + public void setConfigModel(ConfigModel configModel) { + this.configModel = configModel; + } + + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public String getContent() { + return content; + } + + + public void setContent(String content) { + this.content = content; + } + + + public Date getCreationDate() { + return creationDate; + } + + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java new file mode 100644 index 000000000..2e9018837 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java @@ -0,0 +1,171 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.data.annotation.LastModifiedDate; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +@Entity +@Table(name = "CONFIG_MODEL") +public class ConfigModelSearch implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "config_model_id") + private Long id; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @NotNull + @Column(name = "artifact_version") + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @NotNull + @Column(name = "artifact_name") + private String artifactName; + + @NotNull + @Column(name = "published") + private String published; + + @NotNull + @Column(name = "updated_by") + private String updatedBy; + + @NotNull + @Lob + @Column(name = "tags") + private String tags; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } + + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java new file mode 100644 index 000000000..ed6340a65 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -0,0 +1,170 @@ +/* + * 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.domain; + +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + + +/** + * AsdcReference.java Purpose: Provide Configuration Generator AsdcReference Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "MODEL_TYPE") +public class ModelType implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @NotNull + @Column(name = "model_name", nullable = false) + private String modelName; + + @NotNull + @Column(name = "derived_from") + private String derivedFrom; + + @NotNull + @Column(name = "definition_type") + private String definitionType; + + @NotNull + @Lob + @Column(name = "definition") + private String definition; + + @NotNull + @Lob + @Column(name = "description") + private String description; + + @NotNull + @Column(name = "version") + private String version; + + @NotNull + @Lob + @Column(name = "tags") + private String tags; + + // @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date creationDate; + + @NotNull + @Column(name = "updated_by") + private String updatedBy; + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("["); + buffer.append(", modelName = " + modelName); + buffer.append(", derivedFrom = " + derivedFrom); + buffer.append(", definitionType = " + definitionType); + buffer.append(", description = " + description); + buffer.append(", creationDate = " + creationDate); + buffer.append(", version = " + version); + buffer.append(", updatedBy = " + updatedBy); + buffer.append(", tags = " + tags); + buffer.append("]"); + return buffer.toString(); + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDerivedFrom() { + return derivedFrom; + } + + public void setDerivedFrom(String derivedFrom) { + this.derivedFrom = derivedFrom; + } + + public String getDefinitionType() { + return definitionType; + } + + public void setDefinitionType(String definitionType) { + this.definitionType = definitionType; + } + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java new file mode 100644 index 000000000..adb018841 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -0,0 +1,207 @@ +/* + * 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.domain; + +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Date; + +/** + * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "RESOURCE_DICTIONARY") +public class ResourceDictionary implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @NotNull + @Column(name = "name") + private String name; + + @NotNull + @Column(name = "resource_path") + private String resourcePath; + + @NotNull + @Column(name = "resource_type") + private String resourceType; + + @NotNull + @Column(name = "data_type") + private String dataType; + + @Column(name = "entry_schema") + private String entrySchema; + + @Lob + @Column(name = "valid_values") + private String validValues; + + @Lob + @Column(name = "sample_value") + private String sampleValue; + + @NotNull + @Lob + @Column(name = "definition") + private String definition; + + @NotNull + @Lob + @Column(name = "description") + private String description; + + @NotNull + @Lob + @Column(name = "tags") + private String tags; + + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date creationDate; + + @NotNull + @Column(name = "updated_by") + private String updatedBy; + + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("["); + buffer.append(", name = " + name); + buffer.append(", resourcePath = " + resourcePath); + buffer.append(", resourceType = " + resourceType); + buffer.append(", dataType = " + dataType); + buffer.append(", entrySchema = " + entrySchema); + buffer.append(", validValues = " + validValues); + buffer.append(", definition =" + definition); + buffer.append(", description = " + description); + buffer.append(", updatedBy = " + updatedBy); + buffer.append(", tags = " + tags); + buffer.append(", creationDate = " + creationDate); + buffer.append("]"); + return buffer.toString(); + } + + public String getResourcePath() { + return resourcePath; + } + + public void setResourcePath(String resourcePath) { + this.resourcePath = resourcePath; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getEntrySchema() { + return entrySchema; + } + + public void setEntrySchema(String entrySchema) { + this.entrySchema = entrySchema; + } + + public String getValidValues() { + return validValues; + } + + public void setValidValues(String validValues) { + this.validValues = validValues; + } + + public String getSampleValue() { + return sampleValue; + } + + public void setSampleValue(String sampleValue) { + this.sampleValue = sampleValue; + } + + public String getDefinition() { + return definition; + } + + public void setDefinition(String definition) { + this.definition = definition; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java new file mode 100644 index 000000000..2250828ac --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java @@ -0,0 +1,53 @@ +/* + * 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.model; + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; + +import java.util.List; + +/** + * ArtifactRequest.java Purpose: Provide Configuration Generator ArtifactRequest Model + * + * @author Brinda Santh + * @version 1.0 + */ +public class AutoMapResponse { + + private List resourceAssignments; + private List dataDictionaries; + + public List getResourceAssignments() { + return resourceAssignments; + } + + public void setResourceAssignments(List resourceAssignments) { + this.resourceAssignments = resourceAssignments; + } + + public List getDataDictionaries() { + return dataDictionaries; + } + + public void setDataDictionaries(List dataDictionaries) { + this.dataDictionaries = dataDictionaries; + } + + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java new file mode 100644 index 000000000..ad2584a8e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java @@ -0,0 +1,95 @@ +/* + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +/** + * ConfigModelContentRepository.java Purpose: Provide ConfigModelContentRepository of Repository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface ConfigModelContentRepository extends JpaRepository { + + /** + * This is a findById method + * + * @param id + * @return Optional + */ + Optional findById(Long id); + + /** + * This is a findTopByConfigModelAndContentType method + * + * @param configModel + * @param contentType + * @return Optional + */ + Optional findTopByConfigModelAndContentType(ConfigModel configModel, String contentType); + + /** + * This is a findByConfigModelAndContentType method + * + * @param configModel + * @param contentType + * @return Optional + */ + List findByConfigModelAndContentType(ConfigModel configModel, String contentType); + + /** + * This is a findByConfigModel method + * + * @param configModel + * @return Optional + */ + List findByConfigModel(ConfigModel configModel); + + /** + * This is a findByConfigModelAndContentTypeAndName method + * + * @param configModel + * @param contentType + * @param name + * @return Optional + */ + Optional findByConfigModelAndContentTypeAndName(ConfigModel configModel, + String contentType, String name); + + /** + * This is a deleteByMdeleteByConfigModelodelName method + * + * @param configModel + */ + void deleteByConfigModel(ConfigModel configModel); + + /** + * This is a deleteById method + * + * @param id + */ + void deleteById(Long id); + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java new file mode 100644 index 000000000..4822ee971 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java @@ -0,0 +1,90 @@ +/* + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +/** + * AsdcArtifactsRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface ConfigModelRepository extends JpaRepository { + /** + * This is a findById method + * + * @param id + * @return Optional + */ + Optional findById(Long id); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName + * @param artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName + * @return Optional + */ + Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); + + /** + * This is a findTopByArtifactName method + * + * @param artifactName + * @return Optional + */ + List findTopByArtifactName(String artifactName); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); + + /** + * This is a deleteByArtifactNameAndArtifactVersion method + * + * @param artifactName + * @param artifactVersion + */ + void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a deleteById method + * + * @param id + */ + void deleteById(Long id); + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java new file mode 100644 index 000000000..bafc3aa89 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java @@ -0,0 +1,43 @@ +/* + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelSearch; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * ConfigModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface ConfigModelSearchRepository extends JpaRepository { + + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java new file mode 100644 index 000000000..51ae752f9 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java @@ -0,0 +1,98 @@ +/* + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + + +/** + * ModelTypeRepository.java Purpose: Provide Configuration Generator ModelTypeRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface ModelTypeRepository extends JpaRepository { + + + /** + * This is a findByModelName method + * + * @param modelName + * @return Optional + */ + Optional findByModelName(String modelName); + + /** + * This is a findByDerivedFrom method + * + * @param derivedFrom + * @return List + */ + List findByDerivedFrom(String derivedFrom); + + + /** + * This is a findByDerivedFromIn method + * + * @param derivedFroms + * @return List + */ + List findByDerivedFromIn(List derivedFroms); + + /** + * This is a findByDefinitionType method + * + * @param definitionType + * @return List + */ + List findByDefinitionType(String definitionType); + + /** + * This is a findByDefinitionTypeIn method + * + * @param definitionTypes + * @return List + */ + List findByDefinitionTypeIn(List definitionTypes); + + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); + + + /** + * This is a deleteByModelName method + * + * @param modelName + * @return Optional + */ + void deleteByModelName(String modelName); + + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java new file mode 100644 index 000000000..279dcd1c9 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java @@ -0,0 +1,68 @@ +/* + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +/** + * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface ResourceDictionaryRepository extends JpaRepository { + + + /** + * This is a findByName method + * + * @param name + * @return Optional + */ + Optional findByName(String name); + + /** + * This is a findByNameIn method + * + * @param names + * @return Optional + */ + List findByNameIn(List names); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); + + /** + * This is a deleteByName method + * + * @param name + */ + void deleteByName(String name); + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java new file mode 100644 index 000000000..86c89bf90 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -0,0 +1,179 @@ +/* + * 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.rs; + +import io.swagger.annotations.*; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.List; + +/** + * ConfigModelRest.java Purpose: Rest service controller for ConfigModelRest Management + * + * @author Brinda Santh + * @version 1.0 + */ +@Api +@Path("/service") +@Produces({MediaType.APPLICATION_JSON}) +public interface ConfigModelRest { + + /** + * This is a getConfigModel rest service + * + * @param id + * @return ConfigModel + * @throws BluePrintException + */ + @GET + @Path("/configmodel/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + @RequestMapping(value = "/configmodel/{id}", method = RequestMethod.GET) + @ResponseBody ConfigModel getConfigModel(@ApiParam(required = true) @PathParam("id") Long id) + throws BluePrintException; + + + /** + * This is a saveConfigModel rest service + * + * @param configModel + * @return ConfigModel + * @throws BluePrintException + */ + @POST + @Path("/configmodel") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get Model Type by Tags", response = ServiceTemplate.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ConfigModel saveConfigModel(@ApiParam(required = true) ConfigModel configModel) + throws BluePrintException; + + /** + * This is a deleteConfigModel rest service + * + * @param id + * @throws BluePrintException + */ + @DELETE + @Path("/configmodel/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to delete ConfigModel.") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + void deleteConfigModel(@ApiParam(required = true) @PathParam("id") Long id) throws BluePrintException; + + /** + * This is a getInitialConfigModel rest service + * + * @param name + * @return ConfigModel + * @throws BluePrintException + */ + @GET + @Path("/configmodelinitial/{name}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to create default Service Template", response = ConfigModel.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ConfigModel getInitialConfigModel(@ApiParam(required = true) @PathParam("name") String name) + throws BluePrintException; + + /** + * This is a getCloneConfigModel rest service + * + * @param id + * @return ConfigModel + * @throws BluePrintException + */ + @GET + @Path("/configmodelclone/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to create default Service Template", response = ConfigModel.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ConfigModel getCloneConfigModel(@ApiParam(required = true) @PathParam("id") Long id) + throws BluePrintException; + + /** + * This is a publishConfigModel rest service + * + * @param id + * @return ServiceTemplate + * @throws BluePrintException + */ + @GET + @Path("/configmodelpublish/{id}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get Model Type by Tags", response = ConfigModel.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ConfigModel publishConfigModel(@ApiParam(required = true) @PathParam("id") Long id) + throws BluePrintException; + + /** + * This is a getConfigModelByNameAndVersion rest service + * + * @param name + * @param version + * @return ConfigModel + * @throws BluePrintException + */ + @GET + @Path("/configmodelbyname/{name}/version/{version}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ConfigModel getConfigModelByNameAndVersion(@ApiParam(required = true) @PathParam("name") String name, + @ApiParam(required = true) @PathParam("version") String version) throws BluePrintException; + + /** + * This is a searchServiceModels rest service + * + * @param tags + * @return List + * @throws BluePrintException + */ + @GET + @Path("/configmodelsearch/{tags}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List searchConfigModels(@ApiParam(required = true) @PathParam("tags") String tags) + throws BluePrintException; + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java new file mode 100644 index 000000000..a9abcd5ff --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java @@ -0,0 +1,116 @@ +/* + * 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.rs; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * {@inheritDoc} + */ +@Service +public class ConfigModelRestImpl implements ConfigModelRest { + + private ConfigModelService configModelService; + + /** + * This is a ConfigModelRestImpl constructor. + * + * @param configModelService Config Model Service + */ + public ConfigModelRestImpl(ConfigModelService configModelService) { + this.configModelService = configModelService; + + } + + @Override + public ConfigModel getInitialConfigModel(String name) throws BluePrintException { + try { + return this.configModelService.getInitialConfigModel(name); + } catch (Exception e) { + throw new BluePrintException(2000, e.getMessage(), e); + } + } + + @Override + public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { + try { + return this.configModelService.saveConfigModel(configModel); + } catch (Exception e) { + throw new BluePrintException(2200, e.getMessage(), e); + } + } + + @Override + public void deleteConfigModel(Long id) throws BluePrintException { + try { + this.configModelService.deleteConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(4000, e.getMessage(), e); + } + } + + @Override + public ConfigModel publishConfigModel(Long id) throws BluePrintException { + try { + return this.configModelService.publishConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2500, e.getMessage(), e); + } + } + + @Override + public ConfigModel getConfigModel(Long id) throws BluePrintException { + try { + return this.configModelService.getConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2001, e.getMessage(), e); + } + } + + @Override + public ConfigModel getConfigModelByNameAndVersion(String name, String version) throws BluePrintException { + try { + return this.configModelService.getConfigModelByNameAndVersion(name, version); + } catch (Exception e) { + throw new BluePrintException(2002, e.getMessage(), e); + } + } + + @Override + public List searchConfigModels(String tags) throws BluePrintException { + try { + return this.configModelService.searchConfigModels(tags); + } catch (Exception e) { + throw new BluePrintException(2003, e.getMessage(), e); + } + } + + @Override + public ConfigModel getCloneConfigModel(Long id) throws BluePrintException { + try { + return this.configModelService.getCloneConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2004, e.getMessage(), e); + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java new file mode 100644 index 000000000..59b730309 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -0,0 +1,125 @@ +/* + * 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.rs; + +import io.swagger.annotations.*; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.List; + +/** + * ModelTypeRest.java Purpose: Rest service controller for Artifact Handling + * + * @author Brinda Santh + * @version 1.0 + */ +@Api +@Path("/service") +@Produces({MediaType.APPLICATION_JSON}) +public interface ModelTypeRest { + + /** + * This is a getModelTypeByName rest service + * + * @param name + * @return ModelType + * @throws BluePrintException + */ + @GET + @Path("/modeltype/{name}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get Model Type by id", response = ModelType.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ModelType getModelTypeByName(@ApiParam(required = true) @PathParam("name") String name) + throws BluePrintException; + + /** + * This is a saveModelType rest service + * + * @param modelType + * @return ModelType + * @throws BluePrintException + */ + + @POST + @Path("/modeltype") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to Save Model Type", response = ModelType.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ModelType saveModelType(@ApiParam(required = true) ModelType modelType) throws BluePrintException; + + /** + * This is a deleteModelType rest service + * + * @param name + * @throws BluePrintException + */ + @DELETE + @Path("/modeltype/{name}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to delete Model Type") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + void deleteModelTypeByName(@ApiParam(required = true) @PathParam("name") String name) + throws BluePrintException; + + /** + * This is a searchModelType rest service + * + * @param tags + * @return List + * @throws BluePrintException + */ + @GET + @Path("/modeltypesearch/{tags}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get Model Type by tags", response = ModelType.class, + responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List searchModelTypes(@ApiParam(required = true) @PathParam("tags") String tags) + throws BluePrintException; + + /** + * This is a getModelTypeByDefinitionType rest service + * + * @param definitionType + * @return List + * @throws BluePrintException + */ + @GET + @Path("/modeltypebydefinition/{definitionType}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get Model Type by tags", response = ModelType.class, + responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List getModelTypeByDefinitionType( + @ApiParam(required = true) @PathParam("definitionType") String definitionType) + throws BluePrintException; + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java new file mode 100644 index 000000000..6fbc69699 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java @@ -0,0 +1,87 @@ +/* + * 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.rs; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * {@inheritDoc} + */ +@Service +public class ModelTypeRestImpl implements ModelTypeRest { + + private ModelTypeService modelTypeService; + + /** + * This is a ModelTypeResourceImpl, used to save and get the model types stored in database + * + * @param modelTypeService Model Type Service + */ + public ModelTypeRestImpl(ModelTypeService modelTypeService) { + this.modelTypeService = modelTypeService; + } + + @Override + public ModelType getModelTypeByName(String modelName) throws BluePrintException { + try { + return modelTypeService.getModelTypeByName(modelName); + } catch (Exception e) { + throw new BluePrintException(1000, e.getMessage(), e); + } + } + + @Override + public List searchModelTypes(String tags) throws BluePrintException { + try { + return modelTypeService.searchModelTypes(tags); + } catch (Exception e) { + throw new BluePrintException(1001, e.getMessage(), e); + } + } + + @Override + public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { + try { + return modelTypeService.getModelTypeByDefinitionType(definitionType); + } catch (Exception e) { + throw new BluePrintException(1002, e.getMessage(), e); + } + } + + @Override + public ModelType saveModelType(ModelType modelType) throws BluePrintException { + try { + return modelTypeService.saveModel(modelType); + } catch (Exception e) { + throw new BluePrintException(1100, e.getMessage(), e); + } + } + + @Override + public void deleteModelTypeByName(String name) throws BluePrintException { + try { + modelTypeService.deleteByModelName(name); + } catch (Exception e) { + throw new BluePrintException(1400, e.getMessage(), e); + } + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java new file mode 100644 index 000000000..5bc983363 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -0,0 +1,126 @@ +/* + * 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.rs; + +import io.swagger.annotations.*; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.List; + +/** + * ResourceDictionaryRest.java Purpose: Rest service controller for Artifact Handling + * + * @author Brinda Santh + * @version 1.0 + */ +@Api +@Path("/service") +@Produces({MediaType.APPLICATION_JSON}) + +public interface ResourceDictionaryRest { + + /** + * This is a getDataDictionaryByPath rest service + * + * @param name + * @return ResourceDictionary + * @throws BluePrintException + */ + @GET + @Path("/dictionary/{name}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get Resource dictionary", response = ResourceDictionary.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ResourceDictionary getResourceDictionaryByName(@ApiParam(required = true) @PathParam("name") String name) + throws BluePrintException; + + /** + * This is a saveDataDictionary rest service + * + * @param resourceMapping + * @return ResourceDictionary + * @throws BluePrintException + */ + + @POST + @Path("/dictionary") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to Save Resource dictionary Type", response = ResourceDictionary.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ResourceDictionary saveResourceDictionary(@ApiParam(required = true) ResourceDictionary resourceMapping) + throws BluePrintException; + + /** + * This is a deleteDataDictionaryByName rest service + * + * @param name + * @throws BluePrintException + */ + @DELETE + @Path("/dictionary/{name}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to delete ResourceDictionary Type") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + void deleteResourceDictionaryByName(@ApiParam(required = true) @PathParam("name") String name) + throws BluePrintException; + + /** + * This is a searchResourceDictionaryByTags rest service + * + * @param tags + * @return ResourceDictionary + * @throws BluePrintException + */ + @GET + @Path("/dictionarysearch/{tags}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to search Resource dictionary by tags", + response = ResourceDictionary.class, responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List searchResourceDictionaryByTags( + @ApiParam(required = true) @PathParam("tags") String tags) throws BluePrintException; + + /** + * This is a searchResourceDictionaryByNames rest service + * + * @param names + * @return List + * @throws BluePrintException + */ + @POST + @Path("/dictionarybynames") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to get ResourceDictionary Type by names", + response = ResourceDictionary.class, responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List searchResourceDictionaryByNames(@ApiParam(required = true) List names) + throws BluePrintException; + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java new file mode 100644 index 000000000..e3448424d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java @@ -0,0 +1,91 @@ +/* + * 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.rs; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * {@inheritDoc} + */ +@Service +public class ResourceDictionaryRestImpl implements ResourceDictionaryRest { + + + private ResourceDictionaryService resourceDictionaryService; + + /** + * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database + * + * @param dataDictionaryService Data Dictionary Service + */ + public ResourceDictionaryRestImpl(ResourceDictionaryService dataDictionaryService) { + this.resourceDictionaryService = dataDictionaryService; + } + + @Override + public ResourceDictionary saveResourceDictionary(ResourceDictionary dataDictionary) + throws BluePrintException { + try { + return resourceDictionaryService.saveResourceDictionary(dataDictionary); + } catch (Exception e) { + throw new BluePrintException(4100, e.getMessage(), e); + } + } + + @Override + public void deleteResourceDictionaryByName(String name) throws BluePrintException { + try { + resourceDictionaryService.deleteResourceDictionary(name); + } catch (Exception e) { + throw new BluePrintException(4400, e.getMessage(), e); + } + } + + @Override + public ResourceDictionary getResourceDictionaryByName(String resourcePath) throws BluePrintException { + try { + return resourceDictionaryService.getResourceDictionaryByName(resourcePath); + } catch (Exception e) { + throw new BluePrintException(4001, e.getMessage(), e); + } + } + + @Override + public List searchResourceDictionaryByNames(List names) + throws BluePrintException { + try { + return resourceDictionaryService.searchResourceDictionaryByNames(names); + } catch (Exception e) { + throw new BluePrintException(4002, e.getMessage(), e); + } + } + + @Override + public List searchResourceDictionaryByTags(String tags) throws BluePrintException { + try { + return resourceDictionaryService.searchResourceDictionaryByTags(tags); + } catch (Exception e) { + throw new BluePrintException(4003, e.getMessage(), e); + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java new file mode 100644 index 000000000..fcb8f3119 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -0,0 +1,134 @@ +/* + * 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.rs; + +import io.swagger.annotations.*; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.List; + + +/** + * ServiceTemplateRest.java Purpose: ServiceTemplateRest interface + * + * @author Brinda Santh + * @version 1.0 + */ + +@Api +@Path("/service") +@Produces({MediaType.APPLICATION_JSON}) +public interface ServiceTemplateRest { + + /** + * This is a enrichServiceTemplate rest service + * + * @param serviceTemplate + * @return ServiceTemplate + * @throws BluePrintException + */ + @POST + @Path("/servicetemplate/enrich") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to enrich service template", response = ServiceTemplate.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ServiceTemplate enrichServiceTemplate(@ApiParam(required = true) ServiceTemplate serviceTemplate) + throws BluePrintException; + + /** + * This is a validateServiceTemplate rest service + * + * @param serviceTemplate + * @return ServiceTemplate + * @throws BluePrintException + */ + @POST + @Path("/servicetemplate/validate") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to validate service template", response = ServiceTemplate.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + ServiceTemplate validateServiceTemplate(@ApiParam(required = true) ServiceTemplate serviceTemplate) + throws BluePrintException; + + /** + * This is a generateResourceAssignments rest service + * + * @param templateContent + * @return List + * @throws BluePrintException + */ + @POST + @Path("/resourceassignment/generate") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to auto map for the Resource Mapping", + response = ResourceAssignment.class, responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List generateResourceAssignments( + @ApiParam(required = true) ConfigModelContent templateContent) throws BluePrintException; + + /** + * This is a autoMap rest service + * + * @param resourceAssignments + * @return AutoMapResponse + * @throws BluePrintException + */ + @POST + @Path("/resourceassignment/automap") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to auto map for the Resource assignments", + response = AutoMapResponse.class) + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + AutoMapResponse autoMap(@ApiParam(required = true) List resourceAssignments) + throws BluePrintException; + + /** + * This is a validateResourceAssignments rest service + * + * @param resourceAssignments + * @return List + * @throws BluePrintException + */ + @POST + @Path("/resourceassignment/validate") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "Provides Rest service to validate Resource assignments", response = ResourceAssignment.class, + responseContainer = "List") + @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), + @ApiResponse(code = 500, message = "Unexpected Runtime error")}) + List validateResourceAssignments( + @ApiParam(required = true) List resourceAssignments) throws BluePrintException; + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java new file mode 100644 index 000000000..6c49d5c65 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java @@ -0,0 +1,94 @@ +/* + * 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.rs; + + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * {@inheritDoc} + */ +@Service +public class ServiceTemplateRestImpl implements ServiceTemplateRest { + + private ServiceTemplateService serviceTemplateService; + + /** + * This is a ServiceTemplateRestImpl constructor + * + * @param serviceTemplateService Service Template Service + */ + public ServiceTemplateRestImpl(ServiceTemplateService serviceTemplateService) { + this.serviceTemplateService = serviceTemplateService; + } + + @Override + public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + try { + return serviceTemplateService.enrichServiceTemplate(serviceTemplate); + } catch (Exception e) { + throw new BluePrintException(3500, e.getMessage(), e); + } + } + + @Override + public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + try { + return serviceTemplateService.validateServiceTemplate(serviceTemplate); + } catch (Exception e) { + throw new BluePrintException(3501, e.getMessage(), e); + } + } + + @Override + public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { + try { + return serviceTemplateService.autoMap(resourceAssignments); + } catch (Exception e) { + throw new BluePrintException(3502, e.getMessage(), e); + } + } + + @Override + public List validateResourceAssignments(List resourceAssignments) + throws BluePrintException { + try { + return serviceTemplateService.validateResourceAssignments(resourceAssignments); + } catch (Exception e) { + throw new BluePrintException(3503, e.getMessage(), e); + } + } + + @Override + public List generateResourceAssignments(ConfigModelContent templateContent) + throws BluePrintException { + try { + return serviceTemplateService.generateResourceAssignments(templateContent); + } catch (Exception e) { + throw new BluePrintException(3504, e.getMessage(), e); + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java new file mode 100644 index 000000000..e31b04d16 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -0,0 +1,124 @@ +/* + * 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.utils; + +import com.google.common.base.Preconditions; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.filefilter.DirectoryFileFilter; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ConfigModelUtils { + + private ConfigModelUtils(){ + + } + private static Logger log = LoggerFactory.getLogger(ConfigModelUtils.class); + + public static ConfigModel getConfigModel(String blueprintPath) throws Exception { + Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing"); + ToscaMetaData toscaMetaData = BluePrintMetadataUtils.toscaMetaData(blueprintPath); + + Preconditions.checkNotNull(toscaMetaData, "failed to get Blueprint Metadata information"); + Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getEntityDefinitions()), "failed to get Blueprint Definition file"); + Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getCreatedBy()), "failed to get Blueprint created by"); + Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getToscaMetaFileVersion()), "failed to get Blueprint package version"); + + String bluePrintName = FilenameUtils.getBaseName(toscaMetaData.getEntityDefinitions()); + Preconditions.checkArgument(StringUtils.isNotBlank(bluePrintName), "failed to get Blueprint Definition Name"); + + // TODO - Update Rest of the Model + ConfigModel configModel = new ConfigModel(); + configModel.setUpdatedBy(toscaMetaData.getCreatedBy()); + configModel.setArtifactName(bluePrintName); + configModel.setArtifactVersion(toscaMetaData.getToscaMetaFileVersion()); + configModel.setTags(toscaMetaData.getTemplateTags()); + configModel.setArtifactType("SDNC_MODEL"); + + String blueprintContent = + getPathContent(blueprintPath + "/" + toscaMetaData.getEntityDefinitions()); + + Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "failed to get Blueprint content"); + + List configModelContents = new ArrayList<>(); + ConfigModelContent stConfigModelContent = new ConfigModelContent(); + stConfigModelContent.setName(configModel.getArtifactName()); + stConfigModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); + stConfigModelContent.setContent(blueprintContent); + configModelContents.add(stConfigModelContent); + + String velocityDir = blueprintPath + "/Templates"; + List velocityTemplateFiles = getFileOfExtension(velocityDir, new String[]{"vtl"}); + + if (CollectionUtils.isNotEmpty(velocityTemplateFiles)) { + for (File velocityTemplateFile : velocityTemplateFiles) { + if (velocityTemplateFile != null) { + String contentName = velocityTemplateFile.getName().replace(".vtl", ""); + ConfigModelContent velocityConfigModelContent = new ConfigModelContent(); + String velocityConfigContent = getPathContent(velocityTemplateFile); + velocityConfigModelContent.setName(contentName); + velocityConfigModelContent + .setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); + velocityConfigModelContent.setContent(velocityConfigContent); + configModelContents.add(velocityConfigModelContent); + log.info("Loaded blueprint template successfully: {}", velocityTemplateFile.getName()); + } + } + } + configModel.setConfigModelContents(configModelContents); + + return configModel; + + } + + public static String getPathContent(String path) throws IOException { + Preconditions.checkArgument(StringUtils.isNotBlank(path), "Path is missing"); + return FileUtils.readFileToString(new File(path), Charset.defaultCharset()); + } + + public static String getPathContent(File file) throws IOException { + Preconditions.checkNotNull(file, "File is missing"); + return FileUtils.readFileToString(file, Charset.defaultCharset()); + } + + public static List getFileOfExtension(String basePath, String[] extensions) { + Preconditions.checkArgument(StringUtils.isNotBlank(basePath), "Path is missing"); + Preconditions.checkNotNull(extensions, "Extensions is missing"); + return (List) FileUtils.listFiles(new File(basePath), extensions, true); + } + + public static List getBlueprintNames(String pathName) { + File blueprintDir = new File(pathName); + Preconditions.checkNotNull(blueprintDir, "failed to find the blueprint pathName file"); + return Arrays.asList(blueprintDir.list(DirectoryFileFilter.INSTANCE)); + } +} 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 new file mode 100644 index 000000000..85f256ea7 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java @@ -0,0 +1,200 @@ +/* + * 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 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; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; + +import java.util.ArrayList; +import java.util.List; + +/** + * ModelTypeValidation.java Purpose: Provide Validation Service for Model Type ModelTypeValidation + * + * @author Brinda Santh + * @version 1.0 + */ + +public class ModelTypeValidator { + + private ModelTypeValidator() { + + } + + private static List getValidModelDefinitionType() { + List validTypes = new ArrayList<>(); + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE); + validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE); + 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 + * + * @param definitionType + * @param definitionContent + * @return boolean + * @throws BluePrintException + */ + public static boolean validateModelTypeDefinition(String definitionType, String definitionContent) + throws BluePrintException { + boolean valid = true; + if (StringUtils.isNotBlank(definitionContent)) { + if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) { + DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); + if (dataType == null) { + throw new BluePrintException( + "Model type definition is not DataType valid content " + definitionContent); + } + } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE.equalsIgnoreCase(definitionType)) { + NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); + if (nodeType == null) { + throw new BluePrintException( + "Model type definition is not NodeType valid content " + definitionContent); + } + } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE.equalsIgnoreCase(definitionType)) { + ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); + if (artifactType == null) { + throw new BluePrintException( + "Model type definition is not ArtifactType valid content " + definitionContent); + } + }else if (BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE.equalsIgnoreCase(definitionType)) { + CapabilityDefinition capabilityDefinition = + JacksonUtils.readValue(definitionContent, CapabilityDefinition.class); + if (capabilityDefinition == null) { + throw new BluePrintException( + "Model type definition is not CapabilityDefinition valid content " + definitionContent); + } + } + + } + return valid; + } + + /** + * This is a validateModelType method + * + * @param modelType + * @return boolean + */ + public static boolean validateModelType(ModelType modelType) throws BluePrintException { + if (modelType != null) { + + if (StringUtils.isBlank(modelType.getModelName())) { + throw new BluePrintException("Model Name Information is missing."); + } + + if (StringUtils.isBlank(modelType.getDefinitionType())) { + throw new BluePrintException("Model Root Type Information is missing."); + } + if (StringUtils.isBlank(modelType.getDerivedFrom())) { + throw new BluePrintException("Model Type Information is missing."); + } + + if (StringUtils.isBlank(modelType.getDefinition())) { + throw new BluePrintException("Model Definition Information is missing."); + } + if (StringUtils.isBlank(modelType.getDescription())) { + throw new BluePrintException("Model Description Information is missing."); + } + + if (StringUtils.isBlank(modelType.getVersion())) { + throw new BluePrintException("Model Version Information is missing."); + } + + if (StringUtils.isBlank(modelType.getUpdatedBy())) { + throw new BluePrintException("Model Updated By Information is missing."); + } + + List validRootTypes = getValidModelDefinitionType(); + if (!validRootTypes.contains(modelType.getDefinitionType())) { + throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType() + + "), It sould be " + validRootTypes); + } + + validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition()); + + validateNodeType(modelType.getDefinitionType(), modelType.getDerivedFrom()); + + } else { + throw new BluePrintException("Model Type Information is missing."); + } + + return true; + + } + +} 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 new file mode 100644 index 000000000..eb2448e70 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java @@ -0,0 +1,88 @@ +/* + * 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.lang3.StringUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +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 validateResourceDictionaryDefinition + * + * @param definitionContent + * @return boolean + * @throws BluePrintException + */ + public static boolean validateResourceDictionaryDefinition(String definitionContent) + throws BluePrintException { + boolean valid = true; + if (StringUtils.isNotBlank(definitionContent)) { + DictionaryDefinition dictionaryDefinition = + JacksonUtils.readValue(definitionContent, DictionaryDefinition.class); + if (dictionaryDefinition == null) { + throw new BluePrintException( + "Resource dictionary definition is not valid content " + definitionContent); + } + + } + return valid; + } + + /** + * 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.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourcePath()), + "DataDictionary Resource Name Information is missing."); + Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()), + "DataDictionary Resource Type Information is missing."); + Preconditions.checkArgument( StringUtils.isNotBlank(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 new file mode 100644 index 000000000..ea46f3ad3 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java @@ -0,0 +1,123 @@ +/* + * 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.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.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.validator.ResourceAssignmentValidator; + +import java.util.HashMap; +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 metaData = new HashMap(); + + /** + * This is a validateServiceTemplate + * + * @param serviceTemplateContent + * @return boolean + * @throws BluePrintException + */ + public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { + if (StringUtils.isNotBlank(serviceTemplateContent)) { + ServiceTemplate serviceTemplate = + JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + return validateServiceTemplate(serviceTemplate); + } else { + throw new BluePrintException( + "Service Template Content is (" + serviceTemplateContent + ") not Defined."); + } + } + + /** + * This is a validateServiceTemplate + * + * @param serviceTemplate + * @return boolean + * @throws BluePrintException + */ + @SuppressWarnings("squid:S00112") + public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + Map properties = new HashMap<>(); + super.validateBlueprint(serviceTemplate, properties); + return true; + } + + /** + * This is a getMetaData to get the key information during the + * + * @return Map + */ + public Map getMetaData() { + return metaData; + } + + @Override + public void validateMetadata(@NotNull Map metaDataMap) throws BluePrintException { + + Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing."); + + this.metaData.putAll(serviceTemplate.getMetadata()); + + String author = serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR); + String serviceTemplateName = + serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME); + String serviceTemplateVersion = + serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION); + + Preconditions.checkArgument(StringUtils.isNotBlank(author), "Template Metadata (author) Information is missing."); + Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateName), "Template Metadata (service-template-name) Information is missing."); + Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateVersion), "Template Metadata (service-template-version) Information is missing."); + } + + + @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 ("tosca.nodes.Artifact".equals(derivedFrom)) { + ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate); + resourceAssignmentValidator.validateResourceAssignment(); + } + } +} -- cgit From a3c9519d6aa7eb8e1f450a7d041047f2c0a5cc07 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 17 Aug 2018 19:45:00 +0000 Subject: Controller Blueprints Microservice Restcontroller Swagger Implementation with Embeded jar for Controller Bluprints MS Change-Id: I0c0a33f0e29dad0d4aa703e3e381068b510e57d4 Issue-ID: CCSDK-468 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/common/ServiceExceptionMapper.java | 42 ---- .../service/common/SwaggerGenerator.java | 24 +-- .../service/rs/ConfigModelRest.java | 232 ++++++++------------- .../service/rs/ConfigModelRestImpl.java | 116 ----------- .../service/rs/ModelTypeRest.java | 147 +++++-------- .../service/rs/ModelTypeRestImpl.java | 87 -------- .../service/rs/ResourceDictionaryRest.java | 152 ++++++-------- .../service/rs/ResourceDictionaryRestImpl.java | 91 -------- .../service/rs/ServiceTemplateRest.java | 160 ++++++-------- .../service/rs/ServiceTemplateRestImpl.java | 94 --------- 10 files changed, 284 insertions(+), 861 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java deleted file mode 100644 index f223dccb2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceExceptionMapper.java +++ /dev/null @@ -1,42 +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.common; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; -import java.io.PrintWriter; -import java.io.StringWriter; - -@Provider -public class ServiceExceptionMapper implements ExceptionMapper { - - @Override - public Response toResponse(BluePrintException ex) { - ErrorMessage errorMessage = new ErrorMessage(); - errorMessage.setCode(ex.getCode()); - errorMessage.setMessage(ex.getMessage()); - StringWriter errorStackTrace = new StringWriter(); - ex.printStackTrace(new PrintWriter(errorStackTrace)); - errorMessage.setDeveloperMessage(ex.toString()); - return Response.status(500).entity(errorMessage).type(MediaType.APPLICATION_JSON).build(); - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java index e90807633..81f7d7018 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java @@ -1,17 +1,17 @@ /* - * Copyright © 2017-2018 AT&T Intellectual Property. + * 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 + * 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 + * 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. + * 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.common; @@ -20,7 +20,6 @@ import io.swagger.models.*; import io.swagger.models.parameters.BodyParameter; import io.swagger.models.parameters.Parameter; import io.swagger.models.properties.*; -import io.swagger.util.Json; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.BooleanUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; @@ -63,8 +62,7 @@ public class SwaggerGenerator { swagger.setDefinitions(getDefinition()); - swaggerContent = Json.pretty(swagger); - return swaggerContent; + return swagger.toString(); } private Info getInfo() { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index 86c89bf90..94324a808 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -16,164 +16,112 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import java.util.List; /** - * ConfigModelRest.java Purpose: Rest service controller for ConfigModelRest Management - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) -public interface ConfigModelRest { +@RestController +@RequestMapping("/api/v1/config-model") +public class ConfigModelRest { - /** - * This is a getConfigModel rest service - * - * @param id - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodel/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - @RequestMapping(value = "/configmodel/{id}", method = RequestMethod.GET) - @ResponseBody ConfigModel getConfigModel(@ApiParam(required = true) @PathParam("id") Long id) - throws BluePrintException; - + private ConfigModelService configModelService; /** - * This is a saveConfigModel rest service - * - * @param configModel - * @return ConfigModel - * @throws BluePrintException + * This is a ConfigModelRest constructor. + * + * @param configModelService Config Model Service */ - @POST - @Path("/configmodel") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by Tags", response = ServiceTemplate.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel saveConfigModel(@ApiParam(required = true) ConfigModel configModel) - throws BluePrintException; + public ConfigModelRest(ConfigModelService configModelService) { + this.configModelService = configModelService; - /** - * This is a deleteConfigModel rest service - * - * @param id - * @throws BluePrintException - */ - @DELETE - @Path("/configmodel/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to delete ConfigModel.") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - void deleteConfigModel(@ApiParam(required = true) @PathParam("id") Long id) throws BluePrintException; + } - /** - * This is a getInitialConfigModel rest service - * - * @param name - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodelinitial/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to create default Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel getInitialConfigModel(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + @GetMapping(path = "/initial/{name}") + public @ResponseBody + ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { + try { + return this.configModelService.getInitialConfigModel(name); + } catch (Exception e) { + throw new BluePrintException(2000, e.getMessage(), e); + } + } - /** - * This is a getCloneConfigModel rest service - * - * @param id - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodelclone/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to create default Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel getCloneConfigModel(@ApiParam(required = true) @PathParam("id") Long id) - throws BluePrintException; + @PostMapping(path = "/") + public @ResponseBody + ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { + try { + return this.configModelService.saveConfigModel(configModel); + } catch (Exception e) { + throw new BluePrintException(2200, e.getMessage(), e); + } + } - /** - * This is a publishConfigModel rest service - * - * @param id - * @return ServiceTemplate - * @throws BluePrintException - */ - @GET - @Path("/configmodelpublish/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by Tags", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel publishConfigModel(@ApiParam(required = true) @PathParam("id") Long id) - throws BluePrintException; + @DeleteMapping(path = "/{id}") + public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + this.configModelService.deleteConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(4000, e.getMessage(), e); + } + } - /** - * This is a getConfigModelByNameAndVersion rest service - * - * @param name - * @param version - * @return ConfigModel - * @throws BluePrintException - */ - @GET - @Path("/configmodelbyname/{name}/version/{version}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ConfigModel getConfigModelByNameAndVersion(@ApiParam(required = true) @PathParam("name") String name, - @ApiParam(required = true) @PathParam("version") String version) throws BluePrintException; + @GetMapping(path = "/publish/{id}") + public @ResponseBody + ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + return this.configModelService.publishConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2500, e.getMessage(), e); + } + } - /** - * This is a searchServiceModels rest service - * - * @param tags - * @return List - * @throws BluePrintException - */ - @GET - @Path("/configmodelsearch/{tags}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Search Service Template", response = ConfigModel.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchConfigModels(@ApiParam(required = true) @PathParam("tags") String tags) - throws BluePrintException; + @GetMapping(path = "/{id}") + public @ResponseBody + ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + return this.configModelService.getConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2001, e.getMessage(), e); + } + } + + @GetMapping(path = "/by-name/{name}/version/{version}") + public @ResponseBody + ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, + @PathVariable(value = "version") String version) throws BluePrintException { + try { + return this.configModelService.getConfigModelByNameAndVersion(name, version); + } catch (Exception e) { + throw new BluePrintException(2002, e.getMessage(), e); + } + } + + @GetMapping(path = "/search/{tags}") + public @ResponseBody + List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { + try { + return this.configModelService.searchConfigModels(tags); + } catch (Exception e) { + throw new BluePrintException(2003, e.getMessage(), e); + } + } + + @GetMapping(path = "/clone/{id}") + public @ResponseBody + ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { + try { + return this.configModelService.getCloneConfigModel(id); + } catch (Exception e) { + throw new BluePrintException(2004, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java deleted file mode 100644 index a9abcd5ff..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestImpl.java +++ /dev/null @@ -1,116 +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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ConfigModelRestImpl implements ConfigModelRest { - - private ConfigModelService configModelService; - - /** - * This is a ConfigModelRestImpl constructor. - * - * @param configModelService Config Model Service - */ - public ConfigModelRestImpl(ConfigModelService configModelService) { - this.configModelService = configModelService; - - } - - @Override - public ConfigModel getInitialConfigModel(String name) throws BluePrintException { - try { - return this.configModelService.getInitialConfigModel(name); - } catch (Exception e) { - throw new BluePrintException(2000, e.getMessage(), e); - } - } - - @Override - public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { - try { - return this.configModelService.saveConfigModel(configModel); - } catch (Exception e) { - throw new BluePrintException(2200, e.getMessage(), e); - } - } - - @Override - public void deleteConfigModel(Long id) throws BluePrintException { - try { - this.configModelService.deleteConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(4000, e.getMessage(), e); - } - } - - @Override - public ConfigModel publishConfigModel(Long id) throws BluePrintException { - try { - return this.configModelService.publishConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2500, e.getMessage(), e); - } - } - - @Override - public ConfigModel getConfigModel(Long id) throws BluePrintException { - try { - return this.configModelService.getConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2001, e.getMessage(), e); - } - } - - @Override - public ConfigModel getConfigModelByNameAndVersion(String name, String version) throws BluePrintException { - try { - return this.configModelService.getConfigModelByNameAndVersion(name, version); - } catch (Exception e) { - throw new BluePrintException(2002, e.getMessage(), e); - } - } - - @Override - public List searchConfigModels(String tags) throws BluePrintException { - try { - return this.configModelService.searchConfigModels(tags); - } catch (Exception e) { - throw new BluePrintException(2003, e.getMessage(), e); - } - } - - @Override - public ConfigModel getCloneConfigModel(Long id) throws BluePrintException { - try { - return this.configModelService.getCloneConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2004, e.getMessage(), e); - } - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 59b730309..2fa64316f 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -16,110 +16,77 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import java.util.List; /** - * ModelTypeRest.java Purpose: Rest service controller for Artifact Handling - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) -public interface ModelTypeRest { +@RestController +@RequestMapping("/api/v1/model-type") +public class ModelTypeRest { - /** - * This is a getModelTypeByName rest service - * - * @param name - * @return ModelType - * @throws BluePrintException - */ - @GET - @Path("/modeltype/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by id", response = ModelType.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ModelType getModelTypeByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + private ModelTypeService modelTypeService; /** - * This is a saveModelType rest service - * - * @param modelType - * @return ModelType - * @throws BluePrintException + * This is a ModelTypeResourceImpl, used to save and get the model types stored in database + * + * @param modelTypeService Model Type Service */ + public ModelTypeRest(ModelTypeService modelTypeService) { + this.modelTypeService = modelTypeService; + } - @POST - @Path("/modeltype") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Save Model Type", response = ModelType.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ModelType saveModelType(@ApiParam(required = true) ModelType modelType) throws BluePrintException; + @GetMapping(path = "/{name}") + public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + return modelTypeService.getModelTypeByName(name); + } catch (Exception e) { + throw new BluePrintException(1000, e.getMessage(), e); + } + } - /** - * This is a deleteModelType rest service - * - * @param name - * @throws BluePrintException - */ - @DELETE - @Path("/modeltype/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to delete Model Type") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - void deleteModelTypeByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + @GetMapping(path = "/search/{tags}") + public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { + try { + return modelTypeService.searchModelTypes(tags); + } catch (Exception e) { + throw new BluePrintException(1001, e.getMessage(), e); + } + } - /** - * This is a searchModelType rest service - * - * @param tags - * @return List - * @throws BluePrintException - */ - @GET - @Path("/modeltypesearch/{tags}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by tags", response = ModelType.class, - responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchModelTypes(@ApiParam(required = true) @PathParam("tags") String tags) - throws BluePrintException; + @GetMapping(path = "/by-definition/{definitionType}") + public @ResponseBody + List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { + try { + return modelTypeService.getModelTypeByDefinitionType(definitionType); + } catch (Exception e) { + throw new BluePrintException(1002, e.getMessage(), e); + } + } - /** - * This is a getModelTypeByDefinitionType rest service - * - * @param definitionType - * @return List - * @throws BluePrintException - */ - @GET - @Path("/modeltypebydefinition/{definitionType}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Model Type by tags", response = ModelType.class, - responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List getModelTypeByDefinitionType( - @ApiParam(required = true) @PathParam("definitionType") String definitionType) - throws BluePrintException; + @PostMapping(path = "/") + public @ResponseBody + ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { + try { + return modelTypeService.saveModel(modelType); + } catch (Exception e) { + throw new BluePrintException(1100, e.getMessage(), e); + } + } + @DeleteMapping(path = "/{name}") + public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + modelTypeService.deleteByModelName(name); + } catch (Exception e) { + throw new BluePrintException(1400, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java deleted file mode 100644 index 6fbc69699..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestImpl.java +++ /dev/null @@ -1,87 +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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ModelTypeRestImpl implements ModelTypeRest { - - private ModelTypeService modelTypeService; - - /** - * This is a ModelTypeResourceImpl, used to save and get the model types stored in database - * - * @param modelTypeService Model Type Service - */ - public ModelTypeRestImpl(ModelTypeService modelTypeService) { - this.modelTypeService = modelTypeService; - } - - @Override - public ModelType getModelTypeByName(String modelName) throws BluePrintException { - try { - return modelTypeService.getModelTypeByName(modelName); - } catch (Exception e) { - throw new BluePrintException(1000, e.getMessage(), e); - } - } - - @Override - public List searchModelTypes(String tags) throws BluePrintException { - try { - return modelTypeService.searchModelTypes(tags); - } catch (Exception e) { - throw new BluePrintException(1001, e.getMessage(), e); - } - } - - @Override - public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { - try { - return modelTypeService.getModelTypeByDefinitionType(definitionType); - } catch (Exception e) { - throw new BluePrintException(1002, e.getMessage(), e); - } - } - - @Override - public ModelType saveModelType(ModelType modelType) throws BluePrintException { - try { - return modelTypeService.saveModel(modelType); - } catch (Exception e) { - throw new BluePrintException(1100, e.getMessage(), e); - } - } - - @Override - public void deleteModelTypeByName(String name) throws BluePrintException { - try { - modelTypeService.deleteByModelName(name); - } catch (Exception e) { - throw new BluePrintException(1400, e.getMessage(), e); - } - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index 5bc983363..dfb06bba5 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -16,111 +16,83 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; -import javax.ws.rs.*; -import javax.ws.rs.core.MediaType; import java.util.List; /** - * ResourceDictionaryRest.java Purpose: Rest service controller for Artifact Handling - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) +@RestController +@RequestMapping(value = "/api/v1/dictionary") +public class ResourceDictionaryRest { -public interface ResourceDictionaryRest { - /** - * This is a getDataDictionaryByPath rest service - * - * @param name - * @return ResourceDictionary - * @throws BluePrintException - */ - @GET - @Path("/dictionary/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get Resource dictionary", response = ResourceDictionary.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ResourceDictionary getResourceDictionaryByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + private ResourceDictionaryService resourceDictionaryService; /** - * This is a saveDataDictionary rest service - * - * @param resourceMapping - * @return ResourceDictionary - * @throws BluePrintException + * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database + * + * @param dataDictionaryService Data Dictionary Service */ + public ResourceDictionaryRest(ResourceDictionaryService dataDictionaryService) { + this.resourceDictionaryService = dataDictionaryService; + } - @POST - @Path("/dictionary") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to Save Resource dictionary Type", response = ResourceDictionary.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ResourceDictionary saveResourceDictionary(@ApiParam(required = true) ResourceDictionary resourceMapping) - throws BluePrintException; + @PostMapping(path = "/") + public @ResponseBody + ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) + throws BluePrintException { + try { + return resourceDictionaryService.saveResourceDictionary(dataDictionary); + } catch (Exception e) { + throw new BluePrintException(4100, e.getMessage(), e); + } + } - /** - * This is a deleteDataDictionaryByName rest service - * - * @param name - * @throws BluePrintException - */ - @DELETE - @Path("/dictionary/{name}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to delete ResourceDictionary Type") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - void deleteResourceDictionaryByName(@ApiParam(required = true) @PathParam("name") String name) - throws BluePrintException; + @DeleteMapping(path = "/{name}") + public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + resourceDictionaryService.deleteResourceDictionary(name); + } catch (Exception e) { + throw new BluePrintException(4400, e.getMessage(), e); + } + } - /** - * This is a searchResourceDictionaryByTags rest service - * - * @param tags - * @return ResourceDictionary - * @throws BluePrintException - */ - @GET - @Path("/dictionarysearch/{tags}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to search Resource dictionary by tags", - response = ResourceDictionary.class, responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchResourceDictionaryByTags( - @ApiParam(required = true) @PathParam("tags") String tags) throws BluePrintException; + @GetMapping(path = "/{name}") + public @ResponseBody + ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { + try { + return resourceDictionaryService.getResourceDictionaryByName(name); + } catch (Exception e) { + throw new BluePrintException(4001, e.getMessage(), e); + } + } - /** - * This is a searchResourceDictionaryByNames rest service - * - * @param names - * @return List - * @throws BluePrintException - */ - @POST - @Path("/dictionarybynames") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to get ResourceDictionary Type by names", - response = ResourceDictionary.class, responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List searchResourceDictionaryByNames(@ApiParam(required = true) List names) - throws BluePrintException; + @PostMapping(path = "/by-names") + public @ResponseBody + List searchResourceDictionaryByNames(@RequestBody List names) + throws BluePrintException { + try { + return resourceDictionaryService.searchResourceDictionaryByNames(names); + } catch (Exception e) { + throw new BluePrintException(4002, e.getMessage(), e); + } + } + + @GetMapping(path = "/search/{tags}") + public @ResponseBody + List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { + try { + return resourceDictionaryService.searchResourceDictionaryByTags(tags); + } catch (Exception e) { + throw new BluePrintException(4003, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java deleted file mode 100644 index e3448424d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestImpl.java +++ /dev/null @@ -1,91 +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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ResourceDictionaryRestImpl implements ResourceDictionaryRest { - - - private ResourceDictionaryService resourceDictionaryService; - - /** - * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database - * - * @param dataDictionaryService Data Dictionary Service - */ - public ResourceDictionaryRestImpl(ResourceDictionaryService dataDictionaryService) { - this.resourceDictionaryService = dataDictionaryService; - } - - @Override - public ResourceDictionary saveResourceDictionary(ResourceDictionary dataDictionary) - throws BluePrintException { - try { - return resourceDictionaryService.saveResourceDictionary(dataDictionary); - } catch (Exception e) { - throw new BluePrintException(4100, e.getMessage(), e); - } - } - - @Override - public void deleteResourceDictionaryByName(String name) throws BluePrintException { - try { - resourceDictionaryService.deleteResourceDictionary(name); - } catch (Exception e) { - throw new BluePrintException(4400, e.getMessage(), e); - } - } - - @Override - public ResourceDictionary getResourceDictionaryByName(String resourcePath) throws BluePrintException { - try { - return resourceDictionaryService.getResourceDictionaryByName(resourcePath); - } catch (Exception e) { - throw new BluePrintException(4001, e.getMessage(), e); - } - } - - @Override - public List searchResourceDictionaryByNames(List names) - throws BluePrintException { - try { - return resourceDictionaryService.searchResourceDictionaryByNames(names); - } catch (Exception e) { - throw new BluePrintException(4002, e.getMessage(), e); - } - } - - @Override - public List searchResourceDictionaryByTags(String tags) throws BluePrintException { - try { - return resourceDictionaryService.searchResourceDictionaryByTags(tags); - } catch (Exception e) { - throw new BluePrintException(4003, e.getMessage(), e); - } - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index fcb8f3119..d8ea1941b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -16,119 +16,87 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; -import io.swagger.annotations.*; + import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; import java.util.List; - /** - * ServiceTemplateRest.java Purpose: ServiceTemplateRest interface - * - * @author Brinda Santh - * @version 1.0 + * {@inheritDoc} */ +@RestController +@RequestMapping(value = "/api/v1/service-template") +public class ServiceTemplateRest { -@Api -@Path("/service") -@Produces({MediaType.APPLICATION_JSON}) -public interface ServiceTemplateRest { + private ServiceTemplateService serviceTemplateService; /** - * This is a enrichServiceTemplate rest service - * - * @param serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException + * This is a ServiceTemplateRest constructor + * + * @param serviceTemplateService Service Template Service */ - @POST - @Path("/servicetemplate/enrich") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to enrich service template", response = ServiceTemplate.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ServiceTemplate enrichServiceTemplate(@ApiParam(required = true) ServiceTemplate serviceTemplate) - throws BluePrintException; + public ServiceTemplateRest(ServiceTemplateService serviceTemplateService) { + this.serviceTemplateService = serviceTemplateService; + } - /** - * This is a validateServiceTemplate rest service - * - * @param serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException - */ - @POST - @Path("/servicetemplate/validate") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to validate service template", response = ServiceTemplate.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - ServiceTemplate validateServiceTemplate(@ApiParam(required = true) ServiceTemplate serviceTemplate) - throws BluePrintException; + @PostMapping(path = "/enrich") + public @ResponseBody + ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { + try { + return serviceTemplateService.enrichServiceTemplate(serviceTemplate); + } catch (Exception e) { + throw new BluePrintException(3500, e.getMessage(), e); + } + } - /** - * This is a generateResourceAssignments rest service - * - * @param templateContent - * @return List - * @throws BluePrintException - */ - @POST - @Path("/resourceassignment/generate") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to auto map for the Resource Mapping", - response = ResourceAssignment.class, responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List generateResourceAssignments( - @ApiParam(required = true) ConfigModelContent templateContent) throws BluePrintException; + @PostMapping(path = "/validate") + public @ResponseBody + ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { + try { + return serviceTemplateService.validateServiceTemplate(serviceTemplate); + } catch (Exception e) { + throw new BluePrintException(3501, e.getMessage(), e); + } + } - /** - * This is a autoMap rest service - * - * @param resourceAssignments - * @return AutoMapResponse - * @throws BluePrintException - */ - @POST - @Path("/resourceassignment/automap") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to auto map for the Resource assignments", - response = AutoMapResponse.class) - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - AutoMapResponse autoMap(@ApiParam(required = true) List resourceAssignments) - throws BluePrintException; + @PostMapping(path = "/resource-assignment/auto-map") + public @ResponseBody + AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { + try { + return serviceTemplateService.autoMap(resourceAssignments); + } catch (Exception e) { + throw new BluePrintException(3502, e.getMessage(), e); + } + } - /** - * This is a validateResourceAssignments rest service - * - * @param resourceAssignments - * @return List - * @throws BluePrintException - */ - @POST - @Path("/resourceassignment/validate") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Provides Rest service to validate Resource assignments", response = ResourceAssignment.class, - responseContainer = "List") - @ApiResponses(value = {@ApiResponse(code = 404, message = "Service not available"), - @ApiResponse(code = 500, message = "Unexpected Runtime error")}) - List validateResourceAssignments( - @ApiParam(required = true) List resourceAssignments) throws BluePrintException; + @PostMapping(path = "/resource-assignment/validate") + public @ResponseBody + List validateResourceAssignments(@RequestBody List resourceAssignments) + throws BluePrintException { + try { + return serviceTemplateService.validateResourceAssignments(resourceAssignments); + } catch (Exception e) { + throw new BluePrintException(3503, e.getMessage(), e); + } + } + + @PostMapping(path = "/resource-assignment/generate") + public @ResponseBody + List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) + throws BluePrintException { + try { + return serviceTemplateService.generateResourceAssignments(templateContent); + } catch (Exception e) { + throw new BluePrintException(3504, e.getMessage(), e); + } + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java deleted file mode 100644 index 6c49d5c65..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestImpl.java +++ /dev/null @@ -1,94 +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.rs; - - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Service -public class ServiceTemplateRestImpl implements ServiceTemplateRest { - - private ServiceTemplateService serviceTemplateService; - - /** - * This is a ServiceTemplateRestImpl constructor - * - * @param serviceTemplateService Service Template Service - */ - public ServiceTemplateRestImpl(ServiceTemplateService serviceTemplateService) { - this.serviceTemplateService = serviceTemplateService; - } - - @Override - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - try { - return serviceTemplateService.enrichServiceTemplate(serviceTemplate); - } catch (Exception e) { - throw new BluePrintException(3500, e.getMessage(), e); - } - } - - @Override - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - try { - return serviceTemplateService.validateServiceTemplate(serviceTemplate); - } catch (Exception e) { - throw new BluePrintException(3501, e.getMessage(), e); - } - } - - @Override - public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { - try { - return serviceTemplateService.autoMap(resourceAssignments); - } catch (Exception e) { - throw new BluePrintException(3502, e.getMessage(), e); - } - } - - @Override - public List validateResourceAssignments(List resourceAssignments) - throws BluePrintException { - try { - return serviceTemplateService.validateResourceAssignments(resourceAssignments); - } catch (Exception e) { - throw new BluePrintException(3503, e.getMessage(), e); - } - } - - @Override - public List generateResourceAssignments(ConfigModelContent templateContent) - throws BluePrintException { - try { - return serviceTemplateService.generateResourceAssignments(templateContent); - } catch (Exception e) { - throw new BluePrintException(3504, e.getMessage(), e); - } - } - -} -- cgit From 5285007a4e66bc18c69cef96aa32326a139d7642 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 21 Aug 2018 04:11:57 +0000 Subject: Controller Blueprints Microservice Define Controllerblueprint API DataType and Error definitions for Config model, Service Template, Model Type and Resource Dictionary Services Change-Id: I12d8d87292ec101601b0cfb7ba9670730973e318 Issue-ID: CCSDK-469 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ApplicationRegistrationService.java | 39 ++++++++++++++++++++++ .../service/common/ErrorMessage.java | 32 +++++++++++------- .../service/domain/ConfigModel.java | 8 ++++- .../service/domain/ConfigModelContent.java | 6 +++- .../service/domain/ModelType.java | 12 ++++++- .../service/domain/ResourceDictionary.java | 11 ++++++ .../service/rs/ConfigModelRest.java | 21 ++++++------ .../service/rs/ModelTypeRest.java | 11 +++--- .../service/rs/ResourceDictionaryRest.java | 11 +++--- .../service/rs/ServiceTemplateRest.java | 13 ++++---- 10 files changed, 120 insertions(+), 44 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java new file mode 100644 index 000000000..074f18d05 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java @@ -0,0 +1,39 @@ +/* + * 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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component +public class ApplicationRegistrationService { + + @PostConstruct + public void register(){ + registerDictionarySources(); + } + + public void registerDictionarySources(){ + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); + SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java index f7a802e46..431641265 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java @@ -16,24 +16,25 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.io.Serializable; +import java.util.Date; @JsonInclude(Include.NON_NULL) public class ErrorMessage implements Serializable { - private Integer httpStatus; private String message; private Integer code; - private String developerMessage; + private String debugMessage; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private Date timestamp = new Date(); - public Integer getHttpStatus() { - return httpStatus; - } - - public void setHttpStatus(Integer httpStatus) { - this.httpStatus = httpStatus; + public ErrorMessage(String message, Integer code, String debugMessage){ + this.message = message; + this.code = code; + this.debugMessage = debugMessage; } public String getMessage() { @@ -52,12 +53,19 @@ public class ErrorMessage implements Serializable { this.code = code; } - public String getDeveloperMessage() { - return developerMessage; + public String getDebugMessage() { + return debugMessage; } - public void setDeveloperMessage(String developerMessage) { - this.developerMessage = developerMessage; + public void setDebugMessage(String developerMessage) { + this.debugMessage = developerMessage; } + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java index 224960fa5..45382815c 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonManagedReference; +import io.swagger.annotations.ApiModelProperty; import org.hibernate.annotations.Proxy; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -82,6 +83,7 @@ public class ConfigModel implements Serializable { @NotNull @Column(name = "artifact_version") + @ApiModelProperty(required=true) private String artifactVersion; @Lob @@ -91,7 +93,7 @@ public class ConfigModel implements Serializable { @Column(name = "internal_version") private Integer internalVersion; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -99,19 +101,23 @@ public class ConfigModel implements Serializable { @NotNull @Column(name = "artifact_name") + @ApiModelProperty(required=true) private String artifactName; @NotNull @Column(name = "published") + @ApiModelProperty(required=true) private String published; @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index f7bd554df..0c05ef959 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -46,10 +47,12 @@ public class ConfigModelContent { @NotNull @Column(name = "name") + @ApiModelProperty(required=true) private String name; @NotNull @Column(name = "content_type") + @ApiModelProperty(required=true) private String contentType; @@ -65,10 +68,11 @@ public class ConfigModelContent { @NotNull @Lob @Column(name = "content") + @ApiModelProperty(required=true) private String content; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_date") diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index ed6340a65..61e4d1189 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -40,36 +42,43 @@ public class ModelType implements Serializable { @Id @NotNull @Column(name = "model_name", nullable = false) + @ApiModelProperty(required=true) private String modelName; @NotNull @Column(name = "derived_from") + @ApiModelProperty(required=true) private String derivedFrom; @NotNull @Column(name = "definition_type") + @ApiModelProperty(required=true) private String definitionType; @NotNull @Lob @Column(name = "definition") + @ApiModelProperty(required=true) private String definition; @NotNull @Lob @Column(name = "description") + @ApiModelProperty(required=true) private String description; @NotNull @Column(name = "version") + @ApiModelProperty(required=true) private String version; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; - // @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -77,6 +86,7 @@ public class ModelType implements Serializable { @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index adb018841..0d5879db8 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -39,18 +41,22 @@ public class ResourceDictionary implements Serializable { @Id @NotNull @Column(name = "name") + @ApiModelProperty(required=true) private String name; @NotNull @Column(name = "resource_path") + @ApiModelProperty(required=true) private String resourcePath; @NotNull @Column(name = "resource_type") + @ApiModelProperty(required=true) private String resourceType; @NotNull @Column(name = "data_type") + @ApiModelProperty(required=true) private String dataType; @Column(name = "entry_schema") @@ -67,18 +73,22 @@ public class ResourceDictionary implements Serializable { @NotNull @Lob @Column(name = "definition") + @ApiModelProperty(required=true) private String definition; @NotNull @Lob @Column(name = "description") + @ApiModelProperty(required=true) private String description; @NotNull @Lob @Column(name = "tags") + @ApiModelProperty(required=true) private String tags; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") @@ -86,6 +96,7 @@ public class ResourceDictionary implements Serializable { @NotNull @Column(name = "updated_by") + @ApiModelProperty(required=true) private String updatedBy; @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index 94324a808..62b683032 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -19,8 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -29,7 +28,7 @@ import java.util.List; * {@inheritDoc} */ @RestController -@RequestMapping("/api/v1/config-model") +@RequestMapping(value = "/api/v1/config-model") public class ConfigModelRest { private ConfigModelService configModelService; @@ -44,7 +43,7 @@ public class ConfigModelRest { } - @GetMapping(path = "/initial/{name}") + @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { try { @@ -54,7 +53,7 @@ public class ConfigModelRest { } } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { try { @@ -69,11 +68,11 @@ public class ConfigModelRest { try { this.configModelService.deleteConfigModel(id); } catch (Exception e) { - throw new BluePrintException(4000, e.getMessage(), e); + throw new BluePrintException(2400, e.getMessage(), e); } } - @GetMapping(path = "/publish/{id}") + @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { @@ -83,7 +82,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/{id}") + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { @@ -93,7 +92,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/by-name/{name}/version/{version}") + @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, @PathVariable(value = "version") String version) throws BluePrintException { @@ -104,7 +103,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { try { @@ -114,7 +113,7 @@ public class ConfigModelRest { } } - @GetMapping(path = "/clone/{id}") + @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 2fa64316f..f6e5c274f 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.*; @@ -29,7 +30,7 @@ import java.util.List; * {@inheritDoc} */ @RestController -@RequestMapping("/api/v1/model-type") +@RequestMapping(value = "/api/v1/model-type") public class ModelTypeRest { private ModelTypeService modelTypeService; @@ -43,7 +44,7 @@ public class ModelTypeRest { this.modelTypeService = modelTypeService; } - @GetMapping(path = "/{name}") + @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { try { return modelTypeService.getModelTypeByName(name); @@ -52,7 +53,7 @@ public class ModelTypeRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { try { return modelTypeService.searchModelTypes(tags); @@ -61,7 +62,7 @@ public class ModelTypeRest { } } - @GetMapping(path = "/by-definition/{definitionType}") + @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { try { @@ -71,7 +72,7 @@ public class ModelTypeRest { } } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index dfb06bba5..795738cb1 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -19,8 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -44,7 +43,7 @@ public class ResourceDictionaryRest { this.resourceDictionaryService = dataDictionaryService; } - @PostMapping(path = "/") + @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { @@ -64,7 +63,7 @@ public class ResourceDictionaryRest { } } - @GetMapping(path = "/{name}") + @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { try { @@ -74,7 +73,7 @@ public class ResourceDictionaryRest { } } - @PostMapping(path = "/by-names") + @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByNames(@RequestBody List names) throws BluePrintException { @@ -85,7 +84,7 @@ public class ResourceDictionaryRest { } } - @GetMapping(path = "/search/{tags}") + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index d8ea1941b..a22285b88 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -23,8 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -47,7 +46,7 @@ public class ServiceTemplateRest { this.serviceTemplateService = serviceTemplateService; } - @PostMapping(path = "/enrich") + @PostMapping(path = "/enrich", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { try { @@ -57,7 +56,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/validate") + @PostMapping(path = "/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { try { @@ -67,7 +66,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/auto-map") + @PostMapping(path = "/resource-assignment/auto-map", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { try { @@ -77,7 +76,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/validate") + @PostMapping(path = "/resource-assignment/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List validateResourceAssignments(@RequestBody List resourceAssignments) throws BluePrintException { @@ -88,7 +87,7 @@ public class ServiceTemplateRest { } } - @PostMapping(path = "/resource-assignment/generate") + @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) throws BluePrintException { -- cgit From 00bffa6a864d04e7093b6d70a9d321c068d48c7a Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 23 Aug 2018 17:33:38 +0000 Subject: Controller Blueprints Microservice Implement Controller Blueprint Meta File format and Meta names such as template_name, template_version, template_author Change-Id: Id221bb9cb0f9e382e3d59d4e309002de1ceb112b Issue-ID: CCSDK-458 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/validator/ServiceTemplateValidator.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 index ea46f3ad3..430401bc3 100644 --- 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 @@ -77,7 +77,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a getMetaData to get the key information during the * - * @return Map */ public Map getMetaData() { @@ -88,18 +88,9 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { public void validateMetadata(@NotNull Map metaDataMap) throws BluePrintException { Preconditions.checkNotNull(serviceTemplate.getMetadata(), "Service Template Metadata Information is missing."); + super.validateMetadata(metaDataMap); this.metaData.putAll(serviceTemplate.getMetadata()); - - String author = serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR); - String serviceTemplateName = - serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME); - String serviceTemplateVersion = - serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION); - - Preconditions.checkArgument(StringUtils.isNotBlank(author), "Template Metadata (author) Information is missing."); - Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateName), "Template Metadata (service-template-name) Information is missing."); - Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateVersion), "Template Metadata (service-template-version) Information is missing."); } -- cgit From 48c15ed0d02d98acac81773d84e928d0bd5ff07d Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 26 Aug 2018 16:20:04 -0400 Subject: Controller Blueprints Microservice Add Standardized resource definition in Initial data loading and Dictionary management services. Change-Id: Ib33ba2ecf3cb1e1fb9b5dea71532e6bc8280bcbb Issue-ID: CCSDK-487 Signed-off-by: Brinda Santh --- .../service/AutoResourceMappingService.java | 7 ++-- .../service/DataBaseInitService.java | 25 +++++++-------- .../service/ResourceDictionaryService.java | 37 ++++++++++++++-------- 3 files changed, 39 insertions(+), 30 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 6b09c81ff..2c443783e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.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. @@ -22,7 +23,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; 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.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; @@ -102,7 +103,7 @@ public class AutoResourceMappingService { ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) { - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class); if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { @@ -186,7 +187,7 @@ public class AutoResourceMappingService { } if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { - DictionaryDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); PropertyDefinition property = new PropertyDefinition(); property.setRequired(true); ResourceAssignment resourceAssignment = new ResourceAssignment(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 9ab319cb7..3a5c4fde8 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.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. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -26,7 +28,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactType; import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; @@ -160,26 +162,21 @@ public class DataBaseInitService { fileName = file.getFilename(); log.trace("Loading : {}", fileName); String definitionContent = getResourceContent(file); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(definitionContent, DictionaryDefinition.class); + ResourceDefinition dictionaryDefinition = + JacksonUtils.readValue(definitionContent, ResourceDefinition.class); if (dictionaryDefinition != null) { + Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition"); ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); resourceDictionary.setName(dictionaryDefinition.getName()); resourceDictionary.setDefinition(definitionContent); - if (dictionaryDefinition.getValidValues() != null) - resourceDictionary - .setValidValues(String.valueOf(dictionaryDefinition.getValidValues())); - - if (dictionaryDefinition.getSampleValue() != null) - resourceDictionary - .setValidValues(String.valueOf(dictionaryDefinition.getSampleValue())); - resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); - resourceDictionary.setDataType(dictionaryDefinition.getDataType()); - resourceDictionary.setEntrySchema(dictionaryDefinition.getEntrySchema()); - resourceDictionary.setDescription(dictionaryDefinition.getDescription()); + resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); + resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType()); + if(dictionaryDefinition.getProperty().getEntrySchema() != null){ + resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType()); + } resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy()); if (StringUtils.isBlank(dictionaryDefinition.getTags())) { resourceDictionary.setTags( 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 b9567db13..4bb87d7fc 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 @@ -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. @@ -18,8 +19,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema; +import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; 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; @@ -108,24 +111,32 @@ public class ResourceDictionaryService { if (resourceDictionary != null) { ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), DictionaryDefinition.class); + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - if (dictionaryDefinition == null) { + if (resourceDefinition == null) { throw new BluePrintException( "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); } - dictionaryDefinition.setName(resourceDictionary.getName()); - dictionaryDefinition.setResourcePath(resourceDictionary.getResourcePath()); - dictionaryDefinition.setResourceType(resourceDictionary.getResourceType()); - dictionaryDefinition.setDataType(resourceDictionary.getDataType()); - dictionaryDefinition.setEntrySchema(resourceDictionary.getEntrySchema()); - dictionaryDefinition.setTags(resourceDictionary.getTags()); - dictionaryDefinition.setDescription(resourceDictionary.getDescription()); - dictionaryDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + resourceDefinition.setName(resourceDictionary.getName()); + resourceDefinition.setResourcePath(resourceDictionary.getResourcePath()); + resourceDefinition.setResourceType(resourceDictionary.getResourceType()); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(resourceDictionary.getDataType()); + propertyDefinition.setDescription(resourceDictionary.getDescription()); + if(StringUtils.isNotBlank(resourceDictionary.getEntrySchema())){ + EntrySchema entrySchema = new EntrySchema(); + entrySchema.setType(resourceDictionary.getEntrySchema()); + propertyDefinition.setEntrySchema(entrySchema); + }else{ + propertyDefinition.setEntrySchema(null); + } + resourceDefinition.setTags(resourceDictionary.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - String definitionContent = JacksonUtils.getJson(dictionaryDefinition, true); + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); resourceDictionary.setDefinition(definitionContent); Optional dbResourceDictionaryData = -- cgit 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/src/main/java') 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 From 71778e1656729e8e153d844275b2de96d30febca Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 27 Aug 2018 17:29:51 +0000 Subject: Controller Blueprints Microservice Optimise model type repository search for DB and file in blueprint repo service. Change-Id: If5458e218b723d3fff451789a73a667dd75bc91c Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintRepoDBService.java | 63 +++++++------- .../service/ResourceDictionaryService.java | 96 ++++++++++------------ 2 files changed, 72 insertions(+), 87 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 index 4a26119c0..4c11d8c68 100644 --- 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 @@ -26,6 +26,7 @@ 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 reactor.core.publisher.Mono; import java.util.Optional; @@ -43,59 +44,51 @@ public class BluePrintRepoDBService implements BluePrintRepoService { 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); + public Mono getNodeType(String nodeTypeName) throws BluePrintException { + return getModelType(nodeTypeName, 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); + public Mono getDataType(String dataTypeName) throws BluePrintException { + return getModelType(dataTypeName, 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); + public Mono getArtifactType(String artifactTypeName) throws BluePrintException { + return getModelType(artifactTypeName, 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); + public Mono getRelationshipType(String relationshipTypeName) throws BluePrintException { + return getModelType(relationshipTypeName, 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); + public Mono getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } - private String getModelDefinitions(String modelName) throws BluePrintException { + private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing"); + + return getModelDefinitions(modelName).map(content -> { + Preconditions.checkArgument(StringUtils.isNotBlank(content), + String.format("Failed to get model content for model name (%s)", modelName)); + return JacksonUtils.readValue(content, valueClass); + } + ); + } + + private Mono getModelDefinitions(String modelName) throws BluePrintException { String modelDefinition = null; - Optional modelTypedb = modelTypeRepository.findByModelName(modelName); - if (modelTypedb.isPresent()) { - modelDefinition = modelTypedb.get().getDefinition(); + 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; + return Mono.just(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 5420dd390..629b94c01 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 @@ -17,6 +17,7 @@ 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.EntrySchema; @@ -112,60 +113,51 @@ public class ResourceDictionaryService { */ public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) throws BluePrintException { - if (resourceDictionary != null) { - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); - // Check the Source already Present - resourceDictionaryValidationService.validate(resourceDefinition); - - if (resourceDefinition == null) { - throw new BluePrintException( - "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition()); - } - - resourceDefinition.setName(resourceDictionary.getName()); - resourceDefinition.setResourcePath(resourceDictionary.getResourcePath()); - resourceDefinition.setResourceType(resourceDictionary.getResourceType()); - - PropertyDefinition propertyDefinition = new PropertyDefinition(); - propertyDefinition.setType(resourceDictionary.getDataType()); - propertyDefinition.setDescription(resourceDictionary.getDescription()); - if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) { - EntrySchema entrySchema = new EntrySchema(); - entrySchema.setType(resourceDictionary.getEntrySchema()); - propertyDefinition.setEntrySchema(entrySchema); - } else { - propertyDefinition.setEntrySchema(null); - } - resourceDefinition.setTags(resourceDictionary.getTags()); - resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - - String definitionContent = JacksonUtils.getJson(resourceDefinition, true); - resourceDictionary.setDefinition(definitionContent); - - Optional dbResourceDictionaryData = - resourceDictionaryRepository.findByName(resourceDictionary.getName()); - if (dbResourceDictionaryData.isPresent()) { - ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); - - dbResourceDictionary.setName(resourceDictionary.getName()); - dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); - dbResourceDictionary.setDescription(resourceDictionary.getDescription()); - dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); - dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); - dbResourceDictionary.setDataType(resourceDictionary.getDataType()); - dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); - dbResourceDictionary.setTags(resourceDictionary.getTags()); - dbResourceDictionary.setValidValues(resourceDictionary.getValidValues()); - resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); - } else { - resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); - } + Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); + Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), + "Resource Dictionary definition information is missing"); + + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + // Validate the Resource Definitions + resourceDictionaryValidationService.validate(resourceDefinition); + + resourceDictionary.setResourceType(resourceDefinition.getResourceType()); + resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); + resourceDictionary.setTags(resourceDefinition.getTags()); + resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); + // Set the Property Definitions + PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); + resourceDictionary.setDescription(propertyDefinition.getDescription()); + resourceDictionary.setDataType(propertyDefinition.getType()); + if(propertyDefinition.getEntrySchema() != null){ + resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); + } + + String definitionContent = JacksonUtils.getJson(resourceDefinition, true); + resourceDictionary.setDefinition(definitionContent); + + ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); + + Optional dbResourceDictionaryData = + resourceDictionaryRepository.findByName(resourceDictionary.getName()); + if (dbResourceDictionaryData.isPresent()) { + ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); + + dbResourceDictionary.setName(resourceDictionary.getName()); + dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); + dbResourceDictionary.setDescription(resourceDictionary.getDescription()); + dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); + dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); + dbResourceDictionary.setTags(resourceDictionary.getTags()); + dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy()); + dbResourceDictionary.setDataType(resourceDictionary.getDataType()); + dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); + resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); } else { - throw new BluePrintException("Resource Dictionary information is missing"); + resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); } + return resourceDictionary; } -- cgit From 92c6d038046e5089f44c8c84764ff6ff11bbff47 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 27 Aug 2018 19:53:34 -0400 Subject: Controller Blueprints Microservice Remove hard coded resource sources definitions such as Input, DB, MDSAL and Default and their dependencies. Change-Id: I6e00df176415560aa5bbbbf066e5a046878f3c58 Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../service/ApplicationRegistrationService.java | 8 ++----- .../validator/ResourceDictionaryValidator.java | 26 +--------------------- 2 files changed, 3 insertions(+), 31 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java index 074f18d05..6d0ec8899 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.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. @@ -16,8 +17,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.*; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -31,9 +30,6 @@ public class ApplicationRegistrationService { } public void registerDictionarySources(){ - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DB, SourceDb.class); - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_INPUT, SourceInput.class); - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_MDSAL, SourceMdsal.class); - SourceDeserializer.registerSource(ResourceDictionaryConstants.SOURCE_DEFAULT,SourceDefault.class); + } } 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 index eb2448e70..ff0b4ac5c 100644 --- 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 @@ -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. @@ -18,9 +19,6 @@ 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.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; /** @@ -34,28 +32,6 @@ public class ResourceDictionaryValidator { private ResourceDictionaryValidator() {} - /** - * This is a validateResourceDictionaryDefinition - * - * @param definitionContent - * @return boolean - * @throws BluePrintException - */ - public static boolean validateResourceDictionaryDefinition(String definitionContent) - throws BluePrintException { - boolean valid = true; - if (StringUtils.isNotBlank(definitionContent)) { - DictionaryDefinition dictionaryDefinition = - JacksonUtils.readValue(definitionContent, DictionaryDefinition.class); - if (dictionaryDefinition == null) { - throw new BluePrintException( - "Resource dictionary definition is not valid content " + definitionContent); - } - - } - return valid; - } - /** * This is a validateResourceDictionary method * -- cgit From 7c866aaefe19df34cb0c38e1f989179cf21dc497 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Mon, 27 Aug 2018 23:16:39 -0400 Subject: Controller Blueprints Microservice Add resource dictionary node template property assignments validation for primitive and complex types. Change-Id: Ic6f3a521310c8e15ebb5b5b5d6ad3edb0ede9ecb Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../service/BluePrintRepoDBService.java | 2 +- .../service/ConfigModelCreateService.java | 3 ++- .../service/ConfigModelService.java | 5 +++-- .../service/DataBaseInitService.java | 20 ++++++++++---------- .../service/ResourceDictionaryService.java | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 index 4c11d8c68..ae4fed9f4 100644 --- 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 @@ -82,7 +82,7 @@ public class BluePrintRepoDBService implements BluePrintRepoService { } private Mono getModelDefinitions(String modelName) throws BluePrintException { - String modelDefinition = null; + String modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { modelDefinition = modelTypeDb.get().getDefinition(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index 7e96f2f89..e40c2cf42 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.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. @@ -138,7 +139,7 @@ public class ConfigModelCreateService { if (StringUtils.isBlank(artifactVersion)) { throw new BluePrintException("Artifact Version is missing in the Service Template"); } - ConfigModel updateConfigModel = null; + ConfigModel updateConfigModel; Optional dbConfigModelOptional = Optional.empty(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java index feee3a3ea..b729e3e6d 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.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. @@ -144,7 +145,7 @@ public class ConfigModelService { */ public ConfigModel getConfigModelByNameAndVersion(String name, String version) { ConfigModel configModel = null; - Optional dbConfigModel = null; + Optional dbConfigModel; if (StringUtils.isNotBlank(version)) { dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version); } else { @@ -182,7 +183,7 @@ public class ConfigModelService { public ConfigModel getCloneConfigModel(Long id) { - ConfigModel configModel = null; + ConfigModel configModel; ConfigModel cloneConfigModel = null; if (id != null) { Optional dbConfigModel = configModelRepository.findById(id); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 3a5c4fde8..4b732cc30 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -115,31 +115,28 @@ public class DataBaseInitService { try { Resource[] dataTypefiles = getPathResources(dataTypePath, ".json"); StrBuilder errorBuilder = new StrBuilder(); - if (dataTypefiles != null) { for (Resource file : dataTypefiles) { if (file != null) { loadDataType(file, errorBuilder); } } - } Resource[] nodeTypefiles = getPathResources(nodeTypePath, ".json"); - if (nodeTypefiles != null) { - for (Resource file : nodeTypefiles) { + for (Resource file : nodeTypefiles) { if (file != null) { loadNodeType(file, errorBuilder); } } - } + Resource[] artifactTypefiles = getPathResources(artifactTypePath, ".json"); - if (artifactTypefiles != null) { + for (Resource file : artifactTypefiles) { if (file != null) { loadArtifactType(file, errorBuilder); } } - } + if (!errorBuilder.isEmpty()) { log.error(errorBuilder.toString()); @@ -154,9 +151,9 @@ public class DataBaseInitService { " *************************** loadResourceDictionary **********************"); try { Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, ".json"); - if (dataTypefiles != null) { + StrBuilder errorBuilder = new StrBuilder(); - String fileName = null; + String fileName; for (Resource file : dataTypefiles) { try { fileName = file.getFilename(); @@ -201,7 +198,7 @@ public class DataBaseInitService { log.error(errorBuilder.toString()); } - } + } catch (Exception e) { log.error( "Failed in Resource dictionary loading", e); @@ -248,6 +245,7 @@ public class DataBaseInitService { String nodeKey = file.getFilename().replace(".json", ""); String definitionContent = getResourceContent(file); NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); + Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename())); ModelType modelType = new ModelType(); modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); modelType.setDerivedFrom(nodeType.getDerivedFrom()); @@ -271,6 +269,7 @@ public class DataBaseInitService { String dataKey = file.getFilename().replace(".json", ""); String definitionContent = getResourceContent(file); DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); + Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename())); ModelType modelType = new ModelType(); modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelType.setDerivedFrom(dataType.getDerivedFrom()); @@ -294,6 +293,7 @@ public class DataBaseInitService { String dataKey = file.getFilename().replace(".json", ""); String definitionContent = getResourceContent(file); ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); + Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename())); ModelType modelType = new ModelType(); modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); modelType.setDerivedFrom(artifactType.getDerivedFrom()); 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 629b94c01..85e701b41 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 @@ -20,7 +20,6 @@ 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.EntrySchema; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; @@ -119,6 +118,7 @@ public class ResourceDictionaryService { ResourceDefinition resourceDefinition = JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content"); // Validate the Resource Definitions resourceDictionaryValidationService.validate(resourceDefinition); -- cgit From afee4df36caa1a979586c8badf160c3ff49b97a0 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 28 Aug 2018 23:58:12 +0000 Subject: Controller Blueprints Microservice Add Resource Assignment Validation Service and their Test cases. Change-Id: I106be2bfc03115867041ca341947a4662cf126c4 Issue-ID: CCSDK-487 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintRepoDBService.java | 22 ++++++++++--------- .../service/repository/ModelTypeRepository.java | 25 +++++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 index ae4fed9f4..c4aebe52c 100644 --- 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 @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; 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; @@ -36,36 +37,37 @@ import java.util.Optional; * @author Brinda Santh */ @Service +@SuppressWarnings("unused") public class BluePrintRepoDBService implements BluePrintRepoService { private ModelTypeRepository modelTypeRepository; - + @SuppressWarnings("unused") public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; } @Override - public Mono getNodeType(String nodeTypeName) throws BluePrintException { + public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { return getModelType(nodeTypeName, NodeType.class); } @Override - public Mono getDataType(String dataTypeName) throws BluePrintException { + public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { return getModelType(dataTypeName, DataType.class); } @Override - public Mono getArtifactType(String artifactTypeName) throws BluePrintException { + public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { return getModelType(artifactTypeName, ArtifactType.class); } @Override - public Mono getRelationshipType(String relationshipTypeName) throws BluePrintException { + public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { return getModelType(relationshipTypeName, RelationshipType.class); } @Override - public Mono getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException { + public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } @@ -73,15 +75,15 @@ public class BluePrintRepoDBService implements BluePrintRepoService { Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Failed to get model from repo, model name is missing"); - return getModelDefinitions(modelName).map(content -> { - Preconditions.checkArgument(StringUtils.isNotBlank(content), - String.format("Failed to get model content for model name (%s)", modelName)); + return getModelDefinition(modelName).map(content -> { + Preconditions.checkArgument(StringUtils.isNotBlank(content), + String.format("Failed to get model content for model name (%s)", modelName)); return JacksonUtils.readValue(content, valueClass); } ); } - private Mono getModelDefinitions(String modelName) throws BluePrintException { + private Mono getModelDefinition(String modelName) throws BluePrintException { String modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java index 51ae752f9..27823ef33 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java @@ -37,15 +37,23 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByModelName method * - * @param modelName + * @param modelName Model Name * @return Optional */ Optional findByModelName(String modelName); + /** + * This is a findByModelNameIn method + * + * @param modelNames Model Names + * @return List + */ + List findByModelNameIn(List modelNames); + /** * This is a findByDerivedFrom method * - * @param derivedFrom + * @param derivedFrom Derived From * @return List */ List findByDerivedFrom(String derivedFrom); @@ -54,15 +62,16 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByDerivedFromIn method * - * @param derivedFroms + * @param derivedFroms Derived Froms * @return List */ + @SuppressWarnings("unused") List findByDerivedFromIn(List derivedFroms); /** * This is a findByDefinitionType method * - * @param definitionType + * @param definitionType Definition Type * @return List */ List findByDefinitionType(String definitionType); @@ -70,16 +79,17 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a findByDefinitionTypeIn method * - * @param definitionTypes + * @param definitionTypes Definition Types * @return List */ + @SuppressWarnings("unused") List findByDefinitionTypeIn(List definitionTypes); /** * This is a findByTagsContainingIgnoreCase method * - * @param tags + * @param tags Tags * @return Optional */ List findByTagsContainingIgnoreCase(String tags); @@ -88,8 +98,7 @@ public interface ModelTypeRepository extends JpaRepository { /** * This is a deleteByModelName method * - * @param modelName - * @return Optional + * @param modelName ModelName */ void deleteByModelName(String modelName); -- cgit From e10032c90bfcf5c56fc3200e89b142b782eac88f Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Tue, 28 Aug 2018 22:46:02 -0400 Subject: Controller Blueprints Microservice Add resource assignment json data to input property convertor utlity and their test cases. Change-Id: Ie4557048e85df38c75ac3d31ff62d4fce0662d9f Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../ResourceDefinitionValidationService.java | 29 ++++++++++ .../service/ResourceDictionaryService.java | 67 +++++++++------------- .../ResourceDictionaryValidationService.java | 31 ---------- 3 files changed, 56 insertions(+), 71 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java new file mode 100644 index 000000000..d3bf42302 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java @@ -0,0 +1,29 @@ +/* + * 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.ResourceDefinitionDefaultValidationService; +import org.springframework.stereotype.Service; + +@Service +public class ResourceDefinitionValidationService extends ResourceDefinitionDefaultValidationService { + + public ResourceDefinitionValidationService(BluePrintRepoService bluePrintRepoService) { + super(bluePrintRepoService); + } +} 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 85e701b41..ccf4ffcc7 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 @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; 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.data.PropertyDefinition; @@ -43,16 +44,16 @@ public class ResourceDictionaryService { private ResourceDictionaryRepository resourceDictionaryRepository; - private ResourceDictionaryValidationService resourceDictionaryValidationService; + private ResourceDefinitionValidationService resourceDictionaryValidationService; /** * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database * - * @param dataDictionaryRepository - * @param resourceDictionaryValidationService + * @param dataDictionaryRepository dataDictionaryRepository + * @param resourceDictionaryValidationService resourceDictionaryValidationService */ public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository, - ResourceDictionaryValidationService resourceDictionaryValidationService) { + ResourceDefinitionValidationService resourceDictionaryValidationService) { this.resourceDictionaryRepository = dataDictionaryRepository; this.resourceDictionaryValidationService = resourceDictionaryValidationService; } @@ -60,58 +61,49 @@ public class ResourceDictionaryService { /** * This is a getDataDictionaryByName service * - * @param name + * @param name name * @return DataDictionary - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ResourceDictionary getResourceDictionaryByName(String name) throws BluePrintException { - if (StringUtils.isNotBlank(name)) { - return resourceDictionaryRepository.findByName(name).get(); + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + Optional resourceDictionaryDb = resourceDictionaryRepository.findByName(name); + if (resourceDictionaryDb.isPresent()) { + return resourceDictionaryDb.get(); } else { - throw new BluePrintException("Resource Mapping Name Information is missing."); + throw new BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)); } } /** * This is a searchResourceDictionaryByNames service * - * @param names + * @param names names * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByNames(List names) - throws BluePrintException { - if (names != null && !names.isEmpty()) { - return resourceDictionaryRepository.findByNameIn(names); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByNames(List names) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide"); + return resourceDictionaryRepository.findByNameIn(names); } /** * This is a searchResourceDictionaryByTags service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByTags(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide"); + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveDataDictionary service * - * @param resourceDictionary + * @param resourceDictionary resourceDictionary * @return DataDictionary - * @throws BluePrintException */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) - throws BluePrintException { + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), "Resource Dictionary definition information is missing"); @@ -130,7 +122,7 @@ public class ResourceDictionaryService { PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); resourceDictionary.setDescription(propertyDefinition.getDescription()); resourceDictionary.setDataType(propertyDefinition.getType()); - if(propertyDefinition.getEntrySchema() != null){ + if (propertyDefinition.getEntrySchema() != null) { resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); } @@ -164,15 +156,10 @@ public class ResourceDictionaryService { /** * This is a deleteResourceDictionary service * - * @param name - * @throws BluePrintException + * @param name name */ - public void deleteResourceDictionary(String name) throws BluePrintException { - if (name != null) { - resourceDictionaryRepository.deleteByName(name); - } else { - throw new BluePrintException("Resource Mapping Id Information is missing."); - } - + public void deleteResourceDictionary(String name) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + resourceDictionaryRepository.deleteByName(name); } } 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 deleted file mode 100644 index 7de7fc4c3..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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); - } -} -- cgit From 254217ffff5edea9069f96b992a5939b3745d376 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 29 Aug 2018 19:53:08 +0000 Subject: Controller Blueprints Microservice Improve code quality for Performance, JavaDoc, Imports, Probably Bug etc Change-Id: Ib71b62f14e8e8bd212e671a135025258fd9927b4 Issue-ID: CCSDK-491 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ApplicationRegistrationService.java | 1 + .../service/AutoResourceMappingService.java | 39 +++++++++--------- .../service/BluePrintEnhancerService.java | 24 ++++++----- .../service/ConfigModelCreateService.java | 48 +++++++++------------- .../service/DataBaseInitService.java | 8 ++-- .../service/ServiceTemplateService.java | 28 ++++++------- .../service/domain/ConfigModel.java | 17 +++----- .../service/domain/ConfigModelContent.java | 10 ++--- .../service/domain/ConfigModelSearch.java | 16 +++----- .../service/domain/ModelType.java | 23 ++++------- .../service/domain/ResourceDictionary.java | 25 ++++------- .../repository/ConfigModelContentRepository.java | 32 +++++++++------ .../service/repository/ConfigModelRepository.java | 27 +++++++----- .../service/rs/ModelTypeRest.java | 2 - .../service/utils/ConfigModelUtils.java | 7 +++- .../service/validator/ModelTypeValidator.java | 3 +- .../validator/ServiceTemplateValidator.java | 12 +++--- 17 files changed, 144 insertions(+), 178 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java index 6d0ec8899..5a4a2877e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java @@ -22,6 +22,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @Component +@SuppressWarnings("unused") public class ApplicationRegistrationService { @PostConstruct diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 2c443783e..5eba4fc7f 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +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; @@ -45,6 +46,7 @@ import java.util.Map; */ @Service +@SuppressWarnings("unused") public class AutoResourceMappingService { private static Logger log = LoggerFactory.getLogger(AutoResourceMappingService.class); @@ -53,9 +55,8 @@ public class AutoResourceMappingService { /** * This is a AutoResourceMappingService constructor - * - * @param dataDictionaryRepository - * + * + * @param dataDictionaryRepository dataDictionaryRepository */ public AutoResourceMappingService(ResourceDictionaryRepository dataDictionaryRepository) { this.dataDictionaryRepository = dataDictionaryRepository; @@ -63,8 +64,8 @@ public class AutoResourceMappingService { /** * This is a autoMap service to map the template keys automatically to Dictionary fields. - * - * @param resourceAssignments + * + * @param resourceAssignments resourceAssignments * @return AutoMapResponse */ public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { @@ -83,8 +84,6 @@ public class AutoResourceMappingService { log.info("Mapped Resource : {}", resourceAssignment); - } else { - // Do nothins } } } @@ -125,7 +124,7 @@ public class AutoResourceMappingService { if (CollectionUtils.isNotEmpty(names)) { List dictionaries = dataDictionaryRepository.findByNameIn(names); - if (CollectionUtils.isNotEmpty( dictionaries)) { + if (CollectionUtils.isNotEmpty(dictionaries)) { for (ResourceDictionary dataDictionary : dictionaries) { if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName())) { dictionaryMap.put(dataDictionary.getName(), dataDictionary); @@ -167,14 +166,13 @@ public class AutoResourceMappingService { private List getAllAutomapResourceAssignments(List resourceAssignments) { List dictionaries = null; List names = new ArrayList<>(); - List resourceAssignmentsWithDepencies = resourceAssignments; for (ResourceAssignment resourceAssignment : resourceAssignments) { if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { List dependencieNames = resourceAssignment.getDependencies(); for (String dependencieName : dependencieNames) { if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName) - && !checkAssignmentsExists(resourceAssignmentsWithDepencies, dependencieName)) { + && !checkAssignmentsExists(resourceAssignments, dependencieName)) { names.add(dependencieName); } } @@ -188,24 +186,25 @@ public class AutoResourceMappingService { if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); + Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition"); PropertyDefinition property = new PropertyDefinition(); - property.setRequired(true); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(resourcedictionary.getName()); - resourceAssignment.setDictionaryName(resourcedictionary - .getName()); - resourceAssignment.setVersion(0); - resourceAssignment.setProperty(property); + property.setRequired(true); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(resourcedictionary.getName()); + resourceAssignment.setDictionaryName(resourcedictionary + .getName()); + resourceAssignment.setVersion(0); + resourceAssignment.setProperty(property); ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - resourceAssignmentsWithDepencies.add(resourceAssignment); + resourceAssignments.add(resourceAssignment); } } - return resourceAssignmentsWithDepencies; + return resourceAssignments; } - public boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { + private boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { return resourceAssignmentsWithDepencies.stream().anyMatch(names -> names.getName().equalsIgnoreCase(resourceName)); } 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 0cf846c7a..28be75e66 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 @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.fasterxml.jackson.databind.JsonNode; 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.BluePrintException; @@ -47,7 +48,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static Logger log = LoggerFactory.getLogger(BluePrintEnhancerService.class); - private HashMap recipeDataTypes = new HashMap<>(); + private Map recipeDataTypes = new HashMap<>(); public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) { super(bluePrintEnhancerRepoDBService); @@ -119,7 +120,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { if (StringUtils.isNotBlank(recipeName)) { DataType recipeDataType = this.recipeDataTypes.get(recipeName); if (recipeDataType == null) { - log.info("DataType not present for the recipe({})" , recipeName); + log.info("DataType not present for the recipe({})", recipeName); recipeDataType = new DataType(); recipeDataType.setVersion("1.0.0"); recipeDataType.setDescription( @@ -129,7 +130,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { Map dataTypeProperties = new HashMap<>(); recipeDataType.setProperties(dataTypeProperties); } else { - log.info("DataType Already present for the recipe({})" , recipeName); + log.info("DataType Already present for the recipe({})", recipeName); } // Merge all the Recipe Properties @@ -145,7 +146,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { NodeTemplate nodeTemplate) { Map dataTypeProperties = null; - if (nodeTemplate != null) { + if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { CapabilityAssignment capability = nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); @@ -182,17 +183,18 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private void mergeDataTypeProperties(DataType dataType, Map mergeProperties) { if (dataType != null && dataType.getProperties() != null && mergeProperties != null) { // Add the Other Template Properties - mergeProperties.forEach((mappingKey, propertyDefinition) -> { - dataType.getProperties().put(mappingKey, propertyDefinition); - }); + mergeProperties.forEach((mappingKey, propertyDefinition) -> dataType.getProperties().put(mappingKey, propertyDefinition)); } } private void populateRecipeInputs(ServiceTemplate serviceTemplate) { - if (this.recipeDataTypes != null && !this.recipeDataTypes.isEmpty()) { + if (serviceTemplate.getTopologyTemplate() != null + && MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs()) + && MapUtils.isNotEmpty(this.recipeDataTypes) + && MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { this.recipeDataTypes.forEach((recipeName, recipeDataType) -> { - String dataTypePrifix = recipeName.replace("-action", "") + "-request"; - String dataTypeName = "dt-" + dataTypePrifix; + String dataTypePrefix = recipeName.replace("-action", "") + "-request"; + String dataTypeName = "dt-" + dataTypePrefix; serviceTemplate.getDataTypes().put(dataTypeName, recipeDataType); @@ -200,7 +202,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { customInputProperty.setDescription("This is Dynamic Data type for the receipe " + recipeName + "."); customInputProperty.setRequired(Boolean.FALSE); customInputProperty.setType(dataTypeName); - serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrifix, customInputProperty); + serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrefix, customInputProperty); }); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index e40c2cf42..f52137191 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -197,7 +197,7 @@ public class ConfigModelCreateService { private void deleteConfigModelContent(Long dbConfigModelId) { if (dbConfigModelId != null) { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (dbConfigModel != null && CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { + if (CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { dbConfigModel.getConfigModelContents().clear(); log.debug("Configuration Model content deleting : {}", dbConfigModel.getConfigModelContents()); configModelRepository.saveAndFlush(dbConfigModel); @@ -210,18 +210,15 @@ public class ConfigModelCreateService { if (dbConfigModelId != null && configModel != null && CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (dbConfigModel != null) { - for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { - if (configModelContent != null) { - configModelContent.setId(null); - configModelContent.setConfigModel(dbConfigModel); - dbConfigModel.getConfigModelContents().add(configModelContent); - log.debug("Configuration Model content adding : {}", configModelContent); - } + for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { + if (configModelContent != null) { + configModelContent.setId(null); + configModelContent.setConfigModel(dbConfigModel); + dbConfigModel.getConfigModelContents().add(configModelContent); + log.debug("Configuration Model content adding : {}", configModelContent); } - configModelRepository.saveAndFlush(dbConfigModel); } - + configModelRepository.saveAndFlush(dbConfigModel); } } @@ -229,22 +226,19 @@ public class ConfigModelCreateService { String author) throws BluePrintException { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (dbConfigModel != null) { - // Populate tags from metadata - String tags = getConfigModelTags(dbConfigModel); - if (StringUtils.isBlank(tags)) { - throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); - } - dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - dbConfigModel.setArtifactName(artifactName); - dbConfigModel.setArtifactVersion(artifactVersion); - dbConfigModel.setUpdatedBy(author); - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); - dbConfigModel.setTags(tags); - configModelRepository.saveAndFlush(dbConfigModel); - - log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); + // Populate tags from metadata + String tags = getConfigModelTags(dbConfigModel); + if (StringUtils.isBlank(tags)) { + throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); } + dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); + dbConfigModel.setArtifactName(artifactName); + dbConfigModel.setArtifactVersion(artifactVersion); + dbConfigModel.setUpdatedBy(author); + dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); + dbConfigModel.setTags(tags); + configModelRepository.saveAndFlush(dbConfigModel); + log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); return dbConfigModel; } @@ -282,8 +276,6 @@ public class ConfigModelCreateService { configModel.getArtifactName()); } tags = String.valueOf(serviceTemplate.getMetadata()); - } else { - // Do Nothing } } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 4b732cc30..89d482962 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -55,7 +55,7 @@ import java.util.List; */ @Component -@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true", matchIfMissing = false) +@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") public class DataBaseInitService { private static Logger log = LoggerFactory.getLogger(DataBaseInitService.class); @@ -77,9 +77,9 @@ public class DataBaseInitService { /** * This is a DataBaseInitService, used to load the initial data * - * @param modelTypeService - * @param resourceDictionaryService - * @param configModelService + * @param modelTypeService modelTypeService + * @param resourceDictionaryService resourceDictionaryService + * @param configModelService configModelService */ public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService, ConfigModelService configModelService) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 70b7917a4..70cee3c9e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -49,9 +49,9 @@ public class ServiceTemplateService { /** * This is a SchemaGeneratorService constructor * - * @param dataDictionaryRepository - * @param configModelCreateService - * @param bluePrintEnhancerService + * @param dataDictionaryRepository dataDictionaryRepository + * @param configModelCreateService configModelCreateService + * @param bluePrintEnhancerService bluePrintEnhancerService */ public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, ConfigModelCreateService configModelCreateService, @@ -65,9 +65,9 @@ public class ServiceTemplateService { /** * This is a validateServiceTemplate method * - * @param serviceTemplate + * @param serviceTemplate serviceTemplate * @return ServiceTemplate - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { return this.configModelCreateService.validateServiceTemplate(serviceTemplate); @@ -76,11 +76,10 @@ public class ServiceTemplateService { /** * This is a enrichServiceTemplate method * - * @param serviceTemplate + * @param serviceTemplate serviceTemplate * @return ServiceTemplate - * @throws BluePrintException */ - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { + public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) { this.bluePrintEnhancerService.enhance(serviceTemplate); return serviceTemplate; } @@ -88,22 +87,21 @@ public class ServiceTemplateService { /** * This is a autoMap method to map the template keys * - * @param resourceAssignments + * @param resourceAssignments resourceAssignments * @return AutoMapResponse - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository); - AutoMapResponse autoMapResponse = autoMappingService.autoMap(resourceAssignments); - return autoMapResponse; + return autoMappingService.autoMap(resourceAssignments); } /** * This is a validateResourceAssignments method * - * @param resourceAssignments + * @param resourceAssignments resourceAssignments * @return List - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public List validateResourceAssignments(List resourceAssignments) throws BluePrintException { @@ -120,7 +118,7 @@ public class ServiceTemplateService { /** * This is a generateResourceAssignments method * - * @param templateContent + * @param templateContent templateContent * @return List */ public List generateResourceAssignments(ConfigModelContent templateContent) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java index 45382815c..51c9a7c6a 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java @@ -24,7 +24,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -81,8 +80,7 @@ public class ConfigModel implements Serializable { @Column(name = "artifact_type") private String artifactType; - @NotNull - @Column(name = "artifact_version") + @Column(name = "artifact_version", nullable = false) @ApiModelProperty(required=true) private String artifactVersion; @@ -99,30 +97,25 @@ public class ConfigModel implements Serializable { @Column(name = "creation_date") private Date createdDate = new Date(); - @NotNull - @Column(name = "artifact_name") + @Column(name = "artifact_name", nullable = false) @ApiModelProperty(required=true) private String artifactName; - @NotNull - @Column(name = "published") + @Column(name = "published", nullable = false) @ApiModelProperty(required=true) private String published; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) @ApiModelProperty(required=true) private String updatedBy; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) @ApiModelProperty(required=true) private String tags; @OneToMany(mappedBy = "configModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - @Column(nullable = true) @JsonManagedReference private List configModelContents = new ArrayList<>(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index 0c05ef959..60b3ed6b0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -23,7 +23,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.util.Date; import java.util.Objects; @@ -45,13 +44,11 @@ public class ConfigModelContent { @Column(name = "config_model_content_id") private Long id; - @NotNull - @Column(name = "name") + @Column(name = "name", nullable = false) @ApiModelProperty(required=true) private String name; - @NotNull - @Column(name = "content_type") + @Column(name = "content_type", nullable = false) @ApiModelProperty(required=true) private String contentType; @@ -65,9 +62,8 @@ public class ConfigModelContent { @Column(name = "description") private String description; - @NotNull @Lob - @Column(name = "content") + @Column(name = "content", nullable = false) @ApiModelProperty(required=true) private String content; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java index 2e9018837..6ec39ab55 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java @@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonFormat; import org.springframework.data.annotation.LastModifiedDate; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -40,8 +39,7 @@ public class ConfigModelSearch implements Serializable { @Column(name = "artifact_type") private String artifactType; - @NotNull - @Column(name = "artifact_version") + @Column(name = "artifact_version", nullable = false) private String artifactVersion; @Lob @@ -57,21 +55,17 @@ public class ConfigModelSearch implements Serializable { @Column(name = "creation_date") private Date createdDate = new Date(); - @NotNull - @Column(name = "artifact_name") + @Column(name = "artifact_name", nullable = false) private String artifactName; - @NotNull - @Column(name = "published") + @Column(name = "published", nullable = false) private String published; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) private String updatedBy; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) private String tags; public Long getId() { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index 61e4d1189..eaa335b3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -22,7 +22,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -40,41 +39,34 @@ public class ModelType implements Serializable { private static final long serialVersionUID = 1L; @Id - @NotNull @Column(name = "model_name", nullable = false) @ApiModelProperty(required=true) private String modelName; - @NotNull - @Column(name = "derived_from") + @Column(name = "derived_from", nullable = false) @ApiModelProperty(required=true) private String derivedFrom; - @NotNull - @Column(name = "definition_type") + @Column(name = "definition_type", nullable = false) @ApiModelProperty(required=true) private String definitionType; - @NotNull @Lob - @Column(name = "definition") + @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) private String definition; - @NotNull @Lob - @Column(name = "description") + @Column(name = "description", nullable = false) @ApiModelProperty(required=true) private String description; - @NotNull - @Column(name = "version") + @Column(name = "version", nullable = false) @ApiModelProperty(required=true) private String version; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) @ApiModelProperty(required=true) private String tags; @@ -84,8 +76,7 @@ public class ModelType implements Serializable { @Column(name = "creation_date") private Date creationDate; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) @ApiModelProperty(required=true) private String updatedBy; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index 0d5879db8..487586842 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -22,7 +22,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -39,23 +38,19 @@ public class ResourceDictionary implements Serializable { private static final long serialVersionUID = 1L; @Id - @NotNull - @Column(name = "name") + @Column(name = "name", nullable = false) @ApiModelProperty(required=true) private String name; - @NotNull - @Column(name = "resource_path") + @Column(name = "resource_path", nullable = false) @ApiModelProperty(required=true) private String resourcePath; - @NotNull - @Column(name = "resource_type") + @Column(name = "resource_type", nullable = false) @ApiModelProperty(required=true) private String resourceType; - @NotNull - @Column(name = "data_type") + @Column(name = "data_type", nullable = false) @ApiModelProperty(required=true) private String dataType; @@ -70,21 +65,18 @@ public class ResourceDictionary implements Serializable { @Column(name = "sample_value") private String sampleValue; - @NotNull @Lob - @Column(name = "definition") + @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) private String definition; - @NotNull @Lob - @Column(name = "description") + @Column(name = "description", nullable = false) @ApiModelProperty(required=true) private String description; - @NotNull @Lob - @Column(name = "tags") + @Column(name = "tags", nullable = false) @ApiModelProperty(required=true) private String tags; @@ -94,8 +86,7 @@ public class ResourceDictionary implements Serializable { @Column(name = "creation_date") private Date creationDate; - @NotNull - @Column(name = "updated_by") + @Column(name = "updated_by", nullable = false) @ApiModelProperty(required=true) private String updatedBy; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java index ad2584a8e..733cbbdb3 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java @@ -21,6 +21,7 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelConten import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import javax.validation.constraints.NotNull; import java.util.List; import java.util.Optional; @@ -36,60 +37,65 @@ public interface ConfigModelContentRepository extends JpaRepository */ - Optional findById(Long id); + @NotNull + Optional findById(@NotNull Long id); /** * This is a findTopByConfigModelAndContentType method * - * @param configModel - * @param contentType + * @param configModel configModel + * @param contentType contentType * @return Optional */ + @SuppressWarnings("unused") Optional findTopByConfigModelAndContentType(ConfigModel configModel, String contentType); /** * This is a findByConfigModelAndContentType method * - * @param configModel - * @param contentType + * @param configModel configModel + * @param contentType contentType * @return Optional */ + @SuppressWarnings("unused") List findByConfigModelAndContentType(ConfigModel configModel, String contentType); /** * This is a findByConfigModel method * - * @param configModel + * @param configModel configModel * @return Optional */ + @SuppressWarnings("unused") List findByConfigModel(ConfigModel configModel); /** * This is a findByConfigModelAndContentTypeAndName method * - * @param configModel - * @param contentType - * @param name + * @param configModel configModel + * @param contentType contentType + * @param name name * @return Optional */ + @SuppressWarnings("unused") Optional findByConfigModelAndContentTypeAndName(ConfigModel configModel, String contentType, String name); /** * This is a deleteByMdeleteByConfigModelodelName method * - * @param configModel + * @param configModel configModel */ void deleteByConfigModel(ConfigModel configModel); /** * This is a deleteById method * - * @param id + * @param id id */ - void deleteById(Long id); + void deleteById(@NotNull Long id); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java index 4822ee971..0a60ab74d 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java @@ -20,6 +20,7 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import javax.validation.constraints.NotNull; import java.util.List; import java.util.Optional; @@ -34,16 +35,17 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a findById method * - * @param id + * @param id id * @return Optional */ - Optional findById(Long id); + @NotNull + Optional findById(@NotNull Long id); /** * This is a findByArtifactNameAndArtifactVersion method * - * @param artifactName - * @param artifactVersion + * @param artifactName artifactName + * @param artifactVersion artifactVersion * @return Optional */ Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); @@ -51,7 +53,7 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a findTopByArtifactNameOrderByArtifactIdDesc method * - * @param artifactName + * @param artifactName artifactName * @return Optional */ Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); @@ -59,15 +61,16 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a findTopByArtifactName method * - * @param artifactName + * @param artifactName artifactName * @return Optional */ + @SuppressWarnings("unused") List findTopByArtifactName(String artifactName); /** * This is a findByTagsContainingIgnoreCase method * - * @param tags + * @param tags tags * @return Optional */ List findByTagsContainingIgnoreCase(String tags); @@ -75,16 +78,18 @@ public interface ConfigModelRepository extends JpaRepository /** * This is a deleteByArtifactNameAndArtifactVersion method * - * @param artifactName - * @param artifactVersion + * @param artifactName artifactName + * @param artifactVersion artifactVersion */ + @SuppressWarnings("unused") void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); /** * This is a deleteById method * - * @param id + * @param id id */ - void deleteById(Long id); + @SuppressWarnings("unused") + void deleteById(@NotNull Long id); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index f6e5c274f..6bcbae963 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -20,8 +20,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.*; import java.util.List; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java index e31b04d16..bfc89b4ee 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -39,9 +39,10 @@ import java.util.List; public class ConfigModelUtils { - private ConfigModelUtils(){ + private ConfigModelUtils() { } + private static Logger log = LoggerFactory.getLogger(ConfigModelUtils.class); public static ConfigModel getConfigModel(String blueprintPath) throws Exception { @@ -119,6 +120,8 @@ public class ConfigModelUtils { public static List getBlueprintNames(String pathName) { File blueprintDir = new File(pathName); Preconditions.checkNotNull(blueprintDir, "failed to find the blueprint pathName file"); - return Arrays.asList(blueprintDir.list(DirectoryFileFilter.INSTANCE)); + String[] dirs = blueprintDir.list(DirectoryFileFilter.INSTANCE); + Preconditions.checkNotNull(dirs, "failed to find the blueprint directories"); + return Arrays.asList(dirs); } } 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 1201f6b49..aaa445a44 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 @@ -63,7 +63,6 @@ public class ModelTypeValidator { */ public static boolean validateModelTypeDefinition(String definitionType, String definitionContent) throws BluePrintException { - boolean valid = true; if (StringUtils.isNotBlank(definitionContent)) { if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) { DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); @@ -93,7 +92,7 @@ public class ModelTypeValidator { } } - return valid; + 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 index 430401bc3..848a32f5b 100644 --- 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 @@ -19,7 +19,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; import com.google.common.base.Preconditions; 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.data.NodeTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; @@ -40,14 +39,14 @@ import java.util.Map; public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { StringBuilder message = new StringBuilder(); - private Map metaData = new HashMap(); + private Map metaData = new HashMap<>(); /** * This is a validateServiceTemplate * - * @param serviceTemplateContent + * @param serviceTemplateContent serviceTemplateContent * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { if (StringUtils.isNotBlank(serviceTemplateContent)) { @@ -65,7 +64,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { * * @param serviceTemplate * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ @SuppressWarnings("squid:S00112") public boolean validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { @@ -77,8 +76,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a getMetaData to get the key information during the * - * @return Map + * @return Map */ public Map getMetaData() { return metaData; -- cgit From 905d8bf666e0667774bebccfabce65e3497e9c32 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 30 Aug 2018 14:17:06 +0000 Subject: Controller Blueprints Microservice Add Resource Seuencing validation and Optimise resource assignment validation logics Change-Id: I6f31ca5dbeb6f6aa89959b7d96fbfad25468b3a4 Issue-ID: CCSDK-416 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ConfigModelCreateService.java | 39 +++++++++--------- .../ResourceAssignmentValidationService.java | 29 +++++++++++++ .../service/ServiceTemplateService.java | 22 +++++----- .../validator/ServiceTemplateValidator.java | 47 +++++++++++++++++++--- 4 files changed, 98 insertions(+), 39 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index f52137191..9c1a045cd 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; 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; @@ -290,31 +291,29 @@ public class ConfigModelCreateService { * @return ConfigModel * @throws BluePrintException BluePrintException */ - public ConfigModel publishConfigModel(Long id) throws BluePrintException { + public ConfigModel publishConfigModel(@NotNull Long id) throws BluePrintException { ConfigModel dbConfigModel = null; - if (id != null) { - Optional dbConfigModelOptional = configModelRepository.findById(id); - if (dbConfigModelOptional.isPresent()) { - dbConfigModel = dbConfigModelOptional.get(); - List configModelContents = dbConfigModel.getConfigModelContents(); - if (configModelContents != null && !configModelContents.isEmpty()) { - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent.getContentType() - .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { - ServiceTemplate serviceTemplate = JacksonUtils - .readValue(configModelContent.getContent(), ServiceTemplate.class); - if (serviceTemplate != null) { - validateServiceTemplate(serviceTemplate); - } + Optional dbConfigModelOptional = configModelRepository.findById(id); + if (dbConfigModelOptional.isPresent()) { + dbConfigModel = dbConfigModelOptional.get(); + List configModelContents = dbConfigModel.getConfigModelContents(); + if (configModelContents != null && !configModelContents.isEmpty()) { + for (ConfigModelContent configModelContent : configModelContents) { + if (configModelContent.getContentType() + .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { + ServiceTemplate serviceTemplate = JacksonUtils + .readValue(configModelContent.getContent(), ServiceTemplate.class); + if (serviceTemplate != null) { + validateServiceTemplate(serviceTemplate); } } } - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); - configModelRepository.save(dbConfigModel); - log.info("Config model ({}) published successfully.", id); - } - + dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); + configModelRepository.save(dbConfigModel); + log.info("Config model ({}) published successfully.", id); + } else { + throw new BluePrintException(String.format("Couldn't get Config model for id :(%s)", id)); } return dbConfigModel; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java new file mode 100644 index 000000000..1228e2eeb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java @@ -0,0 +1,29 @@ +/* + * 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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService; +import org.springframework.stereotype.Service; +/** + * ResourceAssignmentValidationService. + * + * @author Brinda Santh + */ +@Service +public class ResourceAssignmentValidationService extends ResourceAssignmentValidationDefaultService { + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 70cee3c9e..3e3c8e286 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; @@ -45,21 +44,24 @@ public class ServiceTemplateService { private ConfigModelCreateService configModelCreateService; private BluePrintEnhancerService bluePrintEnhancerService; + private ResourceAssignmentValidationService resourceAssignmentValidationService; /** * This is a SchemaGeneratorService constructor * - * @param dataDictionaryRepository dataDictionaryRepository - * @param configModelCreateService configModelCreateService - * @param bluePrintEnhancerService bluePrintEnhancerService + * @param dataDictionaryRepository dataDictionaryRepository + * @param configModelCreateService configModelCreateService + * @param bluePrintEnhancerService bluePrintEnhancerService + * @param resourceAssignmentValidationService resourceAssignmentValidationService */ public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, ConfigModelCreateService configModelCreateService, - BluePrintEnhancerService bluePrintEnhancerService) { + BluePrintEnhancerService bluePrintEnhancerService, + ResourceAssignmentValidationService resourceAssignmentValidationService) { this.dataDictionaryRepository = dataDictionaryRepository; this.configModelCreateService = configModelCreateService; this.bluePrintEnhancerService = bluePrintEnhancerService; - + this.resourceAssignmentValidationService = resourceAssignmentValidationService; } /** @@ -105,13 +107,7 @@ public class ServiceTemplateService { */ public List validateResourceAssignments(List resourceAssignments) throws BluePrintException { - try { - ResourceAssignmentValidator resourceAssignmentValidator = - new ResourceAssignmentValidator(resourceAssignments); - resourceAssignmentValidator.validateResourceAssignment(); - } catch (BluePrintException e) { - throw new BluePrintException(e.getMessage(), e); - } + resourceAssignmentValidationService.validate(resourceAssignments); return resourceAssignments; } 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 index 848a32f5b..42adf1a3e 100644 --- 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 @@ -17,16 +17,23 @@ 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.validator.ResourceAssignmentValidator; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -62,7 +69,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a validateServiceTemplate * - * @param serviceTemplate + * @param serviceTemplate serviceTemplate * @return boolean * @throws BluePrintException BluePrintException */ @@ -76,7 +83,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { /** * This is a getMetaData to get the key information during the * - * @return Map + * @return Map */ public Map getMetaData() { return metaData; @@ -104,9 +111,37 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { private void validateNodeTemplateCustom(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) throws BluePrintException { String derivedFrom = getBluePrintContext().nodeTemplateNodeType(nodeTemplateName).getDerivedFrom(); - if ("tosca.nodes.Artifact".equals(derivedFrom)) { - ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(nodeTemplate); - resourceAssignmentValidator.validateResourceAssignment(); + + if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) { + List resourceAssignment = getResourceAssignments(nodeTemplate); + ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationDefaultService(); + resourceAssignmentValidationService.validate(resourceAssignment); + } + } + + private List getResourceAssignments(@NotNull NodeTemplate nodeTemplate) { + + List 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.getJson(mappingObject); + Preconditions.checkArgument(StringUtils.isNotBlank(mappingContent), + String.format("Failed to get capability mapping property (%s) ", ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); + + resourceAssignment = JacksonUtils.getListFromJson(mappingContent, ResourceAssignment.class); + + Preconditions.checkNotNull(resourceAssignment, + String.format("Failed to get resource assignment info from the content (%s) ", mappingContent)); + } + } } + return resourceAssignment; } } -- cgit From 5dbc79162b53a0e97be4561719ae0e181944d2c8 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 31 Aug 2018 19:52:48 +0000 Subject: Controller Blueprints Microservice Add resource assignment enhancer, resource definition repo functions and code improvements. Change-Id: I751bf8149a36f80c20d48b86344cd6bd3054ed21 Issue-ID: CCSDK-431 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/AutoResourceMappingService.java | 6 +-- .../service/BluePrintEnhancerService.java | 10 ++-- .../service/ConfigModelCreateService.java | 6 +-- .../service/ConfigModelService.java | 60 +++++++++++----------- .../service/DataBaseInitService.java | 10 ++-- .../service/SchemaGeneratorService.java | 6 +-- .../service/ServiceTemplateService.java | 2 +- .../service/domain/ConfigModelContent.java | 11 ++-- .../service/domain/ModelType.java | 21 ++++---- .../service/domain/ResourceDictionary.java | 27 +++++----- .../service/utils/ConfigModelUtils.java | 6 +-- 11 files changed, 82 insertions(+), 83 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 5eba4fc7f..428c52451 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDict import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -49,7 +49,7 @@ import java.util.Map; @SuppressWarnings("unused") public class AutoResourceMappingService { - private static Logger log = LoggerFactory.getLogger(AutoResourceMappingService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(AutoResourceMappingService.class); private ResourceDictionaryRepository dataDictionaryRepository; 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 28be75e66..8e98f9477 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 @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintEnhancerDe 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; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -46,7 +46,7 @@ import java.util.Map; @Service public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { - private static Logger log = LoggerFactory.getLogger(BluePrintEnhancerService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); private Map recipeDataTypes = new HashMap<>(); @@ -55,7 +55,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { } @Override - public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) { + public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException{ super.enrichTopologyTemplate(serviceTemplate); // Update the Recipe Inputs and DataTypes @@ -143,7 +143,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { } private Map getCapabilityMappingProperties(String nodeTemplateName, - NodeTemplate nodeTemplate) { + NodeTemplate nodeTemplate) throws BluePrintException { Map dataTypeProperties = null; if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index 9c1a045cd..3c92f7e94 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -31,8 +31,8 @@ import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConsta import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.io.IOException; @@ -52,7 +52,7 @@ import java.util.Optional; @Service public class ConfigModelCreateService { - private static Logger log = LoggerFactory.getLogger(ConfigModelCreateService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelCreateService.class); private ConfigModelRepository configModelRepository; private ConfigModelValidatorService configModelValidatorService; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java index b729e3e6d..534394a3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java @@ -29,8 +29,8 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -49,7 +49,7 @@ import java.util.Optional; @Service public class ConfigModelService { - private static Logger log = LoggerFactory.getLogger(ConfigModelService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelService.class); private ConfigModelRepository configModelRepository; private ConfigModelContentRepository configModelContentRepository; @@ -57,14 +57,14 @@ public class ConfigModelService { /** * This is a ConfigModelService constructor. - * - * @param configModelRepository - * @param configModelContentRepository - * @param configModelCreateService + * + * @param configModelRepository configModelRepository + * @param configModelContentRepository configModelContentRepository + * @param configModelCreateService configModelCreateService */ public ConfigModelService(ConfigModelRepository configModelRepository, - ConfigModelContentRepository configModelContentRepository, - ConfigModelCreateService configModelCreateService) { + ConfigModelContentRepository configModelContentRepository, + ConfigModelCreateService configModelCreateService) { this.configModelRepository = configModelRepository; this.configModelContentRepository = configModelContentRepository; this.configModelCreateService = configModelCreateService; @@ -72,10 +72,10 @@ public class ConfigModelService { /** * This is a getInitialConfigModel method - * - * @param templateName + * + * @param templateName templateName * @return ConfigModel - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ConfigModel getInitialConfigModel(String templateName) throws BluePrintException { ConfigModel configModel = null; @@ -100,10 +100,10 @@ public class ConfigModelService { /** * This is a saveConfigModel method - * - * @param configModel + * + * @param configModel configModel * @return ConfigModel - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { return this.configModelCreateService.saveConfigModel(configModel); @@ -111,10 +111,10 @@ public class ConfigModelService { /** * This is a publishConfigModel method - * - * @param id + * + * @param id id * @return ConfigModel - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ConfigModel publishConfigModel(Long id) throws BluePrintException { return this.configModelCreateService.publishConfigModel(id); @@ -122,8 +122,8 @@ public class ConfigModelService { /** * This is a searchConfigModels method - * - * @param tags + * + * @param tags tags * @return ConfigModel */ public List searchConfigModels(String tags) { @@ -138,9 +138,9 @@ public class ConfigModelService { /** * This is a getConfigModelByNameAndVersion method - * - * @param name - * @param version + * + * @param name name + * @param version version * @return ConfigModel */ public ConfigModel getConfigModelByNameAndVersion(String name, String version) { @@ -159,8 +159,8 @@ public class ConfigModelService { /** * This is a getConfigModel method - * - * @param id + * + * @param id id * @return ConfigModel */ public ConfigModel getConfigModel(Long id) { @@ -176,9 +176,9 @@ public class ConfigModelService { /** * This method returns clone of the given model id, by masking the other unrelated fields - * - * @param id - * @return + * + * @param id id + * @return ConfigModel */ public ConfigModel getCloneConfigModel(Long id) { @@ -232,8 +232,8 @@ public class ConfigModelService { /** * This is a deleteConfigModel method - * - * @param id + * + * @param id id */ @Transactional diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 89d482962..4e7c3911c 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -22,6 +22,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.StrBuilder; +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.data.ArtifactType; @@ -33,8 +34,8 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -58,7 +59,7 @@ import java.util.List; @ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") public class DataBaseInitService { - private static Logger log = LoggerFactory.getLogger(DataBaseInitService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); @Value("${blueprints.load.path}") private String modelLoadPath; private ModelTypeService modelTypeService; @@ -91,6 +92,7 @@ public class DataBaseInitService { } @PostConstruct + @SuppressWarnings("unused") private void initDatabase() { log.info("loading Blueprints from DIR : {}", modelLoadPath); dataTypePath = modelLoadPath + "/model_type/data_type"; @@ -263,7 +265,7 @@ public class DataBaseInitService { } } - private void loadDataType(Resource file, StrBuilder errorBuilder) { + private void loadDataType(@NotNull Resource file, StrBuilder errorBuilder) { try { log.trace("Loading Data Type: {}", file.getFilename()); String dataKey = file.getFilename().replace(".json", ""); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java index a75651f19..04a95fd12 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -24,8 +24,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.common.SwaggerGenerator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.util.HashMap; import java.util.Map; @@ -39,7 +39,7 @@ import java.util.Map; */ public class SchemaGeneratorService { - private static Logger log = LoggerFactory.getLogger(SchemaGeneratorService.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorService.class); private Map dataTypes; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 3e3c8e286..898647eaa 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -81,7 +81,7 @@ public class ServiceTemplateService { * @param serviceTemplate serviceTemplate * @return ServiceTemplate */ - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) { + public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { this.bluePrintEnhancerService.enhance(serviceTemplate); return serviceTemplate; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index 60b3ed6b0..ae374a786 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -76,12 +76,11 @@ public class ConfigModelContent { @Override public String toString() { - StringBuilder builder = new StringBuilder("["); - builder.append("id = " + id); - builder.append(", name = " + name); - builder.append(", contentType = " + contentType); - builder.append("]"); - return builder.toString(); + String builder = "[" + "id = " + id + + ", name = " + name + + ", contentType = " + contentType + + "]"; + return builder; } @Override diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index eaa335b3e..cb8d229f3 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -82,17 +82,16 @@ public class ModelType implements Serializable { @Override public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append(", modelName = " + modelName); - buffer.append(", derivedFrom = " + derivedFrom); - buffer.append(", definitionType = " + definitionType); - buffer.append(", description = " + description); - buffer.append(", creationDate = " + creationDate); - buffer.append(", version = " + version); - buffer.append(", updatedBy = " + updatedBy); - buffer.append(", tags = " + tags); - buffer.append("]"); - return buffer.toString(); + String buffer = "[" + ", modelName = " + modelName + + ", derivedFrom = " + derivedFrom + + ", definitionType = " + definitionType + + ", description = " + description + + ", creationDate = " + creationDate + + ", version = " + version + + ", updatedBy = " + updatedBy + + ", tags = " + tags + + "]"; + return buffer; } public String getModelName() { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index 487586842..c88462202 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -92,20 +92,19 @@ public class ResourceDictionary implements Serializable { @Override public String toString() { - StringBuilder buffer = new StringBuilder("["); - buffer.append(", name = " + name); - buffer.append(", resourcePath = " + resourcePath); - buffer.append(", resourceType = " + resourceType); - buffer.append(", dataType = " + dataType); - buffer.append(", entrySchema = " + entrySchema); - buffer.append(", validValues = " + validValues); - buffer.append(", definition =" + definition); - buffer.append(", description = " + description); - buffer.append(", updatedBy = " + updatedBy); - buffer.append(", tags = " + tags); - buffer.append(", creationDate = " + creationDate); - buffer.append("]"); - return buffer.toString(); + String buffer = "[" + ", name = " + name + + ", resourcePath = " + resourcePath + + ", resourceType = " + resourceType + + ", dataType = " + dataType + + ", entrySchema = " + entrySchema + + ", validValues = " + validValues + + ", definition =" + definition + + ", description = " + description + + ", updatedBy = " + updatedBy + + ", tags = " + tags + + ", creationDate = " + creationDate + + "]"; + return buffer; } public String getResourcePath() { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java index bfc89b4ee..dc24c3bfe 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -27,8 +27,8 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData; import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.io.File; import java.io.IOException; @@ -43,7 +43,7 @@ public class ConfigModelUtils { } - private static Logger log = LoggerFactory.getLogger(ConfigModelUtils.class); + private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelUtils.class); public static ConfigModel getConfigModel(String blueprintPath) throws Exception { Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing"); -- cgit From 713a0958b1796d06ca19ad9be396e92999e851d6 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 3 Sep 2018 00:50:25 +0000 Subject: Controller Blueprints Microservice Add Logger MDC using ONAP LoggerAdaptor and change swagger configuration to return the transactions information, version, etc Change-Id: Ie1dccecce0c08e7ae02c0e55c1cc5be75d5fc686 Issue-ID: CCSDK-510 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ConfigModelService.java | 107 ++++++++++++--------- .../service/rs/ConfigModelRest.java | 50 ++-------- .../service/rs/ModelTypeRest.java | 2 +- .../service/rs/ResourceDictionaryRest.java | 2 +- 4 files changed, 70 insertions(+), 91 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java index 534394a3e..a2f653c67 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import org.apache.commons.collections.CollectionUtils; 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; @@ -68,6 +69,7 @@ public class ConfigModelService { this.configModelRepository = configModelRepository; this.configModelContentRepository = configModelContentRepository; this.configModelCreateService = configModelCreateService; + log.info("Config Model Service Initiated..."); } /** @@ -143,8 +145,8 @@ public class ConfigModelService { * @param version version * @return ConfigModel */ - public ConfigModel getConfigModelByNameAndVersion(String name, String version) { - ConfigModel configModel = null; + public ConfigModel getConfigModelByNameAndVersion(@NotNull String name, String version) throws BluePrintException { + ConfigModel configModel; Optional dbConfigModel; if (StringUtils.isNotBlank(version)) { dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version); @@ -153,6 +155,8 @@ public class ConfigModelService { } if (dbConfigModel.isPresent()) { configModel = dbConfigModel.get(); + } else { + throw new BluePrintException(String.format("failed to get config model name(%s), version(%s) from repo", name, version)); } return configModel; } @@ -162,15 +166,17 @@ public class ConfigModelService { * * @param id id * @return ConfigModel + * @throws BluePrintException BluePrintException */ - public ConfigModel getConfigModel(Long id) { - ConfigModel configModel = null; - if (id != null) { - Optional dbConfigModel = configModelRepository.findById(id); - if (dbConfigModel.isPresent()) { - configModel = dbConfigModel.get(); - } + public ConfigModel getConfigModel(@NotNull Long id) throws BluePrintException { + ConfigModel configModel; + Optional dbConfigModel = configModelRepository.findById(id); + if (dbConfigModel.isPresent()) { + configModel = dbConfigModel.get(); + } else { + throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id)); } + return configModel; } @@ -179,54 +185,56 @@ public class ConfigModelService { * * @param id id * @return ConfigModel + * @throws BluePrintException BluePrintException */ - public ConfigModel getCloneConfigModel(Long id) { + public ConfigModel getCloneConfigModel(@NotNull Long id) throws BluePrintException { ConfigModel configModel; - ConfigModel cloneConfigModel = null; - if (id != null) { - Optional dbConfigModel = configModelRepository.findById(id); - if (dbConfigModel.isPresent()) { - configModel = dbConfigModel.get(); - cloneConfigModel = configModel; - cloneConfigModel.setUpdatedBy("xxxxx@xxx.com"); - cloneConfigModel.setArtifactName("XXXX"); - cloneConfigModel.setPublished("XXXX"); - cloneConfigModel.setPublished("XXXX"); - cloneConfigModel.setUpdatedBy("XXXX"); - cloneConfigModel.setId(null); - cloneConfigModel.setTags(null); - cloneConfigModel.setCreatedDate(new Date()); - List configModelContents = cloneConfigModel.getConfigModelContents(); - - if (CollectionUtils.isNotEmpty(configModelContents)) { - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { - configModelContent.setId(null); - configModelContent.setCreationDate(new Date()); - - if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON - .equalsIgnoreCase(configModelContent.getContentType())) { - ServiceTemplate serviceTemplate = JacksonUtils - .readValue(configModelContent.getContent(), ServiceTemplate.class); - if (serviceTemplate != null && serviceTemplate.getMetadata() != null) { - serviceTemplate.getMetadata() - .put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, "XXXX"); - serviceTemplate.getMetadata() - .put(BluePrintConstants.METADATA_TEMPLATE_VERSION, "1.0.0"); - serviceTemplate.getMetadata() - .put(BluePrintConstants.METADATA_TEMPLATE_NAME, "XXXXXX"); - - configModelContent.setContent(JacksonUtils.getJson(serviceTemplate)); - } + ConfigModel cloneConfigModel; + Optional dbConfigModel = configModelRepository.findById(id); + if (dbConfigModel.isPresent()) { + configModel = dbConfigModel.get(); + cloneConfigModel = configModel; + cloneConfigModel.setUpdatedBy("xxxxx@xxx.com"); + cloneConfigModel.setArtifactName("XXXX"); + cloneConfigModel.setPublished("XXXX"); + cloneConfigModel.setPublished("XXXX"); + cloneConfigModel.setUpdatedBy("XXXX"); + cloneConfigModel.setId(null); + cloneConfigModel.setTags(null); + cloneConfigModel.setCreatedDate(new Date()); + List configModelContents = cloneConfigModel.getConfigModelContents(); + + if (CollectionUtils.isNotEmpty(configModelContents)) { + for (ConfigModelContent configModelContent : configModelContents) { + if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { + configModelContent.setId(null); + configModelContent.setCreationDate(new Date()); + + if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON + .equalsIgnoreCase(configModelContent.getContentType())) { + ServiceTemplate serviceTemplate = JacksonUtils + .readValue(configModelContent.getContent(), ServiceTemplate.class); + if (serviceTemplate != null && serviceTemplate.getMetadata() != null) { + serviceTemplate.getMetadata() + .put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, "XXXX"); + serviceTemplate.getMetadata() + .put(BluePrintConstants.METADATA_TEMPLATE_VERSION, "1.0.0"); + serviceTemplate.getMetadata() + .put(BluePrintConstants.METADATA_TEMPLATE_NAME, "XXXXXX"); + + configModelContent.setContent(JacksonUtils.getJson(serviceTemplate)); } } - } + } } + } else { + throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id)); } + return cloneConfigModel; } @@ -234,14 +242,17 @@ public class ConfigModelService { * This is a deleteConfigModel method * * @param id id + * @throws BluePrintException BluePrintException */ @Transactional - public void deleteConfigModel(Long id) { + public void deleteConfigModel(@NotNull Long id) throws BluePrintException { Optional dbConfigModel = configModelRepository.findById(id); if (dbConfigModel.isPresent()) { configModelContentRepository.deleteByConfigModel(dbConfigModel.get()); configModelRepository.delete(dbConfigModel.get()); + } else { + throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id)); } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index 62b683032..fc2956bea 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -46,81 +46,49 @@ public class ConfigModelRest { @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { - try { - return this.configModelService.getInitialConfigModel(name); - } catch (Exception e) { - throw new BluePrintException(2000, e.getMessage(), e); - } + return this.configModelService.getInitialConfigModel(name); } - @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { - try { - return this.configModelService.saveConfigModel(configModel); - } catch (Exception e) { - throw new BluePrintException(2200, e.getMessage(), e); - } + return this.configModelService.saveConfigModel(configModel); } @DeleteMapping(path = "/{id}") public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - try { - this.configModelService.deleteConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2400, e.getMessage(), e); - } + this.configModelService.deleteConfigModel(id); } @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - try { - return this.configModelService.publishConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2500, e.getMessage(), e); - } + return this.configModelService.publishConfigModel(id); } @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - try { - return this.configModelService.getConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2001, e.getMessage(), e); - } + return this.configModelService.getConfigModel(id); } @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, @PathVariable(value = "version") String version) throws BluePrintException { - try { - return this.configModelService.getConfigModelByNameAndVersion(name, version); - } catch (Exception e) { - throw new BluePrintException(2002, e.getMessage(), e); - } + return this.configModelService.getConfigModelByNameAndVersion(name, version); } @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { - try { - return this.configModelService.searchConfigModels(tags); - } catch (Exception e) { - throw new BluePrintException(2003, e.getMessage(), e); - } + return this.configModelService.searchConfigModels(tags); } @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - try { - return this.configModelService.getCloneConfigModel(id); - } catch (Exception e) { - throw new BluePrintException(2004, e.getMessage(), e); - } + return this.configModelService.getCloneConfigModel(id); } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 6bcbae963..082b15078 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -70,7 +70,7 @@ public class ModelTypeRest { } } - @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { try { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index 795738cb1..a4aced60c 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -43,7 +43,7 @@ public class ResourceDictionaryRest { this.resourceDictionaryService = dataDictionaryService; } - @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { -- cgit From c77ee2f8cf2f326fd59a977f7f2775429cbce683 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 5 Sep 2018 01:22:04 -0400 Subject: Controller Blueprints Microservice Add Resource Dictionary reactive repository service for dictionary validation and automap functions. Change-Id: I7cc6d7d976cfe9370f9a74cd8f2e4256de8e8995 Issue-ID: CCSDK-484 Signed-off-by: Brinda Santh --- .../service/repository/ResourceDictionaryRepository.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java index 279dcd1c9..16031b6e0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.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. @@ -62,7 +63,7 @@ public interface ResourceDictionaryRepository extends JpaRepository Date: Wed, 5 Sep 2018 17:42:22 +0000 Subject: Controller Blueprints Microservice Modify Model Type and Resource Defintions persistance and access from String to JSON type for easy handling. Change-Id: Icfe7e95abad715b0ccad16c681ed057d289a6229 Issue-ID: CCSDK-431 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/AutoResourceMappingService.java | 7 ++-- .../service/BluePrintRepoDBService.java | 11 +++--- .../service/DataBaseInitService.java | 8 ++--- .../service/ResourceDictionaryService.java | 9 ++--- .../service/domain/JpaJsonNodeConverter.java | 40 ++++++++++++++++++++++ .../domain/JpaResourceDefinitionConverter.java | 39 +++++++++++++++++++++ .../service/domain/ModelType.java | 8 +++-- .../service/domain/ResourceDictionary.java | 8 +++-- .../service/validator/ModelTypeValidator.java | 18 +++++----- .../validator/ResourceDictionaryValidator.java | 2 +- 10 files changed, 115 insertions(+), 35 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index 428c52451..a763d503c 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -22,7 +22,6 @@ 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.data.PropertyDefinition; -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.ResourceDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; @@ -100,9 +99,9 @@ public class AutoResourceMappingService { private void populateDictionaryMapping(Map dictionaryMap, ResourceAssignment resourceAssignment) { ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); - if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) { + if (dbDataDictionary != null && dbDataDictionary.getDefinition() != null) { - ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class); + ResourceDefinition dictionaryDefinition = dbDataDictionary.getDefinition(); if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { @@ -185,7 +184,7 @@ public class AutoResourceMappingService { } if (dictionaries != null) { for (ResourceDictionary resourcedictionary : dictionaries) { - ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class); + ResourceDefinition dictionaryDefinition = resourcedictionary.getDefinition(); Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition"); PropertyDefinition property = new PropertyDefinition(); property.setRequired(true); 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 index c4aebe52c..5510e480c 100644 --- 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 @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.fasterxml.jackson.databind.JsonNode; import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; @@ -75,16 +76,16 @@ public class BluePrintRepoDBService implements BluePrintRepoService { Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Failed to get model from repo, model name is missing"); - return getModelDefinition(modelName).map(content -> { - Preconditions.checkArgument(StringUtils.isNotBlank(content), + return getModelDefinition(modelName).map(modelDefinition -> { + Preconditions.checkNotNull(modelDefinition, String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(content, valueClass); + return JacksonUtils.readValue(modelDefinition, valueClass); } ); } - private Mono getModelDefinition(String modelName) throws BluePrintException { - String modelDefinition; + private Mono getModelDefinition(String modelName) throws BluePrintException { + JsonNode modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { modelDefinition = modelTypeDb.get().getDefinition(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 4e7c3911c..886809297 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -168,7 +168,7 @@ public class DataBaseInitService { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); resourceDictionary.setName(dictionaryDefinition.getName()); - resourceDictionary.setDefinition(definitionContent); + resourceDictionary.setDefinition(dictionaryDefinition); resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); @@ -252,7 +252,7 @@ public class DataBaseInitService { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); modelType.setDerivedFrom(nodeType.getDerivedFrom()); modelType.setDescription(nodeType.getDescription()); - modelType.setDefinition(definitionContent); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(nodeKey); modelType.setVersion(nodeType.getVersion()); modelType.setUpdatedBy("System"); @@ -276,7 +276,7 @@ public class DataBaseInitService { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelType.setDerivedFrom(dataType.getDerivedFrom()); modelType.setDescription(dataType.getDescription()); - modelType.setDefinition(definitionContent); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(dataKey); modelType.setVersion(dataType.getVersion()); modelType.setUpdatedBy("System"); @@ -300,7 +300,7 @@ public class DataBaseInitService { modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); modelType.setDerivedFrom(artifactType.getDerivedFrom()); modelType.setDescription(artifactType.getDescription()); - modelType.setDefinition(definitionContent); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(dataKey); modelType.setVersion(artifactType.getVersion()); modelType.setUpdatedBy("System"); 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 ccf4ffcc7..70e43d699 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 @@ -105,11 +105,9 @@ public class ResourceDictionaryService { */ public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); - Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), - "Resource Dictionary definition information is missing"); + Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing"); - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class); + ResourceDefinition resourceDefinition = resourceDictionary.getDefinition(); Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content"); // Validate the Resource Definitions resourceDictionaryValidationService.validate(resourceDefinition); @@ -126,9 +124,6 @@ public class ResourceDictionaryService { resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); } - String definitionContent = JacksonUtils.getJson(resourceDefinition, true); - resourceDictionary.setDefinition(definitionContent); - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); Optional dbResourceDictionaryData = diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java new file mode 100644 index 000000000..05f822d5b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java @@ -0,0 +1,40 @@ +/* + * 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.domain; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import com.fasterxml.jackson.databind.JsonNode; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +/** + * @author Brinda Santh + */ +@Converter +public class JpaJsonNodeConverter implements + AttributeConverter { + + @Override + public String convertToDatabaseColumn(JsonNode node) { + return JacksonUtils.getJson(node, true); + } + + @Override + public JsonNode convertToEntityAttribute(String dbData) { + return JacksonUtils.jsonNode(dbData); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java new file mode 100644 index 000000000..18672f1cb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java @@ -0,0 +1,39 @@ +/* + * 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.domain; + +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +/** + * @author Brinda Santh + */ +@Converter +public class JpaResourceDefinitionConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) { + return JacksonUtils.getJson(resourceDefinition); + } + + @Override + public ResourceDefinition convertToEntityAttribute(String content) { + return JacksonUtils.readValue(content, ResourceDefinition.class); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index cb8d229f3..d8fea60e5 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.JsonNode; import io.swagger.annotations.ApiModelProperty; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -52,9 +53,10 @@ public class ModelType implements Serializable { private String definitionType; @Lob + @Convert(converter = JpaJsonNodeConverter.class) @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) - private String definition; + private JsonNode definition; @Lob @Column(name = "description", nullable = false) @@ -118,11 +120,11 @@ public class ModelType implements Serializable { this.definitionType = definitionType; } - public String getDefinition() { + public JsonNode getDefinition() { return definition; } - public void setDefinition(String definition) { + public void setDefinition(JsonNode definition) { this.definition = definition; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index c88462202..7af9972a6 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -66,9 +67,10 @@ public class ResourceDictionary implements Serializable { private String sampleValue; @Lob + @Convert(converter = JpaResourceDefinitionConverter.class) @Column(name = "definition", nullable = false) @ApiModelProperty(required=true) - private String definition; + private ResourceDefinition definition; @Lob @Column(name = "description", nullable = false) @@ -163,11 +165,11 @@ public class ResourceDictionary implements Serializable { this.sampleValue = sampleValue; } - public String getDefinition() { + public ResourceDefinition getDefinition() { return definition; } - public void setDefinition(String definition) { + public void setDefinition(ResourceDefinition definition) { this.definition = definition; } 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 aaa445a44..9641f8973 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 @@ -17,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.validator; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; @@ -56,14 +57,14 @@ public class ModelTypeValidator { /** * This is a validateModelTypeDefinition * - * @param definitionType - * @param definitionContent + * @param definitionType definitionType + * @param definitionContent definitionContent * @return boolean - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ - public static boolean validateModelTypeDefinition(String definitionType, String definitionContent) + public static boolean validateModelTypeDefinition(String definitionType, JsonNode definitionContent) throws BluePrintException { - if (StringUtils.isNotBlank(definitionContent)) { + if (definitionContent != null) { if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) { DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); if (dataType == null) { @@ -98,8 +99,9 @@ public class ModelTypeValidator { /** * This is a validateModelType method * - * @param modelType + * @param modelType modelType * @return boolean + * @throws BluePrintException BluePrintException */ public static boolean validateModelType(ModelType modelType) throws BluePrintException { if (modelType != null) { @@ -115,7 +117,7 @@ public class ModelTypeValidator { throw new BluePrintException("Model Type Information is missing."); } - if (StringUtils.isBlank(modelType.getDefinition())) { + if (modelType.getDefinition() == null) { throw new BluePrintException("Model Definition Information is missing."); } if (StringUtils.isBlank(modelType.getDescription())) { @@ -133,7 +135,7 @@ public class ModelTypeValidator { List validRootTypes = getValidModelDefinitionType(); if (!validRootTypes.contains(modelType.getDefinitionType())) { throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType() - + "), It sould be " + validRootTypes); + + "), It should be " + validRootTypes); } validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition()); 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 index ff0b4ac5c..1c2a7337b 100644 --- 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 @@ -49,7 +49,7 @@ public class ResourceDictionaryValidator { "DataDictionary Resource Name Information is missing."); Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()), "DataDictionary Resource Type Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDefinition()), + Preconditions.checkNotNull( resourceDictionary.getDefinition(), "DataDictionary Definition Information is missing."); Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()), "DataDictionary Description Information is missing."); -- cgit From 2c91cf47dcfc3014dd669627e214b2e8ec34ce4a Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Wed, 5 Sep 2018 23:18:19 -0400 Subject: Controller Blueprints Microservice Add configuration property to load model types and Remove duplicate model type test case files Change-Id: I6a34539cae7377bd133727fde77ff8fefaadf023 Issue-ID: CCSDK-484 Signed-off-by: Brinda Santh --- .../controllerblueprints/service/DataBaseInitService.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 886809297..c6d80cfb6 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -60,16 +60,19 @@ import java.util.List; public class DataBaseInitService { private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); - @Value("${blueprints.load.path}") - private String modelLoadPath; private ModelTypeService modelTypeService; private ResourceDictionaryService resourceDictionaryService; private ConfigModelService configModelService; + @Value("${load.dataTypePath}") private String dataTypePath; + @Value("${load.nodeTypePath}") private String nodeTypePath; + @Value("${load.artifactTypePath}") private String artifactTypePath; + @Value("${load.resourceDictionaryPath}") private String resourceDictionaryPath; + @Value("${load.blueprintsPath}") private String bluePrintsPath; @Autowired @@ -94,13 +97,6 @@ public class DataBaseInitService { @PostConstruct @SuppressWarnings("unused") private void initDatabase() { - log.info("loading Blueprints from DIR : {}", modelLoadPath); - dataTypePath = modelLoadPath + "/model_type/data_type"; - nodeTypePath = modelLoadPath + "/model_type/node_type"; - artifactTypePath = modelLoadPath + "/model_type/artifact_type"; - resourceDictionaryPath = modelLoadPath + "/resource_dictionary"; - bluePrintsPath = modelLoadPath + "/blueprints"; - log.info("loading dataTypePath from DIR : {}", dataTypePath); log.info("loading nodeTypePath from DIR : {}", nodeTypePath); log.info("loading artifactTypePath from DIR : {}", artifactTypePath); -- cgit From cd95bfda8f81a9aa34e1986e352b19e57488e1ae Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 7 Sep 2018 19:20:59 +0000 Subject: Controller Blueprints Microservice Remove Resource Dictionary resource_type, resource_path, sample_values and valid_values parameters. Change-Id: I7ec899e30aaef64130f35eb754a79f9dfc54f71f Issue-ID: CCSDK-488 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/DataBaseInitService.java | 34 +++++++-------- .../service/ResourceDictionaryService.java | 4 -- .../service/domain/ResourceDictionary.java | 51 ---------------------- .../validator/ResourceDictionaryValidator.java | 4 -- 4 files changed, 16 insertions(+), 77 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index c6d80cfb6..cfcf93d29 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -157,30 +157,28 @@ public class DataBaseInitService { fileName = file.getFilename(); log.trace("Loading : {}", fileName); String definitionContent = getResourceContent(file); - ResourceDefinition dictionaryDefinition = + ResourceDefinition resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition.class); - if (dictionaryDefinition != null) { - Preconditions.checkNotNull(dictionaryDefinition.getProperty(), "Failed to get Property Definition"); + if (resourceDefinition != null) { + Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition"); ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath()); - resourceDictionary.setName(dictionaryDefinition.getName()); - resourceDictionary.setDefinition(dictionaryDefinition); - - resourceDictionary.setResourceType(dictionaryDefinition.getResourceType()); - resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription()); - resourceDictionary.setDataType(dictionaryDefinition.getProperty().getType()); - if(dictionaryDefinition.getProperty().getEntrySchema() != null){ - resourceDictionary.setEntrySchema(dictionaryDefinition.getProperty().getEntrySchema().getType()); + resourceDictionary.setName(resourceDefinition.getName()); + resourceDictionary.setDefinition(resourceDefinition); + + Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing"); + resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); + resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); + if(resourceDefinition.getProperty().getEntrySchema() != null){ + resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType()); } - resourceDictionary.setUpdatedBy(dictionaryDefinition.getUpdatedBy()); - if (StringUtils.isBlank(dictionaryDefinition.getTags())) { + resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); + if (StringUtils.isBlank(resourceDefinition.getTags())) { resourceDictionary.setTags( - dictionaryDefinition.getName() + ", " + dictionaryDefinition.getUpdatedBy() - + ", " + dictionaryDefinition.getResourceType() + ", " - + dictionaryDefinition.getUpdatedBy()); + resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy() + + ", " + resourceDefinition.getUpdatedBy()); } else { - resourceDictionary.setTags(dictionaryDefinition.getTags()); + resourceDictionary.setTags(resourceDefinition.getTags()); } resourceDictionaryService.saveResourceDictionary(resourceDictionary); 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 70e43d699..62aa0e29c 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 @@ -112,8 +112,6 @@ public class ResourceDictionaryService { // Validate the Resource Definitions resourceDictionaryValidationService.validate(resourceDefinition); - resourceDictionary.setResourceType(resourceDefinition.getResourceType()); - resourceDictionary.setResourcePath(resourceDefinition.getResourcePath()); resourceDictionary.setTags(resourceDefinition.getTags()); resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); // Set the Property Definitions @@ -134,8 +132,6 @@ public class ResourceDictionaryService { dbResourceDictionary.setName(resourceDictionary.getName()); dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); dbResourceDictionary.setDescription(resourceDictionary.getDescription()); - dbResourceDictionary.setResourceType(resourceDictionary.getResourceType()); - dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath()); dbResourceDictionary.setTags(resourceDictionary.getTags()); dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy()); dbResourceDictionary.setDataType(resourceDictionary.getDataType()); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index 7af9972a6..42c8e83b2 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -43,14 +43,6 @@ public class ResourceDictionary implements Serializable { @ApiModelProperty(required=true) private String name; - @Column(name = "resource_path", nullable = false) - @ApiModelProperty(required=true) - private String resourcePath; - - @Column(name = "resource_type", nullable = false) - @ApiModelProperty(required=true) - private String resourceType; - @Column(name = "data_type", nullable = false) @ApiModelProperty(required=true) private String dataType; @@ -58,14 +50,6 @@ public class ResourceDictionary implements Serializable { @Column(name = "entry_schema") private String entrySchema; - @Lob - @Column(name = "valid_values") - private String validValues; - - @Lob - @Column(name = "sample_value") - private String sampleValue; - @Lob @Convert(converter = JpaResourceDefinitionConverter.class) @Column(name = "definition", nullable = false) @@ -95,11 +79,8 @@ public class ResourceDictionary implements Serializable { @Override public String toString() { String buffer = "[" + ", name = " + name + - ", resourcePath = " + resourcePath + - ", resourceType = " + resourceType + ", dataType = " + dataType + ", entrySchema = " + entrySchema + - ", validValues = " + validValues + ", definition =" + definition + ", description = " + description + ", updatedBy = " + updatedBy + @@ -109,14 +90,6 @@ public class ResourceDictionary implements Serializable { return buffer; } - public String getResourcePath() { - return resourcePath; - } - - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - public String getName() { return name; } @@ -125,14 +98,6 @@ public class ResourceDictionary implements Serializable { this.name = name; } - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - public String getDataType() { return dataType; } @@ -149,22 +114,6 @@ public class ResourceDictionary implements Serializable { this.entrySchema = entrySchema; } - public String getValidValues() { - return validValues; - } - - public void setValidValues(String validValues) { - this.validValues = validValues; - } - - public String getSampleValue() { - return sampleValue; - } - - public void setSampleValue(String sampleValue) { - this.sampleValue = sampleValue; - } - public ResourceDefinition getDefinition() { return definition; } 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 index 1c2a7337b..57330d90f 100644 --- 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 @@ -45,10 +45,6 @@ public class ResourceDictionaryValidator { Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getName()), "DataDictionary Alias Name Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourcePath()), - "DataDictionary Resource Name Information is missing."); - Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()), - "DataDictionary Resource Type Information is missing."); Preconditions.checkNotNull( resourceDictionary.getDefinition(), "DataDictionary Definition Information is missing."); Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()), -- cgit From 41c2e50bad504a7f81978598f39ebe409a2df808 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 9 Sep 2018 19:00:59 -0400 Subject: Controller Blueprints Microservice Add Common Error Handling for ModelType, ServiceTemplate and ResourceDictionary Rest Services. Change-Id: I8fa78bc4b1c38fd6149238da566e0867f64ffcc5 Issue-ID: CCSDK-522 Signed-off-by: Brinda Santh --- .../service/rs/ModelTypeRest.java | 31 ++++----------------- .../service/rs/ResourceDictionaryRest.java | 32 +++++----------------- .../service/rs/ServiceTemplateRest.java | 31 ++++----------------- 3 files changed, 19 insertions(+), 75 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 082b15078..988cad064 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.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. @@ -44,48 +45,28 @@ public class ModelTypeRest { @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { - try { - return modelTypeService.getModelTypeByName(name); - } catch (Exception e) { - throw new BluePrintException(1000, e.getMessage(), e); - } + return modelTypeService.getModelTypeByName(name); } @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { - try { - return modelTypeService.searchModelTypes(tags); - } catch (Exception e) { - throw new BluePrintException(1001, e.getMessage(), e); - } + return modelTypeService.searchModelTypes(tags); } @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { - try { - return modelTypeService.getModelTypeByDefinitionType(definitionType); - } catch (Exception e) { - throw new BluePrintException(1002, e.getMessage(), e); - } + return modelTypeService.getModelTypeByDefinitionType(definitionType); } @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { - try { - return modelTypeService.saveModel(modelType); - } catch (Exception e) { - throw new BluePrintException(1100, e.getMessage(), e); - } + return modelTypeService.saveModel(modelType); } @DeleteMapping(path = "/{name}") public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { - try { - modelTypeService.deleteByModelName(name); - } catch (Exception e) { - throw new BluePrintException(1400, e.getMessage(), e); - } + modelTypeService.deleteByModelName(name); } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index a4aced60c..e0cf6c69b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.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. @@ -47,51 +48,32 @@ public class ResourceDictionaryRest { public @ResponseBody ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { - try { - return resourceDictionaryService.saveResourceDictionary(dataDictionary); - } catch (Exception e) { - throw new BluePrintException(4100, e.getMessage(), e); - } + return resourceDictionaryService.saveResourceDictionary(dataDictionary); } @DeleteMapping(path = "/{name}") public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { - try { - resourceDictionaryService.deleteResourceDictionary(name); - } catch (Exception e) { - throw new BluePrintException(4400, e.getMessage(), e); - } + resourceDictionaryService.deleteResourceDictionary(name); } @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { - try { - return resourceDictionaryService.getResourceDictionaryByName(name); - } catch (Exception e) { - throw new BluePrintException(4001, e.getMessage(), e); - } + return resourceDictionaryService.getResourceDictionaryByName(name); } @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByNames(@RequestBody List names) throws BluePrintException { - try { - return resourceDictionaryService.searchResourceDictionaryByNames(names); - } catch (Exception e) { - throw new BluePrintException(4002, e.getMessage(), e); - } + return resourceDictionaryService.searchResourceDictionaryByNames(names); } @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { - try { - return resourceDictionaryService.searchResourceDictionaryByTags(tags); - } catch (Exception e) { - throw new BluePrintException(4003, e.getMessage(), e); - } + return resourceDictionaryService.searchResourceDictionaryByTags(tags); + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index a22285b88..caa6bba4f 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.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. @@ -49,53 +50,33 @@ public class ServiceTemplateRest { @PostMapping(path = "/enrich", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { - try { - return serviceTemplateService.enrichServiceTemplate(serviceTemplate); - } catch (Exception e) { - throw new BluePrintException(3500, e.getMessage(), e); - } + return serviceTemplateService.enrichServiceTemplate(serviceTemplate); } @PostMapping(path = "/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { - try { - return serviceTemplateService.validateServiceTemplate(serviceTemplate); - } catch (Exception e) { - throw new BluePrintException(3501, e.getMessage(), e); - } + return serviceTemplateService.validateServiceTemplate(serviceTemplate); } @PostMapping(path = "/resource-assignment/auto-map", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { - try { - return serviceTemplateService.autoMap(resourceAssignments); - } catch (Exception e) { - throw new BluePrintException(3502, e.getMessage(), e); - } + return serviceTemplateService.autoMap(resourceAssignments); } @PostMapping(path = "/resource-assignment/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List validateResourceAssignments(@RequestBody List resourceAssignments) throws BluePrintException { - try { - return serviceTemplateService.validateResourceAssignments(resourceAssignments); - } catch (Exception e) { - throw new BluePrintException(3503, e.getMessage(), e); - } + return serviceTemplateService.validateResourceAssignments(resourceAssignments); } @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) throws BluePrintException { - try { - return serviceTemplateService.generateResourceAssignments(templateContent); - } catch (Exception e) { - throw new BluePrintException(3504, e.getMessage(), e); - } + return serviceTemplateService.generateResourceAssignments(templateContent); } } -- cgit From f191f4bbfeb8802ed2b223ad13149aa0f31242b6 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 9 Sep 2018 22:00:59 -0400 Subject: Controller Blueprints Microservice Add ModelType and Resource Dictionary reactor repository service and junit test cases for reactor repositories. Change-Id: Id358082739f81d18b534c224dc7472355e21f026 Issue-ID: CCSDK-491 Signed-off-by: Brinda Santh --- .../service/ModelTypeService.java | 88 +++++++--------------- .../repository/ResourceDictionaryRepository.java | 10 +-- 2 files changed, 34 insertions(+), 64 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java index 2bc2963b6..925a6c492 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.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. @@ -16,6 +17,7 @@ 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.service.domain.ModelType; @@ -43,7 +45,7 @@ public class ModelTypeService { /** * This is a ModelTypeService, used to save and get the model types stored in database * - * @param modelTypeRepository + * @param modelTypeRepository modelTypeRepository */ public ModelTypeService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; @@ -53,19 +55,15 @@ public class ModelTypeService { /** * This is a getModelTypeByName service * - * @param modelTypeName + * @param modelTypeName modelTypeName * @return ModelType - * @throws BluePrintException */ - public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException { + public ModelType getModelTypeByName(String modelTypeName) { ModelType modelType = null; - if (StringUtils.isNotBlank(modelTypeName)) { - Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); - if (modelTypeOption.isPresent()) { - modelType = modelTypeOption.get(); - } - } else { - throw new BluePrintException("Model Name Information is missing."); + Preconditions.checkArgument(StringUtils.isNotBlank(modelTypeName), "Model Name Information is missing."); + Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); + if (modelTypeOption.isPresent()) { + modelType = modelTypeOption.get(); } return modelType; } @@ -74,27 +72,25 @@ public class ModelTypeService { /** * This is a searchModelTypes service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchModelTypes(String tags) throws BluePrintException { - if (tags != null) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchModelTypes(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No Search Information provide"); + return modelTypeRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveModel service * - * @param modelType + * @param modelType modelType * @return ModelType - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ModelType saveModel(ModelType modelType) throws BluePrintException { + Preconditions.checkNotNull(modelType, "Model Type Information is missing."); + ModelTypeValidator.validateModelType(modelType); Optional dbModelType = modelTypeRepository.findByModelName(modelType.getModelName()); @@ -118,60 +114,34 @@ public class ModelTypeService { /** * This is a deleteByModelName service * - * @param modelName - * @throws BluePrintException + * @param modelName modelName */ - public void deleteByModelName(String modelName) throws BluePrintException { - if (modelName != null) { - modelTypeRepository.deleteByModelName(modelName); - } else { - throw new BluePrintException("Model Name Information is missing."); - } - } + public void deleteByModelName(String modelName) { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Model Name Information is missing."); + modelTypeRepository.deleteByModelName(modelName); - /** - * This is a getModelTypeByTags service - * - * @param tags - * @return List - * @throws BluePrintException - */ - public List getModelTypeByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("Model Tag Information is missing."); - } } /** * This is a getModelTypeByDefinitionType service * - * @param definitionType + * @param definitionType definitionType * @return List - * @throws BluePrintException */ - public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { - if (StringUtils.isNotBlank(definitionType)) { - return modelTypeRepository.findByDefinitionType(definitionType); - } else { - throw new BluePrintException("Model definitionType Information is missing."); - } + public List getModelTypeByDefinitionType(String definitionType) { + Preconditions.checkArgument(StringUtils.isNotBlank(definitionType), "Model definitionType Information is missing."); + return modelTypeRepository.findByDefinitionType(definitionType); } /** * This is a getModelTypeByDerivedFrom service * - * @param derivedFrom + * @param derivedFrom derivedFrom * @return List - * @throws BluePrintException */ - public List getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException { - if (StringUtils.isNotBlank(derivedFrom)) { - return modelTypeRepository.findByDerivedFrom(derivedFrom); - } else { - throw new BluePrintException("Model derivedFrom Information is missing."); - } + public List getModelTypeByDerivedFrom(String derivedFrom) { + Preconditions.checkArgument(StringUtils.isNotBlank(derivedFrom), "Model derivedFrom Information is missing."); + return modelTypeRepository.findByDerivedFrom(derivedFrom); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java index 16031b6e0..c53040e2b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java @@ -37,7 +37,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ Optional findByName(String name); @@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByNameIn(List names); @@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByTagsContainingIgnoreCase(String tags); @@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository Date: Wed, 12 Sep 2018 16:26:31 +0000 Subject: Controller Blueprints Microservice Add dynamic resource source mapping rest service. Change-Id: I59274a4c0162bc6718c4248788c0e7f36830a129 Issue-ID: CCSDK-556 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ApplicationRegistrationService.java | 26 +++++++++++++++++++--- .../service/ResourceDictionaryService.java | 13 +++++++++-- .../service/rs/ResourceDictionaryRest.java | 7 ++++++ 3 files changed, 41 insertions(+), 5 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java index 5a4a2877e..fc7410f96 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java @@ -17,20 +17,40 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.collections.CollectionUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; +import java.util.List; @Component @SuppressWarnings("unused") public class ApplicationRegistrationService { + private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class); + + @Value("#{'${resourceSourceMappings}'.split(',')}") + private List resourceSourceMappings; @PostConstruct - public void register(){ + public void register() { registerDictionarySources(); } - public void registerDictionarySources(){ - + public void registerDictionarySources() { + log.info("Registering Dictionary Sources : {}", resourceSourceMappings); + if (CollectionUtils.isNotEmpty(resourceSourceMappings)) { + resourceSourceMappings.forEach(resourceSourceMapping -> { + String[] mappingKeyValue = resourceSourceMapping.split("="); + if (mappingKeyValue != null && mappingKeyValue.length == 2) { + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping(mappingKeyValue[0].trim(), mappingKeyValue[1].trim()); + } else { + log.warn("failed to get resource source mapping {}", resourceSourceMapping); + } + }); + } } } 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 62aa0e29c..fd73db3b6 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 @@ -22,8 +22,9 @@ 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.data.PropertyDefinition; -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.ResourceSourceMapping; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; 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; @@ -105,7 +106,7 @@ public class ResourceDictionaryService { */ public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); - Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing"); + Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing"); ResourceDefinition resourceDefinition = resourceDictionary.getDefinition(); Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content"); @@ -153,4 +154,12 @@ public class ResourceDictionaryService { Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); resourceDictionaryRepository.deleteByName(name); } + + /** + * This is a getResourceSourceMapping service + * + */ + public ResourceSourceMapping getResourceSourceMapping() { + return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); + } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index e0cf6c69b..287d413cc 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.springframework.http.MediaType; @@ -76,4 +77,10 @@ public class ResourceDictionaryRest { } + @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ResourceSourceMapping getResourceSourceMapping() { + return resourceDictionaryService.getResourceSourceMapping(); + } + } -- cgit From 99f4a1e766cf27d35fb7b68b4904d1e49e7fa787 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Sep 2018 00:20:34 +0000 Subject: Controller Blueprints Microservice Add resource assignment enhancement and validation to blueprint validation and enhancement. Change-Id: I547760012e7014cfbb7a1e3a1d8ffb77edc9b6a2 Issue-ID: CCSDK-562 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 23 +++-- .../service/BluePrintRepoDBService.java | 97 ----------------- .../service/ResourceDefinitionRepoDBService.java | 115 +++++++++++++++++++++ 3 files changed, 129 insertions(+), 106 deletions(-) delete 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/ResourceDefinitionRepoDBService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 8e98f9477..ef3b4a48f 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 @@ -25,12 +25,13 @@ import org.jetbrains.annotations.NotNull; 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.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -48,14 +49,18 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); + private ResourceAssignmentEnhancerService resourceAssignmentEnhancerService; + private Map recipeDataTypes = new HashMap<>(); - public BluePrintEnhancerService(BluePrintRepoService bluePrintEnhancerRepoDBService) { - super(bluePrintEnhancerRepoDBService); + public BluePrintEnhancerService(ResourceDefinitionRepoService resourceDefinitionRepoService, + ResourceAssignmentEnhancerService resourceAssignmentEnhancerService) { + super(resourceDefinitionRepoService); + this.resourceAssignmentEnhancerService = resourceAssignmentEnhancerService; } @Override - public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException{ + public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException { super.enrichTopologyTemplate(serviceTemplate); // Update the Recipe Inputs and DataTypes @@ -101,7 +106,7 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { // Modified for ONAP converted Object to JsonNode JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES); - log.info("Processing Receipe Names : {} ", recipeNames); + log.info("Processing Recipe Names : {} ", recipeNames); if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) { @@ -159,6 +164,9 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); + // Enhance Resource Assignment + resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); + dataTypeProperties = new HashMap<>(); for (ResourceAssignment resourceAssignment : resourceAssignments) { @@ -167,9 +175,6 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { && resourceAssignment.getProperty() != null && StringUtils.isNotBlank(resourceAssignment.getName())) { - // Enrich the Property Definition - super.enrichPropertyDefinition(resourceAssignment.getName(), resourceAssignment.getProperty()); - dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty()); } 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 deleted file mode 100644 index 5510e480c..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java +++ /dev/null @@ -1,97 +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; - -import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.jetbrains.annotations.NotNull; -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 reactor.core.publisher.Mono; - -import java.util.Optional; - -/** - * BluePrintRepoDBService - * - * @author Brinda Santh - */ -@Service -@SuppressWarnings("unused") -public class BluePrintRepoDBService implements BluePrintRepoService { - - private ModelTypeRepository modelTypeRepository; - @SuppressWarnings("unused") - public BluePrintRepoDBService(ModelTypeRepository modelTypeRepository) { - this.modelTypeRepository = modelTypeRepository; - } - - @Override - public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { - return getModelType(nodeTypeName, NodeType.class); - } - - @Override - public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { - return getModelType(dataTypeName, DataType.class); - } - - @Override - public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { - return getModelType(artifactTypeName, ArtifactType.class); - } - - @Override - public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { - return getModelType(relationshipTypeName, RelationshipType.class); - } - - @Override - public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { - return getModelType(capabilityDefinitionName, CapabilityDefinition.class); - } - - private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing"); - - return getModelDefinition(modelName).map(modelDefinition -> { - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(modelDefinition, valueClass); - } - ); - } - - private Mono getModelDefinition(String modelName) throws BluePrintException { - JsonNode modelDefinition; - 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 Mono.just(modelDefinition); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java new file mode 100644 index 000000000..16cc8415c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java @@ -0,0 +1,115 @@ +/* + * 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.fasterxml.jackson.databind.JsonNode; +import com.google.common.base.Preconditions; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.data.*; +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.ResourceDefinitionRepoService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.Optional; + +/** + * ResourceDefinitionRepoDBService + * + * @author Brinda Santh + */ +@Service +@SuppressWarnings("unused") +public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoService { + + private ModelTypeRepository modelTypeRepository; + private ResourceDictionaryRepository resourceDictionaryRepository; + + @SuppressWarnings("unused") + public ResourceDefinitionRepoDBService(ModelTypeRepository modelTypeRepository, + ResourceDictionaryRepository resourceDictionaryRepository) { + this.modelTypeRepository = modelTypeRepository; + this.resourceDictionaryRepository = resourceDictionaryRepository; + } + + @Override + public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { + return getModelType(nodeTypeName, NodeType.class); + } + + @Override + public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { + return getModelType(dataTypeName, DataType.class); + } + + @Override + public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { + return getModelType(artifactTypeName, ArtifactType.class); + } + + @Override + public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { + return getModelType(relationshipTypeName, RelationshipType.class); + } + + @Override + public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { + return getModelType(capabilityDefinitionName, CapabilityDefinition.class); + } + + @NotNull + @Override + public Mono getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException{ + Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); + if(dbResourceDictionary.isPresent()){ + return Mono.just(dbResourceDictionary.get().getDefinition()); + }else{ + throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); + } + } + + private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing"); + + return getModelDefinition(modelName).map(modelDefinition -> { + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)); + return JacksonUtils.readValue(modelDefinition, valueClass); + } + ); + } + + private Mono getModelDefinition(String modelName) throws BluePrintException { + JsonNode modelDefinition; + 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 Mono.just(modelDefinition); + } +} -- cgit From 9d2613f87aac3742d681f8dce3e0b82faf601081 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Mon, 24 Sep 2018 14:01:08 -0400 Subject: SDN Controller Blueprints Processor Changing Date Format to consume Blueprints Model Artifact Change-Id: I07a48e4781c27aeff6cec4d1cdeb3539e768f4e9 Issue-ID: CCSDK-596 Signed-off-by: Singal, Kapil (ks220y) --- .../apps/controllerblueprints/service/domain/ConfigModelSearch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java index 6ec39ab55..b6f0f0019 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java @@ -49,7 +49,7 @@ public class ConfigModelSearch implements Serializable { @Column(name = "internal_version") private Integer internalVersion; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy KK:mm:ss a Z") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") @LastModifiedDate @Temporal(TemporalType.TIMESTAMP) @Column(name = "creation_date") -- cgit From 6488fc3cdaf0ea48687f98acc14f689c42f64427 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Sat, 10 Nov 2018 11:54:05 -0500 Subject: Controller Design Studio Upgrade Spring Boot and Kotlin versions. Change-Id: If0d7d0f476d8cfd23916013ff1ab554b26bc6b7a Issue-ID: CCSDK-658 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java index dc24c3bfe..e9ee1bc0a 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -121,7 +121,7 @@ public class ConfigModelUtils { File blueprintDir = new File(pathName); Preconditions.checkNotNull(blueprintDir, "failed to find the blueprint pathName file"); String[] dirs = blueprintDir.list(DirectoryFileFilter.INSTANCE); - Preconditions.checkNotNull(dirs, "failed to find the blueprint directories"); + Preconditions.checkNotNull(dirs, "failed to find the blueprint directories" + blueprintDir.getAbsolutePath()); return Arrays.asList(dirs); } } -- cgit From e407c61c8834f714175d2dc9761ae1b99ee0a1ea Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Sat, 10 Nov 2018 18:02:29 -0500 Subject: Controller Blueprints Microservice Change Application Properties and Docker Blueprint model load Parameters. Change-Id: I799cbab4388916c8e07e9453d93214e788a16fa2 Issue-ID: CCSDK-660 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../apps/controllerblueprints/service/DataBaseInitService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index cfcf93d29..92fe8def0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -39,11 +39,11 @@ import com.att.eelf.configuration.EELFManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; import java.io.IOException; import java.nio.charset.Charset; import java.util.List; @@ -94,8 +94,8 @@ public class DataBaseInitService { } - @PostConstruct @SuppressWarnings("unused") + @EventListener(ApplicationReadyEvent.class) private void initDatabase() { log.info("loading dataTypePath from DIR : {}", dataTypePath); log.info("loading nodeTypePath from DIR : {}", nodeTypePath); -- cgit From eb8c2ccdc80163c141c1114d9d2609ac510a6486 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 12 Nov 2018 15:08:40 -0500 Subject: Controller Blueprints Microservice Add blueprint multiple import file capability. Change-Id: If57aecb08447252b0e84a7e55b081e682d6a0bbd Issue-ID: CCSDK-681 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../ccsdk/apps/controllerblueprints/service/DataBaseInitService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 92fe8def0..a4eb2ae72 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -105,7 +105,8 @@ public class DataBaseInitService { loadModelType(); loadResourceDictionary(); - loadBlueprints(); + // TODO("Enable after Multi file Service Template Repository implementation in place") + //loadBlueprints(); } private void loadModelType() { -- cgit From 84dd2cf102ad1346c061bb0f1f17cc1516f3565f Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 20 Nov 2018 12:31:18 +0530 Subject: Sonar Fix: ModelTypeRest.java fixed sonar issues across this file. Issue-ID: CCSDK-733 Change-Id: I37f587b31290c53e261f0ad15c3099e63cd28ed6 Signed-off-by: Arundathi Patil --- .../ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 988cad064..0f485a081 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -44,18 +44,18 @@ public class ModelTypeRest { } @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { + public ModelType getModelTypeByName(@PathVariable(value = "name") String name) { return modelTypeService.getModelTypeByName(name); } @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public List searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException { + public List searchModelTypes(@PathVariable(value = "tags") String tags) { return modelTypeService.searchModelTypes(tags); } @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException { + List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) { return modelTypeService.getModelTypeByDefinitionType(definitionType); } @@ -66,7 +66,7 @@ public class ModelTypeRest { } @DeleteMapping(path = "/{name}") - public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException { + public void deleteModelTypeByName(@PathVariable(value = "name") String name) { modelTypeService.deleteByModelName(name); } } -- cgit From 63a8b15412390883beaef2c4a76bf5625cb8f584 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Mon, 26 Nov 2018 22:45:46 +0530 Subject: Sonar Issue: ConfigModelContent.java Fixed sonar issue/code-smells across this file Issue-ID: CCSDK-750 Change-Id: I93f97c54bd0e169801cb55bfaa2fa0ae3fd00780 Signed-off-by: Arundathi Patil --- .../apps/controllerblueprints/service/domain/ConfigModelContent.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index ae374a786..71904fb30 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -76,11 +76,10 @@ public class ConfigModelContent { @Override public String toString() { - String builder = "[" + "id = " + id + + return "[" + "id = " + id + ", name = " + name + ", contentType = " + contentType + "]"; - return builder; } @Override -- cgit From 23f826ffd5dcbc0dbf8e3cd9e0ff1c9e01e3f90e Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 27 Nov 2018 11:06:07 +0530 Subject: Sonar Fix: DataBaseInitService.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-751 Change-Id: Id23ba470761de5470b37a5b52830b064fbbf934b Signed-off-by: Arundathi Patil --- .../controllerblueprints/service/DataBaseInitService.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index a4eb2ae72..a1a9b9ca6 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -63,6 +63,7 @@ public class DataBaseInitService { private ModelTypeService modelTypeService; private ResourceDictionaryService resourceDictionaryService; private ConfigModelService configModelService; + private String updateBySystem = "System"; @Value("${load.dataTypePath}") private String dataTypePath; @@ -105,8 +106,6 @@ public class DataBaseInitService { loadModelType(); loadResourceDictionary(); - // TODO("Enable after Multi file Service Template Repository implementation in place") - //loadBlueprints(); } private void loadModelType() { @@ -188,6 +187,7 @@ public class DataBaseInitService { throw new BluePrintException("couldn't get dictionary from content information"); } } catch (Exception e) { + log.error("Exception", e); errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage()); } } @@ -223,6 +223,7 @@ public class DataBaseInitService { log.info("Loaded service template successfully: {}", fileName); } catch (Exception e) { + log.error("Exception", e); errorBuilder.appendln("load config model " + fileName + " error : " + e.getMessage()); } } @@ -250,12 +251,13 @@ public class DataBaseInitService { modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(nodeKey); modelType.setVersion(nodeType.getVersion()); - modelType.setUpdatedBy("System"); + modelType.setUpdatedBy(updateBySystem); modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + "," + nodeType.getDerivedFrom()); modelTypeService.saveModel(modelType); log.trace("Loaded Node Type successfully : {}", file.getFilename()); } catch (Exception e) { + log.error("Exception", e); errorBuilder.appendln("Node type loading error : " + file.getFilename() + ":" + e.getMessage()); } } @@ -274,12 +276,13 @@ public class DataBaseInitService { modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(dataKey); modelType.setVersion(dataType.getVersion()); - modelType.setUpdatedBy("System"); + modelType.setUpdatedBy(updateBySystem); modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); modelTypeService.saveModel(modelType); log.trace(" Loaded Data Type successfully : {}", file.getFilename()); } catch (Exception e) { + log.error("Exception", e); errorBuilder.appendln("Data type loading error : " + file.getFilename() + ":" + e.getMessage()); } } @@ -298,12 +301,13 @@ public class DataBaseInitService { modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); modelType.setModelName(dataKey); modelType.setVersion(artifactType.getVersion()); - modelType.setUpdatedBy("System"); + modelType.setUpdatedBy(updateBySystem); modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); modelTypeService.saveModel(modelType); log.trace("Loaded Artifact Type successfully : {}", file.getFilename()); } catch (Exception e) { + log.error("Exception", e); errorBuilder.appendln("Artifact type loading error : " + file.getFilename() + ":" + e.getMessage()); } } -- cgit From c9616a64578e55f0e4b3b61d9b7b9e1f70824199 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 27 Nov 2018 11:12:54 +0530 Subject: Sonar Fix: ConfigModelRest.java Fixed sonar issue/code-smells across this file Issue-ID: CCSDK-752 Change-Id: I5f3bdb30d8d0c5bf074609d1e93e2566c3ccb098 Signed-off-by: Arundathi Patil --- .../ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index fc2956bea..95e551b14 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -81,7 +81,7 @@ public class ConfigModelRest { @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - List searchConfigModels(@PathVariable(value = "tags") String tags) throws BluePrintException { + List searchConfigModels(@PathVariable(value = "tags") String tags) { return this.configModelService.searchConfigModels(tags); } -- cgit From 4b85a8e36c40b4d8ec8199c3467c3cc179ecf35d Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 13 Nov 2018 14:37:17 +0530 Subject: Sonar issue-ApplicationConstants.java Fixed sonar issues across this file. Issue-ID: CCSDK-684 Change-Id: I783a6294a30df1da35184bedc88ee77d10e98952 Signed-off-by: Arundathi Patil --- .../controllerblueprints/service/common/ApplicationConstants.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java index 8dd748404..d16f1b135 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java @@ -23,11 +23,12 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common; * @version 1.0 */ public final class ApplicationConstants { - private ApplicationConstants() { - - } public static final String ACTIVE_Y = "Y"; public static final String ACTIVE_N = "N"; public static final String ASDC_ARTIFACT_TYPE_SDNC_MODEL = "SDNC_MODEL"; + + private ApplicationConstants() { + + } } -- cgit From b74bd11d41816545b64f190e111a7eba6312b445 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Fri, 30 Nov 2018 15:26:32 +0530 Subject: Sonar fix: ModelType.java Fixed sonar issues/code-smells across this file. Issue-ID: CCSDK-771 Change-Id: I9a36c9b5a955cfa027de3a2c002634ac1755d68d Signed-off-by: Arundathi Patil --- .../onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index d8fea60e5..33c7ae42b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -84,7 +84,7 @@ public class ModelType implements Serializable { @Override public String toString() { - String buffer = "[" + ", modelName = " + modelName + + return "[" + ", modelName = " + modelName + ", derivedFrom = " + derivedFrom + ", definitionType = " + definitionType + ", description = " + description + @@ -93,7 +93,6 @@ public class ModelType implements Serializable { ", updatedBy = " + updatedBy + ", tags = " + tags + "]"; - return buffer; } public String getModelName() { -- cgit From f6fa604cae4a0d5ac6c565af3f411abebd900e3d Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Fri, 30 Nov 2018 15:39:16 +0530 Subject: Sonar Fix: ResourceDictionary.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-772 Change-Id: If7bbf087a50ede882bd469d60c660ccf60bc5521 Signed-off-by: Arundathi Patil --- .../apps/controllerblueprints/service/domain/ResourceDictionary.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java index 42c8e83b2..5352d9c96 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java @@ -78,7 +78,7 @@ public class ResourceDictionary implements Serializable { @Override public String toString() { - String buffer = "[" + ", name = " + name + + return "[" + ", name = " + name + ", dataType = " + dataType + ", entrySchema = " + entrySchema + ", definition =" + definition + @@ -87,7 +87,6 @@ public class ResourceDictionary implements Serializable { ", tags = " + tags + ", creationDate = " + creationDate + "]"; - return buffer; } public String getName() { -- cgit From 0c892f0699b40409ed21cf3ec9c092430b607a17 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Fri, 30 Nov 2018 15:45:42 +0530 Subject: Sonar Fix: ResourceDictionaryRest.java Fixed sonar issues/code-smells across this file. Issue-ID: CCSDK-773 Change-Id: I28a6ebef8f59c32a309ead8ddc032d51c6b0e36d Signed-off-by: Arundathi Patil --- .../service/rs/ResourceDictionaryRest.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index 287d413cc..9b2209e8b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -47,13 +47,12 @@ public class ResourceDictionaryRest { @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) - throws BluePrintException { + ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) { return resourceDictionaryService.saveResourceDictionary(dataDictionary); } @DeleteMapping(path = "/{name}") - public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { + public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) { resourceDictionaryService.deleteResourceDictionary(name); } @@ -65,14 +64,13 @@ public class ResourceDictionaryRest { @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - List searchResourceDictionaryByNames(@RequestBody List names) - throws BluePrintException { + List searchResourceDictionaryByNames(@RequestBody List names) { return resourceDictionaryService.searchResourceDictionaryByNames(names); } @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) throws BluePrintException { + List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) { return resourceDictionaryService.searchResourceDictionaryByTags(tags); } -- cgit From 58a60b154e08c7b210df0c1fb72999e79477d745 Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Fri, 30 Nov 2018 17:57:02 +0530 Subject: fixed sonar issues in SwaggerGenerator.java fixed sonar issues Issue-ID: CCSDK-525 Change-Id: I50b6b8ac8676294f70be1a98755e0069dd489b5a Signed-off-by: Sandeep J --- .../service/common/SwaggerGenerator.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java index 81f7d7018..77de8e7cf 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.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. @@ -40,6 +41,7 @@ import java.util.*; public class SwaggerGenerator { private ServiceTemplate serviceTemplate; + public static final String INPUTS="inputs"; /** * This is a SwaggerGenerator constructor @@ -54,8 +56,7 @@ public class SwaggerGenerator { * @return String */ public String generateSwagger() { - String swaggerContent = null; - + Swagger swagger = new Swagger().info(getInfo()); swagger.setPaths(getPaths()); @@ -86,7 +87,7 @@ public class SwaggerGenerator { List parameters = new ArrayList<>(); Parameter in = new BodyParameter().schema(new RefModel("#/definitions/inputs")); in.setRequired(true); - in.setName("inputs"); + in.setName(INPUTS); parameters.add(in); post.setParameters(parameters); @@ -107,18 +108,17 @@ public class SwaggerGenerator { Map models = new HashMap<>(); ModelImpl inputmodel = new ModelImpl(); - inputmodel.setTitle("inputs"); + inputmodel.setTitle(INPUTS); serviceTemplate.getTopologyTemplate().getInputs().forEach((propertyName, property) -> { Property defProperty = getPropery(propertyName, property); inputmodel.property(propertyName, defProperty); }); - models.put("inputs", inputmodel); + models.put(INPUTS, inputmodel); if (MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { serviceTemplate.getDataTypes().forEach((name, dataType) -> { ModelImpl model = new ModelImpl(); model.setDescription(dataType.getDescription()); - // model.setType("object"); if (dataType != null && MapUtils.isNotEmpty(dataType.getProperties())) { dataType.getProperties().forEach((propertyName, property) -> { -- cgit From a93fcc05dddcda28bab438d5907611a44432b9be Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Fri, 30 Nov 2018 17:04:01 +0530 Subject: fixed sonar issues in DataBaseInitService.java fixed sonar issues Issue-ID: CCSDK-525 Change-Id: I1b38d9656ace1160b7fd93f336f43d37f0d17847 Signed-off-by: Sandeep J --- .../service/DataBaseInitService.java | 648 +++++++++++---------- 1 file changed, 325 insertions(+), 323 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index a1a9b9ca6..74faa4df1 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -1,323 +1,325 @@ -/* - * 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.collections.CollectionUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.text.StrBuilder; -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.data.ArtifactType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.stereotype.Component; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; - -/** - * DataBaseInitService.java Purpose: Provide DataBaseInitService Service - * - * @author Brinda Santh - * @version 1.0 - */ - -@Component -@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") -public class DataBaseInitService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); - private ModelTypeService modelTypeService; - private ResourceDictionaryService resourceDictionaryService; - private ConfigModelService configModelService; - private String updateBySystem = "System"; - - @Value("${load.dataTypePath}") - private String dataTypePath; - @Value("${load.nodeTypePath}") - private String nodeTypePath; - @Value("${load.artifactTypePath}") - private String artifactTypePath; - @Value("${load.resourceDictionaryPath}") - private String resourceDictionaryPath; - @Value("${load.blueprintsPath}") - private String bluePrintsPath; - - @Autowired - private ResourcePatternResolver resourceLoader; - - /** - * This is a DataBaseInitService, used to load the initial data - * - * @param modelTypeService modelTypeService - * @param resourceDictionaryService resourceDictionaryService - * @param configModelService configModelService - */ - public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService, - ConfigModelService configModelService) { - this.modelTypeService = modelTypeService; - this.resourceDictionaryService = resourceDictionaryService; - this.configModelService = configModelService; - log.info("DataBaseInitService started..."); - - } - - @SuppressWarnings("unused") - @EventListener(ApplicationReadyEvent.class) - private void initDatabase() { - log.info("loading dataTypePath from DIR : {}", dataTypePath); - log.info("loading nodeTypePath from DIR : {}", nodeTypePath); - log.info("loading artifactTypePath from DIR : {}", artifactTypePath); - log.info("loading resourceDictionaryPath from DIR : {}", resourceDictionaryPath); - log.info("loading bluePrintsPath from DIR : {}", bluePrintsPath); - - loadModelType(); - loadResourceDictionary(); - } - - private void loadModelType() { - log.info(" *************************** loadModelType **********************"); - try { - Resource[] dataTypefiles = getPathResources(dataTypePath, ".json"); - StrBuilder errorBuilder = new StrBuilder(); - for (Resource file : dataTypefiles) { - if (file != null) { - loadDataType(file, errorBuilder); - } - } - - Resource[] nodeTypefiles = getPathResources(nodeTypePath, ".json"); - for (Resource file : nodeTypefiles) { - if (file != null) { - loadNodeType(file, errorBuilder); - } - } - - - Resource[] artifactTypefiles = getPathResources(artifactTypePath, ".json"); - - for (Resource file : artifactTypefiles) { - if (file != null) { - loadArtifactType(file, errorBuilder); - } - } - - - if (!errorBuilder.isEmpty()) { - log.error(errorBuilder.toString()); - } - } catch (Exception e) { - log.error("Failed in Data type loading", e); - } - } - - private void loadResourceDictionary() { - log.info( - " *************************** loadResourceDictionary **********************"); - try { - Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, ".json"); - - StrBuilder errorBuilder = new StrBuilder(); - String fileName; - for (Resource file : dataTypefiles) { - try { - fileName = file.getFilename(); - log.trace("Loading : {}", fileName); - String definitionContent = getResourceContent(file); - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(definitionContent, ResourceDefinition.class); - if (resourceDefinition != null) { - Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition"); - ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setName(resourceDefinition.getName()); - resourceDictionary.setDefinition(resourceDefinition); - - Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing"); - resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); - resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); - if(resourceDefinition.getProperty().getEntrySchema() != null){ - resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType()); - } - resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); - if (StringUtils.isBlank(resourceDefinition.getTags())) { - resourceDictionary.setTags( - resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy() - + ", " + resourceDefinition.getUpdatedBy()); - - } else { - resourceDictionary.setTags(resourceDefinition.getTags()); - } - resourceDictionaryService.saveResourceDictionary(resourceDictionary); - - log.trace(" Loaded successfully : {}", file.getFilename()); - } else { - throw new BluePrintException("couldn't get dictionary from content information"); - } - } catch (Exception e) { - log.error("Exception", e); - errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage()); - } - } - if (!errorBuilder.isEmpty()) { - log.error(errorBuilder.toString()); - } - - - } catch (Exception e) { - log.error( - "Failed in Resource dictionary loading", e); - } - } - - private void loadBlueprints() { - log.info("*************************** loadServiceTemplate **********************"); - try { - List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(bluePrintsPath); - if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { - StrBuilder errorBuilder = new StrBuilder(); - for (String fileName : serviceTemplateDirs) { - try { - String bluePrintPath = this.bluePrintsPath.concat("/").concat(fileName); - log.debug("***** Loading service template : {}", bluePrintPath); - ConfigModel configModel = ConfigModelUtils.getConfigModel(bluePrintPath); - - configModel = this.configModelService.saveConfigModel(configModel); - - log.info("Publishing : {}", configModel.getId()); - - this.configModelService.publishConfigModel(configModel.getId()); - - log.info("Loaded service template successfully: {}", fileName); - - } catch (Exception e) { - log.error("Exception", e); - errorBuilder.appendln("load config model " + fileName + " error : " + e.getMessage()); - } - } - - if (!errorBuilder.isEmpty()) { - log.error(errorBuilder.toString()); - } - } - } catch (Exception e) { - log.error("Failed in Service Template loading", e); - } - } - - private void loadNodeType(Resource file, StrBuilder errorBuilder) { - try { - log.trace("Loading Node Type : {}", file.getFilename()); - String nodeKey = file.getFilename().replace(".json", ""); - String definitionContent = getResourceContent(file); - NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); - Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename())); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); - modelType.setDerivedFrom(nodeType.getDerivedFrom()); - modelType.setDescription(nodeType.getDescription()); - modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); - modelType.setModelName(nodeKey); - modelType.setVersion(nodeType.getVersion()); - modelType.setUpdatedBy(updateBySystem); - modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + "," - + nodeType.getDerivedFrom()); - modelTypeService.saveModel(modelType); - log.trace("Loaded Node Type successfully : {}", file.getFilename()); - } catch (Exception e) { - log.error("Exception", e); - errorBuilder.appendln("Node type loading error : " + file.getFilename() + ":" + e.getMessage()); - } - } - - private void loadDataType(@NotNull Resource file, StrBuilder errorBuilder) { - try { - log.trace("Loading Data Type: {}", file.getFilename()); - String dataKey = file.getFilename().replace(".json", ""); - String definitionContent = getResourceContent(file); - DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); - Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename())); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setDerivedFrom(dataType.getDerivedFrom()); - modelType.setDescription(dataType.getDescription()); - modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); - modelType.setModelName(dataKey); - modelType.setVersion(dataType.getVersion()); - modelType.setUpdatedBy(updateBySystem); - modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelTypeService.saveModel(modelType); - log.trace(" Loaded Data Type successfully : {}", file.getFilename()); - } catch (Exception e) { - log.error("Exception", e); - errorBuilder.appendln("Data type loading error : " + file.getFilename() + ":" + e.getMessage()); - } - } - - private void loadArtifactType(Resource file, StrBuilder errorBuilder) { - try { - log.trace("Loading Artifact Type: {}", file.getFilename()); - String dataKey = file.getFilename().replace(".json", ""); - String definitionContent = getResourceContent(file); - ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); - Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename())); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); - modelType.setDerivedFrom(artifactType.getDerivedFrom()); - modelType.setDescription(artifactType.getDescription()); - modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); - modelType.setModelName(dataKey); - modelType.setVersion(artifactType.getVersion()); - modelType.setUpdatedBy(updateBySystem); - modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); - modelTypeService.saveModel(modelType); - log.trace("Loaded Artifact Type successfully : {}", file.getFilename()); - } catch (Exception e) { - log.error("Exception", e); - errorBuilder.appendln("Artifact type loading error : " + file.getFilename() + ":" + e.getMessage()); - } - } - - private Resource[] getPathResources(String path, String extension) throws IOException { - return resourceLoader.getResources("file:" + path + "/*" + extension); - } - - private String getResourceContent(Resource resource) throws IOException { - return IOUtils.toString(resource.getInputStream(), Charset.defaultCharset()); - } - -} +/* + * 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.collections.CollectionUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.text.StrBuilder; +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.data.ArtifactType; +import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; +import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; + +/** + * DataBaseInitService.java Purpose: Provide DataBaseInitService Service + * + * @author Brinda Santh + * @version 1.0 + */ + +@Component +@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") +public class DataBaseInitService { + + private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); + private ModelTypeService modelTypeService; + private ResourceDictionaryService resourceDictionaryService; + private ConfigModelService configModelService; + private String updateBySystem = "System"; + private static final String JSON_EXTN= ".json"; + private static final String EXCEPTION= "Exception"; + + @Value("${load.dataTypePath}") + private String dataTypePath; + @Value("${load.nodeTypePath}") + private String nodeTypePath; + @Value("${load.artifactTypePath}") + private String artifactTypePath; + @Value("${load.resourceDictionaryPath}") + private String resourceDictionaryPath; + @Value("${load.blueprintsPath}") + private String bluePrintsPath; + + @Autowired + private ResourcePatternResolver resourceLoader; + + /** + * This is a DataBaseInitService, used to load the initial data + * + * @param modelTypeService modelTypeService + * @param resourceDictionaryService resourceDictionaryService + * @param configModelService configModelService + */ + public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService, + ConfigModelService configModelService) { + this.modelTypeService = modelTypeService; + this.resourceDictionaryService = resourceDictionaryService; + this.configModelService = configModelService; + log.info("DataBaseInitService started..."); + + } + + @SuppressWarnings("unused") + @EventListener(ApplicationReadyEvent.class) + private void initDatabase() { + log.info("loading dataTypePath from DIR : {}", dataTypePath); + log.info("loading nodeTypePath from DIR : {}", nodeTypePath); + log.info("loading artifactTypePath from DIR : {}", artifactTypePath); + log.info("loading resourceDictionaryPath from DIR : {}", resourceDictionaryPath); + log.info("loading bluePrintsPath from DIR : {}", bluePrintsPath); + + loadModelType(); + loadResourceDictionary(); + } + + private void loadModelType() { + log.info(" *************************** loadModelType **********************"); + try { + Resource[] dataTypefiles = getPathResources(dataTypePath, JSON_EXTN); + StrBuilder errorBuilder = new StrBuilder(); + for (Resource file : dataTypefiles) { + if (file != null) { + loadDataType(file, errorBuilder); + } + } + + Resource[] nodeTypefiles = getPathResources(nodeTypePath, JSON_EXTN); + for (Resource file : nodeTypefiles) { + if (file != null) { + loadNodeType(file, errorBuilder); + } + } + + + Resource[] artifactTypefiles = getPathResources(artifactTypePath, JSON_EXTN); + + for (Resource file : artifactTypefiles) { + if (file != null) { + loadArtifactType(file, errorBuilder); + } + } + + + if (!errorBuilder.isEmpty()) { + log.error(errorBuilder.toString()); + } + } catch (Exception e) { + log.error("Failed in Data type loading", e); + } + } + + private void loadResourceDictionary() { + log.info( + " *************************** loadResourceDictionary **********************"); + try { + Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, JSON_EXTN); + + StrBuilder errorBuilder = new StrBuilder(); + String fileName; + for (Resource file : dataTypefiles) { + try { + fileName = file.getFilename(); + log.trace("Loading : {}", fileName); + String definitionContent = getResourceContent(file); + ResourceDefinition resourceDefinition = + JacksonUtils.readValue(definitionContent, ResourceDefinition.class); + if (resourceDefinition != null) { + Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition"); + ResourceDictionary resourceDictionary = new ResourceDictionary(); + resourceDictionary.setName(resourceDefinition.getName()); + resourceDictionary.setDefinition(resourceDefinition); + + Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing"); + resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); + resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); + if(resourceDefinition.getProperty().getEntrySchema() != null){ + resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType()); + } + resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); + if (StringUtils.isBlank(resourceDefinition.getTags())) { + resourceDictionary.setTags( + resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy() + + ", " + resourceDefinition.getUpdatedBy()); + + } else { + resourceDictionary.setTags(resourceDefinition.getTags()); + } + resourceDictionaryService.saveResourceDictionary(resourceDictionary); + + log.trace(" Loaded successfully : {}", file.getFilename()); + } else { + throw new BluePrintException("couldn't get dictionary from content information"); + } + } catch (Exception e) { + log.error(EXCEPTION, e); + errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage()); + } + } + if (!errorBuilder.isEmpty()) { + log.error(errorBuilder.toString()); + } + + + } catch (Exception e) { + log.error( + "Failed in Resource dictionary loading", e); + } + } + + private void loadBlueprints() { + log.info("*************************** loadServiceTemplate **********************"); + try { + List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(bluePrintsPath); + if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { + StrBuilder errorBuilder = new StrBuilder(); + for (String fileName : serviceTemplateDirs) { + try { + String bluePrintPath = this.bluePrintsPath.concat("/").concat(fileName); + log.debug("***** Loading service template : {}", bluePrintPath); + ConfigModel configModel = ConfigModelUtils.getConfigModel(bluePrintPath); + + configModel = this.configModelService.saveConfigModel(configModel); + + log.info("Publishing : {}", configModel.getId()); + + this.configModelService.publishConfigModel(configModel.getId()); + + log.info("Loaded service template successfully: {}", fileName); + + } catch (Exception e) { + log.error(EXCEPTION, e); + errorBuilder.appendln("load config model " + fileName + " error : " + e.getMessage()); + } + } + + if (!errorBuilder.isEmpty()) { + log.error(errorBuilder.toString()); + } + } + } catch (Exception e) { + log.error("Failed in Service Template loading", e); + } + } + + private void loadNodeType(Resource file, StrBuilder errorBuilder) { + try { + log.trace("Loading Node Type : {}", file.getFilename()); + String nodeKey = file.getFilename().replace(JSON_EXTN, ""); + String definitionContent = getResourceContent(file); + NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); + Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename())); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); + modelType.setDerivedFrom(nodeType.getDerivedFrom()); + modelType.setDescription(nodeType.getDescription()); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); + modelType.setModelName(nodeKey); + modelType.setVersion(nodeType.getVersion()); + modelType.setUpdatedBy(updateBySystem); + modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + "," + + nodeType.getDerivedFrom()); + modelTypeService.saveModel(modelType); + log.trace("Loaded Node Type successfully : {}", file.getFilename()); + } catch (Exception e) { + log.error(EXCEPTION, e); + errorBuilder.appendln("Node type loading error : " + file.getFilename() + ":" + e.getMessage()); + } + } + + private void loadDataType(@NotNull Resource file, StrBuilder errorBuilder) { + try { + log.trace("Loading Data Type: {}", file.getFilename()); + String dataKey = file.getFilename().replace(JSON_EXTN, ""); + String definitionContent = getResourceContent(file); + DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); + Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename())); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(dataType.getDerivedFrom()); + modelType.setDescription(dataType.getDescription()); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); + modelType.setModelName(dataKey); + modelType.setVersion(dataType.getVersion()); + modelType.setUpdatedBy(updateBySystem); + modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelTypeService.saveModel(modelType); + log.trace(" Loaded Data Type successfully : {}", file.getFilename()); + } catch (Exception e) { + log.error(EXCEPTION, e); + errorBuilder.appendln("Data type loading error : " + file.getFilename() + ":" + e.getMessage()); + } + } + + private void loadArtifactType(Resource file, StrBuilder errorBuilder) { + try { + log.trace("Loading Artifact Type: {}", file.getFilename()); + String dataKey = file.getFilename().replace(JSON_EXTN, ""); + String definitionContent = getResourceContent(file); + ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); + Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename())); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); + modelType.setDerivedFrom(artifactType.getDerivedFrom()); + modelType.setDescription(artifactType.getDescription()); + modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); + modelType.setModelName(dataKey); + modelType.setVersion(artifactType.getVersion()); + modelType.setUpdatedBy(updateBySystem); + modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); + modelTypeService.saveModel(modelType); + log.trace("Loaded Artifact Type successfully : {}", file.getFilename()); + } catch (Exception e) { + log.error(EXCEPTION, e); + errorBuilder.appendln("Artifact type loading error : " + file.getFilename() + ":" + e.getMessage()); + } + } + + private Resource[] getPathResources(String path, String extension) throws IOException { + return resourceLoader.getResources("file:" + path + "/*" + extension); + } + + private String getResourceContent(Resource resource) throws IOException { + return IOUtils.toString(resource.getInputStream(), Charset.defaultCharset()); + } + +} -- cgit From c872d95d0c4f7b5227c0d05def39986e3eebe5b3 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Sat, 1 Dec 2018 19:54:07 -0500 Subject: Enable Webflux Service. Change-Id: I99bacee9b63aa788bb368dec60981bf19ea759c4 Issue-ID: CCSDK-781 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../ccsdk/apps/controllerblueprints/service/DataBaseInitService.java | 2 +- .../ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java | 2 +- .../apps/controllerblueprints/service/domain/ConfigModelContent.java | 1 + .../service/repository/ConfigModelContentRepository.java | 1 + .../ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java | 1 + .../onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java | 1 + .../apps/controllerblueprints/service/rs/ResourceDictionaryRest.java | 1 + .../ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java | 1 + .../ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java | 1 + 9 files changed, 9 insertions(+), 2 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java index 74faa4df1..a4b874eef 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java @@ -54,7 +54,7 @@ import java.util.List; * @author Brinda Santh * @version 1.0 */ - +@Deprecated @Component @ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") public class DataBaseInitService { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java index 04a95fd12..ff8b07a9d 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -37,7 +37,7 @@ import java.util.Map; * @author Brinda Santh * @version 1.0 */ - +@Deprecated public class SchemaGeneratorService { private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorService.class); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java index 71904fb30..561354713 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java @@ -62,6 +62,7 @@ public class ConfigModelContent { @Column(name = "description") private String description; + @Deprecated @Lob @Column(name = "content", nullable = false) @ApiModelProperty(required=true) diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java index 733cbbdb3..81c26373b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java @@ -31,6 +31,7 @@ import java.util.Optional; * @author Brinda Santh * @version 1.0 */ +@Deprecated @Repository public interface ConfigModelContentRepository extends JpaRepository { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java index 95e551b14..b025b2ffa 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java @@ -27,6 +27,7 @@ import java.util.List; /** * {@inheritDoc} */ +@Deprecated @RestController @RequestMapping(value = "/api/v1/config-model") public class ConfigModelRest { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 0f485a081..69c209258 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -28,6 +28,7 @@ import java.util.List; /** * {@inheritDoc} */ +@Deprecated @RestController @RequestMapping(value = "/api/v1/model-type") public class ModelTypeRest { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index 9b2209e8b..932cdfac8 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -29,6 +29,7 @@ import java.util.List; /** * {@inheritDoc} */ +@Deprecated @RestController @RequestMapping(value = "/api/v1/dictionary") public class ResourceDictionaryRest { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index caa6bba4f..3798ee6d4 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -32,6 +32,7 @@ import java.util.List; /** * {@inheritDoc} */ +@Deprecated @RestController @RequestMapping(value = "/api/v1/service-template") public class ServiceTemplateRest { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java index e9ee1bc0a..3c6b14baf 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -37,6 +37,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +@Deprecated public class ConfigModelUtils { private ConfigModelUtils() { -- cgit From f44e9d39a0d162e76117b4624544497e2136fe6e Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 3 Dec 2018 12:34:39 -0500 Subject: Add Blueprint File utils Change-Id: I9896d934684343358d1c0c7e321725511430c7e6 Issue-ID: CCSDK-783 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 12 ++++++++---- .../service/ConfigModelValidatorService.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 ef3b4a48f..7ea81da04 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 @@ -17,6 +17,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; import com.google.common.base.Preconditions; import org.apache.commons.collections.MapUtils; @@ -25,13 +27,14 @@ import org.jetbrains.annotations.NotNull; 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.resource.dict.service.ResourceDefinitionRepoService; -import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionRepoService; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -45,6 +48,7 @@ import java.util.Map; */ @Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS) public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java index 21b00f8c2..3abdc04d2 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java @@ -30,7 +30,7 @@ import org.springframework.stereotype.Service; * @author Brinda Santh * @version 1.0 */ - +@Deprecated @Service public class ConfigModelValidatorService { -- cgit From 5af5cf4e6abeeec0c5ec0ad5108765a150499567 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 4 Dec 2018 10:54:12 +0530 Subject: Sonar Fix: ServiceTemplateRest.java Fixed sonar issues/code-smells across this file Issue-ID: CCSDK-784 Change-Id: Iedd7c18960ae0db2b19ac7defaecea973891502c Signed-off-by: Arundathi Patil --- .../apps/controllerblueprints/service/rs/ServiceTemplateRest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java index 3798ee6d4..4c34881a9 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java @@ -75,8 +75,7 @@ public class ServiceTemplateRest { @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) - throws BluePrintException { + List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) { return serviceTemplateService.generateResourceAssignments(templateContent); } -- cgit From fa5a3d31885891420a562002a8aea896124d4029 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 4 Dec 2018 20:53:22 -0500 Subject: Add Netconf Executor Function module Change-Id: If264e63d4fc4305bc26dc6b249a462afefcbfe1e Issue-ID: CCSDK-790 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../apps/controllerblueprints/service/BluePrintEnhancerService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 7ea81da04..aaa45e143 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 @@ -34,7 +34,6 @@ import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhanc import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -48,7 +47,7 @@ import java.util.Map; */ @Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS) +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); -- cgit From 531a413df27cfa10910d558342e35edc56c6491d Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Tue, 11 Dec 2018 16:41:46 +0530 Subject: fixed sonar issue in ConfigModelCreateService fixed sonar issue Issue-ID: CCSDK-552 Change-Id: Icbc15de5e0ce425e49e695ece5d40d990b45984e Signed-off-by: Sandeep J --- .../apps/controllerblueprints/service/ConfigModelCreateService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index 3c92f7e94..1875a8022 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -127,7 +127,7 @@ public class ConfigModelCreateService { String artifactName = configModel.getArtifactName(); String artifactVersion = configModel.getArtifactVersion(); String author = configModel.getUpdatedBy(); - // configModel.setTags(artifactName); + if (StringUtils.isBlank(author)) { throw new BluePrintException("Artifact Author is missing in the Service Template"); -- cgit From 29ebc35c200d77c49ea7c989d48bb51a8927c5c6 Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Tue, 11 Dec 2018 17:10:13 +0530 Subject: fixed sonar issues in ConfigModelService.java fixed sonar issues Issue-ID: CCSDK-552 Change-Id: Iab02d1cee2b0cb9e182f9d4af839000307ec99bf Signed-off-by: Sandeep J --- .../apps/controllerblueprints/service/ConfigModelService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java index a2f653c67..b2fff26ef 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java @@ -55,6 +55,7 @@ public class ConfigModelService { private ConfigModelRepository configModelRepository; private ConfigModelContentRepository configModelContentRepository; private ConfigModelCreateService configModelCreateService; + private static final String CONFIG_MODEL_ID_FAILURE_MSG= "failed to get config model id(%d) from repo"; /** * This is a ConfigModelService constructor. @@ -174,7 +175,7 @@ public class ConfigModelService { if (dbConfigModel.isPresent()) { configModel = dbConfigModel.get(); } else { - throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id)); + throw new BluePrintException(String.format(CONFIG_MODEL_ID_FAILURE_MSG, id)); } return configModel; @@ -232,7 +233,7 @@ public class ConfigModelService { } } } else { - throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id)); + throw new BluePrintException(String.format(CONFIG_MODEL_ID_FAILURE_MSG, id)); } return cloneConfigModel; @@ -252,7 +253,7 @@ public class ConfigModelService { configModelContentRepository.deleteByConfigModel(dbConfigModel.get()); configModelRepository.delete(dbConfigModel.get()); } else { - throw new BluePrintException(String.format("failed to get config model id(%d) from repo", id)); + throw new BluePrintException(String.format(CONFIG_MODEL_ID_FAILURE_MSG, id)); } } -- cgit From a490a2830aaa1345fd506df5dd4d913c67784da6 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 11 Dec 2018 19:40:51 -0500 Subject: Implement Enhancer Framework Interfaces Change-Id: Iff85dc50f87ab6d6f7d9ceb4a309ea6e4d55e362 Issue-ID: CCSDK-803 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 9 +++--- .../service/ResourceDefinitionRepoDBService.java | 36 ++++++++++------------ 2 files changed, 22 insertions(+), 23 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 aaa45e143..91df33318 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 @@ -30,7 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.*; 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.ResourceDefinitionRepoService; -import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerDefaultService; +import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerServiceImpl; import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; @@ -46,9 +46,10 @@ import java.util.Map; * @author Brinda Santh DATE : 8/8/2018 */ +@Deprecated @Service @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { +public class BluePrintEnhancerService extends BluePrintEnhancerServiceImpl { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); @@ -167,8 +168,8 @@ public class BluePrintEnhancerService extends BluePrintEnhancerDefaultService { JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); - // Enhance Resource Assignment - resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); + // Enhance Resource Assignment TODO("Plug Resource Assignment Enhancer Service") + //resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); dataTypeProperties = new HashMap<>(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java index 16cc8415c..0af5d9d3e 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java @@ -31,7 +31,6 @@ import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionar import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; import java.util.Optional; @@ -55,54 +54,53 @@ public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoSe } @Override - public Mono getNodeType(@NotNull String nodeTypeName) throws BluePrintException { + public NodeType getNodeType(@NotNull String nodeTypeName) throws BluePrintException { return getModelType(nodeTypeName, NodeType.class); } @Override - public Mono getDataType(@NotNull String dataTypeName) throws BluePrintException { + public DataType getDataType(@NotNull String dataTypeName) throws BluePrintException { return getModelType(dataTypeName, DataType.class); } @Override - public Mono getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { + public ArtifactType getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { return getModelType(artifactTypeName, ArtifactType.class); } @Override - public Mono getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { + public RelationshipType getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { return getModelType(relationshipTypeName, RelationshipType.class); } @Override - public Mono getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { + public CapabilityDefinition getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { return getModelType(capabilityDefinitionName, CapabilityDefinition.class); } @NotNull @Override - public Mono getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException{ + public ResourceDefinition getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException { Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); - if(dbResourceDictionary.isPresent()){ - return Mono.just(dbResourceDictionary.get().getDefinition()); - }else{ + if (dbResourceDictionary.isPresent()) { + return dbResourceDictionary.get().getDefinition(); + } else { throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); } } - private Mono getModelType(String modelName, Class valueClass) throws BluePrintException { + private T getModelType(String modelName, Class valueClass) throws BluePrintException { Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Failed to get model from repo, model name is missing"); - return getModelDefinition(modelName).map(modelDefinition -> { - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - return JacksonUtils.readValue(modelDefinition, valueClass); - } - ); + JsonNode modelDefinition = getModelDefinition(modelName); + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)); + + return JacksonUtils.readValue(modelDefinition, valueClass); } - private Mono getModelDefinition(String modelName) throws BluePrintException { + private JsonNode getModelDefinition(String modelName) throws BluePrintException { JsonNode modelDefinition; Optional modelTypeDb = modelTypeRepository.findByModelName(modelName); if (modelTypeDb.isPresent()) { @@ -110,6 +108,6 @@ public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoSe } else { throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)); } - return Mono.just(modelDefinition); + return modelDefinition; } } -- cgit From 58941edd551c2a3f324a5b0750e254151cec66c9 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 12 Dec 2018 10:03:26 -0500 Subject: Decompose enhancer to multiple types. Change-Id: I508ce5919680f6e7f994776e58404729b55eace8 Issue-ID: CCSDK-803 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 47 +--------------------- .../service/ServiceTemplateService.java | 6 +-- 2 files changed, 2 insertions(+), 51 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 91df33318..930c88d8d 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 @@ -29,12 +29,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.*; 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.ResourceDefinitionRepoService; -import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.BluePrintEnhancerServiceImpl; import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; @@ -47,9 +42,7 @@ import java.util.Map; */ @Deprecated -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class BluePrintEnhancerService extends BluePrintEnhancerServiceImpl { +public class BluePrintEnhancerService { private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); @@ -57,44 +50,6 @@ public class BluePrintEnhancerService extends BluePrintEnhancerServiceImpl { private Map recipeDataTypes = new HashMap<>(); - public BluePrintEnhancerService(ResourceDefinitionRepoService resourceDefinitionRepoService, - ResourceAssignmentEnhancerService resourceAssignmentEnhancerService) { - super(resourceDefinitionRepoService); - this.resourceAssignmentEnhancerService = resourceAssignmentEnhancerService; - } - - @Override - public void enrichTopologyTemplate(@NotNull ServiceTemplate serviceTemplate) throws BluePrintException { - super.enrichTopologyTemplate(serviceTemplate); - - // Update the Recipe Inputs and DataTypes - populateRecipeInputs(serviceTemplate); - } - - - @Override - public void enrichNodeTemplate(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) throws BluePrintException { - super.enrichNodeTemplate(nodeTemplateName, nodeTemplate); - - String nodeTypeName = nodeTemplate.getType(); - log.info("*** Enriching NodeType: {}", nodeTypeName); - // Get NodeType from Repo and Update Service Template - NodeType nodeType = super.populateNodeType(nodeTypeName); - - // Enrich NodeType - super.enrichNodeType(nodeTypeName, nodeType); - - // Custom for Artifact Population - if (StringUtils.isNotBlank(nodeType.getDerivedFrom()) - && ConfigModelConstant.MODEL_TYPE_NODE_ARTIFACT.equalsIgnoreCase(nodeType.getDerivedFrom())) { - populateArtifactTemplateMappingDataType(nodeTemplateName, nodeTemplate); - } - - //Enrich Node Template Artifacts - super.enrichNodeTemplateArtifactDefinition(nodeTemplateName, nodeTemplate); - - } - private void populateArtifactTemplateMappingDataType(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) throws BluePrintException { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 898647eaa..57096c7fd 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -43,7 +43,6 @@ public class ServiceTemplateService { private ResourceDictionaryRepository dataDictionaryRepository; private ConfigModelCreateService configModelCreateService; - private BluePrintEnhancerService bluePrintEnhancerService; private ResourceAssignmentValidationService resourceAssignmentValidationService; /** @@ -51,16 +50,13 @@ public class ServiceTemplateService { * * @param dataDictionaryRepository dataDictionaryRepository * @param configModelCreateService configModelCreateService - * @param bluePrintEnhancerService bluePrintEnhancerService * @param resourceAssignmentValidationService resourceAssignmentValidationService */ public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, ConfigModelCreateService configModelCreateService, - BluePrintEnhancerService bluePrintEnhancerService, ResourceAssignmentValidationService resourceAssignmentValidationService) { this.dataDictionaryRepository = dataDictionaryRepository; this.configModelCreateService = configModelCreateService; - this.bluePrintEnhancerService = bluePrintEnhancerService; this.resourceAssignmentValidationService = resourceAssignmentValidationService; } @@ -82,7 +78,7 @@ public class ServiceTemplateService { * @return ServiceTemplate */ public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - this.bluePrintEnhancerService.enhance(serviceTemplate); + //FIXME("Connect New Enrichment service") return serviceTemplate; } -- cgit From 132c8fd5be0cedc747e36d203a076ef594922f83 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Wed, 12 Dec 2018 16:49:04 -0500 Subject: Add multiple location repo for enhancer. Change-Id: I5333b30fad8d754caf8dc89956132e4637f28c26 Issue-ID: CCSDK-803 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ResourceDefinitionRepoDBService.java | 113 --------------------- .../ResourceDefinitionValidationService.java | 2 +- 2 files changed, 1 insertion(+), 114 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java deleted file mode 100644 index 0af5d9d3e..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionRepoDBService.java +++ /dev/null @@ -1,113 +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; - -import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.*; -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.ResourceDefinitionRepoService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.springframework.stereotype.Service; - -import java.util.Optional; - -/** - * ResourceDefinitionRepoDBService - * - * @author Brinda Santh - */ -@Service -@SuppressWarnings("unused") -public class ResourceDefinitionRepoDBService implements ResourceDefinitionRepoService { - - private ModelTypeRepository modelTypeRepository; - private ResourceDictionaryRepository resourceDictionaryRepository; - - @SuppressWarnings("unused") - public ResourceDefinitionRepoDBService(ModelTypeRepository modelTypeRepository, - ResourceDictionaryRepository resourceDictionaryRepository) { - this.modelTypeRepository = modelTypeRepository; - this.resourceDictionaryRepository = resourceDictionaryRepository; - } - - @Override - public NodeType getNodeType(@NotNull String nodeTypeName) throws BluePrintException { - return getModelType(nodeTypeName, NodeType.class); - } - - @Override - public DataType getDataType(@NotNull String dataTypeName) throws BluePrintException { - return getModelType(dataTypeName, DataType.class); - } - - @Override - public ArtifactType getArtifactType(@NotNull String artifactTypeName) throws BluePrintException { - return getModelType(artifactTypeName, ArtifactType.class); - } - - @Override - public RelationshipType getRelationshipType(@NotNull String relationshipTypeName) throws BluePrintException { - return getModelType(relationshipTypeName, RelationshipType.class); - } - - @Override - public CapabilityDefinition getCapabilityDefinition(@NotNull String capabilityDefinitionName) throws BluePrintException { - return getModelType(capabilityDefinitionName, CapabilityDefinition.class); - } - - @NotNull - @Override - public ResourceDefinition getResourceDefinition(@NotNull String resourceDefinitionName) throws BluePrintException { - Optional dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName); - if (dbResourceDictionary.isPresent()) { - return dbResourceDictionary.get().getDefinition(); - } else { - throw new BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)); - } - } - - private T getModelType(String modelName, Class valueClass) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing"); - - JsonNode modelDefinition = getModelDefinition(modelName); - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)); - - return JacksonUtils.readValue(modelDefinition, valueClass); - } - - private JsonNode getModelDefinition(String modelName) throws BluePrintException { - JsonNode modelDefinition; - 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/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java index d3bf42302..485896627 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java @@ -16,7 +16,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionDefaultValidationService; import org.springframework.stereotype.Service; -- cgit From 3854151c6f07ae1bb4c68ce114aae247011f98c8 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 13 Dec 2018 15:10:35 -0500 Subject: Add blueprint runtime service to validator Change-Id: I0e4375e422b55002f1666ee9e61a1469482f77d2 Issue-ID: CCSDK-757 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ConfigModelCreateService.java | 19 +++--- .../service/ConfigModelValidatorService.java | 67 ---------------------- .../ResourceAssignmentValidationService.java | 29 ---------- .../ResourceDefinitionValidationService.java | 29 ---------- .../service/ResourceDictionaryService.java | 4 +- .../service/ServiceTemplateService.java | 1 + .../service/rs/ResourceDictionaryRest.java | 2 +- .../validator/ServiceTemplateValidator.java | 4 +- 8 files changed, 14 insertions(+), 141 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java index 1875a8022..fa8e32b69 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -17,6 +17,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; @@ -31,8 +33,6 @@ import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConsta import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.io.IOException; @@ -48,25 +48,21 @@ import java.util.Optional; * @author Brinda Santh * @version 1.0 */ - +@Deprecated @Service public class ConfigModelCreateService { private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelCreateService.class); private ConfigModelRepository configModelRepository; - private ConfigModelValidatorService configModelValidatorService; /** * This is a ConfigModelCreateService * - * @param configModelRepository ConfigModelRepository - * @param configModelValidatorService ConfigModelValidatorService + * @param configModelRepository ConfigModelRepository */ - public ConfigModelCreateService(ConfigModelRepository configModelRepository, - ConfigModelValidatorService configModelValidatorService) { + public ConfigModelCreateService(ConfigModelRepository configModelRepository) { this.configModelRepository = configModelRepository; - this.configModelValidatorService = configModelValidatorService; } /** @@ -127,7 +123,7 @@ public class ConfigModelCreateService { String artifactName = configModel.getArtifactName(); String artifactVersion = configModel.getArtifactVersion(); String author = configModel.getUpdatedBy(); - + if (StringUtils.isBlank(author)) { throw new BluePrintException("Artifact Author is missing in the Service Template"); @@ -326,6 +322,7 @@ public class ConfigModelCreateService { * @throws BluePrintException BluePrintException */ public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - return this.configModelValidatorService.validateServiceTemplate(serviceTemplate); + // FIXME("Plug right Validator") + return serviceTemplate; } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java deleted file mode 100644 index 3abdc04d2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelValidatorService.java +++ /dev/null @@ -1,67 +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.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator; -import org.springframework.stereotype.Service; - -/** - * ServiceTemplateValidatorService.java Purpose: Provide Service to Validate Service Model Template - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Service -public class ConfigModelValidatorService { - - /** - * This is a validateServiceTemplate - * - * @param serviceTemplateContent - * @return ServiceTemplate - * @throws BluePrintException - */ - public ServiceTemplate validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(serviceTemplateContent), "Service Template Content is (" + serviceTemplateContent + ") not Defined."); - ServiceTemplate serviceTemplate = - JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - return validateServiceTemplate(serviceTemplate); - } - - /** - * This is a enhanceServiceTemplate - * - * @param serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException - */ - @SuppressWarnings("squid:S00112") - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined."); - ServiceTemplateValidator validator = new ServiceTemplateValidator(); - validator.validateServiceTemplate(serviceTemplate); - return serviceTemplate; - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java deleted file mode 100644 index 1228e2eeb..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceAssignmentValidationService.java +++ /dev/null @@ -1,29 +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 org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationDefaultService; -import org.springframework.stereotype.Service; -/** - * ResourceAssignmentValidationService. - * - * @author Brinda Santh - */ -@Service -public class ResourceAssignmentValidationService extends ResourceAssignmentValidationDefaultService { - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java deleted file mode 100644 index 485896627..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.interfaces.BluePrintRepoService; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionDefaultValidationService; -import org.springframework.stereotype.Service; - -@Service -public class ResourceDefinitionValidationService extends ResourceDefinitionDefaultValidationService { - - public ResourceDefinitionValidationService(BluePrintRepoService bluePrintRepoService) { - super(bluePrintRepoService); - } -} 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 fd73db3b6..eacc90251 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 @@ -25,6 +25,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; 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; @@ -104,7 +105,7 @@ public class ResourceDictionaryService { * @param resourceDictionary resourceDictionary * @return DataDictionary */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) throws BluePrintException { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing"); @@ -157,7 +158,6 @@ public class ResourceDictionaryService { /** * This is a getResourceSourceMapping service - * */ public ResourceSourceMapping getResourceSourceMapping() { return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java index 57096c7fd..60a83f9bd 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java @@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; 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.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index 932cdfac8..504420426 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -48,7 +48,7 @@ public class ResourceDictionaryRest { @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) { + ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { return resourceDictionaryService.saveResourceDictionary(dataDictionary); } 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 index 42adf1a3e..c5e9e86f4 100644 --- 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 @@ -29,7 +29,7 @@ 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.ResourceAssignmentValidationDefaultService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationService; import java.util.HashMap; @@ -114,7 +114,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { if (BluePrintConstants.MODEL_TYPE_NODE_ARTIFACT.equals(derivedFrom)) { List resourceAssignment = getResourceAssignments(nodeTemplate); - ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationDefaultService(); + ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl(); resourceAssignmentValidationService.validate(resourceAssignment); } } -- cgit From ed2e6c9ab708184398718ed0c112806e32a23d05 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 14 Dec 2018 16:41:37 -0500 Subject: Add blueprint resource definition enrichment. Change-Id: I01234093028ffdc8bf1688e41baba20fae7da5ce Issue-ID: CCSDK-747 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/BluePrintEnhancerService.java | 174 --------------------- 1 file changed, 174 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 deleted file mode 100644 index 930c88d8d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintEnhancerService.java +++ /dev/null @@ -1,174 +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; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -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.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.data.*; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.service.enhancer.ResourceAssignmentEnhancerService; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * BluePrintEnhancerService - * - * @author Brinda Santh DATE : 8/8/2018 - */ - -@Deprecated -public class BluePrintEnhancerService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(BluePrintEnhancerService.class); - - private ResourceAssignmentEnhancerService resourceAssignmentEnhancerService; - - private Map recipeDataTypes = new HashMap<>(); - - - private void populateArtifactTemplateMappingDataType(@NotNull String nodeTemplateName, @NotNull NodeTemplate nodeTemplate) - throws BluePrintException { - log.info("****** Processing Artifact Node Template : {}", nodeTemplateName); - - if (nodeTemplate.getProperties() != null) { - - if (!nodeTemplate.getProperties().containsKey(ConfigModelConstant.PROPERTY_RECIPE_NAMES)) { - throw new BluePrintException("Node Template (" + nodeTemplateName + ") doesn't have " - + ConfigModelConstant.PROPERTY_RECIPE_NAMES + " property."); - } - - // Modified for ONAP converted Object to JsonNode - JsonNode recipeNames = nodeTemplate.getProperties().get(ConfigModelConstant.PROPERTY_RECIPE_NAMES); - - log.info("Processing Recipe Names : {} ", recipeNames); - - if (recipeNames != null && recipeNames.isArray() && recipeNames.size() > 0) { - - Map mappingProperties = - getCapabilityMappingProperties(nodeTemplateName, nodeTemplate); - - for (JsonNode recipeNameNode : recipeNames) { - String recipeName = recipeNameNode.textValue(); - processRecipe(nodeTemplateName, mappingProperties, recipeName); - } - } - } - } - - private void processRecipe(@NotNull String nodeTemplateName, Map mappingProperties, String recipeName) { - if (StringUtils.isNotBlank(recipeName)) { - DataType recipeDataType = this.recipeDataTypes.get(recipeName); - if (recipeDataType == null) { - log.info("DataType not present for the recipe({})", recipeName); - recipeDataType = new DataType(); - recipeDataType.setVersion("1.0.0"); - recipeDataType.setDescription( - "This is Dynamic Data type definition generated from resource mapping for the config template name " - + nodeTemplateName + "."); - recipeDataType.setDerivedFrom(ConfigModelConstant.MODEL_TYPE_DATA_TYPE_DYNAMIC); - Map dataTypeProperties = new HashMap<>(); - recipeDataType.setProperties(dataTypeProperties); - } else { - log.info("DataType Already present for the recipe({})", recipeName); - } - - // Merge all the Recipe Properties - mergeDataTypeProperties(recipeDataType, mappingProperties); - - // Overwrite Recipe DataType - this.recipeDataTypes.put(recipeName, recipeDataType); - - } - } - - private Map getCapabilityMappingProperties(String nodeTemplateName, - NodeTemplate nodeTemplate) throws BluePrintException { - - Map dataTypeProperties = null; - if (nodeTemplate != null && MapUtils.isNotEmpty(nodeTemplate.getCapabilities())) { - CapabilityAssignment capability = - nodeTemplate.getCapabilities().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); - - if (capability != null && capability.getProperties() != null) { - - String resourceAssignmentContent = JacksonUtils - .getJson(capability.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING)); - - List resourceAssignments = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); - - Preconditions.checkNotNull(resourceAssignments, "Failed to Processing Resource Mapping " + resourceAssignmentContent); - // Enhance Resource Assignment TODO("Plug Resource Assignment Enhancer Service") - //resourceAssignmentEnhancerService.enhanceBluePrint(this, resourceAssignments); - - dataTypeProperties = new HashMap<>(); - - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null - // && Boolean.valueOf(resourceAssignment.getInputParameter()) - && resourceAssignment.getProperty() != null - && StringUtils.isNotBlank(resourceAssignment.getName())) { - - dataTypeProperties.put(resourceAssignment.getName(), resourceAssignment.getProperty()); - - } - } - - } - } - return dataTypeProperties; - } - - private void mergeDataTypeProperties(DataType dataType, Map mergeProperties) { - if (dataType != null && dataType.getProperties() != null && mergeProperties != null) { - // Add the Other Template Properties - mergeProperties.forEach((mappingKey, propertyDefinition) -> dataType.getProperties().put(mappingKey, propertyDefinition)); - } - } - - private void populateRecipeInputs(ServiceTemplate serviceTemplate) { - if (serviceTemplate.getTopologyTemplate() != null - && MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs()) - && MapUtils.isNotEmpty(this.recipeDataTypes) - && MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { - this.recipeDataTypes.forEach((recipeName, recipeDataType) -> { - String dataTypePrefix = recipeName.replace("-action", "") + "-request"; - String dataTypeName = "dt-" + dataTypePrefix; - - serviceTemplate.getDataTypes().put(dataTypeName, recipeDataType); - - PropertyDefinition customInputProperty = new PropertyDefinition(); - customInputProperty.setDescription("This is Dynamic Data type for the receipe " + recipeName + "."); - customInputProperty.setRequired(Boolean.FALSE); - customInputProperty.setType(dataTypeName); - serviceTemplate.getTopologyTemplate().getInputs().put(dataTypePrefix, customInputProperty); - - }); - } - } -} -- cgit From 8899e7a0f1ba7481cbcbe7ff581c285a9d0e98b6 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 14 Dec 2018 20:38:44 -0500 Subject: Add multiple path load service. Change-Id: Ib2e5f60663991d097b7446106bb883a45db1bdb8 Issue-ID: CCSDK-746 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/DataBaseInitService.java | 325 --------------------- 1 file changed, 325 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java deleted file mode 100644 index a4b874eef..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/DataBaseInitService.java +++ /dev/null @@ -1,325 +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; - -import com.google.common.base.Preconditions; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.text.StrBuilder; -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.data.ArtifactType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.stereotype.Component; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.List; - -/** - * DataBaseInitService.java Purpose: Provide DataBaseInitService Service - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Component -@ConditionalOnProperty(name = "blueprints.load.initial-data", havingValue = "true") -public class DataBaseInitService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(DataBaseInitService.class); - private ModelTypeService modelTypeService; - private ResourceDictionaryService resourceDictionaryService; - private ConfigModelService configModelService; - private String updateBySystem = "System"; - private static final String JSON_EXTN= ".json"; - private static final String EXCEPTION= "Exception"; - - @Value("${load.dataTypePath}") - private String dataTypePath; - @Value("${load.nodeTypePath}") - private String nodeTypePath; - @Value("${load.artifactTypePath}") - private String artifactTypePath; - @Value("${load.resourceDictionaryPath}") - private String resourceDictionaryPath; - @Value("${load.blueprintsPath}") - private String bluePrintsPath; - - @Autowired - private ResourcePatternResolver resourceLoader; - - /** - * This is a DataBaseInitService, used to load the initial data - * - * @param modelTypeService modelTypeService - * @param resourceDictionaryService resourceDictionaryService - * @param configModelService configModelService - */ - public DataBaseInitService(ModelTypeService modelTypeService, ResourceDictionaryService resourceDictionaryService, - ConfigModelService configModelService) { - this.modelTypeService = modelTypeService; - this.resourceDictionaryService = resourceDictionaryService; - this.configModelService = configModelService; - log.info("DataBaseInitService started..."); - - } - - @SuppressWarnings("unused") - @EventListener(ApplicationReadyEvent.class) - private void initDatabase() { - log.info("loading dataTypePath from DIR : {}", dataTypePath); - log.info("loading nodeTypePath from DIR : {}", nodeTypePath); - log.info("loading artifactTypePath from DIR : {}", artifactTypePath); - log.info("loading resourceDictionaryPath from DIR : {}", resourceDictionaryPath); - log.info("loading bluePrintsPath from DIR : {}", bluePrintsPath); - - loadModelType(); - loadResourceDictionary(); - } - - private void loadModelType() { - log.info(" *************************** loadModelType **********************"); - try { - Resource[] dataTypefiles = getPathResources(dataTypePath, JSON_EXTN); - StrBuilder errorBuilder = new StrBuilder(); - for (Resource file : dataTypefiles) { - if (file != null) { - loadDataType(file, errorBuilder); - } - } - - Resource[] nodeTypefiles = getPathResources(nodeTypePath, JSON_EXTN); - for (Resource file : nodeTypefiles) { - if (file != null) { - loadNodeType(file, errorBuilder); - } - } - - - Resource[] artifactTypefiles = getPathResources(artifactTypePath, JSON_EXTN); - - for (Resource file : artifactTypefiles) { - if (file != null) { - loadArtifactType(file, errorBuilder); - } - } - - - if (!errorBuilder.isEmpty()) { - log.error(errorBuilder.toString()); - } - } catch (Exception e) { - log.error("Failed in Data type loading", e); - } - } - - private void loadResourceDictionary() { - log.info( - " *************************** loadResourceDictionary **********************"); - try { - Resource[] dataTypefiles = getPathResources(resourceDictionaryPath, JSON_EXTN); - - StrBuilder errorBuilder = new StrBuilder(); - String fileName; - for (Resource file : dataTypefiles) { - try { - fileName = file.getFilename(); - log.trace("Loading : {}", fileName); - String definitionContent = getResourceContent(file); - ResourceDefinition resourceDefinition = - JacksonUtils.readValue(definitionContent, ResourceDefinition.class); - if (resourceDefinition != null) { - Preconditions.checkNotNull(resourceDefinition.getProperty(), "Failed to get Property Definition"); - ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setName(resourceDefinition.getName()); - resourceDictionary.setDefinition(resourceDefinition); - - Preconditions.checkNotNull(resourceDefinition.getProperty(), "Property field is missing"); - resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); - resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); - if(resourceDefinition.getProperty().getEntrySchema() != null){ - resourceDictionary.setEntrySchema(resourceDefinition.getProperty().getEntrySchema().getType()); - } - resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); - if (StringUtils.isBlank(resourceDefinition.getTags())) { - resourceDictionary.setTags( - resourceDefinition.getName() + ", " + resourceDefinition.getUpdatedBy() - + ", " + resourceDefinition.getUpdatedBy()); - - } else { - resourceDictionary.setTags(resourceDefinition.getTags()); - } - resourceDictionaryService.saveResourceDictionary(resourceDictionary); - - log.trace(" Loaded successfully : {}", file.getFilename()); - } else { - throw new BluePrintException("couldn't get dictionary from content information"); - } - } catch (Exception e) { - log.error(EXCEPTION, e); - errorBuilder.appendln("Dictionary loading Errors : " + file.getFilename() + ":" + e.getMessage()); - } - } - if (!errorBuilder.isEmpty()) { - log.error(errorBuilder.toString()); - } - - - } catch (Exception e) { - log.error( - "Failed in Resource dictionary loading", e); - } - } - - private void loadBlueprints() { - log.info("*************************** loadServiceTemplate **********************"); - try { - List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(bluePrintsPath); - if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { - StrBuilder errorBuilder = new StrBuilder(); - for (String fileName : serviceTemplateDirs) { - try { - String bluePrintPath = this.bluePrintsPath.concat("/").concat(fileName); - log.debug("***** Loading service template : {}", bluePrintPath); - ConfigModel configModel = ConfigModelUtils.getConfigModel(bluePrintPath); - - configModel = this.configModelService.saveConfigModel(configModel); - - log.info("Publishing : {}", configModel.getId()); - - this.configModelService.publishConfigModel(configModel.getId()); - - log.info("Loaded service template successfully: {}", fileName); - - } catch (Exception e) { - log.error(EXCEPTION, e); - errorBuilder.appendln("load config model " + fileName + " error : " + e.getMessage()); - } - } - - if (!errorBuilder.isEmpty()) { - log.error(errorBuilder.toString()); - } - } - } catch (Exception e) { - log.error("Failed in Service Template loading", e); - } - } - - private void loadNodeType(Resource file, StrBuilder errorBuilder) { - try { - log.trace("Loading Node Type : {}", file.getFilename()); - String nodeKey = file.getFilename().replace(JSON_EXTN, ""); - String definitionContent = getResourceContent(file); - NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); - Preconditions.checkNotNull(nodeType, String.format("failed to get node type from file : %s", file.getFilename())); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); - modelType.setDerivedFrom(nodeType.getDerivedFrom()); - modelType.setDescription(nodeType.getDescription()); - modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); - modelType.setModelName(nodeKey); - modelType.setVersion(nodeType.getVersion()); - modelType.setUpdatedBy(updateBySystem); - modelType.setTags(nodeKey + "," + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + "," - + nodeType.getDerivedFrom()); - modelTypeService.saveModel(modelType); - log.trace("Loaded Node Type successfully : {}", file.getFilename()); - } catch (Exception e) { - log.error(EXCEPTION, e); - errorBuilder.appendln("Node type loading error : " + file.getFilename() + ":" + e.getMessage()); - } - } - - private void loadDataType(@NotNull Resource file, StrBuilder errorBuilder) { - try { - log.trace("Loading Data Type: {}", file.getFilename()); - String dataKey = file.getFilename().replace(JSON_EXTN, ""); - String definitionContent = getResourceContent(file); - DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); - Preconditions.checkNotNull(dataType, String.format("failed to get data type from file : %s", file.getFilename())); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setDerivedFrom(dataType.getDerivedFrom()); - modelType.setDescription(dataType.getDescription()); - modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); - modelType.setModelName(dataKey); - modelType.setVersion(dataType.getVersion()); - modelType.setUpdatedBy(updateBySystem); - modelType.setTags(dataKey + "," + dataType.getDerivedFrom() + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelTypeService.saveModel(modelType); - log.trace(" Loaded Data Type successfully : {}", file.getFilename()); - } catch (Exception e) { - log.error(EXCEPTION, e); - errorBuilder.appendln("Data type loading error : " + file.getFilename() + ":" + e.getMessage()); - } - } - - private void loadArtifactType(Resource file, StrBuilder errorBuilder) { - try { - log.trace("Loading Artifact Type: {}", file.getFilename()); - String dataKey = file.getFilename().replace(JSON_EXTN, ""); - String definitionContent = getResourceContent(file); - ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); - Preconditions.checkNotNull(artifactType, String.format("failed to get artifact type from file : %s", file.getFilename())); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); - modelType.setDerivedFrom(artifactType.getDerivedFrom()); - modelType.setDescription(artifactType.getDescription()); - modelType.setDefinition(JacksonUtils.jsonNode(definitionContent)); - modelType.setModelName(dataKey); - modelType.setVersion(artifactType.getVersion()); - modelType.setUpdatedBy(updateBySystem); - modelType.setTags(dataKey + "," + artifactType.getDerivedFrom() + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); - modelTypeService.saveModel(modelType); - log.trace("Loaded Artifact Type successfully : {}", file.getFilename()); - } catch (Exception e) { - log.error(EXCEPTION, e); - errorBuilder.appendln("Artifact type loading error : " + file.getFilename() + ":" + e.getMessage()); - } - } - - private Resource[] getPathResources(String path, String extension) throws IOException { - return resourceLoader.getResources("file:" + path + "/*" + extension); - } - - private String getResourceContent(Resource resource) throws IOException { - return IOUtils.toString(resource.getInputStream(), Charset.defaultCharset()); - } - -} -- cgit From 40d739b066bbc44b82e484ec204132c4652552b2 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Tue, 18 Dec 2018 08:16:28 -0500 Subject: Add attribute definition enhancer. Change-Id: Ie8ac60910f04dfca477d0276aa451821cfcd8510 Issue-ID: CCSDK-718 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java index 3c6b14baf..96931014b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java @@ -48,7 +48,7 @@ public class ConfigModelUtils { public static ConfigModel getConfigModel(String blueprintPath) throws Exception { Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing"); - ToscaMetaData toscaMetaData = BluePrintMetadataUtils.toscaMetaData(blueprintPath); + ToscaMetaData toscaMetaData = BluePrintMetadataUtils.Companion.toscaMetaData(blueprintPath); Preconditions.checkNotNull(toscaMetaData, "failed to get Blueprint Metadata information"); Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getEntityDefinitions()), "failed to get Blueprint Definition file"); -- cgit From 8e8bfd22535e03f6c7df847813b5eaadd07c73ef Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 20 Dec 2018 11:16:31 -0500 Subject: Add modelType service reactive compatible. Change-Id: I0058a8136fe9ad62781f3d4556d2b95d11507f3f Issue-ID: CCSDK-864 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../service/ModelTypeService.java | 148 ------------------ .../service/ResourceDictionaryService.java | 165 --------------------- .../service/domain/ModelType.java | 2 +- .../service/repository/ModelTypeRepository.java | 107 ------------- .../service/rs/ModelTypeRest.java | 10 +- .../service/rs/ResourceDictionaryRest.java | 22 +-- 6 files changed, 17 insertions(+), 437 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java deleted file mode 100644 index 925a6c492..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java +++ /dev/null @@ -1,148 +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; - -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.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ModelTypeValidator; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.Optional; - -/** - * ModelTypeService.java Purpose: Provide ModelTypeService Service ModelTypeService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -@Transactional -public class ModelTypeService { - - private ModelTypeRepository modelTypeRepository; - - /** - * This is a ModelTypeService, used to save and get the model types stored in database - * - * @param modelTypeRepository modelTypeRepository - */ - public ModelTypeService(ModelTypeRepository modelTypeRepository) { - this.modelTypeRepository = modelTypeRepository; - } - - - /** - * This is a getModelTypeByName service - * - * @param modelTypeName modelTypeName - * @return ModelType - */ - public ModelType getModelTypeByName(String modelTypeName) { - ModelType modelType = null; - Preconditions.checkArgument(StringUtils.isNotBlank(modelTypeName), "Model Name Information is missing."); - Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); - if (modelTypeOption.isPresent()) { - modelType = modelTypeOption.get(); - } - return modelType; - } - - - /** - * This is a searchModelTypes service - * - * @param tags tags - * @return List - */ - public List searchModelTypes(String tags) { - Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No Search Information provide"); - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } - - /** - * This is a saveModel service - * - * @param modelType modelType - * @return ModelType - * @throws BluePrintException BluePrintException - */ - public ModelType saveModel(ModelType modelType) throws BluePrintException { - - Preconditions.checkNotNull(modelType, "Model Type Information is missing."); - - ModelTypeValidator.validateModelType(modelType); - - Optional dbModelType = modelTypeRepository.findByModelName(modelType.getModelName()); - if (dbModelType.isPresent()) { - ModelType dbModel = dbModelType.get(); - dbModel.setDescription(modelType.getDescription()); - dbModel.setDefinition(modelType.getDefinition()); - dbModel.setDefinitionType(modelType.getDefinitionType()); - dbModel.setDerivedFrom(modelType.getDerivedFrom()); - dbModel.setTags(modelType.getTags()); - dbModel.setVersion(modelType.getVersion()); - dbModel.setUpdatedBy(modelType.getUpdatedBy()); - modelType = modelTypeRepository.save(dbModel); - } else { - modelType = modelTypeRepository.save(modelType); - } - return modelType; - } - - - /** - * This is a deleteByModelName service - * - * @param modelName modelName - */ - public void deleteByModelName(String modelName) { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Model Name Information is missing."); - modelTypeRepository.deleteByModelName(modelName); - - } - - /** - * This is a getModelTypeByDefinitionType service - * - * @param definitionType definitionType - * @return List - */ - public List getModelTypeByDefinitionType(String definitionType) { - Preconditions.checkArgument(StringUtils.isNotBlank(definitionType), "Model definitionType Information is missing."); - return modelTypeRepository.findByDefinitionType(definitionType); - } - - /** - * This is a getModelTypeByDerivedFrom service - * - * @param derivedFrom derivedFrom - * @return List - */ - public List getModelTypeByDerivedFrom(String derivedFrom) { - Preconditions.checkArgument(StringUtils.isNotBlank(derivedFrom), "Model derivedFrom Information is missing."); - return modelTypeRepository.findByDerivedFrom(derivedFrom); - } - - -} 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 deleted file mode 100644 index eacc90251..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ /dev/null @@ -1,165 +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; - -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.data.PropertyDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -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; - -import java.util.List; -import java.util.Optional; - -/** - * ResourceDictionaryService.java Purpose: Provide DataDictionaryService Service - * DataDictionaryService - * - * @author Brinda Santh - * @version 1.0 - */ -@Service -public class ResourceDictionaryService { - - private ResourceDictionaryRepository resourceDictionaryRepository; - - private ResourceDefinitionValidationService resourceDictionaryValidationService; - - /** - * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database - * - * @param dataDictionaryRepository dataDictionaryRepository - * @param resourceDictionaryValidationService resourceDictionaryValidationService - */ - public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository, - ResourceDefinitionValidationService resourceDictionaryValidationService) { - this.resourceDictionaryRepository = dataDictionaryRepository; - this.resourceDictionaryValidationService = resourceDictionaryValidationService; - } - - /** - * This is a getDataDictionaryByName service - * - * @param name name - * @return DataDictionary - * @throws BluePrintException BluePrintException - */ - public ResourceDictionary getResourceDictionaryByName(String name) throws BluePrintException { - Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); - Optional resourceDictionaryDb = resourceDictionaryRepository.findByName(name); - if (resourceDictionaryDb.isPresent()) { - return resourceDictionaryDb.get(); - } else { - throw new BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)); - } - } - - /** - * This is a searchResourceDictionaryByNames service - * - * @param names names - * @return List - */ - public List searchResourceDictionaryByNames(List names) { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide"); - return resourceDictionaryRepository.findByNameIn(names); - } - - /** - * This is a searchResourceDictionaryByTags service - * - * @param tags tags - * @return List - */ - public List searchResourceDictionaryByTags(String tags) { - Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide"); - return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); - } - - /** - * This is a saveDataDictionary service - * - * @param resourceDictionary resourceDictionary - * @return DataDictionary - */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) throws BluePrintException { - Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); - Preconditions.checkNotNull(resourceDictionary.getDefinition(), "Resource Dictionary definition information is missing"); - - ResourceDefinition resourceDefinition = resourceDictionary.getDefinition(); - Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content"); - // Validate the Resource Definitions - resourceDictionaryValidationService.validate(resourceDefinition); - - resourceDictionary.setTags(resourceDefinition.getTags()); - resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy()); - // Set the Property Definitions - PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); - resourceDictionary.setDescription(propertyDefinition.getDescription()); - resourceDictionary.setDataType(propertyDefinition.getType()); - if (propertyDefinition.getEntrySchema() != null) { - resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); - } - - ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary); - - Optional dbResourceDictionaryData = - resourceDictionaryRepository.findByName(resourceDictionary.getName()); - if (dbResourceDictionaryData.isPresent()) { - ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get(); - - dbResourceDictionary.setName(resourceDictionary.getName()); - dbResourceDictionary.setDefinition(resourceDictionary.getDefinition()); - dbResourceDictionary.setDescription(resourceDictionary.getDescription()); - dbResourceDictionary.setTags(resourceDictionary.getTags()); - dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy()); - dbResourceDictionary.setDataType(resourceDictionary.getDataType()); - dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema()); - resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary); - } else { - resourceDictionary = resourceDictionaryRepository.save(resourceDictionary); - } - - return resourceDictionary; - } - - /** - * This is a deleteResourceDictionary service - * - * @param name name - */ - public void deleteResourceDictionary(String name) { - Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); - resourceDictionaryRepository.deleteByName(name); - } - - /** - * This is a getResourceSourceMapping service - */ - public ResourceSourceMapping getResourceSourceMapping() { - return ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java index 33c7ae42b..65a135c19 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java @@ -84,7 +84,7 @@ public class ModelType implements Serializable { @Override public String toString() { - return "[" + ", modelName = " + modelName + + return "[" + "modelName = " + modelName + ", derivedFrom = " + derivedFrom + ", definitionType = " + definitionType + ", description = " + description + diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java deleted file mode 100644 index 27823ef33..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.java +++ /dev/null @@ -1,107 +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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - - -/** - * ModelTypeRepository.java Purpose: Provide Configuration Generator ModelTypeRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ModelTypeRepository extends JpaRepository { - - - /** - * This is a findByModelName method - * - * @param modelName Model Name - * @return Optional - */ - Optional findByModelName(String modelName); - - /** - * This is a findByModelNameIn method - * - * @param modelNames Model Names - * @return List - */ - List findByModelNameIn(List modelNames); - - /** - * This is a findByDerivedFrom method - * - * @param derivedFrom Derived From - * @return List - */ - List findByDerivedFrom(String derivedFrom); - - - /** - * This is a findByDerivedFromIn method - * - * @param derivedFroms Derived Froms - * @return List - */ - @SuppressWarnings("unused") - List findByDerivedFromIn(List derivedFroms); - - /** - * This is a findByDefinitionType method - * - * @param definitionType Definition Type - * @return List - */ - List findByDefinitionType(String definitionType); - - /** - * This is a findByDefinitionTypeIn method - * - * @param definitionTypes Definition Types - * @return List - */ - @SuppressWarnings("unused") - List findByDefinitionTypeIn(List definitionTypes); - - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags Tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); - - - /** - * This is a deleteByModelName method - * - * @param modelName ModelName - */ - void deleteByModelName(String modelName); - - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java index 69c209258..12ed0a579 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java @@ -18,8 +18,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.apps.controllerblueprints.service.handler.ModelTypeHandler; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -29,18 +29,18 @@ import java.util.List; * {@inheritDoc} */ @Deprecated -@RestController -@RequestMapping(value = "/api/v1/model-type") +//@RestController +//@RequestMapping(value = "/api/v1/model-type") public class ModelTypeRest { - private ModelTypeService modelTypeService; + private ModelTypeHandler modelTypeService; /** * This is a ModelTypeResourceImpl, used to save and get the model types stored in database * * @param modelTypeService Model Type Service */ - public ModelTypeRest(ModelTypeService modelTypeService) { + public ModelTypeRest(ModelTypeHandler modelTypeService) { this.modelTypeService = modelTypeService; } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java index 504420426..8b7a95776 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java @@ -19,8 +19,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.rs; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; -import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDictionaryService; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.apps.controllerblueprints.service.handler.ResourceDictionaryHandler; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -35,51 +35,51 @@ import java.util.List; public class ResourceDictionaryRest { - private ResourceDictionaryService resourceDictionaryService; + private ResourceDictionaryHandler resourceDictionaryHandler; /** * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database * - * @param dataDictionaryService Data Dictionary Service + * @param resourceDictionaryHandler Data Dictionary Handler */ - public ResourceDictionaryRest(ResourceDictionaryService dataDictionaryService) { - this.resourceDictionaryService = dataDictionaryService; + public ResourceDictionaryRest(ResourceDictionaryHandler resourceDictionaryHandler) { + this.resourceDictionaryHandler = resourceDictionaryHandler; } @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { - return resourceDictionaryService.saveResourceDictionary(dataDictionary); + return resourceDictionaryHandler.saveResourceDictionary(dataDictionary); } @DeleteMapping(path = "/{name}") public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) { - resourceDictionaryService.deleteResourceDictionary(name); + resourceDictionaryHandler.deleteResourceDictionary(name); } @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { - return resourceDictionaryService.getResourceDictionaryByName(name); + return resourceDictionaryHandler.getResourceDictionaryByName(name); } @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByNames(@RequestBody List names) { - return resourceDictionaryService.searchResourceDictionaryByNames(names); + return resourceDictionaryHandler.searchResourceDictionaryByNames(names); } @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) { - return resourceDictionaryService.searchResourceDictionaryByTags(tags); + return resourceDictionaryHandler.searchResourceDictionaryByTags(tags); } @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResourceSourceMapping getResourceSourceMapping() { - return resourceDictionaryService.getResourceSourceMapping(); + return resourceDictionaryHandler.getResourceSourceMapping(); } } -- cgit From a19a6d1683689ffcc95f160b0c2ed4718505e7f4 Mon Sep 17 00:00:00 2001 From: Steve Alphonse Siani Date: Fri, 21 Dec 2018 10:31:48 -0500 Subject: Applied comments from review: Change 74622 - Draft Change-Id: I8ec37a628af98a332f568dc254e499dfdcf886ce Issue-ID: CCSDK-418 Signed-off-by: Steve Alphonse Siani --- .../service/CBAContentService.java | 97 +++++++++++ .../service/CbaFileManagementService.java | 128 ++++++++++++++ .../controllerblueprints/service/CbaService.java | 192 +++++++++++++++++++++ .../service/CbaToDatabaseService.java | 132 ++++++++++++++ .../service/ConfigModelCreateService.java | 8 +- .../service/domain/CbaContent.java | 114 ++++++++++++ .../service/domain/ConfigModel.java | 12 ++ .../service/model/BlueprintModelResponse.java | 78 +++++++++ .../service/model/ItemCbaResponse.java | 58 +++++++ .../service/repository/CBAContentRepository.java | 59 +++++++ .../controllerblueprints/service/rs/CbaRest.java | 84 +++++++++ .../service/utils/CbaStateEnum.java | 15 ++ .../service/utils/CloseCondition.java | 36 ++++ 13 files changed, 1010 insertions(+), 3 deletions(-) create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java mode change 100644 => 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java mode change 100644 => 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java new file mode 100755 index 000000000..66ef6a934 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java @@ -0,0 +1,97 @@ +/* + * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.CBAContentRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +/** + * CBAContentService.java Purpose: Provide CBAContent Template Service processing + * CBAContentService + * + * @author Ruben Chang + * @version 1.0 + */ + +@Service +public class CBAContentService { + + private static EELFLogger log = EELFManager.getInstance().getLogger(CBAContentService.class); + + private CBAContentRepository cbaContentRepository; + + /** + * Constructor of the class + * @param cbaContentRepository CRUD methods for entity CBAContentRepository + */ + public CBAContentService(CBAContentRepository cbaContentRepository) { + this.cbaContentRepository = cbaContentRepository; + log.info("CBAContentRepository sucessfully instantiated"); + } + + /** + * Save the CBAContent into the CBA_CONTENT table + * @param cbaName The name of the file + * @param cbaVersion version number of the CBA archive + * @param cbaState int that would represent the state. Refer to the CbaStateEnum + * @param cbaDescription Brief description that would help to identify and recognize the CBA archive + * @param file the file + * @return CbaContent the record saved into the table CBA_CONTENT + */ + public CbaContent saveCBAContent(String cbaName, String cbaVersion, int cbaState, String cbaDescription, byte[] file){ + CbaContent cbaContent = new CbaContent(); + cbaContent.setCbaName(cbaName); + cbaContent.setCbaVersion(cbaVersion); + cbaContent.setCbaState(cbaState); + cbaContent.setCbaDescription(cbaDescription); + cbaContent.setCbaFile(file); + cbaContentRepository.saveAndFlush(cbaContent); + return cbaContent; + } + + /** + * Get the list of Controller Blueprint archives + * @return List list with the controller blueprint archives + */ + public List getList(){ + return cbaContentRepository.findAll(); + } + + /** + * Get a single Controller Blueprint archive by uuID + * @param uuID the userID controller blueprint identifier + * @return Optional + */ + public Optional findByUUID(String uuID) { + return cbaContentRepository.findById(uuID); + } + + /** + * Method deleteCBAById: Delete a CBA in data base with it associated Blueprint Model + * @param uuid the uuid that identify the CBA + */ + public void deleteCBAById(String uuid) { + cbaContentRepository.deleteById(uuid); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java new file mode 100755 index 000000000..2011172dc --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java @@ -0,0 +1,128 @@ +/* + * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.codec.multipart.FilePart; +import org.springframework.stereotype.Service; +import org.springframework.util.FileSystemUtils; +import org.springframework.util.StringUtils; +import reactor.core.publisher.Mono; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * CbaFileManagementService.java Purpose: Provide Service processing CBA file management + * + * @author Steve Siani + * @version 1.0 + */ +@Service +public class CbaFileManagementService { + private static EELFLogger log = EELFManager.getInstance().getLogger(CbaFileManagementService.class); + + @Value("${controllerblueprints.loadCbaExtension}") + private String cbaExtension; + + private static final String CBA_FILE_NAME_PATTERN = "CBA_{0}_{1}"; + + + /** + * cleanupSavedCBA: This method cleanup the Zip file and the unzip directory that was added. + * + * @param zipFileName zipFileName + * @param cbaFileLocation cbaFileLocation + * @return + * @throws BluePrintException BluePrintException + */ + public void cleanupSavedCBA(String zipFileName, Path cbaFileLocation) throws BluePrintException { + + String fileNameWithoutExtension = BluePrintFileUtils.Companion.stripFileExtension(zipFileName); + + //Delete the Zip file from the repository + FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(zipFileName,cbaFileLocation)); + + //Delete the CBA directory from the repository + FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(fileNameWithoutExtension,cbaFileLocation)); + } + + /** + * This is a saveCBAFile method + * take a {@link FilePart}, transfer it to disk using a Flux of FilePart and return a {@link Mono} representing the CBA file name + * + * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save + * @return a {@link Mono} String representing the result of the operation + * @throws (BluePrintException, IOException) BluePrintException, IOException + */ + public Mono saveCBAFile(FilePart filePart, Path targetDirectory) throws BluePrintException, IOException { + + // Normalize file name + final String fileName = StringUtils.cleanPath(filePart.filename()); + + // Check if the file's extension is "CBA" + if(!StringUtils.getFilenameExtension(fileName).equals(cbaExtension)) { + throw new BluePrintException("Invalid file extension required " + cbaExtension); + } + + // Change file name to match a pattern + String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); + + // Copy file to the target location (Replacing existing file with the same name) + Path targetLocation = targetDirectory.resolve(changedFileName); + + // if a file with the same name already exists in a repository, delete and recreate it + File file = new File(targetLocation.toString()); + if (file.exists()) + file.delete(); + file.createNewFile(); + + return filePart.transferTo(file).thenReturn(changedFileName); + } + + /** + * Decompress the file into the cbaFileLocation parameter + * @param zipFileName name of the zipped file + * @param cbaFileLocation path in which the zipped file will get decompressed + * @return String the path in which the file is decompressed + * @throws BluePrintException Exception in the process + */ + public String decompressCBAFile(final String zipFileName, Path cbaFileLocation) throws BluePrintException { + + File file = BluePrintFileUtils.Companion.getBluePrintFile(zipFileName, cbaFileLocation); + try { + Path directoryPath = Files.createDirectories(cbaFileLocation.resolve(BluePrintFileUtils.Companion.stripFileExtension(zipFileName))); + BluePrintArchiveUtils.Companion.deCompress(file, directoryPath.toString()); + return directoryPath.toString(); + + } catch (BluePrintProcessorException | IOException ex) { + throw new BluePrintException(" Fail to decompress " + zipFileName, ex); + } + + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java new file mode 100755 index 000000000..7d616a76f --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java @@ -0,0 +1,192 @@ +/* + * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse; +import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.multipart.FilePart; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * CbaService.java Purpose: Provide Service Template Service processing CbaService + * + * @author Steve Siani + * @version 1.0 + */ + +@Service +public class CbaService { + + private static EELFLogger log = EELFManager.getInstance().getLogger(CbaService.class); + + @Value("${controllerblueprints.blueprintArchivePath}") + private String cbaArchivePath; + private Path cbaLocation; + + @Autowired + private CbaFileManagementService cbaFileManagementService; + + @Autowired + private CbaToDatabaseService cbaToDatabaseService; + + + /** + * This method would be used by SpringBoot to initialize the cba location + */ + @EventListener(ApplicationReadyEvent.class) + private void initCbaService() { + this.cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaArchivePath); + log.info("CBA service Initiated..."); + } + + /** + * This is a uploadCBAFile method + * take a {@link FilePart}, transfer it to disk using WebFlux and return a {@link Mono} representing the result + * + * @param filePart - the request part containing the file to be saved + * @return a {@link Mono< BlueprintModelResponse >} representing the result of the operation + */ + public Mono uploadCBAFile(FilePart filePart) { + + try { + return this.cbaFileManagementService.saveCBAFile(filePart, cbaLocation).map(fileName -> { + ConfigModel configModel; + BlueprintModelResponse blueprintModelResponse = null; + + try { + String cbaDirectory = this.cbaFileManagementService.decompressCBAFile(fileName, cbaLocation); + configModel = this.cbaToDatabaseService.storeBluePrints(cbaDirectory, fileName, cbaLocation.resolve(fileName)); + blueprintModelResponse = new BlueprintModelResponse(configModel.getId(), configModel.getArtifactName(), configModel.getArtifactVersion(), configModel.getArtifactDescription(), configModel.getConfigModelCBA().getCbaUUID()); + } catch (BluePrintException be) { + Mono.error(new BluePrintException("Error loading CBA in database.", be)); + } finally { + try { + this.cbaFileManagementService.cleanupSavedCBA(fileName, cbaLocation); + } catch (BluePrintException be) { + Mono.error(new BluePrintException("Error while cleaning up.", be)); + } + } + return blueprintModelResponse; + }); + } catch (IOException | BluePrintException e) { + return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e)); + } + } + + /** + * This is a deleteCba method + * + * @param id id + * @throws BluePrintException BluePrintException + */ + public void deleteCBA(@NotNull Long id) throws BluePrintException { + this.cbaToDatabaseService.deleteCBA(id); + } + + /** + * This is a downloadCBAFile method to find the target file to download and return a file ressource using MONO + * + * @param (id) + * @return ResponseEntity + */ + public ResponseEntity downloadCBAFile(@NotNull String id) { + Optional optionalContent = this.cbaToDatabaseService.findByUUID(id); + + CbaContent cbaContent = optionalContent.get(); + + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + cbaContent.getCbaName() + "\"") + .body(new ByteArrayResource(cbaContent.getCbaFile())); + } + + /** + * This is a findCBAByID method to find a CBA By the UUID + * + * @param (id) + * @return ItemCbaResponse + */ + public ItemCbaResponse findCBAByID(@NotNull String id) { + ItemCbaResponse response = new ItemCbaResponse(); + Optional optionalContent = this.cbaToDatabaseService.findByUUID(id); + + CbaContent cbaContent = optionalContent.get(); + response.setName(cbaContent.getCbaName()); + response.setState(cbaContent.getCbaState()); + response.setId(cbaContent.getCbaUUID()); + response.setVersion(cbaContent.getCbaVersion()); + response.setDescription(cbaContent.getCbaDescription()); + return response; + } + + /** + * This is a findAllCBA method to retrieve all the CBAs in Database + * + * @return List list with the controller blueprint archives + */ + public List findAllCBA() { + List responseList = new ArrayList<>(); + List cbaContents = this.cbaToDatabaseService.listCBAFiles(); + + for(CbaContent content: cbaContents){ + ItemCbaResponse response = new ItemCbaResponse(); + response.setName(content.getCbaName()); + response.setState(content.getCbaState()); + response.setId(content.getCbaUUID()); + response.setVersion(content.getCbaVersion()); + response.setDescription(content.getCbaDescription()); + + responseList.add(response); + } + return responseList; + } + + /** + * This is a findCBAByNameAndVersion method to find a CBA by Name and version + * + * @param (name, version) + * @return + * @throws BluePrintException BluePrintException + */ + public ItemCbaResponse findCBAByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException { + return null; + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java new file mode 100755 index 000000000..34204202d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java @@ -0,0 +1,132 @@ +/* + * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.collections.CollectionUtils; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +/** + * This class acts as a Rest Service that would store in the Database the Blueprints. + * @author Ruben Chang + */ + +@Service +public class CbaToDatabaseService { + + //Log used to trace the transactions using the EELFLogger class + private static EELFLogger log = EELFManager.getInstance().getLogger(CbaToDatabaseService.class); + + @Autowired + private ConfigModelRepository configModelRepository; + @Autowired + private ConfigModelContentRepository configModelContentRepository; + @Autowired + private ConfigModelCreateService configModelCreateService; + @Autowired + private CBAContentService cbaContentService; + + /** + * This method will store the blueprints into the DB on the tables CONFIG_MODEL and CONFIG_MODEL_CONTENT + * @param cbaArchiveToSave Path in which the components are stored + * @return ConfigModel The Blueprint object stored in the DB + */ + public ConfigModel storeBluePrints(String cbaDirectory, String cbaFileName, Path cbaArchiveToSave) throws BluePrintException { + log.info("*************************** storeBluePrints **********************"); + ConfigModel configModel = null; + CbaContent cbaContent; + String version = "1.0";//TODO Read these information from metadata + String description = "Initial description for CBA archive " + cbaFileName;//TODO + + List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(cbaDirectory); + if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { + for (String fileName : serviceTemplateDirs) { + try { + String bluePrintPath = cbaDirectory.concat("/").concat(fileName); + log.debug("***** Loading service template : {}", bluePrintPath); + configModel = ConfigModelUtils.getConfigModel(bluePrintPath); + + configModel = this.configModelCreateService.saveConfigModel(configModel); + + log.info("Loaded service template successfully: {}", fileName); + } catch (Exception e) { + throw new BluePrintException("Load config model " + fileName + " error : "+e.getMessage()); + } + } + } else { + throw new BluePrintException("Invalid structure. The unzipped file does not contains Blueprints"); + } + + byte[] file; + try { + file = Files.readAllBytes(cbaArchiveToSave); + } catch (IOException e) { + throw new BluePrintException("Fail to read the CBA to save in database.", e); + } + + cbaContent = this.cbaContentService.saveCBAContent(cbaFileName, version, CbaStateEnum.DRAFT.getState(), description, file); + configModel.setConfigModelCBA(cbaContent); + + return configModel; + } + + /** + * This is a deleteConfigModel method + * + * @param id id + * @throws BluePrintException BluePrintException + */ + public void deleteCBA(@NotNull Long id) throws BluePrintException { + Optional dbConfigModel = configModelRepository.findById(id); + + //TODO: Delete CBA and COnfigModel + + } + + /** + * Get a list of the controller blueprint archives + * @return List List with the controller blueprint archives + */ + public List listCBAFiles() { + return this.cbaContentService.getList(); + } + + /** + * Find a Controller Blueprint Archive by UUID + * @param uuID the User Identifier Controller Blueprint archive + * @return Optional the Controller Blueprint archive + */ + public Optional findByUUID(String uuID) { + return this.cbaContentService.findByUUID(uuID); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java old mode 100644 new mode 100755 index fa8e32b69..f31a0ceb1 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java @@ -30,6 +30,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; @@ -123,7 +124,7 @@ public class ConfigModelCreateService { String artifactName = configModel.getArtifactName(); String artifactVersion = configModel.getArtifactVersion(); String author = configModel.getUpdatedBy(); - + CbaContent configModelCBA = configModel.getConfigModelCBA(); if (StringUtils.isBlank(author)) { throw new BluePrintException("Artifact Author is missing in the Service Template"); @@ -181,7 +182,7 @@ public class ConfigModelCreateService { addConfigModelContent(dbConfigModelId, configModel); // Populate Content model types - updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author); + updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author, configModelCBA); return updateConfigModel; @@ -220,7 +221,7 @@ public class ConfigModelCreateService { } private ConfigModel updateConfigModel(Long dbConfigModelId, String artifactName, String artifactVersion, - String author) throws BluePrintException { + String author, CbaContent configModelCBA) throws BluePrintException { ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); // Populate tags from metadata @@ -234,6 +235,7 @@ public class ConfigModelCreateService { dbConfigModel.setUpdatedBy(author); dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); dbConfigModel.setTags(tags); + dbConfigModel.setConfigModelCBA(configModelCBA); configModelRepository.saveAndFlush(dbConfigModel); log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); return dbConfigModel; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java new file mode 100755 index 000000000..14ac6af1d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java @@ -0,0 +1,114 @@ +/* + * Copyright © 2018 IBM 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.domain; + +import com.fasterxml.jackson.annotation.JsonManagedReference; +import org.hibernate.annotations.Proxy; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * CbaContent.java Purpose: Provide Configuration Generator for CbaContent Entity + * + * @author Ruben Chang + * @version 1.0 + */ + +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CBA_CONTENT") +@Proxy(lazy=false) +public class CbaContent implements Serializable { + + private static final long serialVersionUID = 1L; + + public CbaContent() { + this.cbaUUID = UUID.randomUUID().toString(); + } + + @Id + @Column(name = "cba_uuid", nullable = false) + private String cbaUUID; + + @Lob + @Column(name = "cba_file") + private byte[] cbaFile; + + @Column(name = "cba_name") + private String cbaName; + + @Column(name = "cba_version") + private String cbaVersion; + + @Column(name = "cba_state") + private int cbaState; + + @Column(name="cba_description") + private String cbaDescription; + + @OneToMany(mappedBy = "configModelCBA", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) + @JsonManagedReference + private List models = new ArrayList<>(); + + public String getCbaUUID() { + return cbaUUID; + } + + public void setCbaUUID(String cbaUUID) { + this.cbaUUID = cbaUUID; + } + + public String getCbaName() { + return cbaName; + } + + public void setCbaName(String cbaName) { + this.cbaName = cbaName; + } + + public String getCbaVersion() { + return cbaVersion; + } + + public void setCbaVersion(String cbaVersion) { + this.cbaVersion = cbaVersion; + } + + public List getModels() { + return models; + } + + public void setModels(List models) { this.models = models; } + + public int getCbaState() { return cbaState; } + + public void setCbaState(int cbaState) { this.cbaState = cbaState; } + + public String getCbaDescription() { return cbaDescription; } + + public void setCbaDescription(String cbaDescription) { this.cbaDescription = cbaDescription; } + + public byte[] getCbaFile() { return cbaFile; } + + public void setCbaFile(byte[] cbaFile) { this.cbaFile = cbaFile; } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java old mode 100644 new mode 100755 index 51c9a7c6a..dea5757d2 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java @@ -119,6 +119,10 @@ public class ConfigModel implements Serializable { @JsonManagedReference private List configModelContents = new ArrayList<>(); + @ManyToOne + @JoinColumn(name = "cba_content_uuid") + private CbaContent configModelCBA; + public Long getId() { return id; } @@ -287,4 +291,12 @@ public class ConfigModel implements Serializable { this.configModelContents = configModelContents; } + public CbaContent getConfigModelCBA() { + return configModelCBA; + } + + public void setConfigModelCBA(CbaContent configModelCBA) { + this.configModelCBA = configModelCBA; + } + } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java new file mode 100755 index 000000000..1b67ed823 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java @@ -0,0 +1,78 @@ +/* + * Copyright © 2018 IBM 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.model; + +/** + * BlueprintModelResponse.java Purpose: Model response for Upload CBA service + * + */ +public class BlueprintModelResponse { + private Long id; + private String name; + private String version; + private String description; + private String cbaUUID; + + public BlueprintModelResponse(Long id, String name, String version, String description, String cbaUUID) { + this.id = id; + this.name = name; + this.version = version; + this.description = description; + this.cbaUUID = cbaUUID; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCbaUUID() { + return cbaUUID; + } + + public void setCbaUUID(String cbaUUID) { + this.cbaUUID = cbaUUID; + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java new file mode 100755 index 000000000..0752df9b6 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java @@ -0,0 +1,58 @@ +package org.onap.ccsdk.apps.controllerblueprints.service.model; + +/** + * CLass that would represent the response for the GET methods on the CBAService class + */ +public class ItemCbaResponse { + + private String id; + private String description; + private String name; + private int state; + private String version; + + public ItemCbaResponse() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java new file mode 100755 index 000000000..273a19d66 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2018 IBM 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.repository; + +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; + +/** + * CBAContentRepository.java Purpose: Provide Configuration Generator CRUD methods for CBAContent table + * + * @author Ruben Chang + * @version 1.0 + */ +@Repository +public interface CBAContentRepository extends JpaRepository { + + /** + * This is a findAll method + * @return List + */ + @Override + List findAll(); + + /** + * Returns a CbaContent based on the cbaUUID + * @param cbaUUID the CbaUUID + * @return Optional + */ + @Override + @NotNull + Optional findById(@NotNull String cbaUUID); + + /** + * This is a deleteById methid + * @param cbaUUID the user ID for a particular CBAFile + */ + @Override + void deleteById(@NotNull String cbaUUID); +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java new file mode 100755 index 000000000..4608b1755 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java @@ -0,0 +1,84 @@ +/* + * Copyright © 2018 IBM 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.rs; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.CbaService; +import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse; +import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.multipart.FilePart; +import org.springframework.http.codec.multipart.Part; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Flux; + +import java.util.List; + +/** + * CbaRest.java Purpose: Provide a REST API to upload single and multiple CBA + * + * @author Steve Siani + * @version 1.0 + */ +@RestController +@RequestMapping(value = "/api/v1/cba") +public class CbaRest { + + @Autowired + private CbaService cbaService; + + @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public Flux uploadCBA(@RequestBody Flux parts) { + return parts.filter(part -> part instanceof FilePart) // only retain file parts + .ofType(FilePart.class) // convert the flux to FilePart + .flatMap(filePart -> cbaService.uploadCBAFile(filePart)); // save each file and flatmap it to a flux of results + } + + @DeleteMapping(path = "/{id}") + public void deleteCBA(@PathVariable(value = "id") Long id) throws BluePrintException { + this.cbaService.deleteCBA(id); + } + + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ItemCbaResponse getCBA(@PathVariable(value = "id") String id) { + return this.cbaService.findCBAByID(id); + } + + @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + List getAllCBA() { + return this.cbaService.findAllCBA(); + } + + @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ItemCbaResponse getCBAByNameAndVersion(@PathVariable(value = "name") String name, + @PathVariable(value = "version") String version) throws BluePrintException { + return this.cbaService.findCBAByNameAndVersion(name, version); + } + + @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ResponseEntity downloadCBA(@PathVariable(value = "id") String id) { + return this.cbaService.downloadCBAFile(id); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java new file mode 100755 index 000000000..57785dd8c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java @@ -0,0 +1,15 @@ +package org.onap.ccsdk.apps.controllerblueprints.service.utils; + +public enum CbaStateEnum { + + DRAFT(0), VALIDATED(1), APPROVED(2); + int state; + + CbaStateEnum(int state) { + this.state = state; + } + + public int getState() { + return state; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java new file mode 100755 index 000000000..d7b4aa938 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java @@ -0,0 +1,36 @@ +package org.onap.ccsdk.apps.controllerblueprints.service.utils; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +public class CloseCondition { + + AtomicInteger tasksSubmitted = new AtomicInteger(0); + AtomicInteger tasksCompleted = new AtomicInteger(0); + AtomicBoolean allTaskssubmitted = new AtomicBoolean(false); + + /** + * notify all tasks have been subitted, determine of the file channel can be closed + * @return true if the asynchronous file stream can be closed + */ + public boolean canCloseOnComplete() { + allTaskssubmitted.set(true); + return tasksCompleted.get() == tasksSubmitted.get(); + } + + /** + * notify a task has been submitted + */ + public void onTaskSubmitted() { + tasksSubmitted.incrementAndGet(); + } + + /** + * notify a task has been completed + * @return true if the asynchronous file stream can be closed + */ + public boolean onTaskCompleted() { + boolean allSubmittedClosed = tasksSubmitted.get() == tasksCompleted.incrementAndGet(); + return allSubmittedClosed && allTaskssubmitted.get(); + } +} -- cgit From faa40b64cdc416298ccdd3d0839a17266c0f337b Mon Sep 17 00:00:00 2001 From: Steve Alphonse Siani Date: Fri, 28 Dec 2018 14:58:27 -0500 Subject: 1st drop integration with BluePrintCatalogService Change-Id: I0824dcaf0a36e4616c12f3ac53530e6863bee290 Issue-ID: CCSDK-418 Signed-off-by: Steve Alphonse Siani --- .../service/AutoResourceMappingService.java | 4 +- .../service/BlueprintModelService.java | 227 ++++++++++++++ .../service/CBAContentService.java | 97 ------ .../service/CbaFileManagementService.java | 128 -------- .../controllerblueprints/service/CbaService.java | 192 ------------ .../service/CbaToDatabaseService.java | 132 --------- .../service/ConfigModelCreateService.java | 330 --------------------- .../service/ConfigModelService.java | 260 ---------------- .../service/SchemaGeneratorService.java | 4 +- .../service/ServiceTemplateService.java | 131 -------- .../service/domain/BlueprintModel.java | 284 ++++++++++++++++++ .../service/domain/BlueprintModelContent.java | 170 +++++++++++ .../service/domain/BlueprintModelSearch.java | 162 ++++++++++ .../service/domain/CbaContent.java | 114 ------- .../service/domain/ConfigModel.java | 302 ------------------- .../service/domain/ConfigModelContent.java | 174 ----------- .../service/domain/ConfigModelSearch.java | 165 ----------- .../service/domain/JpaJsonNodeConverter.java | 6 +- .../service/model/BlueprintModelResponse.java | 78 ----- .../service/model/ItemCbaResponse.java | 58 ---- .../BlueprintModelContentRepository.java | 102 +++++++ .../repository/BlueprintModelRepository.java | 96 ++++++ .../repository/BlueprintModelSearchRepository.java | 69 +++++ .../service/repository/CBAContentRepository.java | 59 ---- .../repository/ConfigModelContentRepository.java | 102 ------- .../service/repository/ConfigModelRepository.java | 95 ------ .../repository/ConfigModelSearchRepository.java | 43 --- .../service/rs/BlueprintModelRest.java | 90 ++++++ .../controllerblueprints/service/rs/CbaRest.java | 84 ------ .../service/rs/ConfigModelRest.java | 95 ------ .../service/rs/ModelTypeRest.java | 73 ----- .../service/rs/ServiceTemplateRest.java | 82 ----- .../service/utils/CbaStateEnum.java | 15 - .../service/utils/CloseCondition.java | 36 --- .../service/utils/ConfigModelUtils.java | 128 -------- .../validator/ServiceTemplateValidator.java | 2 +- 36 files changed, 1208 insertions(+), 2981 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java index a763d503c..1965ac901 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java @@ -17,6 +17,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.base.Preconditions; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -28,8 +30,6 @@ import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDict import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.springframework.stereotype.Service; import java.util.ArrayList; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java new file mode 100644 index 000000000..ba27742af --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java @@ -0,0 +1,227 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.jetbrains.annotations.NotNull; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.onap.ccsdk.apps.controllerblueprints.service.load.BluePrintLoadConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelContentRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelSearchRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.multipart.FilePart; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; + +/** + * BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +public class BlueprintModelService { + + private static EELFLogger log = EELFManager.getInstance().getLogger(BlueprintModelService.class); + + @Autowired + private BluePrintLoadConfiguration bluePrintLoadConfiguration; + + @Autowired + private BluePrintCatalogService bluePrintCatalogService; + + @Autowired + private BlueprintModelSearchRepository blueprintModelSearchRepository; + + @Autowired + private BlueprintModelRepository blueprintModelRepository; + + @Autowired + private BlueprintModelContentRepository blueprintModelContentRepository; + + private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%d) from repo"; + private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%d)" + + " and version(%d) from repo"; + + /** + * This is a saveBlueprintModel method + * + * @param filePart filePart + * @return Mono + * @throws BluePrintException BluePrintException + */ + public Mono saveBlueprintModel(FilePart filePart) throws BluePrintException { + try { + Path cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); + return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> { + String blueprintId = bluePrintCatalogService.uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); + return blueprintModelSearchRepository.findById(blueprintId).get(); + }); + + } catch (IOException | BluePrintException e) { + return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e)); + } + } + + /** + * This is a publishBlueprintModel method + * + * @param id id + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException { + // TODO Implement publish Functionality + return null; + } + + /** + * This is a searchBlueprintModels method + * + * @param tags tags + * @return List + */ + public List searchBlueprintModels(String tags) { + return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags); + } + + /** + * This is a getBlueprintModelByNameAndVersion method + * + * @param name name + * @param version version + * @return BlueprintModelSearch + */ + public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException { + BlueprintModelSearch blueprintModelSearch; + Optional dbBlueprintModel = blueprintModelSearchRepository + .findByArtifactNameAndArtifactVersion(name, version); + if (dbBlueprintModel.isPresent()) { + blueprintModelSearch = dbBlueprintModel.get(); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); + } + + return blueprintModelSearch; + } + + /** + * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource using MONO + * + * @param (id) + * @return ResponseEntity + */ + public ResponseEntity downloadBlueprintModelFile(@NotNull String id) throws BluePrintException { + BlueprintModel blueprintModel; + try { + blueprintModel = getBlueprintModel(id); + } catch (BluePrintException e) { + throw new BluePrintException("Error uploading the CBA file in channel.", e); + } + String fileName = blueprintModel.getId() + ".zip"; + byte[] file = blueprintModel.getBlueprintModelContent().getContent(); + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") + .body(new ByteArrayResource(file)); + } + + /** + * This is a getBlueprintModel method + * + * @param id id + * @return BlueprintModel + * @throws BluePrintException BluePrintException + */ + private BlueprintModel getBlueprintModel(@NotNull String id) throws BluePrintException { + BlueprintModel blueprintModel; + Optional dbBlueprintModel = blueprintModelRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModel = dbBlueprintModel.get(); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + } + + return blueprintModel; + } + + /** + * This is a getBlueprintModelSearch method + * + * @param id id + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + public BlueprintModelSearch getBlueprintModelSearch(@NotNull String id) throws BluePrintException { + BlueprintModelSearch blueprintModelSearch; + Optional dbBlueprintModel = blueprintModelSearchRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModelSearch = dbBlueprintModel.get(); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + } + + return blueprintModelSearch; + } + + /** + * This is a deleteBlueprintModel method + * + * @param id id + * @throws BluePrintException BluePrintException + */ + @Transactional + public void deleteBlueprintModel(@NotNull String id) throws BluePrintException { + Optional dbBlueprintModel = blueprintModelRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get()); + blueprintModelRepository.delete(dbBlueprintModel.get()); + } else { + throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + } + } + + /** + * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database + * + * @return List list with the controller blueprint archives + */ + public List getAllBlueprintModel() { + return blueprintModelSearchRepository.findAll(); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java deleted file mode 100755 index 66ef6a934..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CBAContentService.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.CBAContentRepository; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; - -/** - * CBAContentService.java Purpose: Provide CBAContent Template Service processing - * CBAContentService - * - * @author Ruben Chang - * @version 1.0 - */ - -@Service -public class CBAContentService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(CBAContentService.class); - - private CBAContentRepository cbaContentRepository; - - /** - * Constructor of the class - * @param cbaContentRepository CRUD methods for entity CBAContentRepository - */ - public CBAContentService(CBAContentRepository cbaContentRepository) { - this.cbaContentRepository = cbaContentRepository; - log.info("CBAContentRepository sucessfully instantiated"); - } - - /** - * Save the CBAContent into the CBA_CONTENT table - * @param cbaName The name of the file - * @param cbaVersion version number of the CBA archive - * @param cbaState int that would represent the state. Refer to the CbaStateEnum - * @param cbaDescription Brief description that would help to identify and recognize the CBA archive - * @param file the file - * @return CbaContent the record saved into the table CBA_CONTENT - */ - public CbaContent saveCBAContent(String cbaName, String cbaVersion, int cbaState, String cbaDescription, byte[] file){ - CbaContent cbaContent = new CbaContent(); - cbaContent.setCbaName(cbaName); - cbaContent.setCbaVersion(cbaVersion); - cbaContent.setCbaState(cbaState); - cbaContent.setCbaDescription(cbaDescription); - cbaContent.setCbaFile(file); - cbaContentRepository.saveAndFlush(cbaContent); - return cbaContent; - } - - /** - * Get the list of Controller Blueprint archives - * @return List list with the controller blueprint archives - */ - public List getList(){ - return cbaContentRepository.findAll(); - } - - /** - * Get a single Controller Blueprint archive by uuID - * @param uuID the userID controller blueprint identifier - * @return Optional - */ - public Optional findByUUID(String uuID) { - return cbaContentRepository.findById(uuID); - } - - /** - * Method deleteCBAById: Delete a CBA in data base with it associated Blueprint Model - * @param uuid the uuid that identify the CBA - */ - public void deleteCBAById(String uuid) { - cbaContentRepository.deleteById(uuid); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java deleted file mode 100755 index 2011172dc..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaFileManagementService.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.stereotype.Service; -import org.springframework.util.FileSystemUtils; -import org.springframework.util.StringUtils; -import reactor.core.publisher.Mono; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * CbaFileManagementService.java Purpose: Provide Service processing CBA file management - * - * @author Steve Siani - * @version 1.0 - */ -@Service -public class CbaFileManagementService { - private static EELFLogger log = EELFManager.getInstance().getLogger(CbaFileManagementService.class); - - @Value("${controllerblueprints.loadCbaExtension}") - private String cbaExtension; - - private static final String CBA_FILE_NAME_PATTERN = "CBA_{0}_{1}"; - - - /** - * cleanupSavedCBA: This method cleanup the Zip file and the unzip directory that was added. - * - * @param zipFileName zipFileName - * @param cbaFileLocation cbaFileLocation - * @return - * @throws BluePrintException BluePrintException - */ - public void cleanupSavedCBA(String zipFileName, Path cbaFileLocation) throws BluePrintException { - - String fileNameWithoutExtension = BluePrintFileUtils.Companion.stripFileExtension(zipFileName); - - //Delete the Zip file from the repository - FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(zipFileName,cbaFileLocation)); - - //Delete the CBA directory from the repository - FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(fileNameWithoutExtension,cbaFileLocation)); - } - - /** - * This is a saveCBAFile method - * take a {@link FilePart}, transfer it to disk using a Flux of FilePart and return a {@link Mono} representing the CBA file name - * - * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save - * @return a {@link Mono} String representing the result of the operation - * @throws (BluePrintException, IOException) BluePrintException, IOException - */ - public Mono saveCBAFile(FilePart filePart, Path targetDirectory) throws BluePrintException, IOException { - - // Normalize file name - final String fileName = StringUtils.cleanPath(filePart.filename()); - - // Check if the file's extension is "CBA" - if(!StringUtils.getFilenameExtension(fileName).equals(cbaExtension)) { - throw new BluePrintException("Invalid file extension required " + cbaExtension); - } - - // Change file name to match a pattern - String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); - - // Copy file to the target location (Replacing existing file with the same name) - Path targetLocation = targetDirectory.resolve(changedFileName); - - // if a file with the same name already exists in a repository, delete and recreate it - File file = new File(targetLocation.toString()); - if (file.exists()) - file.delete(); - file.createNewFile(); - - return filePart.transferTo(file).thenReturn(changedFileName); - } - - /** - * Decompress the file into the cbaFileLocation parameter - * @param zipFileName name of the zipped file - * @param cbaFileLocation path in which the zipped file will get decompressed - * @return String the path in which the file is decompressed - * @throws BluePrintException Exception in the process - */ - public String decompressCBAFile(final String zipFileName, Path cbaFileLocation) throws BluePrintException { - - File file = BluePrintFileUtils.Companion.getBluePrintFile(zipFileName, cbaFileLocation); - try { - Path directoryPath = Files.createDirectories(cbaFileLocation.resolve(BluePrintFileUtils.Companion.stripFileExtension(zipFileName))); - BluePrintArchiveUtils.Companion.deCompress(file, directoryPath.toString()); - return directoryPath.toString(); - - } catch (BluePrintProcessorException | IOException ex) { - throw new BluePrintException(" Fail to decompress " + zipFileName, ex); - } - - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java deleted file mode 100755 index 7d616a76f..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaService.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; -import java.io.IOException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * CbaService.java Purpose: Provide Service Template Service processing CbaService - * - * @author Steve Siani - * @version 1.0 - */ - -@Service -public class CbaService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(CbaService.class); - - @Value("${controllerblueprints.blueprintArchivePath}") - private String cbaArchivePath; - private Path cbaLocation; - - @Autowired - private CbaFileManagementService cbaFileManagementService; - - @Autowired - private CbaToDatabaseService cbaToDatabaseService; - - - /** - * This method would be used by SpringBoot to initialize the cba location - */ - @EventListener(ApplicationReadyEvent.class) - private void initCbaService() { - this.cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaArchivePath); - log.info("CBA service Initiated..."); - } - - /** - * This is a uploadCBAFile method - * take a {@link FilePart}, transfer it to disk using WebFlux and return a {@link Mono} representing the result - * - * @param filePart - the request part containing the file to be saved - * @return a {@link Mono< BlueprintModelResponse >} representing the result of the operation - */ - public Mono uploadCBAFile(FilePart filePart) { - - try { - return this.cbaFileManagementService.saveCBAFile(filePart, cbaLocation).map(fileName -> { - ConfigModel configModel; - BlueprintModelResponse blueprintModelResponse = null; - - try { - String cbaDirectory = this.cbaFileManagementService.decompressCBAFile(fileName, cbaLocation); - configModel = this.cbaToDatabaseService.storeBluePrints(cbaDirectory, fileName, cbaLocation.resolve(fileName)); - blueprintModelResponse = new BlueprintModelResponse(configModel.getId(), configModel.getArtifactName(), configModel.getArtifactVersion(), configModel.getArtifactDescription(), configModel.getConfigModelCBA().getCbaUUID()); - } catch (BluePrintException be) { - Mono.error(new BluePrintException("Error loading CBA in database.", be)); - } finally { - try { - this.cbaFileManagementService.cleanupSavedCBA(fileName, cbaLocation); - } catch (BluePrintException be) { - Mono.error(new BluePrintException("Error while cleaning up.", be)); - } - } - return blueprintModelResponse; - }); - } catch (IOException | BluePrintException e) { - return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e)); - } - } - - /** - * This is a deleteCba method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - public void deleteCBA(@NotNull Long id) throws BluePrintException { - this.cbaToDatabaseService.deleteCBA(id); - } - - /** - * This is a downloadCBAFile method to find the target file to download and return a file ressource using MONO - * - * @param (id) - * @return ResponseEntity - */ - public ResponseEntity downloadCBAFile(@NotNull String id) { - Optional optionalContent = this.cbaToDatabaseService.findByUUID(id); - - CbaContent cbaContent = optionalContent.get(); - - return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + cbaContent.getCbaName() + "\"") - .body(new ByteArrayResource(cbaContent.getCbaFile())); - } - - /** - * This is a findCBAByID method to find a CBA By the UUID - * - * @param (id) - * @return ItemCbaResponse - */ - public ItemCbaResponse findCBAByID(@NotNull String id) { - ItemCbaResponse response = new ItemCbaResponse(); - Optional optionalContent = this.cbaToDatabaseService.findByUUID(id); - - CbaContent cbaContent = optionalContent.get(); - response.setName(cbaContent.getCbaName()); - response.setState(cbaContent.getCbaState()); - response.setId(cbaContent.getCbaUUID()); - response.setVersion(cbaContent.getCbaVersion()); - response.setDescription(cbaContent.getCbaDescription()); - return response; - } - - /** - * This is a findAllCBA method to retrieve all the CBAs in Database - * - * @return List list with the controller blueprint archives - */ - public List findAllCBA() { - List responseList = new ArrayList<>(); - List cbaContents = this.cbaToDatabaseService.listCBAFiles(); - - for(CbaContent content: cbaContents){ - ItemCbaResponse response = new ItemCbaResponse(); - response.setName(content.getCbaName()); - response.setState(content.getCbaState()); - response.setId(content.getCbaUUID()); - response.setVersion(content.getCbaVersion()); - response.setDescription(content.getCbaDescription()); - - responseList.add(response); - } - return responseList; - } - - /** - * This is a findCBAByNameAndVersion method to find a CBA by Name and version - * - * @param (name, version) - * @return - * @throws BluePrintException BluePrintException - */ - public ItemCbaResponse findCBAByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException { - return null; - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java deleted file mode 100755 index 34204202d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/CbaToDatabaseService.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright © 2018 IBM 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.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.collections.CollectionUtils; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.CbaStateEnum; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; - -/** - * This class acts as a Rest Service that would store in the Database the Blueprints. - * @author Ruben Chang - */ - -@Service -public class CbaToDatabaseService { - - //Log used to trace the transactions using the EELFLogger class - private static EELFLogger log = EELFManager.getInstance().getLogger(CbaToDatabaseService.class); - - @Autowired - private ConfigModelRepository configModelRepository; - @Autowired - private ConfigModelContentRepository configModelContentRepository; - @Autowired - private ConfigModelCreateService configModelCreateService; - @Autowired - private CBAContentService cbaContentService; - - /** - * This method will store the blueprints into the DB on the tables CONFIG_MODEL and CONFIG_MODEL_CONTENT - * @param cbaArchiveToSave Path in which the components are stored - * @return ConfigModel The Blueprint object stored in the DB - */ - public ConfigModel storeBluePrints(String cbaDirectory, String cbaFileName, Path cbaArchiveToSave) throws BluePrintException { - log.info("*************************** storeBluePrints **********************"); - ConfigModel configModel = null; - CbaContent cbaContent; - String version = "1.0";//TODO Read these information from metadata - String description = "Initial description for CBA archive " + cbaFileName;//TODO - - List serviceTemplateDirs = ConfigModelUtils.getBlueprintNames(cbaDirectory); - if (CollectionUtils.isNotEmpty(serviceTemplateDirs)) { - for (String fileName : serviceTemplateDirs) { - try { - String bluePrintPath = cbaDirectory.concat("/").concat(fileName); - log.debug("***** Loading service template : {}", bluePrintPath); - configModel = ConfigModelUtils.getConfigModel(bluePrintPath); - - configModel = this.configModelCreateService.saveConfigModel(configModel); - - log.info("Loaded service template successfully: {}", fileName); - } catch (Exception e) { - throw new BluePrintException("Load config model " + fileName + " error : "+e.getMessage()); - } - } - } else { - throw new BluePrintException("Invalid structure. The unzipped file does not contains Blueprints"); - } - - byte[] file; - try { - file = Files.readAllBytes(cbaArchiveToSave); - } catch (IOException e) { - throw new BluePrintException("Fail to read the CBA to save in database.", e); - } - - cbaContent = this.cbaContentService.saveCBAContent(cbaFileName, version, CbaStateEnum.DRAFT.getState(), description, file); - configModel.setConfigModelCBA(cbaContent); - - return configModel; - } - - /** - * This is a deleteConfigModel method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - public void deleteCBA(@NotNull Long id) throws BluePrintException { - Optional dbConfigModel = configModelRepository.findById(id); - - //TODO: Delete CBA and COnfigModel - - } - - /** - * Get a list of the controller blueprint archives - * @return List List with the controller blueprint archives - */ - public List listCBAFiles() { - return this.cbaContentService.getList(); - } - - /** - * Find a Controller Blueprint Archive by UUID - * @param uuID the User Identifier Controller Blueprint archive - * @return Optional the Controller Blueprint archive - */ - public Optional findByUUID(String uuID) { - return this.cbaContentService.findByUUID(uuID); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java deleted file mode 100755 index f31a0ceb1..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelCreateService.java +++ /dev/null @@ -1,330 +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; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.base.Preconditions; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.IOUtils; -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.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * ServiceTemplateCreateService.java Purpose: Provide Service Template Create Service processing - * ServiceTemplateCreateService - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Service -public class ConfigModelCreateService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelCreateService.class); - - private ConfigModelRepository configModelRepository; - - /** - * This is a ConfigModelCreateService - * - * @param configModelRepository ConfigModelRepository - */ - public ConfigModelCreateService(ConfigModelRepository configModelRepository) { - this.configModelRepository = configModelRepository; - } - - /** - * This is a createInitialServiceTemplateContent method - * - * @param templateName templateName - * @return String - * @throws BluePrintException BluePrintException - */ - public String createInitialServiceTemplateContent(String templateName) throws BluePrintException { - String serviceTemplateContent = null; - if (StringUtils.isNotBlank(templateName)) { - try { - serviceTemplateContent = IOUtils.toString(ConfigModelCreateService.class.getClassLoader() - .getResourceAsStream("service_template/" + templateName + ".json"), Charset.defaultCharset()); - } catch (IOException e) { - throw new BluePrintException(e.getMessage(), e); - } - - } - return serviceTemplateContent; - } - - /** - * This is a createInitialServiceTemplate method - * - * @param templateName templateName - * @return ServiceTemplate - * @throws BluePrintException BluePrintException - */ - public ServiceTemplate createInitialServiceTemplate(String templateName) throws BluePrintException { - ServiceTemplate serviceTemplate = null; - if (StringUtils.isNotBlank(templateName)) { - try { - String serviceTemplateContent = IOUtils.toString(ConfigModelCreateService.class.getClassLoader() - .getResourceAsStream("service_template/" + templateName + ".json"), Charset.defaultCharset()); - if (StringUtils.isNotBlank(serviceTemplateContent)) { - serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); - } - } catch (IOException e) { - throw new BluePrintException(e.getMessage(), e); - } - - } - return serviceTemplate; - } - - /** - * This is a saveConfigModel method - * - * @param configModel configModel - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { - - if (configModel != null) { - String artifactName = configModel.getArtifactName(); - String artifactVersion = configModel.getArtifactVersion(); - String author = configModel.getUpdatedBy(); - CbaContent configModelCBA = configModel.getConfigModelCBA(); - - if (StringUtils.isBlank(author)) { - throw new BluePrintException("Artifact Author is missing in the Service Template"); - } - - if (StringUtils.isBlank(artifactName)) { - throw new BluePrintException("Artifact Name is missing in the Service Template"); - } - - if (StringUtils.isBlank(artifactVersion)) { - throw new BluePrintException("Artifact Version is missing in the Service Template"); - } - ConfigModel updateConfigModel; - - Optional dbConfigModelOptional = Optional.empty(); - - if (configModel.getId() != null) { - log.info("Searching for config model id : {}", configModel.getId()); - dbConfigModelOptional = configModelRepository.findById(configModel.getId()); - } - - if (!dbConfigModelOptional.isPresent()) { - log.info("Searching for config model name :" - + configModel.getArtifactName() + ", version " + configModel.getArtifactVersion()); - dbConfigModelOptional = configModelRepository.findByArtifactNameAndArtifactVersion( - configModel.getArtifactName(), configModel.getArtifactVersion()); - } - - if (dbConfigModelOptional.isPresent()) { - updateConfigModel = dbConfigModelOptional.get(); - log.info("Processing for config model id : {} with config model content count : {}" - , updateConfigModel.getId(), updateConfigModel.getConfigModelContents().size()); - } else { - ConfigModel tempConfigModel = new ConfigModel(); - tempConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - tempConfigModel.setArtifactName(artifactName); - tempConfigModel.setArtifactVersion(artifactVersion); - tempConfigModel.setUpdatedBy(author); - tempConfigModel.setPublished(ApplicationConstants.ACTIVE_N); - tempConfigModel.setTags(artifactName); - configModelRepository.saveAndFlush(tempConfigModel); - updateConfigModel = tempConfigModel; - } - - Long dbConfigModelId = updateConfigModel.getId(); - - if (dbConfigModelId == null) { - throw new BluePrintException("failed to get the initial saved config model id."); - } - - log.info("Processing for config model id : {}", dbConfigModelId); - - deleteConfigModelContent(dbConfigModelId); - - addConfigModelContent(dbConfigModelId, configModel); - - // Populate Content model types - updateConfigModel = updateConfigModel(dbConfigModelId, artifactName, artifactVersion, author, configModelCBA); - - - return updateConfigModel; - } else { - throw new BluePrintException("Config model information is missing"); - } - - } - - private void deleteConfigModelContent(Long dbConfigModelId) { - if (dbConfigModelId != null) { - ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - if (CollectionUtils.isNotEmpty(dbConfigModel.getConfigModelContents())) { - dbConfigModel.getConfigModelContents().clear(); - log.debug("Configuration Model content deleting : {}", dbConfigModel.getConfigModelContents()); - configModelRepository.saveAndFlush(dbConfigModel); - } - - } - } - - private void addConfigModelContent(Long dbConfigModelId, ConfigModel configModel) { - if (dbConfigModelId != null && configModel != null - && CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { - ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { - if (configModelContent != null) { - configModelContent.setId(null); - configModelContent.setConfigModel(dbConfigModel); - dbConfigModel.getConfigModelContents().add(configModelContent); - log.debug("Configuration Model content adding : {}", configModelContent); - } - } - configModelRepository.saveAndFlush(dbConfigModel); - } - } - - private ConfigModel updateConfigModel(Long dbConfigModelId, String artifactName, String artifactVersion, - String author, CbaContent configModelCBA) throws BluePrintException { - - ConfigModel dbConfigModel = configModelRepository.getOne(dbConfigModelId); - // Populate tags from metadata - String tags = getConfigModelTags(dbConfigModel); - if (StringUtils.isBlank(tags)) { - throw new BluePrintException("Failed to populate tags for the config model name " + artifactName); - } - dbConfigModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - dbConfigModel.setArtifactName(artifactName); - dbConfigModel.setArtifactVersion(artifactVersion); - dbConfigModel.setUpdatedBy(author); - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_N); - dbConfigModel.setTags(tags); - dbConfigModel.setConfigModelCBA(configModelCBA); - configModelRepository.saveAndFlush(dbConfigModel); - log.info("Config model ({}) saved successfully.", dbConfigModel.getId()); - return dbConfigModel; - } - - private List getValidContentTypes() { - List valids = new ArrayList<>(); - valids.add(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - valids.add(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); - return valids; - - } - - private String getConfigModelTags(ConfigModel configModel) throws BluePrintException { - String tags = null; - if (CollectionUtils.isNotEmpty(configModel.getConfigModelContents())) { - - for (ConfigModelContent configModelContent : configModel.getConfigModelContents()) { - if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { - - if (!getValidContentTypes().contains(configModelContent.getContentType())) { - throw new BluePrintException(configModelContent.getContentType() - + " is not a valid content type, It should be any one of this " - + getValidContentTypes()); - } - - if (configModelContent.getContentType().equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { - ServiceTemplate serviceTemplate = - JacksonUtils.readValue(configModelContent.getContent(), ServiceTemplate.class); - Preconditions.checkNotNull(serviceTemplate, "failed to transform service template content"); - if (serviceTemplate.getMetadata() != null) { - serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, - configModel.getUpdatedBy()); - serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_VERSION, - configModel.getArtifactVersion()); - serviceTemplate.getMetadata().put(BluePrintConstants.METADATA_TEMPLATE_NAME, - configModel.getArtifactName()); - } - tags = String.valueOf(serviceTemplate.getMetadata()); - } - } - } - } - return tags; - } - - /** - * This is a publishConfigModel method - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel publishConfigModel(@NotNull Long id) throws BluePrintException { - ConfigModel dbConfigModel = null; - Optional dbConfigModelOptional = configModelRepository.findById(id); - if (dbConfigModelOptional.isPresent()) { - dbConfigModel = dbConfigModelOptional.get(); - List configModelContents = dbConfigModel.getConfigModelContents(); - if (configModelContents != null && !configModelContents.isEmpty()) { - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent.getContentType() - .equals(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON)) { - ServiceTemplate serviceTemplate = JacksonUtils - .readValue(configModelContent.getContent(), ServiceTemplate.class); - if (serviceTemplate != null) { - validateServiceTemplate(serviceTemplate); - } - } - } - } - dbConfigModel.setPublished(ApplicationConstants.ACTIVE_Y); - configModelRepository.save(dbConfigModel); - log.info("Config model ({}) published successfully.", id); - } else { - throw new BluePrintException(String.format("Couldn't get Config model for id :(%s)", id)); - } - return dbConfigModel; - } - - /** - * This is a validateServiceTemplate method - * - * @param serviceTemplate Service Template - * @return ServiceTemplate - * @throws BluePrintException BluePrintException - */ - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - // FIXME("Plug right Validator") - return serviceTemplate; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java deleted file mode 100644 index b2fff26ef..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ConfigModelService.java +++ /dev/null @@ -1,260 +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; - -import org.apache.commons.collections.CollectionUtils; -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.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ApplicationConstants; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ConfigModelRepository; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; - -/** - * ConfigModelService.java Purpose: Provide Service Template Service processing ConfigModelService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -public class ConfigModelService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelService.class); - - private ConfigModelRepository configModelRepository; - private ConfigModelContentRepository configModelContentRepository; - private ConfigModelCreateService configModelCreateService; - private static final String CONFIG_MODEL_ID_FAILURE_MSG= "failed to get config model id(%d) from repo"; - - /** - * This is a ConfigModelService constructor. - * - * @param configModelRepository configModelRepository - * @param configModelContentRepository configModelContentRepository - * @param configModelCreateService configModelCreateService - */ - public ConfigModelService(ConfigModelRepository configModelRepository, - ConfigModelContentRepository configModelContentRepository, - ConfigModelCreateService configModelCreateService) { - this.configModelRepository = configModelRepository; - this.configModelContentRepository = configModelContentRepository; - this.configModelCreateService = configModelCreateService; - log.info("Config Model Service Initiated..."); - } - - /** - * This is a getInitialConfigModel method - * - * @param templateName templateName - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel getInitialConfigModel(String templateName) throws BluePrintException { - ConfigModel configModel = null; - if (StringUtils.isNotBlank(templateName)) { - configModel = new ConfigModel(); - configModel.setArtifactName(templateName); - configModel.setArtifactType(ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL); - configModel.setUpdatedBy("xxxxx@xxx.com"); - ConfigModelContent configModelContent = new ConfigModelContent(); - configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - configModelContent.setName(templateName); - String content = this.configModelCreateService.createInitialServiceTemplateContent(templateName); - configModelContent.setContent(content); - - List configModelContents = new ArrayList<>(); - configModelContents.add(configModelContent); - - configModel.setConfigModelContents(configModelContents); - } - return configModel; - } - - /** - * This is a saveConfigModel method - * - * @param configModel configModel - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel saveConfigModel(ConfigModel configModel) throws BluePrintException { - return this.configModelCreateService.saveConfigModel(configModel); - } - - /** - * This is a publishConfigModel method - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel publishConfigModel(Long id) throws BluePrintException { - return this.configModelCreateService.publishConfigModel(id); - } - - /** - * This is a searchConfigModels method - * - * @param tags tags - * @return ConfigModel - */ - public List searchConfigModels(String tags) { - List models = configModelRepository.findByTagsContainingIgnoreCase(tags); - if (models != null) { - for (ConfigModel configModel : models) { - configModel.setConfigModelContents(null); - } - } - return models; - } - - /** - * This is a getConfigModelByNameAndVersion method - * - * @param name name - * @param version version - * @return ConfigModel - */ - public ConfigModel getConfigModelByNameAndVersion(@NotNull String name, String version) throws BluePrintException { - ConfigModel configModel; - Optional dbConfigModel; - if (StringUtils.isNotBlank(version)) { - dbConfigModel = configModelRepository.findByArtifactNameAndArtifactVersion(name, version); - } else { - dbConfigModel = configModelRepository.findTopByArtifactNameOrderByArtifactVersionDesc(name); - } - if (dbConfigModel.isPresent()) { - configModel = dbConfigModel.get(); - } else { - throw new BluePrintException(String.format("failed to get config model name(%s), version(%s) from repo", name, version)); - } - return configModel; - } - - /** - * This is a getConfigModel method - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - public ConfigModel getConfigModel(@NotNull Long id) throws BluePrintException { - ConfigModel configModel; - Optional dbConfigModel = configModelRepository.findById(id); - if (dbConfigModel.isPresent()) { - configModel = dbConfigModel.get(); - } else { - throw new BluePrintException(String.format(CONFIG_MODEL_ID_FAILURE_MSG, id)); - } - - return configModel; - } - - /** - * This method returns clone of the given model id, by masking the other unrelated fields - * - * @param id id - * @return ConfigModel - * @throws BluePrintException BluePrintException - */ - - public ConfigModel getCloneConfigModel(@NotNull Long id) throws BluePrintException { - - ConfigModel configModel; - ConfigModel cloneConfigModel; - Optional dbConfigModel = configModelRepository.findById(id); - if (dbConfigModel.isPresent()) { - configModel = dbConfigModel.get(); - cloneConfigModel = configModel; - cloneConfigModel.setUpdatedBy("xxxxx@xxx.com"); - cloneConfigModel.setArtifactName("XXXX"); - cloneConfigModel.setPublished("XXXX"); - cloneConfigModel.setPublished("XXXX"); - cloneConfigModel.setUpdatedBy("XXXX"); - cloneConfigModel.setId(null); - cloneConfigModel.setTags(null); - cloneConfigModel.setCreatedDate(new Date()); - List configModelContents = cloneConfigModel.getConfigModelContents(); - - if (CollectionUtils.isNotEmpty(configModelContents)) { - for (ConfigModelContent configModelContent : configModelContents) { - if (configModelContent != null && StringUtils.isNotBlank(configModelContent.getContentType())) { - configModelContent.setId(null); - configModelContent.setCreationDate(new Date()); - - if (ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON - .equalsIgnoreCase(configModelContent.getContentType())) { - ServiceTemplate serviceTemplate = JacksonUtils - .readValue(configModelContent.getContent(), ServiceTemplate.class); - if (serviceTemplate != null && serviceTemplate.getMetadata() != null) { - serviceTemplate.getMetadata() - .put(BluePrintConstants.METADATA_TEMPLATE_AUTHOR, "XXXX"); - serviceTemplate.getMetadata() - .put(BluePrintConstants.METADATA_TEMPLATE_VERSION, "1.0.0"); - serviceTemplate.getMetadata() - .put(BluePrintConstants.METADATA_TEMPLATE_NAME, "XXXXXX"); - - configModelContent.setContent(JacksonUtils.getJson(serviceTemplate)); - } - } - } - - } - } - } else { - throw new BluePrintException(String.format(CONFIG_MODEL_ID_FAILURE_MSG, id)); - } - - return cloneConfigModel; - } - - /** - * This is a deleteConfigModel method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - - @Transactional - public void deleteConfigModel(@NotNull Long id) throws BluePrintException { - Optional dbConfigModel = configModelRepository.findById(id); - if (dbConfigModel.isPresent()) { - configModelContentRepository.deleteByConfigModel(dbConfigModel.get()); - configModelRepository.delete(dbConfigModel.get()); - } else { - throw new BluePrintException(String.format(CONFIG_MODEL_ID_FAILURE_MSG, id)); - } - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java index ff8b07a9d..89af9e9a9 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -16,6 +16,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.base.Preconditions; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -24,8 +26,6 @@ import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; import org.onap.ccsdk.apps.controllerblueprints.service.common.SwaggerGenerator; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import java.util.HashMap; import java.util.Map; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java deleted file mode 100644 index 60a83f9bd..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ServiceTemplateService.java +++ /dev/null @@ -1,131 +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 org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -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.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * ServiceTemplateService.java Purpose: Provide Service Template Create Service processing ServiceTemplateService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -public class ServiceTemplateService { - - private ResourceDictionaryRepository dataDictionaryRepository; - - private ConfigModelCreateService configModelCreateService; - private ResourceAssignmentValidationService resourceAssignmentValidationService; - - /** - * This is a SchemaGeneratorService constructor - * - * @param dataDictionaryRepository dataDictionaryRepository - * @param configModelCreateService configModelCreateService - * @param resourceAssignmentValidationService resourceAssignmentValidationService - */ - public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository, - ConfigModelCreateService configModelCreateService, - ResourceAssignmentValidationService resourceAssignmentValidationService) { - this.dataDictionaryRepository = dataDictionaryRepository; - this.configModelCreateService = configModelCreateService; - this.resourceAssignmentValidationService = resourceAssignmentValidationService; - } - - /** - * This is a validateServiceTemplate method - * - * @param serviceTemplate serviceTemplate - * @return ServiceTemplate - * @throws BluePrintException BluePrintException - */ - public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - return this.configModelCreateService.validateServiceTemplate(serviceTemplate); - } - - /** - * This is a enrichServiceTemplate method - * - * @param serviceTemplate serviceTemplate - * @return ServiceTemplate - */ - public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException { - //FIXME("Connect New Enrichment service") - return serviceTemplate; - } - - /** - * This is a autoMap method to map the template keys - * - * @param resourceAssignments resourceAssignments - * @return AutoMapResponse - * @throws BluePrintException BluePrintException - */ - public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { - AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository); - return autoMappingService.autoMap(resourceAssignments); - } - - /** - * This is a validateResourceAssignments method - * - * @param resourceAssignments resourceAssignments - * @return List - * @throws BluePrintException BluePrintException - */ - public List validateResourceAssignments(List resourceAssignments) - throws BluePrintException { - resourceAssignmentValidationService.validate(resourceAssignments); - return resourceAssignments; - } - - /** - * This is a generateResourceAssignments method - * - * @param templateContent templateContent - * @return List - */ - public List generateResourceAssignments(ConfigModelContent templateContent) { - List resourceAssignments = new ArrayList<>(); - if (templateContent != null && StringUtils.isNotBlank(templateContent.getContent())) { - Pattern p = Pattern.compile("(?<=\\$\\{)([^\\}]+)(?=\\})"); - Matcher m = p.matcher(templateContent.getContent()); - while (m.find()) { - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(m.group()); - resourceAssignments.add(resourceAssignment); - } - } - return resourceAssignments; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java new file mode 100755 index 000000000..93954daa2 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java @@ -0,0 +1,284 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.annotations.Proxy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * BlueprintModel.java Purpose: Provide Configuration Generator BlueprintModel Entity + * + * @author Brinda Santh + * @version 1.0 + */ + +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL") +@Proxy(lazy=false) +public class BlueprintModel implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @Column(name = "config_model_id") + private String id; + + @Column(name = "service_uuid") + private String serviceUUID; + + @Column(name = "distribution_id") + private String distributionId; + + @Column(name = "service_name") + private String serviceName; + + @Column(name = "service_description") + private String serviceDescription; + + @Column(name = "resource_uuid") + private String resourceUUID; + + @Column(name = "resource_instance_name") + private String resourceInstanceName; + + @Column(name = "resource_name") + private String resourceName; + + @Column(name = "resource_version") + private String resourceVersion; + + @Column(name = "resource_type") + private String resourceType; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @Column(name = "artifact_version", nullable = false) + @ApiModelProperty(required=true) + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @Column(name = "artifact_name", nullable = false) + @ApiModelProperty(required=true) + private String artifactName; + + @Column(name = "published", nullable = false) + @ApiModelProperty(required=true) + private String published; + + @Column(name = "updated_by", nullable = false) + @ApiModelProperty(required=true) + private String updatedBy; + + @Lob + @Column(name = "tags", nullable = false) + @ApiModelProperty(required=true) + private String tags; + + @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) + private BlueprintModelContent blueprintModelContent; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceDescription() { + return serviceDescription; + } + + public void setServiceDescription(String serviceDescription) { + this.serviceDescription = serviceDescription; + } + + public String getResourceUUID() { + return resourceUUID; + } + + public void setResourceUUID(String resourceUUID) { + this.resourceUUID = resourceUUID; + } + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public BlueprintModelContent getBlueprintModelContent() { + return blueprintModelContent; + } + + public void setBlueprintModelContent(BlueprintModelContent blueprintModelContent) { + this.blueprintModelContent = blueprintModelContent; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java new file mode 100644 index 000000000..0bfa0f124 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java @@ -0,0 +1,170 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.Objects; + +/** + * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL_CONTENT") +public class BlueprintModelContent implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "config_model_content_id") + private String id; + + @Column(name = "name", nullable = false) + @ApiModelProperty(required=true) + private String name; + + @Column(name = "content_type", nullable = false) + @ApiModelProperty(required=true) + private String contentType; + + @OneToOne + @JoinColumn(name = "config_model_id") + private BlueprintModel blueprintModel; + + @Lob + @Column(name = "description") + private String description; + + @Lob + @Column(name = "content", nullable = false) + @ApiModelProperty(required=true) + private byte[] content; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "updated_date") + private Date creationDate = new Date(); + + @Override + public String toString() { + return "[" + "id = " + id + + ", name = " + name + + ", contentType = " + contentType + + "]"; + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + if (!(o instanceof BlueprintModelContent)) { + return false; + } + BlueprintModelContent blueprintModelContent = (BlueprintModelContent) o; + return Objects.equals(id, blueprintModelContent.id) && Objects.equals(name, blueprintModelContent.name) + && Objects.equals(contentType, blueprintModelContent.contentType); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, contentType); + } + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getContentType() { + return contentType; + } + + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + + public BlueprintModel getBlueprintModel() { + return blueprintModel; + } + + + public void setBlueprintModel(BlueprintModel blueprintModel) { + this.blueprintModel = blueprintModel; + } + + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public byte[] getContent() { + return content; + } + + + public void setContent(byte[] content) { + this.content = content; + } + + + public Date getCreationDate() { + return creationDate; + } + + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java new file mode 100644 index 000000000..8b51bce32 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java @@ -0,0 +1,162 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.data.annotation.LastModifiedDate; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@Entity +@Table(name = "CONFIG_MODEL") +public class BlueprintModelSearch implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "config_model_id") + private String id; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @Column(name = "artifact_version", nullable = false) + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @Column(name = "artifact_name", nullable = false) + private String artifactName; + + @Column(name = "published", nullable = false) + private String published; + + @Column(name = "updated_by", nullable = false) + private String updatedBy; + + @Lob + @Column(name = "tags", nullable = false) + private String tags; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java deleted file mode 100755 index 14ac6af1d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/CbaContent.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright © 2018 IBM 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.domain; - -import com.fasterxml.jackson.annotation.JsonManagedReference; -import org.hibernate.annotations.Proxy; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -/** - * CbaContent.java Purpose: Provide Configuration Generator for CbaContent Entity - * - * @author Ruben Chang - * @version 1.0 - */ - -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CBA_CONTENT") -@Proxy(lazy=false) -public class CbaContent implements Serializable { - - private static final long serialVersionUID = 1L; - - public CbaContent() { - this.cbaUUID = UUID.randomUUID().toString(); - } - - @Id - @Column(name = "cba_uuid", nullable = false) - private String cbaUUID; - - @Lob - @Column(name = "cba_file") - private byte[] cbaFile; - - @Column(name = "cba_name") - private String cbaName; - - @Column(name = "cba_version") - private String cbaVersion; - - @Column(name = "cba_state") - private int cbaState; - - @Column(name="cba_description") - private String cbaDescription; - - @OneToMany(mappedBy = "configModelCBA", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - @JsonManagedReference - private List models = new ArrayList<>(); - - public String getCbaUUID() { - return cbaUUID; - } - - public void setCbaUUID(String cbaUUID) { - this.cbaUUID = cbaUUID; - } - - public String getCbaName() { - return cbaName; - } - - public void setCbaName(String cbaName) { - this.cbaName = cbaName; - } - - public String getCbaVersion() { - return cbaVersion; - } - - public void setCbaVersion(String cbaVersion) { - this.cbaVersion = cbaVersion; - } - - public List getModels() { - return models; - } - - public void setModels(List models) { this.models = models; } - - public int getCbaState() { return cbaState; } - - public void setCbaState(int cbaState) { this.cbaState = cbaState; } - - public String getCbaDescription() { return cbaDescription; } - - public void setCbaDescription(String cbaDescription) { this.cbaDescription = cbaDescription; } - - public byte[] getCbaFile() { return cbaFile; } - - public void setCbaFile(byte[] cbaFile) { this.cbaFile = cbaFile; } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java deleted file mode 100755 index dea5757d2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModel.java +++ /dev/null @@ -1,302 +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.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonManagedReference; -import io.swagger.annotations.ApiModelProperty; -import org.hibernate.annotations.Proxy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * ConfigModel.java Purpose: Provide Configuration Generator ConfigModel Entity - * - * @author Brinda Santh - * @version 1.0 - */ - -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CONFIG_MODEL") -@Proxy(lazy=false) -public class ConfigModel implements Serializable { - private static final long serialVersionUID = 1L; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "config_model_id") - private Long id; - - @Column(name = "service_uuid") - private String serviceUUID; - - @Column(name = "distribution_id") - private String distributionId; - - @Column(name = "service_name") - private String serviceName; - - @Column(name = "service_description") - private String serviceDescription; - - @Column(name = "resource_uuid") - private String resourceUUID; - - @Column(name = "resource_instance_name") - private String resourceInstanceName; - - @Column(name = "resource_name") - private String resourceName; - - @Column(name = "resource_version") - private String resourceVersion; - - @Column(name = "resource_type") - private String resourceType; - - @Column(name = "artifact_uuid") - private String artifactUUId; - - @Column(name = "artifact_type") - private String artifactType; - - @Column(name = "artifact_version", nullable = false) - @ApiModelProperty(required=true) - private String artifactVersion; - - @Lob - @Column(name = "artifact_description") - private String artifactDescription; - - @Column(name = "internal_version") - private Integer internalVersion; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date createdDate = new Date(); - - @Column(name = "artifact_name", nullable = false) - @ApiModelProperty(required=true) - private String artifactName; - - @Column(name = "published", nullable = false) - @ApiModelProperty(required=true) - private String published; - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required=true) - private String updatedBy; - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required=true) - private String tags; - - - @OneToMany(mappedBy = "configModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - @JsonManagedReference - private List configModelContents = new ArrayList<>(); - - @ManyToOne - @JoinColumn(name = "cba_content_uuid") - private CbaContent configModelCBA; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getServiceUUID() { - return serviceUUID; - } - - public void setServiceUUID(String serviceUUID) { - this.serviceUUID = serviceUUID; - } - - public String getDistributionId() { - return distributionId; - } - - public void setDistributionId(String distributionId) { - this.distributionId = distributionId; - } - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getServiceDescription() { - return serviceDescription; - } - - public void setServiceDescription(String serviceDescription) { - this.serviceDescription = serviceDescription; - } - - public String getResourceUUID() { - return resourceUUID; - } - - public void setResourceUUID(String resourceUUID) { - this.resourceUUID = resourceUUID; - } - - public String getResourceInstanceName() { - return resourceInstanceName; - } - - public void setResourceInstanceName(String resourceInstanceName) { - this.resourceInstanceName = resourceInstanceName; - } - - public String getResourceName() { - return resourceName; - } - - public void setResourceName(String resourceName) { - this.resourceName = resourceName; - } - - public String getResourceVersion() { - return resourceVersion; - } - - public void setResourceVersion(String resourceVersion) { - this.resourceVersion = resourceVersion; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public List getConfigModelContents() { - return configModelContents; - } - - public void setConfigModelContents(List configModelContents) { - this.configModelContents = configModelContents; - } - - public CbaContent getConfigModelCBA() { - return configModelCBA; - } - - public void setConfigModelCBA(CbaContent configModelCBA) { - this.configModelCBA = configModelCBA; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java deleted file mode 100644 index 561354713..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelContent.java +++ /dev/null @@ -1,174 +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.domain; - -import com.fasterxml.jackson.annotation.JsonBackReference; -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.util.Date; -import java.util.Objects; - -/** - * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity - * - * @author Brinda Santh - * @version 1.0 - */ -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CONFIG_MODEL_CONTENT") -public class ConfigModelContent { - - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "config_model_content_id") - private Long id; - - @Column(name = "name", nullable = false) - @ApiModelProperty(required=true) - private String name; - - @Column(name = "content_type", nullable = false) - @ApiModelProperty(required=true) - private String contentType; - - - @ManyToOne - @JoinColumn(name = "config_model_id") - @JsonBackReference - private ConfigModel configModel; - - @Lob - @Column(name = "description") - private String description; - - @Deprecated - @Lob - @Column(name = "content", nullable = false) - @ApiModelProperty(required=true) - private String content; - - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "updated_date") - private Date creationDate; - - @Override - public String toString() { - return "[" + "id = " + id + - ", name = " + name + - ", contentType = " + contentType + - "]"; - } - - @Override - public boolean equals(Object o) { - - if (o == this) { - return true; - } - if (!(o instanceof ConfigModelContent)) { - return false; - } - ConfigModelContent configModelContent = (ConfigModelContent) o; - return Objects.equals(id, configModelContent.id) && Objects.equals(name, configModelContent.name) - && Objects.equals(contentType, configModelContent.contentType); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, contentType); - } - - public Long getId() { - return id; - } - - - public void setId(Long id) { - this.id = id; - } - - - public String getName() { - return name; - } - - - public void setName(String name) { - this.name = name; - } - - - public String getContentType() { - return contentType; - } - - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - - public ConfigModel getConfigModel() { - return configModel; - } - - - public void setConfigModel(ConfigModel configModel) { - this.configModel = configModel; - } - - - public String getDescription() { - return description; - } - - - public void setDescription(String description) { - this.description = description; - } - - - public String getContent() { - return content; - } - - - public void setContent(String content) { - this.content = content; - } - - - public Date getCreationDate() { - return creationDate; - } - - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java deleted file mode 100644 index b6f0f0019..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ConfigModelSearch.java +++ /dev/null @@ -1,165 +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.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import org.springframework.data.annotation.LastModifiedDate; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - -@Entity -@Table(name = "CONFIG_MODEL") -public class ConfigModelSearch implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "config_model_id") - private Long id; - - @Column(name = "artifact_uuid") - private String artifactUUId; - - @Column(name = "artifact_type") - private String artifactType; - - @Column(name = "artifact_version", nullable = false) - private String artifactVersion; - - @Lob - @Column(name = "artifact_description") - private String artifactDescription; - - @Column(name = "internal_version") - private Integer internalVersion; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date createdDate = new Date(); - - @Column(name = "artifact_name", nullable = false) - private String artifactName; - - @Column(name = "published", nullable = false) - private String published; - - @Column(name = "updated_by", nullable = false) - private String updatedBy; - - @Lob - @Column(name = "tags", nullable = false) - private String tags; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public static long getSerialversionuid() { - return serialVersionUID; - } - - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java index 05f822d5b..23d3a977b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java @@ -16,11 +16,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; - import com.fasterxml.jackson.databind.JsonNode; import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; /** * @author Brinda Santh */ diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java deleted file mode 100755 index 1b67ed823..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/BlueprintModelResponse.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2018 IBM 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.model; - -/** - * BlueprintModelResponse.java Purpose: Model response for Upload CBA service - * - */ -public class BlueprintModelResponse { - private Long id; - private String name; - private String version; - private String description; - private String cbaUUID; - - public BlueprintModelResponse(Long id, String name, String version, String description, String cbaUUID) { - this.id = id; - this.name = name; - this.version = version; - this.description = description; - this.cbaUUID = cbaUUID; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getCbaUUID() { - return cbaUUID; - } - - public void setCbaUUID(String cbaUUID) { - this.cbaUUID = cbaUUID; - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java deleted file mode 100755 index 0752df9b6..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/ItemCbaResponse.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.onap.ccsdk.apps.controllerblueprints.service.model; - -/** - * CLass that would represent the response for the GET methods on the CBAService class - */ -public class ItemCbaResponse { - - private String id; - private String description; - private String name; - private int state; - private String version; - - public ItemCbaResponse() { - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java new file mode 100644 index 000000000..7940c9447 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java @@ -0,0 +1,102 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * BlueprintModelContentRepository.java Purpose: Provide BlueprintModelContentRepository of Repository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface BlueprintModelContentRepository extends JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findTopByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional + */ + @SuppressWarnings("unused") + Optional findTopByBlueprintModelAndContentType(BlueprintModel blueprintModel, String contentType); + + /** + * This is a findByBlueprintModelAndContentType method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @return Optional + */ + @SuppressWarnings("unused") + List findByBlueprintModelAndContentType(BlueprintModel blueprintModel, String contentType); + + /** + * This is a findByBlueprintModel method + * + * @param blueprintModel blueprintModel + * @return Optional + */ + @SuppressWarnings("unused") + List findByBlueprintModel(BlueprintModel blueprintModel); + + /** + * This is a findByBlueprintModelAndContentTypeAndName method + * + * @param blueprintModel blueprintModel + * @param contentType contentType + * @param name name + * @return Optional + */ + @SuppressWarnings("unused") + Optional findByBlueprintModelAndContentTypeAndName(BlueprintModel blueprintModel, + String contentType, String name); + + /** + * This is a deleteByMdeleteByBlueprintModelodelName method + * + * @param blueprintModel blueprintModel + */ + void deleteByBlueprintModel(BlueprintModel blueprintModel); + + /** + * This is a deleteById method + * + * @param id id + */ + void deleteById(@NotNull String id); + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java new file mode 100644 index 000000000..413160498 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java @@ -0,0 +1,96 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * AsdcArtifactsRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface BlueprintModelRepository extends JpaRepository { + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findTopByArtifactNameOrderByArtifactIdDesc method + * + * @param artifactName artifactName + * @return Optional + */ + Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); + + /** + * This is a findTopByArtifactName method + * + * @param artifactName artifactName + * @return Optional + */ + @SuppressWarnings("unused") + List findTopByArtifactName(String artifactName); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); + + /** + * This is a deleteByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + */ + @SuppressWarnings("unused") + void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a deleteById method + * + * @param id id + */ + @SuppressWarnings("unused") + void deleteById(@NotNull String id); + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java new file mode 100644 index 000000000..ed863563a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * BlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface BlueprintModelSearchRepository extends JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findAll method + * @return List + */ + @Override + List findAll(); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java deleted file mode 100755 index 273a19d66..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/CBAContentRepository.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2018 IBM 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.repository; - -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -/** - * CBAContentRepository.java Purpose: Provide Configuration Generator CRUD methods for CBAContent table - * - * @author Ruben Chang - * @version 1.0 - */ -@Repository -public interface CBAContentRepository extends JpaRepository { - - /** - * This is a findAll method - * @return List - */ - @Override - List findAll(); - - /** - * Returns a CbaContent based on the cbaUUID - * @param cbaUUID the CbaUUID - * @return Optional - */ - @Override - @NotNull - Optional findById(@NotNull String cbaUUID); - - /** - * This is a deleteById methid - * @param cbaUUID the user ID for a particular CBAFile - */ - @Override - void deleteById(@NotNull String cbaUUID); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java deleted file mode 100644 index 81c26373b..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelContentRepository.java +++ /dev/null @@ -1,102 +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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * ConfigModelContentRepository.java Purpose: Provide ConfigModelContentRepository of Repository - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -@Repository -public interface ConfigModelContentRepository extends JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull Long id); - - /** - * This is a findTopByConfigModelAndContentType method - * - * @param configModel configModel - * @param contentType contentType - * @return Optional - */ - @SuppressWarnings("unused") - Optional findTopByConfigModelAndContentType(ConfigModel configModel, String contentType); - - /** - * This is a findByConfigModelAndContentType method - * - * @param configModel configModel - * @param contentType contentType - * @return Optional - */ - @SuppressWarnings("unused") - List findByConfigModelAndContentType(ConfigModel configModel, String contentType); - - /** - * This is a findByConfigModel method - * - * @param configModel configModel - * @return Optional - */ - @SuppressWarnings("unused") - List findByConfigModel(ConfigModel configModel); - - /** - * This is a findByConfigModelAndContentTypeAndName method - * - * @param configModel configModel - * @param contentType contentType - * @param name name - * @return Optional - */ - @SuppressWarnings("unused") - Optional findByConfigModelAndContentTypeAndName(ConfigModel configModel, - String contentType, String name); - - /** - * This is a deleteByMdeleteByConfigModelodelName method - * - * @param configModel configModel - */ - void deleteByConfigModel(ConfigModel configModel); - - /** - * This is a deleteById method - * - * @param id id - */ - void deleteById(@NotNull Long id); - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java deleted file mode 100644 index 0a60ab74d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelRepository.java +++ /dev/null @@ -1,95 +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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * AsdcArtifactsRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ConfigModelRepository extends JpaRepository { - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull Long id); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional - */ - Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findTopByArtifactNameOrderByArtifactIdDesc method - * - * @param artifactName artifactName - * @return Optional - */ - Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); - - /** - * This is a findTopByArtifactName method - * - * @param artifactName artifactName - * @return Optional - */ - @SuppressWarnings("unused") - List findTopByArtifactName(String artifactName); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - */ - @SuppressWarnings("unused") - void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a deleteById method - * - * @param id id - */ - @SuppressWarnings("unused") - void deleteById(@NotNull Long id); - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java deleted file mode 100644 index bafc3aa89..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ConfigModelSearchRepository.java +++ /dev/null @@ -1,43 +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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelSearch; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * ConfigModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ConfigModelSearchRepository extends JpaRepository { - - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java new file mode 100644 index 000000000..9d0b1e3e4 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java @@ -0,0 +1,90 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.rs; + +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.service.BlueprintModelService; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.http.codec.multipart.FilePart; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.List; + +/** + * {@inheritDoc} + */ +@RestController +@RequestMapping(value = "/api/v1/blueprint-model") +public class BlueprintModelRest { + + @Autowired + private BlueprintModelService blueprintModelService; + + @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public @ResponseBody + Mono saveBluePrint(@RequestPart("file") FilePart file) throws BluePrintException{ + return blueprintModelService.saveBlueprintModel(file); + } + + @DeleteMapping(path = "/{id}") + public void deleteBluePrint(@PathVariable(value = "id") String id) throws BluePrintException { + this.blueprintModelService.deleteBlueprintModel(id); + } + + @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + BlueprintModelSearch getBluePrintByNameAndVersion(@PathVariable(value = "name") String name, + @PathVariable(value = "version") String version) throws BluePrintException { + return this.blueprintModelService.getBlueprintModelByNameAndVersion(name, version); + } + + @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + BlueprintModelSearch getCBA(@PathVariable(value = "id") String id) throws BluePrintException { + return this.blueprintModelService.getBlueprintModelSearch(id); + } + + @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + List getAllCBA() { + return this.blueprintModelService.getAllBlueprintModel(); + } + + @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ResponseEntity downloadBluePrint(@PathVariable(value = "id") String id) throws BluePrintException { + return this.blueprintModelService.downloadBlueprintModelFile(id); + } + + @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException { + return this.blueprintModelService.publishBlueprintModel(id); + } + + @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + List searchBlueprintModels(@PathVariable(value = "tags") String tags) { + return this.blueprintModelService.searchBlueprintModels(tags); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java deleted file mode 100755 index 4608b1755..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/CbaRest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2018 IBM 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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.CbaService; -import org.onap.ccsdk.apps.controllerblueprints.service.model.BlueprintModelResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.model.ItemCbaResponse; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.http.codec.multipart.Part; -import org.springframework.web.bind.annotation.*; -import reactor.core.publisher.Flux; - -import java.util.List; - -/** - * CbaRest.java Purpose: Provide a REST API to upload single and multiple CBA - * - * @author Steve Siani - * @version 1.0 - */ -@RestController -@RequestMapping(value = "/api/v1/cba") -public class CbaRest { - - @Autowired - private CbaService cbaService; - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public Flux uploadCBA(@RequestBody Flux parts) { - return parts.filter(part -> part instanceof FilePart) // only retain file parts - .ofType(FilePart.class) // convert the flux to FilePart - .flatMap(filePart -> cbaService.uploadCBAFile(filePart)); // save each file and flatmap it to a flux of results - } - - @DeleteMapping(path = "/{id}") - public void deleteCBA(@PathVariable(value = "id") Long id) throws BluePrintException { - this.cbaService.deleteCBA(id); - } - - @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ItemCbaResponse getCBA(@PathVariable(value = "id") String id) { - return this.cbaService.findCBAByID(id); - } - - @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List getAllCBA() { - return this.cbaService.findAllCBA(); - } - - @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ItemCbaResponse getCBAByNameAndVersion(@PathVariable(value = "name") String name, - @PathVariable(value = "version") String version) throws BluePrintException { - return this.cbaService.findCBAByNameAndVersion(name, version); - } - - @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResponseEntity downloadCBA(@PathVariable(value = "id") String id) { - return this.cbaService.downloadCBAFile(id); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java deleted file mode 100644 index b025b2ffa..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRest.java +++ /dev/null @@ -1,95 +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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.ConfigModelService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -@RestController -@RequestMapping(value = "/api/v1/config-model") -public class ConfigModelRest { - - private ConfigModelService configModelService; - - /** - * This is a ConfigModelRest constructor. - * - * @param configModelService Config Model Service - */ - public ConfigModelRest(ConfigModelService configModelService) { - this.configModelService = configModelService; - - } - - @GetMapping(path = "/initial/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel getInitialConfigModel(@PathVariable(value = "name") String name) throws BluePrintException { - return this.configModelService.getInitialConfigModel(name); - } - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel saveConfigModel(@RequestBody ConfigModel configModel) throws BluePrintException { - return this.configModelService.saveConfigModel(configModel); - } - - @DeleteMapping(path = "/{id}") - public void deleteConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - this.configModelService.deleteConfigModel(id); - } - - @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel publishConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - return this.configModelService.publishConfigModel(id); - } - - @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel getConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - return this.configModelService.getConfigModel(id); - } - - @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel getConfigModelByNameAndVersion(@PathVariable(value = "name") String name, - @PathVariable(value = "version") String version) throws BluePrintException { - return this.configModelService.getConfigModelByNameAndVersion(name, version); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchConfigModels(@PathVariable(value = "tags") String tags) { - return this.configModelService.searchConfigModels(tags); - } - - @GetMapping(path = "/clone/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ConfigModel getCloneConfigModel(@PathVariable(value = "id") Long id) throws BluePrintException { - return this.configModelService.getCloneConfigModel(id); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java deleted file mode 100644 index 12ed0a579..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRest.java +++ /dev/null @@ -1,73 +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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ModelTypeHandler; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -//@RestController -//@RequestMapping(value = "/api/v1/model-type") -public class ModelTypeRest { - - private ModelTypeHandler modelTypeService; - - /** - * This is a ModelTypeResourceImpl, used to save and get the model types stored in database - * - * @param modelTypeService Model Type Service - */ - public ModelTypeRest(ModelTypeHandler modelTypeService) { - this.modelTypeService = modelTypeService; - } - - @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public ModelType getModelTypeByName(@PathVariable(value = "name") String name) { - return modelTypeService.getModelTypeByName(name); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public List searchModelTypes(@PathVariable(value = "tags") String tags) { - return modelTypeService.searchModelTypes(tags); - } - - @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) { - return modelTypeService.getModelTypeByDefinitionType(definitionType); - } - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException { - return modelTypeService.saveModel(modelType); - } - - @DeleteMapping(path = "/{name}") - public void deleteModelTypeByName(@PathVariable(value = "name") String name) { - modelTypeService.deleteByModelName(name); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java deleted file mode 100644 index 4c34881a9..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRest.java +++ /dev/null @@ -1,82 +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.rs; - - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.service.ServiceTemplateService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -@RestController -@RequestMapping(value = "/api/v1/service-template") -public class ServiceTemplateRest { - - private ServiceTemplateService serviceTemplateService; - - /** - * This is a ServiceTemplateRest constructor - * - * @param serviceTemplateService Service Template Service - */ - public ServiceTemplateRest(ServiceTemplateService serviceTemplateService) { - this.serviceTemplateService = serviceTemplateService; - } - - @PostMapping(path = "/enrich", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ServiceTemplate enrichServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { - return serviceTemplateService.enrichServiceTemplate(serviceTemplate); - } - - @PostMapping(path = "/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ServiceTemplate validateServiceTemplate(@RequestBody ServiceTemplate serviceTemplate) throws BluePrintException { - return serviceTemplateService.validateServiceTemplate(serviceTemplate); - } - - @PostMapping(path = "/resource-assignment/auto-map", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - AutoMapResponse autoMap(@RequestBody List resourceAssignments) throws BluePrintException { - return serviceTemplateService.autoMap(resourceAssignments); - } - - @PostMapping(path = "/resource-assignment/validate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List validateResourceAssignments(@RequestBody List resourceAssignments) - throws BluePrintException { - return serviceTemplateService.validateResourceAssignments(resourceAssignments); - } - - @PostMapping(path = "/resource-assignment/generate", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List generateResourceAssignments(@RequestBody ConfigModelContent templateContent) { - return serviceTemplateService.generateResourceAssignments(templateContent); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java deleted file mode 100755 index 57785dd8c..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CbaStateEnum.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.onap.ccsdk.apps.controllerblueprints.service.utils; - -public enum CbaStateEnum { - - DRAFT(0), VALIDATED(1), APPROVED(2); - int state; - - CbaStateEnum(int state) { - this.state = state; - } - - public int getState() { - return state; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java deleted file mode 100755 index d7b4aa938..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/CloseCondition.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.onap.ccsdk.apps.controllerblueprints.service.utils; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -public class CloseCondition { - - AtomicInteger tasksSubmitted = new AtomicInteger(0); - AtomicInteger tasksCompleted = new AtomicInteger(0); - AtomicBoolean allTaskssubmitted = new AtomicBoolean(false); - - /** - * notify all tasks have been subitted, determine of the file channel can be closed - * @return true if the asynchronous file stream can be closed - */ - public boolean canCloseOnComplete() { - allTaskssubmitted.set(true); - return tasksCompleted.get() == tasksSubmitted.get(); - } - - /** - * notify a task has been submitted - */ - public void onTaskSubmitted() { - tasksSubmitted.incrementAndGet(); - } - - /** - * notify a task has been completed - * @return true if the asynchronous file stream can be closed - */ - public boolean onTaskCompleted() { - boolean allSubmittedClosed = tasksSubmitted.get() == tasksCompleted.incrementAndGet(); - return allSubmittedClosed && allTaskssubmitted.get(); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java deleted file mode 100644 index 96931014b..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtils.java +++ /dev/null @@ -1,128 +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.utils; - -import com.google.common.base.Preconditions; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.filefilter.DirectoryFileFilter; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ToscaMetaData; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Deprecated -public class ConfigModelUtils { - - private ConfigModelUtils() { - - } - - private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigModelUtils.class); - - public static ConfigModel getConfigModel(String blueprintPath) throws Exception { - Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "Blueprint Path is missing"); - ToscaMetaData toscaMetaData = BluePrintMetadataUtils.Companion.toscaMetaData(blueprintPath); - - Preconditions.checkNotNull(toscaMetaData, "failed to get Blueprint Metadata information"); - Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getEntityDefinitions()), "failed to get Blueprint Definition file"); - Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getCreatedBy()), "failed to get Blueprint created by"); - Preconditions.checkArgument(StringUtils.isNotBlank(toscaMetaData.getToscaMetaFileVersion()), "failed to get Blueprint package version"); - - String bluePrintName = FilenameUtils.getBaseName(toscaMetaData.getEntityDefinitions()); - Preconditions.checkArgument(StringUtils.isNotBlank(bluePrintName), "failed to get Blueprint Definition Name"); - - // TODO - Update Rest of the Model - ConfigModel configModel = new ConfigModel(); - configModel.setUpdatedBy(toscaMetaData.getCreatedBy()); - configModel.setArtifactName(bluePrintName); - configModel.setArtifactVersion(toscaMetaData.getToscaMetaFileVersion()); - configModel.setTags(toscaMetaData.getTemplateTags()); - configModel.setArtifactType("SDNC_MODEL"); - - String blueprintContent = - getPathContent(blueprintPath + "/" + toscaMetaData.getEntityDefinitions()); - - Preconditions.checkArgument(StringUtils.isNotBlank(blueprintPath), "failed to get Blueprint content"); - - List configModelContents = new ArrayList<>(); - ConfigModelContent stConfigModelContent = new ConfigModelContent(); - stConfigModelContent.setName(configModel.getArtifactName()); - stConfigModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); - stConfigModelContent.setContent(blueprintContent); - configModelContents.add(stConfigModelContent); - - String velocityDir = blueprintPath + "/Templates"; - List velocityTemplateFiles = getFileOfExtension(velocityDir, new String[]{"vtl"}); - - if (CollectionUtils.isNotEmpty(velocityTemplateFiles)) { - for (File velocityTemplateFile : velocityTemplateFiles) { - if (velocityTemplateFile != null) { - String contentName = velocityTemplateFile.getName().replace(".vtl", ""); - ConfigModelContent velocityConfigModelContent = new ConfigModelContent(); - String velocityConfigContent = getPathContent(velocityTemplateFile); - velocityConfigModelContent.setName(contentName); - velocityConfigModelContent - .setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); - velocityConfigModelContent.setContent(velocityConfigContent); - configModelContents.add(velocityConfigModelContent); - log.info("Loaded blueprint template successfully: {}", velocityTemplateFile.getName()); - } - } - } - configModel.setConfigModelContents(configModelContents); - - return configModel; - - } - - public static String getPathContent(String path) throws IOException { - Preconditions.checkArgument(StringUtils.isNotBlank(path), "Path is missing"); - return FileUtils.readFileToString(new File(path), Charset.defaultCharset()); - } - - public static String getPathContent(File file) throws IOException { - Preconditions.checkNotNull(file, "File is missing"); - return FileUtils.readFileToString(file, Charset.defaultCharset()); - } - - public static List getFileOfExtension(String basePath, String[] extensions) { - Preconditions.checkArgument(StringUtils.isNotBlank(basePath), "Path is missing"); - Preconditions.checkNotNull(extensions, "Extensions is missing"); - return (List) FileUtils.listFiles(new File(basePath), extensions, true); - } - - public static List getBlueprintNames(String pathName) { - File blueprintDir = new File(pathName); - Preconditions.checkNotNull(blueprintDir, "failed to find the blueprint pathName file"); - String[] dirs = blueprintDir.list(DirectoryFileFilter.INSTANCE); - Preconditions.checkNotNull(dirs, "failed to find the blueprint directories" + blueprintDir.getAbsolutePath()); - return Arrays.asList(dirs); - } -} 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 index c5e9e86f4..6d02544e4 100644 --- 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 @@ -29,8 +29,8 @@ 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.ResourceAssignmentValidationServiceImpl; 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; -- cgit From 7f6c527bac8c0c60a2988e59ff7251178f904cdd Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 7 Jan 2019 16:33:02 -0500 Subject: Add support for blueprintprocessor runtime DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - created db-resources module to store controller blueprint related controller blueprint repository and entities. Also create an abstract BlueprintCatalogServiceImpl so it can be used both by controllerblueprint and blueprintprocessor - created blueprint-validation to store the implementation of the validation interface. - change controllerblueprint service to levrage db-resources - implement CatalogService for blueprintprocessor db-lib by using db-resources. Change-Id: I0539e414e4ff3b7a6edf0f6304d6cbc5e6eac404 Issue-ID: CCSDK-664 Signed-off-by: Alexis de Talhouët --- .../service/BlueprintModelService.java | 32 ++++--- .../service/common/ApplicationConstants.java | 34 ------- .../BlueprintModelContentRepository.java | 102 --------------------- .../repository/BlueprintModelRepository.java | 96 ------------------- .../repository/BlueprintModelSearchRepository.java | 69 -------------- .../ControllerBlueprintModelSearchRepository.java | 69 ++++++++++++++ 6 files changed, 86 insertions(+), 316 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java index ba27742af..ca0e24393 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java @@ -21,14 +21,14 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration; import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; -import org.onap.ccsdk.apps.controllerblueprints.service.load.BluePrintLoadConfiguration; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.BlueprintModelSearchRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository; +import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository; import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ByteArrayResource; @@ -65,17 +65,17 @@ public class BlueprintModelService { private BluePrintCatalogService bluePrintCatalogService; @Autowired - private BlueprintModelSearchRepository blueprintModelSearchRepository; + private ControllerBlueprintModelSearchRepository blueprintModelSearchRepository; @Autowired - private BlueprintModelRepository blueprintModelRepository; + private ControllerBlueprintModelRepository blueprintModelRepository; @Autowired - private BlueprintModelContentRepository blueprintModelContentRepository; + private ControllerBlueprintModelContentRepository blueprintModelContentRepository; private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%d) from repo"; private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%d)" + - " and version(%d) from repo"; + " and version(%d) from repo"; /** * This is a saveBlueprintModel method @@ -86,10 +86,12 @@ public class BlueprintModelService { */ public Mono saveBlueprintModel(FilePart filePart) throws BluePrintException { try { - Path cbaLocation = BluePrintFileUtils.Companion.getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); + Path cbaLocation = BluePrintFileUtils.Companion + .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> { - String blueprintId = bluePrintCatalogService.uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); - return blueprintModelSearchRepository.findById(blueprintId).get(); + String blueprintId = bluePrintCatalogService + .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); + return blueprintModelSearchRepository.findById(blueprintId).get(); }); } catch (IOException | BluePrintException e) { @@ -122,14 +124,15 @@ public class BlueprintModelService { /** * This is a getBlueprintModelByNameAndVersion method * - * @param name name + * @param name name * @param version version * @return BlueprintModelSearch */ - public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) throws BluePrintException { + public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) + throws BluePrintException { BlueprintModelSearch blueprintModelSearch; Optional dbBlueprintModel = blueprintModelSearchRepository - .findByArtifactNameAndArtifactVersion(name, version); + .findByArtifactNameAndArtifactVersion(name, version); if (dbBlueprintModel.isPresent()) { blueprintModelSearch = dbBlueprintModel.get(); } else { @@ -142,7 +145,6 @@ public class BlueprintModelService { /** * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource using MONO * - * @param (id) * @return ResponseEntity */ public ResponseEntity downloadBlueprintModelFile(@NotNull String id) throws BluePrintException { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java deleted file mode 100644 index d16f1b135..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ApplicationConstants.java +++ /dev/null @@ -1,34 +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.common; - -/** - * ApplicationConstants.java Purpose: Provide ControllerBluprintsApplication Constant Information - * - * @author Brinda Santh - * @version 1.0 - */ -public final class ApplicationConstants { - public static final String ACTIVE_Y = "Y"; - public static final String ACTIVE_N = "N"; - public static final String ASDC_ARTIFACT_TYPE_SDNC_MODEL = "SDNC_MODEL"; - - private ApplicationConstants() { - - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java deleted file mode 100644 index 7940c9447..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelContentRepository.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * BlueprintModelContentRepository.java Purpose: Provide BlueprintModelContentRepository of Repository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface BlueprintModelContentRepository extends JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull String id); - - /** - * This is a findTopByBlueprintModelAndContentType method - * - * @param blueprintModel blueprintModel - * @param contentType contentType - * @return Optional - */ - @SuppressWarnings("unused") - Optional findTopByBlueprintModelAndContentType(BlueprintModel blueprintModel, String contentType); - - /** - * This is a findByBlueprintModelAndContentType method - * - * @param blueprintModel blueprintModel - * @param contentType contentType - * @return Optional - */ - @SuppressWarnings("unused") - List findByBlueprintModelAndContentType(BlueprintModel blueprintModel, String contentType); - - /** - * This is a findByBlueprintModel method - * - * @param blueprintModel blueprintModel - * @return Optional - */ - @SuppressWarnings("unused") - List findByBlueprintModel(BlueprintModel blueprintModel); - - /** - * This is a findByBlueprintModelAndContentTypeAndName method - * - * @param blueprintModel blueprintModel - * @param contentType contentType - * @param name name - * @return Optional - */ - @SuppressWarnings("unused") - Optional findByBlueprintModelAndContentTypeAndName(BlueprintModel blueprintModel, - String contentType, String name); - - /** - * This is a deleteByMdeleteByBlueprintModelodelName method - * - * @param blueprintModel blueprintModel - */ - void deleteByBlueprintModel(BlueprintModel blueprintModel); - - /** - * This is a deleteById method - * - * @param id id - */ - void deleteById(@NotNull String id); - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java deleted file mode 100644 index 413160498..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelRepository.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * AsdcArtifactsRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface BlueprintModelRepository extends JpaRepository { - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull String id); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional - */ - Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findTopByArtifactNameOrderByArtifactIdDesc method - * - * @param artifactName artifactName - * @return Optional - */ - Optional findTopByArtifactNameOrderByArtifactVersionDesc(String artifactName); - - /** - * This is a findTopByArtifactName method - * - * @param artifactName artifactName - * @return Optional - */ - @SuppressWarnings("unused") - List findTopByArtifactName(String artifactName); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - */ - @SuppressWarnings("unused") - void deleteByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a deleteById method - * - * @param id id - */ - @SuppressWarnings("unused") - void deleteById(@NotNull String id); - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java deleted file mode 100644 index ed863563a..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/BlueprintModelSearchRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.repository; - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * BlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface BlueprintModelSearchRepository extends JpaRepository { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull String id); - - /** - * This is a findAll method - * @return List - */ - @Override - List findAll(); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional - */ - Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java new file mode 100644 index 000000000..343f8c67b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java @@ -0,0 +1,69 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * + * 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.repository; + +import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import javax.validation.constraints.NotNull; +import java.util.List; +import java.util.Optional; + +/** + * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +public interface ControllerBlueprintModelSearchRepository extends JpaRepository { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findAll method + * @return List + */ + @Override + List findAll(); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List findByTagsContainingIgnoreCase(String tags); +} -- cgit From 1393e526211aa64852ff27d322af411e205c35a4 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Tue, 8 Jan 2019 11:17:05 -0500 Subject: Add relationships type files load structure. Change-Id: I1be3ba493956674b476058094e05d681ce358711 Issue-ID: CCSDK-746 Signed-off-by: Muthuramalingam, Brinda Santh --- .../service/validator/ModelTypeValidator.java | 151 --------------------- 1 file changed, 151 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 deleted file mode 100644 index 9641f8973..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.java +++ /dev/null @@ -1,151 +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.fasterxml.jackson.databind.JsonNode; -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.data.ArtifactType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.CapabilityDefinition; -import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; - -import java.util.ArrayList; -import java.util.List; - -/** - * ModelTypeValidation.java Purpose: Provide Validation Service for Model Type ModelTypeValidation - * - * @author Brinda Santh - * @version 1.0 - */ - -public class ModelTypeValidator { - - private ModelTypeValidator() { - - } - - private static List getValidModelDefinitionType() { - List validTypes = new ArrayList<>(); - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE); - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE); - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE); - validTypes.add(BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE); - return validTypes; - } - - /** - * This is a validateModelTypeDefinition - * - * @param definitionType definitionType - * @param definitionContent definitionContent - * @return boolean - * @throws BluePrintException BluePrintException - */ - public static boolean validateModelTypeDefinition(String definitionType, JsonNode definitionContent) - throws BluePrintException { - if (definitionContent != null) { - if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) { - DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class); - if (dataType == null) { - throw new BluePrintException( - "Model type definition is not DataType valid content " + definitionContent); - } - } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE.equalsIgnoreCase(definitionType)) { - NodeType nodeType = JacksonUtils.readValue(definitionContent, NodeType.class); - if (nodeType == null) { - throw new BluePrintException( - "Model type definition is not NodeType valid content " + definitionContent); - } - } else if (BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE.equalsIgnoreCase(definitionType)) { - ArtifactType artifactType = JacksonUtils.readValue(definitionContent, ArtifactType.class); - if (artifactType == null) { - throw new BluePrintException( - "Model type definition is not ArtifactType valid content " + definitionContent); - } - }else if (BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE.equalsIgnoreCase(definitionType)) { - CapabilityDefinition capabilityDefinition = - JacksonUtils.readValue(definitionContent, CapabilityDefinition.class); - if (capabilityDefinition == null) { - throw new BluePrintException( - "Model type definition is not CapabilityDefinition valid content " + definitionContent); - } - } - - } - return true; - } - - /** - * This is a validateModelType method - * - * @param modelType modelType - * @return boolean - * @throws BluePrintException BluePrintException - */ - public static boolean validateModelType(ModelType modelType) throws BluePrintException { - if (modelType != null) { - - if (StringUtils.isBlank(modelType.getModelName())) { - throw new BluePrintException("Model Name Information is missing."); - } - - if (StringUtils.isBlank(modelType.getDefinitionType())) { - throw new BluePrintException("Model Root Type Information is missing."); - } - if (StringUtils.isBlank(modelType.getDerivedFrom())) { - throw new BluePrintException("Model Type Information is missing."); - } - - if (modelType.getDefinition() == null) { - throw new BluePrintException("Model Definition Information is missing."); - } - if (StringUtils.isBlank(modelType.getDescription())) { - throw new BluePrintException("Model Description Information is missing."); - } - - if (StringUtils.isBlank(modelType.getVersion())) { - throw new BluePrintException("Model Version Information is missing."); - } - - if (StringUtils.isBlank(modelType.getUpdatedBy())) { - throw new BluePrintException("Model Updated By Information is missing."); - } - - List validRootTypes = getValidModelDefinitionType(); - if (!validRootTypes.contains(modelType.getDefinitionType())) { - throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType() - + "), It should be " + validRootTypes); - } - - validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition()); - - } else { - throw new BluePrintException("Model Type Information is missing."); - } - - return true; - - } - -} -- cgit From d098102efddefe8370227d5a71c6f8cb1c531613 Mon Sep 17 00:00:00 2001 From: Steve Alphonse Siani Date: Wed, 9 Jan 2019 14:34:06 -0500 Subject: Blueprint exception handler and REST responses Change-Id: I5727238cd4c3f3f5475c3f3022e56f1acc0d73bf Issue-ID: CCSDK-418 Signed-off-by: Steve Alphonse Siani Signed-off-by: Balazinski --- .../service/BlueprintModelService.java | 124 +++++++++++++++------ .../service/common/ErrorMessage.java | 4 + .../service/domain/BlueprintModel.java | 2 +- .../service/domain/BlueprintModelSearch.java | 4 + .../service/rs/BlueprintModelRest.java | 23 ++-- 5 files changed, 117 insertions(+), 40 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java index ca0e24393..e80fa8cdc 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java @@ -17,11 +17,11 @@ package org.onap.ccsdk.apps.controllerblueprints.service; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants; import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode; import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService; import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; @@ -56,8 +56,6 @@ import java.util.Optional; @Service public class BlueprintModelService { - private static EELFLogger log = EELFManager.getInstance().getLogger(BlueprintModelService.class); - @Autowired private BluePrintLoadConfiguration bluePrintLoadConfiguration; @@ -73,9 +71,9 @@ public class BlueprintModelService { @Autowired private ControllerBlueprintModelContentRepository blueprintModelContentRepository; - private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%d) from repo"; - private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%d)" + - " and version(%d) from repo"; + private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo"; + private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + + " and version(%s) from repo"; /** * This is a saveBlueprintModel method @@ -87,28 +85,36 @@ public class BlueprintModelService { public Mono saveBlueprintModel(FilePart filePart) throws BluePrintException { try { Path cbaLocation = BluePrintFileUtils.Companion - .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); + .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> { String blueprintId = bluePrintCatalogService - .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); + .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); return blueprintModelSearchRepository.findById(blueprintId).get(); }); - - } catch (IOException | BluePrintException e) { - return Mono.error(new BluePrintException("Error uploading the CBA file in channel.", e)); + } catch (IOException e) { + throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(), + String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e); } } /** - * This is a publishBlueprintModel method + * This is a publishBlueprintModel method to change the status published to YES * * @param id id * @return BlueprintModelSearch * @throws BluePrintException BluePrintException */ public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException { - // TODO Implement publish Functionality - return null; + BlueprintModelSearch blueprintModelSearch; + Optional dbBlueprintModel = blueprintModelSearchRepository.findById(id); + if (dbBlueprintModel.isPresent()) { + blueprintModelSearch = dbBlueprintModel.get(); + } else { + String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); + } + blueprintModelSearch.setPublished(ApplicationConstants.ACTIVE_Y); + return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch); } /** @@ -122,44 +128,78 @@ public class BlueprintModelService { } /** - * This is a getBlueprintModelByNameAndVersion method + * This is a getBlueprintModelSearchByNameAndVersion method * * @param name name * @param version version * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException */ - public BlueprintModelSearch getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) - throws BluePrintException { + public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version) + throws BluePrintException { BlueprintModelSearch blueprintModelSearch; Optional dbBlueprintModel = blueprintModelSearchRepository - .findByArtifactNameAndArtifactVersion(name, version); + .findByArtifactNameAndArtifactVersion(name, version); if (dbBlueprintModel.isPresent()) { blueprintModelSearch = dbBlueprintModel.get(); } else { - throw new BluePrintException(String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), + String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); } - return blueprintModelSearch; } /** - * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource using MONO + * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version * + * @param name name + * @param version version * @return ResponseEntity + * @throws BluePrintException BluePrintException + */ + public ResponseEntity downloadBlueprintModelFileByNameAndVersion(@NotNull String name, @NotNull String version) + throws BluePrintException { + BlueprintModel blueprintModel; + try { + blueprintModel = getBlueprintModelByNameAndVersion(name, version); + } catch (BluePrintException e) { + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " + + "downloading the CBA file: %s", e.getMessage()), e); + } + String fileName = blueprintModel.getId() + ".zip"; + byte[] file = blueprintModel.getBlueprintModelContent().getContent(); + return prepareResourceEntity(fileName, file); + } + + /** + * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource + * + * @return ResponseEntity + * @throws BluePrintException BluePrintException */ public ResponseEntity downloadBlueprintModelFile(@NotNull String id) throws BluePrintException { BlueprintModel blueprintModel; try { blueprintModel = getBlueprintModel(id); } catch (BluePrintException e) { - throw new BluePrintException("Error uploading the CBA file in channel.", e); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " + + "downloading the CBA file: %s", e.getMessage()), e); } String fileName = blueprintModel.getId() + ".zip"; byte[] file = blueprintModel.getBlueprintModelContent().getContent(); + return prepareResourceEntity(fileName, file); + } + + /** + * + * @param (fileName, file) + * @return ResponseEntity + */ + private ResponseEntity prepareResourceEntity(String fileName, byte[] file) { return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") - .body(new ByteArrayResource(file)); + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") + .body(new ByteArrayResource(file)); } /** @@ -175,9 +215,30 @@ public class BlueprintModelService { if (dbBlueprintModel.isPresent()) { blueprintModel = dbBlueprintModel.get(); } else { - throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); } + return blueprintModel; + } + /** + * This is a getBlueprintModelByNameAndVersion method + * + * @param name name + * @param version version + * @return BlueprintModel + * @throws BluePrintException BluePrintException + */ + private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) + throws BluePrintException { + BlueprintModel blueprintModel; + Optional dbBlueprintModel = blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version); + if (dbBlueprintModel.isPresent()) { + blueprintModel = dbBlueprintModel.get(); + } else { + String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); + } return blueprintModel; } @@ -194,7 +255,8 @@ public class BlueprintModelService { if (dbBlueprintModel.isPresent()) { blueprintModelSearch = dbBlueprintModel.get(); } else { - throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); } return blueprintModelSearch; @@ -213,17 +275,17 @@ public class BlueprintModelService { blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get()); blueprintModelRepository.delete(dbBlueprintModel.get()); } else { - throw new BluePrintException(String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id)); + String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); + throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); } } /** * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database * - * @return List list with the controller blueprint archives + * @return List list of the controller blueprint archives */ public List getAllBlueprintModel() { return blueprintModelSearchRepository.findAll(); } - } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java index 431641265..5486262f6 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java @@ -19,11 +19,15 @@ package org.onap.ccsdk.apps.controllerblueprints.service.common; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; import java.io.Serializable; import java.util.Date; @JsonInclude(Include.NON_NULL) +@JsonTypeName("errorMessage") +@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) public class ErrorMessage implements Serializable { private String message; private Integer code; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java index 93954daa2..245e4a80a 100755 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java @@ -36,7 +36,7 @@ import java.util.Date; @EntityListeners({AuditingEntityListener.class}) @Entity -@Table(name = "CONFIG_MODEL") +@Table(name = "CONFIG_MODEL", uniqueConstraints=@UniqueConstraint(columnNames={"artifact_name","artifact_version"})) @Proxy(lazy=false) public class BlueprintModel implements Serializable { private static final long serialVersionUID = 1L; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java index 8b51bce32..33753b2f2 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java @@ -18,6 +18,8 @@ package org.onap.ccsdk.apps.controllerblueprints.service.domain; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; import org.springframework.data.annotation.LastModifiedDate; import javax.persistence.*; @@ -26,6 +28,8 @@ import java.util.Date; @Entity @Table(name = "CONFIG_MODEL") +@JsonTypeName("blueprintModel") +@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) public class BlueprintModelSearch implements Serializable { private static final long serialVersionUID = 1L; diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java index 9d0b1e3e4..255137bf5 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java @@ -42,31 +42,38 @@ public class BlueprintModelRest { @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public @ResponseBody - Mono saveBluePrint(@RequestPart("file") FilePart file) throws BluePrintException{ + Mono saveBlueprint(@RequestPart("file") FilePart file) throws BluePrintException{ return blueprintModelService.saveBlueprintModel(file); } @DeleteMapping(path = "/{id}") - public void deleteBluePrint(@PathVariable(value = "id") String id) throws BluePrintException { + public void deleteBlueprint(@PathVariable(value = "id") String id) throws BluePrintException { this.blueprintModelService.deleteBlueprintModel(id); } @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - BlueprintModelSearch getBluePrintByNameAndVersion(@PathVariable(value = "name") String name, - @PathVariable(value = "version") String version) throws BluePrintException { - return this.blueprintModelService.getBlueprintModelByNameAndVersion(name, version); + BlueprintModelSearch getBlueprintByNameAndVersion(@PathVariable(value = "name") String name, + @PathVariable(value = "version") String version) throws BluePrintException { + return this.blueprintModelService.getBlueprintModelSearchByNameAndVersion(name, version); + } + + @GetMapping(path = "/download/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody + ResponseEntity downloadBlueprintByNameAndVersion(@PathVariable(value = "name") String name, + @PathVariable(value = "version") String version) throws BluePrintException { + return this.blueprintModelService.downloadBlueprintModelFileByNameAndVersion(name, version); } @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - BlueprintModelSearch getCBA(@PathVariable(value = "id") String id) throws BluePrintException { + BlueprintModelSearch getBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException { return this.blueprintModelService.getBlueprintModelSearch(id); } @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody - List getAllCBA() { + List getAllBlueprintModel() { return this.blueprintModelService.getAllBlueprintModel(); } @@ -76,7 +83,7 @@ public class BlueprintModelRest { return this.blueprintModelService.downloadBlueprintModelFile(id); } - @GetMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + @PutMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException { return this.blueprintModelService.publishBlueprintModel(id); -- cgit From cd0ba407a455cc5c8ccca1e1e44e8b5052b92b1c Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Thu, 10 Jan 2019 12:50:06 -0500 Subject: Resource Resoulution Service Implement Input Resource Resolution Processor Service along with Resource Resolution Utilities Change-Id: Ibb4899e415f4b79cd6cd1b190b0f4969b09c3fe4 Issue-ID: CCSDK-936 Signed-off-by: Singal, Kapil (ks220y) --- .../apps/controllerblueprints/service/SchemaGeneratorService.java | 2 +- .../controllerblueprints/service/domain/JpaJsonNodeConverter.java | 4 ++-- .../service/domain/JpaResourceDefinitionConverter.java | 4 ++-- .../service/validator/ServiceTemplateValidator.java | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java index 89af9e9a9..3a1535ac0 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java @@ -59,7 +59,7 @@ public class SchemaGeneratorService { */ public String generateSchema(String serviceTemplateContent) throws BluePrintException { if (StringUtils.isNotBlank(serviceTemplateContent)) { - ServiceTemplate serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, + ServiceTemplate serviceTemplate = JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class); return generateSchema(serviceTemplate); } else { diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java index 23d3a977b..074483a7c 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java @@ -30,11 +30,11 @@ public class JpaJsonNodeConverter implements @Override public String convertToDatabaseColumn(JsonNode node) { - return JacksonUtils.getJson(node, true); + return JacksonUtils.Companion.getJson(node, true); } @Override public JsonNode convertToEntityAttribute(String dbData) { - return JacksonUtils.jsonNode(dbData); + return JacksonUtils.Companion.jsonNode(dbData); } } \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java index 18672f1cb..e28cdcd5b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java @@ -29,11 +29,11 @@ public class JpaResourceDefinitionConverter implements AttributeConverter { @Override public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) { - return JacksonUtils.getJson(resourceDefinition); + return JacksonUtils.Companion.getJson(resourceDefinition); } @Override public ResourceDefinition convertToEntityAttribute(String content) { - return JacksonUtils.readValue(content, ResourceDefinition.class); + return JacksonUtils.Companion.readValue(content, ResourceDefinition.class); } } 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 index 6d02544e4..5d15e0876 100644 --- 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 @@ -58,7 +58,7 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { public boolean validateServiceTemplate(String serviceTemplateContent) throws BluePrintException { if (StringUtils.isNotBlank(serviceTemplateContent)) { ServiceTemplate serviceTemplate = - JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + JacksonUtils.Companion.readValue(serviceTemplateContent, ServiceTemplate.class); return validateServiceTemplate(serviceTemplate); } else { throw new BluePrintException( @@ -131,11 +131,11 @@ public class ServiceTemplateValidator extends BluePrintValidatorDefaultService { Object mappingObject = capabilityAssignment.getProperties().get(ConfigModelConstant.CAPABILITY_PROPERTY_MAPPING); if (mappingObject != null) { - String mappingContent = JacksonUtils.getJson(mappingObject); + 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.getListFromJson(mappingContent, ResourceAssignment.class); + resourceAssignment = JacksonUtils.Companion.getListFromJson(mappingContent, ResourceAssignment.class); Preconditions.checkNotNull(resourceAssignment, String.format("Failed to get resource assignment info from the content (%s) ", mappingContent)); -- cgit From c70b934e10fcd07c01d1720b6e5cb1cec3d34732 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Sat, 12 Jan 2019 15:48:20 -0500 Subject: Implement BluePrintCatalogService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ifcb0d730daec4da747d704c270b72b991e01f474 Issue-ID: CCSDK-908 Signed-off-by: Alexis de Talhouët --- .../service/BlueprintModelService.java | 62 +++++++++++----------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java index e80fa8cdc..3cf144f17 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java @@ -17,6 +17,10 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; import org.jetbrains.annotations.NotNull; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants; @@ -41,11 +45,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Mono; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; - /** * BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService * @@ -73,7 +72,7 @@ public class BlueprintModelService { private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo"; private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + - " and version(%s) from repo"; + " and version(%s) from repo"; /** * This is a saveBlueprintModel method @@ -85,15 +84,20 @@ public class BlueprintModelService { public Mono saveBlueprintModel(FilePart filePart) throws BluePrintException { try { Path cbaLocation = BluePrintFileUtils.Companion - .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); + .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> { - String blueprintId = bluePrintCatalogService - .uploadToDataBase(cbaLocation.resolve(fileName).toString(), false); + String blueprintId = null; + try { + blueprintId = bluePrintCatalogService + .saveToDatabase(cbaLocation.toFile(), false); + } catch (BluePrintException e) { + // FIXME handle expection + } return blueprintModelSearchRepository.findById(blueprintId).get(); }); } catch (IOException e) { throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(), - String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e); + String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e); } } @@ -136,15 +140,15 @@ public class BlueprintModelService { * @throws BluePrintException BluePrintException */ public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version) - throws BluePrintException { + throws BluePrintException { BlueprintModelSearch blueprintModelSearch; Optional dbBlueprintModel = blueprintModelSearchRepository - .findByArtifactNameAndArtifactVersion(name, version); + .findByArtifactNameAndArtifactVersion(name, version); if (dbBlueprintModel.isPresent()) { blueprintModelSearch = dbBlueprintModel.get(); } else { throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), - String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); + String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); } return blueprintModelSearch; } @@ -152,19 +156,20 @@ public class BlueprintModelService { /** * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version * - * @param name name + * @param name name * @param version version * @return ResponseEntity * @throws BluePrintException BluePrintException */ - public ResponseEntity downloadBlueprintModelFileByNameAndVersion(@NotNull String name, @NotNull String version) - throws BluePrintException { + public ResponseEntity downloadBlueprintModelFileByNameAndVersion(@NotNull String name, + @NotNull String version) + throws BluePrintException { BlueprintModel blueprintModel; try { blueprintModel = getBlueprintModelByNameAndVersion(name, version); } catch (BluePrintException e) { throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " + - "downloading the CBA file: %s", e.getMessage()), e); + "downloading the CBA file: %s", e.getMessage()), e); } String fileName = blueprintModel.getId() + ".zip"; byte[] file = blueprintModel.getBlueprintModelContent().getContent(); @@ -183,7 +188,7 @@ public class BlueprintModelService { blueprintModel = getBlueprintModel(id); } catch (BluePrintException e) { throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " + - "downloading the CBA file: %s", e.getMessage()), e); + "downloading the CBA file: %s", e.getMessage()), e); } String fileName = blueprintModel.getId() + ".zip"; byte[] file = blueprintModel.getBlueprintModelContent().getContent(); @@ -191,15 +196,13 @@ public class BlueprintModelService { } /** - * - * @param (fileName, file) * @return ResponseEntity */ private ResponseEntity prepareResourceEntity(String fileName, byte[] file) { return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") - .body(new ByteArrayResource(file)); + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") + .body(new ByteArrayResource(file)); } /** @@ -224,22 +227,21 @@ public class BlueprintModelService { /** * This is a getBlueprintModelByNameAndVersion method * - * @param name name + * @param name name * @param version version * @return BlueprintModel * @throws BluePrintException BluePrintException */ private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) - throws BluePrintException { - BlueprintModel blueprintModel; - Optional dbBlueprintModel = blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version); - if (dbBlueprintModel.isPresent()) { - blueprintModel = dbBlueprintModel.get(); + throws BluePrintException { + BlueprintModel blueprintModel = blueprintModelRepository + .findByArtifactNameAndArtifactVersion(name, version); + if (blueprintModel != null) { + return blueprintModel; } else { String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version); throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); } - return blueprintModel; } /** -- cgit From f47c36f44fc04a50f7a9f7da5d845d854dea0d14 Mon Sep 17 00:00:00 2001 From: Vinal Date: Wed, 16 Jan 2019 11:09:27 -0500 Subject: Integration test at API level Change-Id: I6f15b5693f494e39bf8d135a96730f2379f5e3fd Issue-ID: CCSDK-954 Signed-off-by: Vinal --- .../service/BlueprintModelService.java | 293 --------------------- .../service/rs/BlueprintModelRest.java | 97 ------- 2 files changed, 390 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java deleted file mode 100644 index 3cf144f17..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BlueprintModelService.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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 java.io.IOException; -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import org.jetbrains.annotations.NotNull; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode; -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository; -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.ByteArrayResource; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import reactor.core.publisher.Mono; - -/** - * BlueprintModelService.java Purpose: Provide Service Template Service processing BlueprintModelService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -public class BlueprintModelService { - - @Autowired - private BluePrintLoadConfiguration bluePrintLoadConfiguration; - - @Autowired - private BluePrintCatalogService bluePrintCatalogService; - - @Autowired - private ControllerBlueprintModelSearchRepository blueprintModelSearchRepository; - - @Autowired - private ControllerBlueprintModelRepository blueprintModelRepository; - - @Autowired - private ControllerBlueprintModelContentRepository blueprintModelContentRepository; - - private static final String BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo"; - private static final String BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + - " and version(%s) from repo"; - - /** - * This is a saveBlueprintModel method - * - * @param filePart filePart - * @return Mono - * @throws BluePrintException BluePrintException - */ - public Mono saveBlueprintModel(FilePart filePart) throws BluePrintException { - try { - Path cbaLocation = BluePrintFileUtils.Companion - .getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath); - return BluePrintEnhancerUtils.Companion.saveCBAFile(filePart, cbaLocation).map(fileName -> { - String blueprintId = null; - try { - blueprintId = bluePrintCatalogService - .saveToDatabase(cbaLocation.toFile(), false); - } catch (BluePrintException e) { - // FIXME handle expection - } - return blueprintModelSearchRepository.findById(blueprintId).get(); - }); - } catch (IOException e) { - throw new BluePrintException(ErrorCode.IO_FILE_INTERRUPT.getValue(), - String.format("I/O Error while uploading the CBA file: %s", e.getMessage()), e); - } - } - - /** - * This is a publishBlueprintModel method to change the status published to YES - * - * @param id id - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - public BlueprintModelSearch publishBlueprintModel(String id) throws BluePrintException { - BlueprintModelSearch blueprintModelSearch; - Optional dbBlueprintModel = blueprintModelSearchRepository.findById(id); - if (dbBlueprintModel.isPresent()) { - blueprintModelSearch = dbBlueprintModel.get(); - } else { - String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); - } - blueprintModelSearch.setPublished(ApplicationConstants.ACTIVE_Y); - return blueprintModelSearchRepository.saveAndFlush(blueprintModelSearch); - } - - /** - * This is a searchBlueprintModels method - * - * @param tags tags - * @return List - */ - public List searchBlueprintModels(String tags) { - return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags); - } - - /** - * This is a getBlueprintModelSearchByNameAndVersion method - * - * @param name name - * @param version version - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - public BlueprintModelSearch getBlueprintModelSearchByNameAndVersion(@NotNull String name, @NotNull String version) - throws BluePrintException { - BlueprintModelSearch blueprintModelSearch; - Optional dbBlueprintModel = blueprintModelSearchRepository - .findByArtifactNameAndArtifactVersion(name, version); - if (dbBlueprintModel.isPresent()) { - blueprintModelSearch = dbBlueprintModel.get(); - } else { - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), - String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)); - } - return blueprintModelSearch; - } - - /** - * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version - * - * @param name name - * @param version version - * @return ResponseEntity - * @throws BluePrintException BluePrintException - */ - public ResponseEntity downloadBlueprintModelFileByNameAndVersion(@NotNull String name, - @NotNull String version) - throws BluePrintException { - BlueprintModel blueprintModel; - try { - blueprintModel = getBlueprintModelByNameAndVersion(name, version); - } catch (BluePrintException e) { - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " + - "downloading the CBA file: %s", e.getMessage()), e); - } - String fileName = blueprintModel.getId() + ".zip"; - byte[] file = blueprintModel.getBlueprintModelContent().getContent(); - return prepareResourceEntity(fileName, file); - } - - /** - * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource - * - * @return ResponseEntity - * @throws BluePrintException BluePrintException - */ - public ResponseEntity downloadBlueprintModelFile(@NotNull String id) throws BluePrintException { - BlueprintModel blueprintModel; - try { - blueprintModel = getBlueprintModel(id); - } catch (BluePrintException e) { - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), String.format("Error while " + - "downloading the CBA file: %s", e.getMessage()), e); - } - String fileName = blueprintModel.getId() + ".zip"; - byte[] file = blueprintModel.getBlueprintModelContent().getContent(); - return prepareResourceEntity(fileName, file); - } - - /** - * @return ResponseEntity - */ - private ResponseEntity prepareResourceEntity(String fileName, byte[] file) { - return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") - .body(new ByteArrayResource(file)); - } - - /** - * This is a getBlueprintModel method - * - * @param id id - * @return BlueprintModel - * @throws BluePrintException BluePrintException - */ - private BlueprintModel getBlueprintModel(@NotNull String id) throws BluePrintException { - BlueprintModel blueprintModel; - Optional dbBlueprintModel = blueprintModelRepository.findById(id); - if (dbBlueprintModel.isPresent()) { - blueprintModel = dbBlueprintModel.get(); - } else { - String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); - } - return blueprintModel; - } - - /** - * This is a getBlueprintModelByNameAndVersion method - * - * @param name name - * @param version version - * @return BlueprintModel - * @throws BluePrintException BluePrintException - */ - private BlueprintModel getBlueprintModelByNameAndVersion(@NotNull String name, @NotNull String version) - throws BluePrintException { - BlueprintModel blueprintModel = blueprintModelRepository - .findByArtifactNameAndArtifactVersion(name, version); - if (blueprintModel != null) { - return blueprintModel; - } else { - String msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version); - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); - } - } - - /** - * This is a getBlueprintModelSearch method - * - * @param id id - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - public BlueprintModelSearch getBlueprintModelSearch(@NotNull String id) throws BluePrintException { - BlueprintModelSearch blueprintModelSearch; - Optional dbBlueprintModel = blueprintModelSearchRepository.findById(id); - if (dbBlueprintModel.isPresent()) { - blueprintModelSearch = dbBlueprintModel.get(); - } else { - String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); - } - - return blueprintModelSearch; - } - - /** - * This is a deleteBlueprintModel method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - @Transactional - public void deleteBlueprintModel(@NotNull String id) throws BluePrintException { - Optional dbBlueprintModel = blueprintModelRepository.findById(id); - if (dbBlueprintModel.isPresent()) { - blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get()); - blueprintModelRepository.delete(dbBlueprintModel.get()); - } else { - String msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id); - throw new BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.getValue(), msg); - } - } - - /** - * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database - * - * @return List list of the controller blueprint archives - */ - public List getAllBlueprintModel() { - return blueprintModelSearchRepository.findAll(); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java deleted file mode 100644 index 255137bf5..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/BlueprintModelRest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * 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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.service.BlueprintModelService; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.multipart.FilePart; -import org.springframework.web.bind.annotation.*; -import reactor.core.publisher.Mono; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@RestController -@RequestMapping(value = "/api/v1/blueprint-model") -public class BlueprintModelRest { - - @Autowired - private BlueprintModelService blueprintModelService; - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public @ResponseBody - Mono saveBlueprint(@RequestPart("file") FilePart file) throws BluePrintException{ - return blueprintModelService.saveBlueprintModel(file); - } - - @DeleteMapping(path = "/{id}") - public void deleteBlueprint(@PathVariable(value = "id") String id) throws BluePrintException { - this.blueprintModelService.deleteBlueprintModel(id); - } - - @GetMapping(path = "/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - BlueprintModelSearch getBlueprintByNameAndVersion(@PathVariable(value = "name") String name, - @PathVariable(value = "version") String version) throws BluePrintException { - return this.blueprintModelService.getBlueprintModelSearchByNameAndVersion(name, version); - } - - @GetMapping(path = "/download/by-name/{name}/version/{version}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResponseEntity downloadBlueprintByNameAndVersion(@PathVariable(value = "name") String name, - @PathVariable(value = "version") String version) throws BluePrintException { - return this.blueprintModelService.downloadBlueprintModelFileByNameAndVersion(name, version); - } - - @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - BlueprintModelSearch getBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException { - return this.blueprintModelService.getBlueprintModelSearch(id); - } - - @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List getAllBlueprintModel() { - return this.blueprintModelService.getAllBlueprintModel(); - } - - @GetMapping(path = "/download/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResponseEntity downloadBluePrint(@PathVariable(value = "id") String id) throws BluePrintException { - return this.blueprintModelService.downloadBlueprintModelFile(id); - } - - @PutMapping(path = "/publish/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - BlueprintModelSearch publishBlueprintModel(@PathVariable(value = "id") String id) throws BluePrintException { - return this.blueprintModelService.publishBlueprintModel(id); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchBlueprintModels(@PathVariable(value = "tags") String tags) { - return this.blueprintModelService.searchBlueprintModels(tags); - } -} -- cgit From a5130dcf4e70f394c1432baefffc198882f04dc1 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 27 Feb 2019 20:16:47 -0500 Subject: Add blueprint runtime validator Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh --- .../validator/ResourceDictionaryValidator.java | 60 --------- .../validator/ServiceTemplateValidator.java | 147 --------------------- 2 files changed, 207 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ResourceDictionaryValidator.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/validator/ServiceTemplateValidator.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') 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 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 properties = new HashMap<>(); - super.validateBlueprint(serviceTemplate, properties); - return true; - } - - /** - * This is a getMetaData to get the key information during the - * - * @return Map - */ - public Map getMetaData() { - return metaData; - } - - @Override - public void validateMetadata(@NotNull Map 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 = getResourceAssignments(nodeTemplate); - ResourceAssignmentValidationService resourceAssignmentValidationService = new ResourceAssignmentValidationServiceImpl(); - resourceAssignmentValidationService.validate(resourceAssignment); - } - } - - private List getResourceAssignments(@NotNull NodeTemplate nodeTemplate) { - - List 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; - } -} -- cgit From 3c7739c914b01fae525d7755b4eff5f2c60c955d Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 11 Mar 2019 13:10:00 -0400 Subject: Code improvement CB controllers Change-Id: I9cc49bb8f93d72e4e642be18381cd562953cc678 Issue-ID: CCSDK-1137 Signed-off-by: Muthuramalingam, Brinda Santh --- .../service/rs/ResourceDictionaryRest.java | 85 ---------------------- 1 file changed, 85 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java (limited to 'ms/controllerblueprints/modules/service/src/main/java') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java deleted file mode 100644 index 8b7a95776..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRest.java +++ /dev/null @@ -1,85 +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.rs; - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ResourceDictionaryHandler; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * {@inheritDoc} - */ -@Deprecated -@RestController -@RequestMapping(value = "/api/v1/dictionary") -public class ResourceDictionaryRest { - - - private ResourceDictionaryHandler resourceDictionaryHandler; - - /** - * This is a DataDictionaryRestImpl, used to save and get the Resource Mapping stored in database - * - * @param resourceDictionaryHandler Data Dictionary Handler - */ - public ResourceDictionaryRest(ResourceDictionaryHandler resourceDictionaryHandler) { - this.resourceDictionaryHandler = resourceDictionaryHandler; - } - - @PostMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResourceDictionary saveResourceDictionary(@RequestBody ResourceDictionary dataDictionary) throws BluePrintException { - return resourceDictionaryHandler.saveResourceDictionary(dataDictionary); - } - - @DeleteMapping(path = "/{name}") - public void deleteResourceDictionaryByName(@PathVariable(value = "name") String name) { - resourceDictionaryHandler.deleteResourceDictionary(name); - } - - @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResourceDictionary getResourceDictionaryByName(@PathVariable(value = "name") String name) throws BluePrintException { - return resourceDictionaryHandler.getResourceDictionaryByName(name); - } - - @PostMapping(path = "/by-names", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchResourceDictionaryByNames(@RequestBody List names) { - return resourceDictionaryHandler.searchResourceDictionaryByNames(names); - } - - @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - List searchResourceDictionaryByTags(@PathVariable(value = "tags") String tags) { - return resourceDictionaryHandler.searchResourceDictionaryByTags(tags); - - } - - @GetMapping(path = "/source-mapping", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - ResourceSourceMapping getResourceSourceMapping() { - return resourceDictionaryHandler.getResourceSourceMapping(); - } - -} -- cgit