2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.controllerblueprints.service;
19 import com.att.eelf.configuration.EELFLogger;
20 import com.att.eelf.configuration.EELFManager;
21 import com.google.common.base.Preconditions;
22 import org.apache.commons.collections.MapUtils;
23 import org.apache.commons.lang3.StringUtils;
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException;
25 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType;
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate;
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils;
28 import org.onap.ccsdk.cds.controllerblueprints.service.common.SwaggerGenerator;
30 import java.util.HashMap;
34 * SchemaGeneratorService.java Purpose: Provide Service to generate service template input schema definition and Sample
37 * @author Brinda Santh
41 public class SchemaGeneratorService {
42 private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorService.class);
44 private Map<String, DataType> dataTypes;
47 * This is a SchemaGeneratorService constructor
49 public SchemaGeneratorService() {
50 dataTypes = new HashMap<>();
54 * This is a generateSchema
56 * @param serviceTemplateContent service template content
58 * @throws BluePrintException Blueprint Exception
60 public String generateSchema(String serviceTemplateContent) throws BluePrintException {
61 if (StringUtils.isNotBlank(serviceTemplateContent)) {
62 ServiceTemplate serviceTemplate = JacksonUtils.Companion.readValue(serviceTemplateContent,
63 ServiceTemplate.class);
64 return generateSchema(serviceTemplate);
66 throw new BluePrintException(
67 "Service Template Content is (" + serviceTemplateContent + ") not Defined.");
72 * This is a generateSchema
74 * @param serviceTemplate service template content
76 * @throws BluePrintException Blueprint Exception
78 public String generateSchema(ServiceTemplate serviceTemplate) throws BluePrintException {
79 String schemaContent = null;
80 Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined.");
82 if (serviceTemplate.getTopologyTemplate() != null
83 && serviceTemplate.getTopologyTemplate().getInputs() != null) {
84 SwaggerGenerator swaggerGenerator = new SwaggerGenerator(serviceTemplate);
85 schemaContent = swaggerGenerator.generateSwagger();
87 } catch (Exception e) {
88 throw new BluePrintException(e.getMessage(), e);
94 private void manageServiceTemplateActions(ServiceTemplate serviceTemplate, String actionName) {
95 if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null
96 && StringUtils.isNotBlank(actionName)) {
98 if (MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs())) {
100 serviceTemplate.getTopologyTemplate().getInputs().entrySet().removeIf(entity -> {
101 String keyName = entity.getKey();
102 String replacedAction = actionName.replace("-action", "-request");
103 log.debug("Key name : " + keyName + ", actionName "
104 + actionName + ", replacedAction :" + replacedAction);
105 if (keyName.endsWith("-request") && !keyName.equals(replacedAction)) {
106 log.info("deleting input property {} ", keyName);