Merge "switch drools pdp image to new one"
[integration.git] / test / mocks / mass-pnf-sim / pnf-sim-lightweight / src / main / java / org / onap / pnfsimulator / simulator / SimulatorFactory.java
1 /*
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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=========================================================
16  */
17
18 package org.onap.pnfsimulator.simulator;
19
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.PnfSimConfig;
28 import org.springframework.stereotype.Service;
29
30 @Service
31 public class SimulatorFactory {
32
33     public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams,
34             Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) {
35         PnfSimConfig configuration = ConfigurationProvider.getConfigInstance();
36
37         String xnfUrl = null;
38         if (configuration.getDefaultfileserver().equals("sftp")) {
39             xnfUrl = configuration.getUrlsftp() + "/";
40         } else if (configuration.getDefaultfileserver().equals("ftps")) {
41             xnfUrl = configuration.getUrlftps() + "/";
42         }
43
44         String urlVes = configuration.getUrlves();
45         Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION)));
46         Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL)));
47
48         return Simulator.builder().withVesUrl(urlVes).withXnfUrl(xnfUrl).withDuration(duration)
49                 .withCommonEventHeaderParams(commonEventHeaderParams).withNotificationParams(notificationParams)
50                 .withPnfRegistrationParams(pnfRegistrationParams).withInterval(interval).build();
51     }
52 }