Added oparent to sdc main
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / main / VrfObjectFixMenu.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.asdctool.main;
22
23 import org.openecomp.sdc.asdctool.configuration.VrfObjectFixConfiguration;
24 import org.openecomp.sdc.asdctool.impl.VrfObjectFixHandler;
25 import org.openecomp.sdc.be.config.ConfigurationManager;
26 import org.openecomp.sdc.common.api.ConfigurationSource;
27 import org.openecomp.sdc.common.impl.ExternalConfiguration;
28 import org.openecomp.sdc.common.impl.FSConfigurationSource;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
31
32 import java.util.Arrays;
33
34 public class VrfObjectFixMenu {
35
36     private static final Logger log = Logger.getLogger(VrfObjectFixMenu.class);
37
38     private VrfObjectFixMenu(){}
39
40     public static void main(String[] args) {
41         if (isNotValidArguments(args)) {
42             log.debug("#main - The invalid array of the arguments have been received: {}", Arrays.toString(args));
43             log.debug("#main - Usage: <configuration dir> <'detect'/'fix'> <output folder path>");
44             System.exit(1);
45         }
46         initConfig(args[0]);
47         VrfObjectFixHandler vrfObjectFixHandler = getVrfObjectFixHandler();
48         if (vrfObjectFixHandler.handle(args[1], args.length == 3 ? args[2] : null)) {
49             log.info("#main - The {} operation of the corrupted VRFObject Node Types has been finished successfully", args[1]);
50         } else{
51             log.info("#main - The {} operation of the corrupted VRFObject Node Types has been failed", args[1]);
52             System.exit(2);
53         }
54         System.exit(0);
55     }
56
57     private static VrfObjectFixHandler getVrfObjectFixHandler() {
58         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(VrfObjectFixConfiguration.class);
59         return context.getBean(VrfObjectFixHandler.class);
60     }
61
62     private static boolean isNotValidArguments(String[] args) {
63         return args == null || args.length < 2;
64     }
65
66
67     private static void initConfig(String configDir) {
68         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), configDir);
69         new ConfigurationManager(configurationSource);
70     }
71
72 }