2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.tools.model.generator.model2event;
23 import org.apache.commons.cli.CommandLine;
24 import org.apache.commons.cli.HelpFormatter;
25 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
26 import org.onap.policy.apex.tools.common.CliOptions;
27 import org.onap.policy.apex.tools.common.CliParser;
30 * Model 2 event generator with main method.
32 * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
34 public final class Application {
36 /** The name of the application. */
37 public static final String APP_NAME = "gen-model2event";
39 /** The description 1-liner of the application. */
40 public static final String APP_DESCRIPTION = "generates JSON templates for events generated from a policy model";
42 /** Private constructor to prevent instantiation. */
43 private Application() {}
46 * Main method to start the application.
48 * @param args the command line arguments
50 public static void main(final String[] args) {
51 final CliParser cli = new CliParser();
52 cli.addOption(CliOptions.HELP);
53 cli.addOption(CliOptions.VERSION);
54 cli.addOption(CliOptions.MODELFILE);
55 cli.addOption(CliOptions.TYPE);
57 final CommandLine cmd = cli.parseCli(args);
59 // help is an exit option, print usage and exit
60 if (cmd.hasOption('h') || cmd.hasOption("help")) {
61 final HelpFormatter formatter = new HelpFormatter();
62 System.out.println(APP_NAME + " v" + cli.getAppVersion() + " - " + APP_DESCRIPTION);
63 formatter.printHelp(APP_NAME, cli.getOptions());
68 // version is an exit option, print version and exit
69 if (cmd.hasOption('v') || cmd.hasOption("version")) {
70 System.out.println(APP_NAME + " " + cli.getAppVersion());
75 String modelFile = cmd.getOptionValue('m');
76 if (modelFile == null) {
77 modelFile = cmd.getOptionValue("model");
79 if (modelFile == null) {
80 System.err.println(APP_NAME + ": no model file given, cannot proceed (try -h for help)");
84 String type = cmd.getOptionValue('t');
86 type = cmd.getOptionValue("type");
89 System.err.println(APP_NAME + ": no event type given, cannot proceed (try -h for help)");
92 if (!type.equals("stimuli") && !type.equals("response") && !type.equals("internal")) {
93 System.err.println(APP_NAME + ": unknown type <" + type + ">, cannot proceed (try -h for help)");
98 System.out.println(APP_NAME + ": starting Event generator");
99 System.out.println(" --> model file: " + modelFile);
100 System.out.println(" --> type: " + type);
101 System.out.println();
102 System.out.println();
105 final Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
107 } catch (final ApexException aex) {
108 System.err.println(APP_NAME + ": caught APEX exception with message: " + aex.getMessage());