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 com.github.fge.jsonschema.core.exceptions.ProcessingException;
24 import java.io.IOException;
25 import java.time.Duration;
26 import java.util.List;
27 import java.util.Optional;
28 import org.json.JSONObject;
29 import org.onap.pnfsimulator.ConfigurationProvider;
30 import org.onap.pnfsimulator.FileProvider;
31 import org.onap.pnfsimulator.PnfSimConfig;
32 import org.onap.pnfsimulator.message.MessageProvider;
33 import org.onap.pnfsimulator.simulator.validation.JSONValidator;
34 import org.onap.pnfsimulator.simulator.validation.ValidationException;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
39 public class SimulatorFactory {
41 private static final String DEFAULT_OUTPUT_SCHEMA_PATH = "json_schema/output_validator_ves_schema_30.0.1.json";
43 private MessageProvider messageProvider;
44 private JSONValidator validator;
47 public SimulatorFactory(MessageProvider messageProvider, JSONValidator validator) {
48 this.messageProvider = messageProvider;
49 this.validator = validator;
52 public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams,
53 Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams)
54 throws ProcessingException, IOException, ValidationException {
55 PnfSimConfig configuration = ConfigurationProvider.getConfigInstance();
56 String xnfUrl = "sftp://onap:pano@" + configuration.getIpsftp() + "/";
57 String vesUrl = configuration.getVesip() + "/eventListener/v7";
59 Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION)));
60 Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL)));
62 List<String> fileList = FileProvider.getFiles();
63 JSONObject messageBody = messageProvider
64 .createMessage(commonEventHeaderParams, pnfRegistrationParams, notificationParams, fileList, xnfUrl);
65 validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH);
67 return Simulator.builder().withVesUrl(vesUrl).withDuration(duration).withInterval(interval)
68 .withMessageBody(messageBody).build();