0b332af6071b28de30636375d87c153936142bd4
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2020, CMCC Technologies Co., Ltd.
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
21 package org.onap.so.adapters.nssmf.manager;
22
23 import org.onap.so.adapters.nssmf.config.NssmfAdapterConfig;
24 import org.onap.so.adapters.nssmf.consts.NssmfAdapterConsts;
25 import org.onap.so.adapters.nssmf.enums.ActionType;
26 import org.onap.so.adapters.nssmf.enums.ExecutorType;
27 import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
28 import org.onap.so.adapters.nssmf.manager.impl.external.ExternalAnNssmfManager;
29 import org.onap.so.adapters.nssmf.manager.impl.external.ExternalCnNssmfManager;
30 import org.onap.so.adapters.nssmf.manager.impl.internal.InternalAnNssmfManager;
31 import org.onap.so.adapters.nssmf.manager.impl.internal.InternalCnNssmfManager;
32 import org.onap.so.adapters.nssmf.manager.impl.internal.InternalTnNssmfManager;
33 import org.onap.so.adapters.nssmf.manager.impl.*;
34 import org.onap.so.adapters.nssmf.util.RestUtil;
35 import org.onap.so.beans.nsmf.EsrInfo;
36 import org.onap.so.beans.nsmf.NetworkType;
37 import org.onap.so.beans.nsmf.ServiceInfo;
38 import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
39
40 public class NssmfManagerBuilder {
41
42     private BaseNssmfManager nssmfManger;
43
44     private RestUtil restUtil;
45
46     private ActionType actionType;
47
48     private ResourceOperationStatusRepository repository;
49
50     private ServiceInfo serviceInfo;
51
52     private NssmfAdapterConfig adapterConfig;
53
54     public NssmfManagerBuilder(EsrInfo esrInfo) throws ApplicationException {
55
56         ExecutorType executorType = getExecutorType(esrInfo);
57         NetworkType networkType = esrInfo.getNetworkType();
58
59         if (ExecutorType.INTERNAL.equals(executorType) && NetworkType.CORE.equals(networkType)) {
60             this.nssmfManger = new InternalCnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType);
61             return;
62         }
63
64         if (ExecutorType.INTERNAL.equals(executorType) && NetworkType.TRANSPORT.equals(networkType)) {
65             this.nssmfManger = new InternalTnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType);
66             return;
67         }
68
69         if (ExecutorType.INTERNAL.equals(executorType) && NetworkType.ACCESS.equals(networkType)) {
70             this.nssmfManger = new InternalAnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType);
71             return;
72         }
73
74         if (ExecutorType.EXTERNAL.equals(executorType) && NetworkType.CORE.equals(networkType)) {
75             this.nssmfManger = new ExternalCnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType)
76                     .setInitStatus("deactivated");
77             return;
78         }
79
80         if (ExecutorType.EXTERNAL.equals(executorType) && NetworkType.ACCESS.equals(networkType)) {
81             this.nssmfManger = new ExternalAnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType)
82                     .setInitStatus("activated");
83             return;
84         }
85
86         throw new ApplicationException(404, "invalid domain and simulator");
87     }
88
89     private ExecutorType getExecutorType(EsrInfo esrInfo) {
90         if (NssmfAdapterConsts.ONAP_INTERNAL_TAG.equals(esrInfo.getVendor())) {
91             return ExecutorType.INTERNAL;
92         }
93         return ExecutorType.EXTERNAL;
94     }
95
96     public NssmfManagerBuilder setRestUtil(RestUtil restUtil) {
97         this.restUtil = restUtil;
98         return this;
99     }
100
101     public NssmfManagerBuilder setActionType(ActionType actionType) {
102         this.actionType = actionType;
103         return this;
104     }
105
106     public NssmfManagerBuilder setRepository(ResourceOperationStatusRepository repository) {
107         this.repository = repository;
108         return this;
109     }
110
111     public NssmfManagerBuilder setServiceInfo(ServiceInfo serviceInfo) {
112         this.serviceInfo = serviceInfo;
113         return this;
114     }
115
116     public NssmfManagerBuilder setAdapterConfig(NssmfAdapterConfig adapterConfig) {
117         this.adapterConfig = adapterConfig;
118         return this;
119     }
120
121     public NssmfManager build() {
122         return this.nssmfManger.setRestUtil(restUtil).setAdapterConfig(adapterConfig).setRepository(repository)
123                 .setActionType(actionType).setServiceInfo(serviceInfo);
124     }
125 }