leonard.se
2022-03-01 c6e76869f5a02cd52b8f4f9c7d78c0b433b22997
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package za.co.taulite.tools.smppclient.commands;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellMethodAvailability;
import org.springframework.util.StringUtils;
import za.co.taulite.tools.smppclient.InputReader;
import za.co.taulite.tools.smppclient.ShellHelper;
import za.co.taulite.tools.smppclient.services.SmppService;
 
@ShellComponent
@ShellCommandGroup("Submit Commands")
public class SmppCommands {
 
    @Autowired
    private ShellHelper shellHelper;
 
    @Autowired
    private InputReader inputReader;
 
    @Autowired
    private SmppService smppService;
 
    @ShellMethodAvailability({"send"})
    public Availability availabilityCheck() {
        return smppService.availabilityCheck();
    }
 
    @ShellMethod("send")
    public void send(String anumber, String bnumber, String message) {
        smppService.send(anumber, bnumber, message);
    }
 
    @ShellMethod("connect")
    public String connect(String systemId,
                          String host,
                          int port) {
        String password = null;
        do {
            password = inputReader.prompt("Password", "secret", false);
            if (!StringUtils.hasText(password)) {
                shellHelper.printWarning("Password be empty string?");
            }
        } while (password == null);
 
        try {
            smppService.connect(systemId, password, host, port);
            return "Connected";
        } catch (Exception ex) {
            return ex.getMessage();
        }
    }
 
    @ShellMethod("disconnect")
    public void disconnect() {
        smppService.disconnect();
    }
 
    @ShellMethod("status")
    public String status() {
        return smppService.status();
    }
}