2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service;
\r
19 import org.apache.commons.lang3.StringUtils;
\r
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate;
\r
22 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
\r
23 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.validator.ResourceAssignmentValidator;
\r
24 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent;
\r
25 import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse;
\r
26 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository;
\r
27 import org.springframework.stereotype.Service;
\r
29 import java.util.ArrayList;
\r
30 import java.util.List;
\r
31 import java.util.regex.Matcher;
\r
32 import java.util.regex.Pattern;
\r
35 * ServiceTemplateService.java Purpose: Provide Service Template Create Service processing ServiceTemplateService
\r
37 * @author Brinda Santh
\r
42 public class ServiceTemplateService {
\r
44 private ResourceDictionaryRepository dataDictionaryRepository;
\r
46 private ConfigModelCreateService configModelCreateService;
\r
47 private BluePrintEnhancerService bluePrintEnhancerService;
\r
50 * This is a SchemaGeneratorService constructor
\r
52 * @param dataDictionaryRepository dataDictionaryRepository
\r
53 * @param configModelCreateService configModelCreateService
\r
54 * @param bluePrintEnhancerService bluePrintEnhancerService
\r
56 public ServiceTemplateService(ResourceDictionaryRepository dataDictionaryRepository,
\r
57 ConfigModelCreateService configModelCreateService,
\r
58 BluePrintEnhancerService bluePrintEnhancerService) {
\r
59 this.dataDictionaryRepository = dataDictionaryRepository;
\r
60 this.configModelCreateService = configModelCreateService;
\r
61 this.bluePrintEnhancerService = bluePrintEnhancerService;
\r
66 * This is a validateServiceTemplate method
\r
68 * @param serviceTemplate serviceTemplate
\r
69 * @return ServiceTemplate
\r
70 * @throws BluePrintException BluePrintException
\r
72 public ServiceTemplate validateServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {
\r
73 return this.configModelCreateService.validateServiceTemplate(serviceTemplate);
\r
77 * This is a enrichServiceTemplate method
\r
79 * @param serviceTemplate serviceTemplate
\r
80 * @return ServiceTemplate
\r
82 public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) {
\r
83 this.bluePrintEnhancerService.enhance(serviceTemplate);
\r
84 return serviceTemplate;
\r
88 * This is a autoMap method to map the template keys
\r
90 * @param resourceAssignments resourceAssignments
\r
91 * @return AutoMapResponse
\r
92 * @throws BluePrintException BluePrintException
\r
94 public AutoMapResponse autoMap(List<ResourceAssignment> resourceAssignments) throws BluePrintException {
\r
95 AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository);
\r
96 return autoMappingService.autoMap(resourceAssignments);
\r
100 * This is a validateResourceAssignments method
\r
102 * @param resourceAssignments resourceAssignments
\r
103 * @return List<ResourceAssignment>
\r
104 * @throws BluePrintException BluePrintException
\r
106 public List<ResourceAssignment> validateResourceAssignments(List<ResourceAssignment> resourceAssignments)
\r
107 throws BluePrintException {
\r
109 ResourceAssignmentValidator resourceAssignmentValidator =
\r
110 new ResourceAssignmentValidator(resourceAssignments);
\r
111 resourceAssignmentValidator.validateResourceAssignment();
\r
112 } catch (BluePrintException e) {
\r
113 throw new BluePrintException(e.getMessage(), e);
\r
115 return resourceAssignments;
\r
119 * This is a generateResourceAssignments method
\r
121 * @param templateContent templateContent
\r
122 * @return List<ResourceAssignment>
\r
124 public List<ResourceAssignment> generateResourceAssignments(ConfigModelContent templateContent) {
\r
125 List<ResourceAssignment> resourceAssignments = new ArrayList<>();
\r
126 if (templateContent != null && StringUtils.isNotBlank(templateContent.getContent())) {
\r
127 Pattern p = Pattern.compile("(?<=\\$\\{)([^\\}]+)(?=\\})");
\r
128 Matcher m = p.matcher(templateContent.getContent());
\r
130 ResourceAssignment resourceAssignment = new ResourceAssignment();
\r
131 resourceAssignment.setName(m.group());
\r
132 resourceAssignments.add(resourceAssignment);
\r
135 return resourceAssignments;
\r