aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportManager.java
blob: fa079d2f65c523ccfabd38697c77d5bdfa996c10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2020 CMCC Intellectual Property. All rights reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.be.components.impl;


import javax.servlet.ServletContext;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.UploadServiceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;


//upload Service model by Shiyong1989@hotmail.com
@Component("ServiceImportManager")
public class ServiceImportManager {

  private ServletContext servletContext;

  private ResponseFormatManager responseFormatManager;

  @Autowired
  private ServiceBusinessLogic serviceBusinessLogic;

  public ServiceImportBusinessLogic getServiceImportBusinessLogic() {
    return serviceImportBusinessLogic;
  }

  public void setServiceImportBusinessLogic(
      ServiceImportBusinessLogic serviceImportBusinessLogic) {
    this.serviceImportBusinessLogic = serviceImportBusinessLogic;
  }

  @Autowired
  private ServiceImportBusinessLogic serviceImportBusinessLogic;

  public boolean isServiceExist(String serviceName) {
    return serviceBusinessLogic.isServiceExist(serviceName);
  }


  public ServiceBusinessLogic getServiceBusinessLogic() {
    return serviceBusinessLogic;
  }

  public void setServiceBusinessLogic(
      ServiceBusinessLogic serviceBusinessLogic) {
    this.serviceBusinessLogic = serviceBusinessLogic;
  }


  public void populateServiceMetadata(UploadServiceInfo serviceMetaData, Service service) {
    if (service != null && serviceMetaData != null) {
      service.setDescription(serviceMetaData.getDescription());
      service.setTags(serviceMetaData.getTags());
      service.setCategories(serviceMetaData.getCategories());
      service.setContactId(serviceMetaData.getContactId());
      service.setName(serviceMetaData.getName());
      service.setIcon(serviceMetaData.getServiceIconPath());
      service.setServiceVendorModelNumber(serviceMetaData.getServiceVendorModelNumber());
      ServiceMetadataDataDefinition serviceMetadataDataDefinition = (ServiceMetadataDataDefinition) service
          .getComponentMetadataDefinition().getMetadataDataDefinition();
      serviceMetadataDataDefinition.getServiceVendorModelNumber();
      service.setServiceType("");
      service.setProjectCode(serviceMetaData.getProjectCode());
      if (serviceMetaData.getVendorName() != null) {
        service.setVendorName(serviceMetaData.getVendorName());
      }
      if (serviceMetaData.getVendorRelease() != null) {
        service.setVendorRelease(serviceMetaData.getVendorRelease());
      }
    }
  }

  public synchronized void init(ServletContext servletContext) {
    if (this.servletContext == null) {
      this.servletContext = servletContext;
      responseFormatManager = ResponseFormatManager.getInstance();
      serviceBusinessLogic = getServiceBL(servletContext);
    }
  }

  private ServiceBusinessLogic getServiceBL(ServletContext context) {
    WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(org.openecomp.sdc.common.api.Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
    WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
    return webApplicationContext.getBean(ServiceBusinessLogic.class);
  }
}