e397201e4b3308c22309f9ce5ea6e9b0ce191cea
[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.TRANSPORT.equals(networkType)) {
81             this.nssmfManger = new ExternalAnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType)
82                     .setInitStatus("activated");
83             return;
84         }
85
86         if (ExecutorType.EXTERNAL.equals(executorType) && NetworkType.ACCESS.equals(networkType)) {
87             this.nssmfManger = new ExternalAnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType)
88                     .setInitStatus("activated");
89             return;
90         }
91
92         throw new ApplicationException(404, "invalid domain and simulator");
93     }
94
95     private ExecutorType getExecutorType(EsrInfo esrInfo) {
96         if (NssmfAdapterConsts.ONAP_INTERNAL_TAG.equals(esrInfo.getVendor())) {
97             return ExecutorType.INTERNAL;
98         }
99         return ExecutorType.EXTERNAL;
100     }
101
102     public NssmfManagerBuilder setRestUtil(RestUtil restUtil) {
103         this.restUtil = restUtil;
104         return this;
105     }
106
107     public NssmfManagerBuilder setActionType(ActionType actionType) {
108         this.actionType = actionType;
109         return this;
110     }
111
112     public NssmfManagerBuilder setRepository(ResourceOperationStatusRepository repository) {
113         this.repository = repository;
114         return this;
115     }
116
117     public NssmfManagerBuilder setServiceInfo(ServiceInfo serviceInfo) {
118         this.serviceInfo = serviceInfo;
119         return this;
120     }
121
122     public NssmfManagerBuilder setAdapterConfig(NssmfAdapterConfig adapterConfig) {
123         this.adapterConfig = adapterConfig;
124         return this;
125     }
126
127     public NssmfManager build() {
128         return this.nssmfManger.setRestUtil(restUtil).setAdapterConfig(adapterConfig).setRepository(repository)
129                 .setActionType(actionType).setServiceInfo(serviceInfo);
130     }
131 }