Added oparent to sdc main
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / main / DeleteComponentTool.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 java.util.Scanner;
24
25 import org.openecomp.sdc.asdctool.configuration.ConfigurationUploader;
26 import org.openecomp.sdc.asdctool.configuration.InternalToolConfiguration;
27 import org.openecomp.sdc.asdctool.impl.internal.tool.DeleteComponentHandler;
28 import org.openecomp.sdc.asdctool.utils.ConsoleWriter;
29 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
30
31 public class DeleteComponentTool extends SdcInternalTool{
32     private static final String PSW = "ItIsTimeToDelete";
33
34     public static void main(String[] args) {
35         if (args == null || args.length < 2) {
36             ConsoleWriter.dataLine("Usage: <configuration dir> <password>");
37             System.exit(1);
38         }
39         String appConfigDir = args[0];
40         String password = args[1];
41         
42         if ( !PSW.equals(password) ){
43             ConsoleWriter.dataLine("Wrong password");
44             System.exit(1);
45         }
46         
47         disableConsole();
48         ConsoleWriter.dataLine("STARTED... ");
49
50         ConfigurationUploader.uploadConfigurationFiles(appConfigDir);
51         AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(InternalToolConfiguration.class);
52         DeleteComponentHandler deleteComponentHandler = context.getBean(DeleteComponentHandler.class);
53
54
55         String input = "";
56         Scanner scanner = new Scanner(System.in);
57         do {
58             ConsoleWriter.dataLine("Enter next component unique id or exit: ");
59             input = scanner.nextLine();
60             if (!input.equals("exit")) {
61                 if (!input.isEmpty()) {
62                     ConsoleWriter.dataLine("Your id is " ,input);
63                     deleteComponentHandler.deleteComponent(input, scanner);
64                 }else{
65                     ConsoleWriter.dataLine("Your id is empty. Try again.");
66                 }
67             }
68         } while (!input.equals("exit"));
69         deleteComponentHandler.closeAll();
70         ConsoleWriter.dataLine("DeleteComponentTool exit...");
71         System.exit(0);
72     }
73
74
75 }