Implement 'Update Service by importing Tosca Template'-story
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / ServiceImportManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 CMCC Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.be.components.impl;
21
22 import lombok.Getter;
23 import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
24 import org.openecomp.sdc.be.model.Service;
25 import org.openecomp.sdc.be.model.UploadServiceInfo;
26 import org.springframework.stereotype.Component;
27
28 //upload Service model by Shiyong1989@hotmail.com
29 @Component("ServiceImportManager")
30 @Getter
31 public class ServiceImportManager {
32
33     private final ServiceBusinessLogic serviceBusinessLogic;
34     private final ServiceImportBusinessLogic serviceImportBusinessLogic;
35
36     public ServiceImportManager(ServiceBusinessLogic serviceBusinessLogic, ServiceImportBusinessLogic serviceImportBusinessLogic) {
37         this.serviceBusinessLogic = serviceBusinessLogic;
38         this.serviceImportBusinessLogic = serviceImportBusinessLogic;
39     }
40
41     public boolean isServiceExist(String serviceName) {
42         return serviceBusinessLogic.isServiceExist(serviceName);
43     }
44
45     public void populateServiceMetadata(UploadServiceInfo serviceMetaData, Service service) {
46         if (service != null && serviceMetaData != null) {
47             service.setDescription(serviceMetaData.getDescription());
48             service.setTenant(serviceMetaData.getTenant());
49             service.setTags(serviceMetaData.getTags());
50             service.setCategories(serviceMetaData.getCategories());
51             service.setContactId(serviceMetaData.getContactId());
52             service.setName(serviceMetaData.getName());
53             service.setIcon(serviceMetaData.getServiceIconPath());
54             service.setServiceVendorModelNumber(serviceMetaData.getServiceVendorModelNumber());
55             ServiceMetadataDataDefinition serviceMetadataDataDefinition = (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition()
56                     .getMetadataDataDefinition();
57             serviceMetadataDataDefinition.getServiceVendorModelNumber();
58             service.setServiceType(serviceMetaData.getServiceType());
59             service.setServiceRole(serviceMetaData.getServiceRole());
60             service.setNamingPolicy(serviceMetaData.getNamingPolicy());
61             boolean ecompGeneratedNaming = serviceMetaData.getEcompGeneratedNaming() == null
62                     || serviceMetaData.getEcompGeneratedNaming().equals("true");
63             service.setEcompGeneratedNaming(ecompGeneratedNaming);
64             service.setServiceFunction(serviceMetaData.getServiceFunction());
65             service.setInstantiationType(serviceMetaData.getInstantiationType());
66             service.setEnvironmentContext(serviceMetaData.getEnvironmentContext());
67             service.setProjectCode(serviceMetaData.getProjectCode());
68             service.setModel(serviceMetaData.getModel());
69             if (serviceMetaData.getVendorName() != null) {
70                 service.setVendorName(serviceMetaData.getVendorName());
71             }
72             if (serviceMetaData.getVendorRelease() != null) {
73                 service.setVendorRelease(serviceMetaData.getVendorRelease());
74             }
75             service.setCategorySpecificMetadata(serviceMetaData.getCategorySpecificMetadata());
76             service.setDerivedFromGenericType(serviceMetaData.getDerivedFromGenericType());
77             service.setDerivedFromGenericVersion(serviceMetaData.getDerivedFromGenericVersion());
78         }
79     }
80
81 }