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
\r
53 * @param configModelCreateService
\r
54 * @param 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
\r
69 * @return ServiceTemplate
\r
70 * @throws 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
\r
80 * @return ServiceTemplate
\r
81 * @throws BluePrintException
\r
83 public ServiceTemplate enrichServiceTemplate(ServiceTemplate serviceTemplate) throws BluePrintException {
\r
84 this.bluePrintEnhancerService.enhance(serviceTemplate);
\r
85 return serviceTemplate;
\r
89 * This is a autoMap method to map the template keys
\r
91 * @param resourceAssignments
\r
92 * @return AutoMapResponse
\r
93 * @throws BluePrintException
\r
95 public AutoMapResponse autoMap(List<ResourceAssignment> resourceAssignments) throws BluePrintException {
\r
96 AutoResourceMappingService autoMappingService = new AutoResourceMappingService(dataDictionaryRepository);
\r
97 AutoMapResponse autoMapResponse = autoMappingService.autoMap(resourceAssignments);
\r
98 return autoMapResponse;
\r
102 * This is a validateResourceAssignments method
\r
104 * @param resourceAssignments
\r
105 * @return List<ResourceAssignment>
\r
106 * @throws BluePrintException
\r
108 public List<ResourceAssignment> validateResourceAssignments(List<ResourceAssignment> resourceAssignments)
\r
109 throws BluePrintException {
\r
111 ResourceAssignmentValidator resourceAssignmentValidator =
\r
112 new ResourceAssignmentValidator(resourceAssignments);
\r
113 resourceAssignmentValidator.validateResourceAssignment();
\r
114 } catch (BluePrintException e) {
\r
115 throw new BluePrintException(e.getMessage(), e);
\r
117 return resourceAssignments;
\r
121 * This is a generateResourceAssignments method
\r
123 * @param templateContent
\r
124 * @return List<ResourceAssignment>
\r
126 public List<ResourceAssignment> generateResourceAssignments(ConfigModelContent templateContent) {
\r
127 List<ResourceAssignment> resourceAssignments = new ArrayList<>();
\r
128 if (templateContent != null && StringUtils.isNotBlank(templateContent.getContent())) {
\r
129 Pattern p = Pattern.compile("(?<=\\$\\{)([^\\}]+)(?=\\})");
\r
130 Matcher m = p.matcher(templateContent.getContent());
\r
132 ResourceAssignment resourceAssignment = new ResourceAssignment();
\r
133 resourceAssignment.setName(m.group());
\r
134 resourceAssignments.add(resourceAssignment);
\r
137 return resourceAssignments;
\r