2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================ Copyright (C)
5 * 2018 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================ Licensed under
7 * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
15 * the License. ============LICENSE_END=========================================================
18 package org.onap.pnfsimulator.simulator;
20 import static java.lang.Integer.parseInt;
21 import static org.onap.pnfsimulator.message.MessageConstants.MESSAGE_INTERVAL;
22 import static org.onap.pnfsimulator.message.MessageConstants.TEST_DURATION;
23 import java.time.Duration;
24 import java.util.Optional;
25 import org.json.JSONObject;
26 import org.onap.pnfsimulator.ConfigurationProvider;
27 import org.onap.pnfsimulator.FileProvider;
28 import org.onap.pnfsimulator.PnfSimConfig;
29 import org.springframework.stereotype.Service;
32 public class SimulatorFactory {
34 public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams,
35 Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) {
36 PnfSimConfig configuration = ConfigurationProvider.getConfigInstance();
39 if (configuration.getTypefileserver().equals("sftp")) {
40 xnfUrl = configuration.getUrlsftp() + "/";
41 } else if (configuration.getTypefileserver().equals("ftps")) {
42 xnfUrl = configuration.getUrlftps() + "/";
45 String urlVes = configuration.getUrlves();
46 Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION)));
47 Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL)));
49 return Simulator.builder().withVesUrl(urlVes).withXnfUrl(xnfUrl).withDuration(duration)
50 .withFileProvider(new FileProvider()).withCommonEventHeaderParams(commonEventHeaderParams)
51 .withNotificationParams(notificationParams).withPnfRegistrationParams(pnfRegistrationParams)
52 .withInterval(interval).build();