[sdc] update code of sdc
[sdc.git] / openecomp-be / tools / zusammen-tools / src / main / java / org / openecomp / core / tools / main / ZusammenMainTool.java
1 package org.openecomp.core.tools.main;
2
3 import com.amdocs.zusammen.datatypes.SessionContext;
4 import com.amdocs.zusammen.datatypes.UserInfo;
5 import org.openecomp.core.tools.Commands.ResetOldVersion;
6 import org.openecomp.core.tools.util.ToolsUtil;
7 import org.openecomp.sdc.logging.api.Logger;
8 import org.openecomp.sdc.logging.api.LoggerFactory;
9
10 import java.time.Duration;
11 import java.time.Instant;
12
13 import static org.openecomp.core.tools.util.Utils.printMessage;
14
15 public class ZusammenMainTool {
16
17   private static final String GLOBAL_USER = "GLOBAL_USER";
18   private static Logger logger = LoggerFactory.getLogger(ZusammenMainTool.class);
19   private static int status = 0;
20
21   public static void main(String[] args) {
22
23     String command = ToolsUtil.getParam("c",args);
24     if(command == null){
25       printMessage(logger,
26           "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " +
27               "[additional arguments depending on the command] ");
28       System.exit(-1);
29     }
30     Instant startTime = Instant.now();
31
32     SessionContext context = new SessionContext();
33     context.setUser(new UserInfo(GLOBAL_USER));
34     context.setTenant("dox");
35
36
37     switch (COMMANDS.valueOf(command)){
38       case RESET_OLD_VERSION:
39         ResetOldVersion.reset(context,ToolsUtil.getParam("v",args));
40         break;
41       case EXPORT:
42         break;
43       case IMPORT:
44         break;
45
46     }
47
48     Instant stopTime = Instant.now();
49     Duration duration = Duration.between(startTime, stopTime);
50     long minutesPart = duration.toMinutes();
51     long secondsPart = duration.minusMinutes(minutesPart).getSeconds();
52
53
54     printMessage(logger,
55         "Zusammen tools command:[] finished . Total run time was : " + minutesPart + ":" +
56             secondsPart
57             + " minutes");
58     System.exit(status);
59
60   }
61
62   private enum COMMANDS{
63
64
65     RESET_OLD_VERSION("reset-old-version"),
66     EXPORT("export"),
67     IMPORT("import");
68
69     COMMANDS(String command) {
70       this.command  = command;
71     }
72
73     private String command;
74   }
75
76 }