Update license files, sonar plugin and fix tests
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / util / AAIConfigCommandLinePropGetter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 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.aai.util;
22
23 import org.openecomp.aai.exceptions.AAIException;
24
25 /*
26  * The script deobfuscatePW.sh needs to retrieve pws from the AAIConfig file.
27  * As AAIConfig has no main to be callable on the command line, this class helps
28  * by providing one for accessing AAIConfig that way.
29  * (AAIConfig deobfuscates pws itself, so we just need to call its .get() on the desired pw.)
30  * 
31  * This could be used to get any property from AAIConfig via the command line,
32  * not just the pws, even though it was made for pw-related needs.
33  */
34 public class AAIConfigCommandLinePropGetter {
35
36         /**
37          * The main method.
38          *
39          * @param args the arguments
40          */
41         /*
42          * usage:
43          * AAIConfigCommandLinePropGetter propertyname
44          */
45         public static void main(String[] args) {
46                 if (args.length != 1) {
47                         System.out.println("only one property may be requested at a time");
48                         System.out.println("usage: AAIConfigCommandLinePropGetter propertyname");
49                 }
50                 try {
51                         AAIConfig.init();
52                         String value = AAIConfig.get(args[0]);
53                         if (value != null) {
54                                 System.out.println(value); //bc this utility used by a shell script so it needs the result sent to stdout
55                         } else {
56                                 System.out.println("requested property could not be found");
57                         }
58                 } catch(AAIException e) {
59                         System.out.println("exception:" + e.toString()); //TODO is this reasonable?
60                 } finally {
61                         System.exit(0);
62                 }
63
64         }
65
66 }