2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, CMCC Technologies Co., Ltd.
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.nssmf.manager;
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;
40 public class NssmfManagerBuilder {
42 private BaseNssmfManager nssmfManger;
44 private RestUtil restUtil;
46 private ActionType actionType;
48 private ResourceOperationStatusRepository repository;
50 private ServiceInfo serviceInfo;
52 private NssmfAdapterConfig adapterConfig;
54 public NssmfManagerBuilder(EsrInfo esrInfo) throws ApplicationException {
56 ExecutorType executorType = getExecutorType(esrInfo);
57 NetworkType networkType = esrInfo.getNetworkType();
59 if (ExecutorType.INTERNAL.equals(executorType) && NetworkType.CORE.equals(networkType)) {
60 this.nssmfManger = new InternalCnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType);
64 if (ExecutorType.INTERNAL.equals(executorType) && NetworkType.TRANSPORT.equals(networkType)) {
65 this.nssmfManger = new InternalTnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType);
69 if (ExecutorType.INTERNAL.equals(executorType) && NetworkType.ACCESS.equals(networkType)) {
70 this.nssmfManger = new InternalAnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType);
74 if (ExecutorType.EXTERNAL.equals(executorType) && NetworkType.CORE.equals(networkType)) {
75 this.nssmfManger = new ExternalCnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType)
76 .setInitStatus("deactivated");
80 if (ExecutorType.EXTERNAL.equals(executorType) && NetworkType.ACCESS.equals(networkType)) {
81 this.nssmfManger = new ExternalAnNssmfManager().setEsrInfo(esrInfo).setExecutorType(executorType)
82 .setInitStatus("activated");
86 throw new ApplicationException(404, "invalid domain and simulator");
89 private ExecutorType getExecutorType(EsrInfo esrInfo) {
90 if (NssmfAdapterConsts.ONAP_INTERNAL_TAG.equals(esrInfo.getVendor())) {
91 return ExecutorType.INTERNAL;
93 return ExecutorType.EXTERNAL;
96 public NssmfManagerBuilder setRestUtil(RestUtil restUtil) {
97 this.restUtil = restUtil;
101 public NssmfManagerBuilder setActionType(ActionType actionType) {
102 this.actionType = actionType;
106 public NssmfManagerBuilder setRepository(ResourceOperationStatusRepository repository) {
107 this.repository = repository;
111 public NssmfManagerBuilder setServiceInfo(ServiceInfo serviceInfo) {
112 this.serviceInfo = serviceInfo;
116 public NssmfManagerBuilder setAdapterConfig(NssmfAdapterConfig adapterConfig) {
117 this.adapterConfig = adapterConfig;
121 public NssmfManager build() {
122 return this.nssmfManger.setRestUtil(restUtil).setAdapterConfig(adapterConfig).setRepository(repository)
123 .setActionType(actionType).setServiceInfo(serviceInfo);