This repository was archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathSignalsExample.java
More file actions
139 lines (118 loc) · 4.47 KB
/
SignalsExample.java
File metadata and controls
139 lines (118 loc) · 4.47 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
*
*
* Copyright 2018 The Symphony Software Foundation
*
* Licensed to The Symphony Software Foundation (SSF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package signals;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.symphonyoss.client.SymphonyClient;
import org.symphonyoss.client.SymphonyClientConfig;
import org.symphonyoss.client.SymphonyClientFactory;
import org.symphonyoss.client.SymphonyClientFactory.TYPE;
import org.symphonyoss.client.exceptions.SignalsException;
import org.symphonyoss.symphony.agent.invoker.ApiException;
import org.symphonyoss.symphony.clients.model.SymSignal;
/**
* Simple example to list signals
* <p>
* It will send a message to a call.home.user and listen/create new Chat
* sessions.
* <p>
* <p>
* <p>
* REQUIRED VM Arguments or System Properties:
* <p>
* -Dtruststore.file= -Dtruststore.password=password
* -Dsessionauth.url=https://(hostname)/sessionauth
* -Dkeyauth.url=https://(hostname)/keyauth
* -Duser.call.home=frank.tarsillo@markit.com -Duser.cert.password=password
* -Duser.cert.file=bot.user2.p12 -Duser.email=bot.user2@domain.com
* -Dpod.url=https://(pod host)/pod -Dagent.url=https://(agent server
* host)/agent -Dreceiver.email=bot.user2@markit.com or bot user email
*
* @author Dov Katz
*/
// NOSONAR
public class SignalsExample {
private final Logger logger = LoggerFactory.getLogger(SignalsExample.class);
private SymphonyClient symClient;
public SignalsExample() {
init();
}
public static void main(String[] args) {
new SignalsExample();
}
public void init() {
logger.info("Signal Client example starting...");
try {
// Create an initialized client
symClient = SymphonyClientFactory.getClient(TYPE.V4);
symClient.init(new SymphonyClientConfig(true));
logger.info("My bot email is {}", symClient.getLocalUser().getEmailAddress());
logger.info("My bot' name is {}", symClient.getLocalUser().getDisplayName());
// List Signals
List<SymSignal> signals = symClient.getSignalsClient().listSignals(0, 10);
logger.info("Found (max 10) {} signals", signals.size());
signals.forEach(signal -> {
logger.info("Signal :{}", signal);
});
// Create Signal
SymSignal signal = new SymSignal();
signal.setVisibleOnProfile(false);
signal.setName("Test Signal " + System.currentTimeMillis());
signal.setQuery("HASHTAG:testSignal AND CASHTAG:money");
signal.setCompanyWide(false);
;
logger.info("Going to create a signal : Name {}, Query: {}", signal.getName(), signal.getQuery());
;
SymSignal result = symClient.getSignalsClient().createSignal(signal);
logger.info("Created Signal ID {}, Name {}", result.getId(), result.getName());
;
// Search for the one we just created
logger.info("Let's search for our new signal");
SymSignal found = symClient.getSignalsClient().getSignal(result.getId());
logger.info("Found signal we just created by ID {} --> {} ( {} )", result.getId(), found.getName(),
found.getQuery());
// Delete Signal
logger.info("Let's delete our signal");
symClient.getSignalsClient().deleteSignal(result.getId());
logger.info("Deleted Signal {}, Let's prove it", result.getId());
// Search for the one we just deleted
try {
found = symClient.getSignalsClient().getSignal(result.getId());
logger.info("We didn't delete the signal, it seems this was found {}: ",found);
} catch (SignalsException sigExc) {
if (sigExc.getCause() instanceof ApiException && ((ApiException) sigExc.getCause()).getCode() == 404) {
logger.info(
"Successfully got a 404 when trying to search for a non-existent signal. Deletion succeeded");
;
}
}
logger.info("Client shutting down.");
symClient.shutdown();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
}