diff --git a/.travis.yml b/.travis.yml index 790877b7..f68cf6bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,3 +71,4 @@ addons: build_command_prepend: "mvn clean" build_command: "mvn -DskipTests=true compile install" branch_pattern: $COVERITY_BRANCH_PATTERN +dist: trusty \ No newline at end of file diff --git a/README.md b/README.md index ec140a4b..7c525242 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ The Symphony java client provides a real-time wrapper around the Symphony REST A ## Change log and notes ## V1.1.5 (SNAPSHOT) +* Updated with latest 1.50 spec. symphony-java-api v1.50.1 +* Implementation of signals ## V1.1.4 * Major bug fix (1.50+) to accept real-time events that do not include event ids as this is now optional. diff --git a/examples/pom.xml b/examples/pom.xml index 5024b56f..967f9b99 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -29,7 +29,7 @@ 4.0.0 org.symphonyoss symphony-client-examples - 1.1.4-SNAPSHOT + 1.1.5-SNAPSHOT Symphony Client Examples Symphony Client Examples @@ -67,7 +67,7 @@ org.symphonyoss.symphony symphony-client - 1.1.3-SNAPSHOT + 1.1.5-SNAPSHOT com.rometools diff --git a/examples/signals/SignalsExample.java b/examples/signals/SignalsExample.java new file mode 100644 index 00000000..6d90abff --- /dev/null +++ b/examples/signals/SignalsExample.java @@ -0,0 +1,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 + *

+ * It will send a message to a call.home.user and listen/create new Chat + * sessions. + *

+ *

+ *

+ * REQUIRED VM Arguments or System Properties: + *

+ * -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 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(); + } + + } + +} diff --git a/examples/utils/CopyChatRoom.java b/examples/utils/CopyChatRoom.java index ed9d0fd9..4ae54ea9 100644 --- a/examples/utils/CopyChatRoom.java +++ b/examples/utils/CopyChatRoom.java @@ -192,9 +192,9 @@ public void init() { String userName = symClient.getUsersClient().getUserFromId(symMessage.getFromUserId()).getDisplayName(); - logger.debug("{}:{}:{}:{}", userName, new Date(Long.valueOf(symMessage.getTimestamp())).toString(), symMessage.getMessage(), symMessage.getAttachments().size()); + logger.debug("{}:{}:{}:{}", userName, new Date(Long.valueOf(symMessage.getTimestamp())).toString(), symMessage.getMessage()); - if (symMessage.getAttachments().size() > 0) { + if (symMessage.getAttachments() != null && symMessage.getAttachments().size() > 0) { symAttachmentInfos.addAll(symMessage.getAttachments()); diff --git a/pom.xml b/pom.xml index 251f41e0..f23adf3b 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,11 @@ jackson-jaxrs-json-provider ${jackson.version} + + com.diffblue + deeptestutils + 1.1.0 + diff --git a/symphony-client/pom.xml b/symphony-client/pom.xml index 7a713242..5e899549 100644 --- a/symphony-client/pom.xml +++ b/symphony-client/pom.xml @@ -21,7 +21,8 @@ ~ under the License. --> - + symphony-java-client org.symphonyoss.symphony @@ -42,7 +43,7 @@ 1.11.2 - 1.50.0 + 1.51.0-SNAPSHOT 2.8.2 3.22.0-GA -Dlog4j.configurationFile=src/test/resources/log4j.properties -Xmx1024m @@ -70,6 +71,16 @@ org.symphonyoss.symphony symphony-authenticator-java-jersey2-client ${symphony-api-version} + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + org.symphonyoss.symphony @@ -152,18 +163,18 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClient.java b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClient.java index 92863681..0312063d 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClient.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClient.java @@ -241,6 +241,13 @@ public interface SymphonyClient { */ ShareClient getShareClient(); + /** + * Provides instance of the Signals client. This client supports the management of signals. + * + * @return {@link SignalsClient} + */ + SignalsClient getSignalsClient(); + /** * If set, returns the custom http client set during initialization. * diff --git a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfig.java b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfig.java index 2ea22c07..9559e36e 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfig.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfig.java @@ -104,8 +104,28 @@ public void load() throws ProgramFault { } + /** + * This method is intended for use in unit tests that need to be able to treat this class as a DTO. + * + * @param id The configuration parameter to retrieve. + * @return The value of that configuration parameter, as stored in memory. + */ + public String rawGet(SymphonyClientConfigID id) + { + return(config.getProperty(id.getPropName())); + } + + + /** + * This method does some unusual shenanigans that probably belong elsewhere, so that this class can be a true DTO. + * A refactoring task for another day... + * + * @param id The configuration parameter to retrieve. + * @return The value of that configuration parameter, as stored in memory, or one of several Java "system properties" + * or environment variables with names vaguely similar to id. Basically non-deterministic, so YMMV. + */ public String get(SymphonyClientConfigID id) { - String value = config.getProperty(id.getPropName()); + String value = rawGet(id); if (value == null) value = System.getProperty(id.getPropName()); diff --git a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java index 3c9d6902..4b0ac96e 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigBuilder.java @@ -81,6 +81,7 @@ public static interface UserCredsStep public static interface BuildStep { BuildStep withReceiverEmail(String receiverEmail); + BuildStep withGetAllUsersTimeout(String getAllUsersTimeout); BuildStep withServices(boolean enabled); BuildStep withJMXHealthcheck(boolean enabled); SymphonyClientConfig build(); @@ -105,6 +106,7 @@ private static class Steps private String userCertFilename = null; private char[] userCertPassword = null; private String receiverEmail = null; + private String getAllUsersTimeout = null; private boolean servicesEnabled = true; private boolean jmxHealthCheckEnabled = true; @@ -160,6 +162,13 @@ public BuildStep withReceiverEmail(String receiverEmail) return (this); } + @Override + public BuildStep withGetAllUsersTimeout(String getAllUsersTimeout) + { + this.getAllUsersTimeout = getAllUsersTimeout; + return (this); + } + @Override public BuildStep withServices(boolean enabled) { @@ -179,16 +188,18 @@ public SymphonyClientConfig build() { SymphonyClientConfig result = new SymphonyClientConfig(); - result.set(SymphonyClientConfigID.SESSIONAUTH_URL, this.sessionAuthUrl); - result.set(SymphonyClientConfigID.KEYAUTH_URL, this.keyAuthUrl); - result.set(SymphonyClientConfigID.POD_URL, this.podUrl); - result.set(SymphonyClientConfigID.AGENT_URL, this.agentUrl); - result.set(SymphonyClientConfigID.TRUSTSTORE_FILE, this.trustStoreFilename); - result.set(SymphonyClientConfigID.TRUSTSTORE_PASSWORD, new String(this.trustStorePassword)); // SECURITY HOLE DUE TO STRING INTERNING - result.set(SymphonyClientConfigID.USER_EMAIL, this.userEmail); - result.set(SymphonyClientConfigID.USER_CERT_FILE, this.userCertFilename); - result.set(SymphonyClientConfigID.USER_CERT_PASSWORD, new String(this.userCertPassword)); // SECURITY HOLE DUE TO STRING INTERNING - result.set(SymphonyClientConfigID.RECEIVER_EMAIL, this.receiverEmail); + if (this.sessionAuthUrl != null) result.set(SymphonyClientConfigID.SESSIONAUTH_URL, this.sessionAuthUrl); + if (this.keyAuthUrl != null) result.set(SymphonyClientConfigID.KEYAUTH_URL, this.keyAuthUrl); + if (this.podUrl != null) result.set(SymphonyClientConfigID.POD_URL, this.podUrl); + if (this.agentUrl != null) result.set(SymphonyClientConfigID.AGENT_URL, this.agentUrl); + if (this.trustStoreFilename != null) result.set(SymphonyClientConfigID.TRUSTSTORE_FILE, this.trustStoreFilename); + if (this.trustStorePassword != null) result.set(SymphonyClientConfigID.TRUSTSTORE_PASSWORD, new String(this.trustStorePassword)); // SECURITY HOLE DUE TO STRING INTERNING + if (this.userEmail != null) result.set(SymphonyClientConfigID.USER_EMAIL, this.userEmail); + if (this.userCertFilename != null) result.set(SymphonyClientConfigID.USER_CERT_FILE, this.userCertFilename); + if (this.userCertPassword != null) result.set(SymphonyClientConfigID.USER_CERT_PASSWORD, new String(this.userCertPassword)); // SECURITY HOLE DUE TO STRING INTERNING + if (this.receiverEmail != null) result.set(SymphonyClientConfigID.RECEIVER_EMAIL, this.receiverEmail); + if (this.getAllUsersTimeout != null) result.set(SymphonyClientConfigID.GET_ALL_USERS_TIMEOUT, this.getAllUsersTimeout); + result.set(SymphonyClientConfigID.DISABLE_SERVICES, String.valueOf(!this.servicesEnabled)); result.set(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED, String.valueOf(this.jmxHealthCheckEnabled)); diff --git a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigID.java b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigID.java index 66de9add..c52b7b9c 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigID.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/SymphonyClientConfigID.java @@ -28,6 +28,7 @@ public enum SymphonyClientConfigID { USER_CERT_PASSWORD("javax.net.ssl.keyStorePassword"), USER_EMAIL, RECEIVER_EMAIL(false), + GET_ALL_USERS_TIMEOUT(false), DISABLE_SERVICES(false), HEALTHCHECK_JMX_ENABLED(false); diff --git a/symphony-client/src/main/java/org/symphonyoss/client/exceptions/SignalsException.java b/symphony-client/src/main/java/org/symphonyoss/client/exceptions/SignalsException.java new file mode 100644 index 00000000..7948e18d --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/client/exceptions/SignalsException.java @@ -0,0 +1,43 @@ +/* + * + * + * 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 org.symphonyoss.client.exceptions; + +/** + * @author dovkatz on 03/13/2018 + */ +public class SignalsException extends SymException { + @SuppressWarnings("unused") + public SignalsException(String message) { + super(message); + } + + @SuppressWarnings("unused") + public SignalsException(Throwable cause) { + super(cause); + } + + public SignalsException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/symphony-client/src/main/java/org/symphonyoss/client/impl/AuthRefreshTask.java b/symphony-client/src/main/java/org/symphonyoss/client/impl/AuthRefreshTask.java index 32f2f3b8..ef8bb914 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/impl/AuthRefreshTask.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/impl/AuthRefreshTask.java @@ -66,9 +66,16 @@ public SymAuth runTask() { AuthenticationClient authClient; + //Init the Symphony authorization client, which requires both the key and session URL's. In most cases, - //the same fqdn but different URLs. - if (symClient.getSymAuth() != null && symClient.getSymAuth().getHttpClient() != null) { + //the same fqdn but different URLs. Also take into account if there are different HTTP clients being used between POD and key manager. + if (symClient.getSymAuth() != null && symClient.getSymAuth().getHttpClientForKeyToken() != null && symClient.getSymAuth().getHttpClientForSessionToken() != null) { + + //Take the stored http client configuration with the pre-loaded keystores. + authClient = new AuthenticationClient(symClient.getSymAuth().getSessionUrl(), symClient.getSymAuth().getKeyUrl(), symClient.getSymAuth().getHttpClientForSessionToken(), symClient.getSymAuth().getHttpClientForKeyToken()); + + + } else if (symClient.getSymAuth() != null && symClient.getSymAuth().getHttpClient() != null) { //Take the stored http client configuration with the pre-loaded keystores. authClient = new AuthenticationClient(symClient.getSymAuth().getSessionUrl(), symClient.getSymAuth().getKeyUrl(), symClient.getSymAuth().getHttpClient()); @@ -92,14 +99,14 @@ public SymAuth runTask() { //Create a SymAuth which holds both key and session tokens. This will call the external service. - symAuth = authClient.authenticate(); + symAuth = authClient.authenticate(); symClient.getSymAuth().setKeyToken(symAuth.getKeyToken()); symClient.getSymAuth().setSessionToken(symAuth.getSessionToken()); logger.info("Successfully refreshed SymAuth tokens..."); - } catch (NetworkException e) { + } catch (NetworkException | RuntimeException e) { logger.error("Unable to refresh SymAuth keys...", e); } diff --git a/symphony-client/src/main/java/org/symphonyoss/client/impl/SymphonyBasicClient.java b/symphony-client/src/main/java/org/symphonyoss/client/impl/SymphonyBasicClient.java index ca052c9b..9ed2077a 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/impl/SymphonyBasicClient.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/impl/SymphonyBasicClient.java @@ -42,7 +42,7 @@ import org.symphonyoss.symphony.clients.jmx.ClientCheck; import org.symphonyoss.symphony.clients.model.ApiVersion; import org.symphonyoss.symphony.clients.model.SymUser; -import org.symphonyoss.symphony.pod.invoker.JSON; + import javax.management.*; import javax.ws.rs.client.Client; @@ -78,6 +78,7 @@ public class SymphonyBasicClient implements SymphonyClient { private UsersClient usersClient; private StreamsClient streamsClient; private PresenceClient presenceClient; + private SignalsClient signalsClient; private RoomMembershipClient roomMembershipClient; private AttachmentsClient attachmentsClient; private ConnectionsClient connectionsClient; @@ -285,6 +286,7 @@ public void init(SymAuth symAuth, SymphonyClientConfig config) throws InitExcept dataFeedClient = DataFeedFactory.getClient(this); messagesClient = MessagesFactory.getClient(this); presenceClient = PresenceFactory.getClient(this); + signalsClient = SignalsFactory.getClient(this); streamsClient = StreamsFactory.getClient(this); usersClient = UsersFactory.getClient(this); shareClient = ShareFactory.getClient(this); @@ -461,6 +463,10 @@ public ShareClient getShareClient() { return shareClient; } + @Override + public SignalsClient getSignalsClient() { + return signalsClient; + } /** * Provides the default http client if one is set. * diff --git a/symphony-client/src/main/java/org/symphonyoss/client/model/SymAuth.java b/symphony-client/src/main/java/org/symphonyoss/client/model/SymAuth.java index 01175c1c..b5d67198 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/model/SymAuth.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/model/SymAuth.java @@ -44,6 +44,8 @@ public class SymAuth { private String serverTruststorePassword; private String clientKeystorePassword; private Client httpClient; + private Client httpClientForSessionToken; + private Client httpClientForKeyToken; public String getServerTruststore() { @@ -130,6 +132,22 @@ public void setKeyUrl(String keyUrl) { this.keyUrl = keyUrl; } + public Client getHttpClientForSessionToken() { + return httpClientForSessionToken; + } + + public void setHttpClientForSessionToken(Client httpClientForSessionToken) { + this.httpClientForSessionToken = httpClientForSessionToken; + } + + public Client getHttpClientForKeyToken() { + return httpClientForKeyToken; + } + + public void setHttpClientForKeyToken(Client httpClientForKeyToken) { + this.httpClientForKeyToken = httpClientForKeyToken; + } + public static SymAuth fromOboAuth(OboAuthResponse oboAuthResponse) { if(oboAuthResponse==null) diff --git a/symphony-client/src/main/java/org/symphonyoss/client/util/MlMessageParser.java b/symphony-client/src/main/java/org/symphonyoss/client/util/MlMessageParser.java index 4e2ecd65..4f80756e 100644 --- a/symphony-client/src/main/java/org/symphonyoss/client/util/MlMessageParser.java +++ b/symphony-client/src/main/java/org/symphonyoss/client/util/MlMessageParser.java @@ -296,7 +296,9 @@ private void updateMentionUidToEmail(SymphonyClient symClient, List nodesL } } - updateMentionUidToEmail(symClient, node.childNodes()); + + if(node.childNodeSize() > 0) + updateMentionUidToEmail(symClient, node.childNodes()); } diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/AuthenticationClient.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/AuthenticationClient.java index ae6427f9..233c5b72 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/AuthenticationClient.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/AuthenticationClient.java @@ -27,6 +27,8 @@ import org.symphonyoss.client.SymphonyClientConfig; import org.symphonyoss.client.SymphonyClientConfigID; import org.symphonyoss.client.exceptions.AuthenticationException; +import org.symphonyoss.client.exceptions.NetworkException; +import org.symphonyoss.client.exceptions.SymFault; import org.symphonyoss.client.impl.CustomHttpClient; import org.symphonyoss.client.model.SymAuth; import org.symphonyoss.symphony.authenticator.api.AuthenticationApi; @@ -37,6 +39,7 @@ import org.symphonyoss.symphony.clients.model.SymExtensionAppAuth; import org.symphonyoss.symphony.clients.model.SymUser; +import javax.ws.rs.ProcessingException; import javax.ws.rs.client.Client; /** @@ -146,6 +149,7 @@ public SymAuth authenticate() throws AuthenticationException { if (httpClientForSessionToken != null) { Configuration.getDefaultApiClient().setHttpClient(httpClientForSessionToken); + symAuth.setHttpClientForSessionToken(httpClientForSessionToken); } symAuth.setSessionToken(authenticationApi.v1AuthenticatePost()); @@ -157,6 +161,7 @@ public SymAuth authenticate() throws AuthenticationException { if (httpClientForKeyToken != null) { Configuration.getDefaultApiClient().setHttpClient(httpClientForKeyToken); + symAuth.setHttpClientForKeyToken(httpClientForKeyToken); } symAuth.setKeyToken(authenticationApi.v1AuthenticatePost()); @@ -167,6 +172,9 @@ public SymAuth authenticate() throws AuthenticationException { throw new AuthenticationException("Please check certificates, tokens and paths.. ", e.getCode(), e); + } catch(ProcessingException e){ + + throw new AuthenticationException("Network connection issues or bad API call.. ", 500, e); } loginStatus = true; diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsClient.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsClient.java new file mode 100644 index 00000000..b884a068 --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsClient.java @@ -0,0 +1,61 @@ +/* + * + * + * 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 org.symphonyoss.symphony.clients; + + +import java.math.BigDecimal; +import java.util.List; + +import org.symphonyoss.client.exceptions.SignalsException; +import org.symphonyoss.symphony.agent.model.ChannelSubscriptionResponse; +import org.symphonyoss.symphony.clients.model.SymChannelSubscriberResponse; +import org.symphonyoss.symphony.clients.model.SymSignal; + +/** + * @author dovkatz on 03/13/2018 + */ +public interface SignalsClient { + + public SymSignal createSignal(SymSignal signal) throws SignalsException; + + public SymSignal updateSignal(String id, SymSignal signal) throws SignalsException; + + public void deleteSignal(String id) throws SignalsException; + + public SymSignal getSignal(String id) throws SignalsException; + + public List listSignals(int skip, int limit) throws SignalsException; + + public SymChannelSubscriberResponse listSubscribers(String id, Integer skip, Integer limit) throws SignalsException; + + public ChannelSubscriptionResponse subscribe(String id) throws SignalsException; + + public ChannelSubscriptionResponse bulkSubscribe(String id, boolean pushed, List userIds) throws SignalsException; + + public ChannelSubscriptionResponse unsubscribe(String id) throws SignalsException; + + public ChannelSubscriptionResponse bulkUnsubscribe(String id, List userIds) throws SignalsException; + +} diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsFactory.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsFactory.java new file mode 100644 index 00000000..3684e86d --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsFactory.java @@ -0,0 +1,47 @@ +/* + * + * Copyright 20168 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 org.symphonyoss.symphony.clients; + +import org.symphonyoss.client.SymphonyClient; +import org.symphonyoss.client.SymphonyClientConfig; +import org.symphonyoss.client.model.SymAuth; +import org.symphonyoss.symphony.clients.impl.SignalsClientImpl; + +/** + * @author dovkatz on 3/13/2018 + */ +public class SignalsFactory { + + public static SignalsClient getClient(SymphonyClient symClient){ + + return new SignalsClientImpl(symClient.getSymAuth(),symClient.getConfig(), symClient.getAgentHttpClient()); + + } + + public static SignalsClient getClient(SymAuth symAuth, SymphonyClientConfig config){ + + return new SignalsClientImpl(symAuth, config); + + } + +} diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SymphonyApis.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SymphonyApis.java index be2749a0..c0fca96c 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SymphonyApis.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SymphonyApis.java @@ -28,6 +28,7 @@ import org.symphonyoss.symphony.agent.api.DatafeedApi; import org.symphonyoss.symphony.agent.api.MessagesApi; import org.symphonyoss.symphony.agent.api.ShareApi; +import org.symphonyoss.symphony.agent.api.SignalsApi; import org.symphonyoss.symphony.pod.api.*; /** @@ -71,4 +72,6 @@ public interface SymphonyApis { SecurityApi getSecurityApi(); SessionApi getSessionApi(); + + SignalsApi getSignalsApi(); } diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SignalsClientImpl.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SignalsClientImpl.java new file mode 100644 index 00000000..6d763931 --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SignalsClientImpl.java @@ -0,0 +1,333 @@ +/* + * + * + * 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. + * + */ +/** + * @author dovkatz on 03/13/2018 + */ +package org.symphonyoss.symphony.clients.impl; + +import java.math.BigDecimal; +import java.util.List; + +import javax.ws.rs.client.Client; + +import org.symphonyoss.client.SymphonyClientConfig; +import org.symphonyoss.client.SymphonyClientConfigID; +import org.symphonyoss.client.exceptions.SignalsException; +import org.symphonyoss.client.model.SymAuth; +import org.symphonyoss.symphony.agent.api.SignalsApi; +import org.symphonyoss.symphony.agent.invoker.ApiClient; +import org.symphonyoss.symphony.agent.invoker.ApiException; +import org.symphonyoss.symphony.agent.model.BaseSignal; +import org.symphonyoss.symphony.agent.model.ChannelSubscriberResponse; +import org.symphonyoss.symphony.agent.model.ChannelSubscriptionResponse; +import org.symphonyoss.symphony.agent.model.Signal; +import org.symphonyoss.symphony.agent.model.SignalList; +import org.symphonyoss.symphony.clients.SignalsClient; +import org.symphonyoss.symphony.clients.model.SymChannelSubscriberResponse; +import org.symphonyoss.symphony.clients.model.SymSignal; + +public class SignalsClientImpl implements SignalsClient { + + private final SymAuth symAuth; + private final ApiClient apiClient; + + /** + * Init + * + * @param symAuth + * Authorization model containing session and key tokens + * @param config + * Symphony Client Config + */ + public SignalsClientImpl(SymAuth symAuth, SymphonyClientConfig config) { + + this(symAuth, config, null); + + } + + /** + * If you need to override HttpClient. Important for handling individual client + * certs. + * + * @param symAuth + * Authorization model containing session and key tokens + * @param config + * Symphony client config + * @param httpClient + * Custom HTTP client + */ + public SignalsClientImpl(SymAuth symAuth, SymphonyClientConfig config, Client httpClient) { + this.symAuth = symAuth; + + // Get Service client to query for userID. + apiClient = org.symphonyoss.symphony.agent.invoker.Configuration.getDefaultApiClient(); + + if (httpClient != null) + apiClient.setHttpClient(httpClient); + + apiClient.setBasePath(config.get(SymphonyClientConfigID.AGENT_URL)); + } + + /** + * Creates a signal based on a given query + * + * @param signal + * The Signal object containing the query, name, and + * visibility/company-wide settings to use + * + * @return the SymSignal object that was created, including the timestamp, and + * ID + */ + @Override + public SymSignal createSignal(SymSignal signal) throws SignalsException { + SignalsApi api = createSignalsApi(); + BaseSignal base = SymSignal.toBaseSignal(signal); + try { + Signal result = api.v1SignalsCreatePost(symAuth.getSessionToken().getToken(), base, + symAuth.getKeyToken().getToken()); + return SymSignal.toSymSignal(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * @return SignalsApi instance + */ + public SignalsApi createSignalsApi() { + SignalsApi api = new SignalsApi(apiClient); + return api; + } + + /** + * Updates an existing signal + * + * @param id + * The ID of the signal to be updated + * + * @param signal + * The SymSignal object containing the updated fields + * + * @return the SymSignal object that was updated + * + */ + @Override + public SymSignal updateSignal(String id, SymSignal signal) throws SignalsException { + SignalsApi api = createSignalsApi(); + BaseSignal base = SymSignal.toBaseSignal(signal); + try { + Signal result = api.v1SignalsIdUpdatePost(symAuth.getSessionToken().getToken(), id, base, + symAuth.getKeyToken().getToken()); + return SymSignal.toSymSignal(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Deletes an existing signal + * + * @param id + * The ID of the signal to be deleted + * + */ + @Override + public void deleteSignal(String id) throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + api.v1SignalsIdDeletePost(symAuth.getSessionToken().getToken(), id, symAuth.getKeyToken().getToken()); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Retrieves an existing signal. Can be public signals, or signals owned by the + * current session owner + * + * @param id + * The ID of the signal to be updated + * + * @return the SymSignal object with that ID + * + */ + @Override + public SymSignal getSignal(String id) throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + Signal result = api.v1SignalsIdGetGet(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken()); + return SymSignal.toSymSignal(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Lists all signals owned by or subscribed to by the current session owner. + * + * @param skip + * Offset - number of items to skip in the list + * + * @param limit + * Maximum number of results to return (Hard maximum according to + * REST API is 500) + * + * @return List of SymSignal instances + * + */ + @Override + public List listSignals(int skip, int limit) throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + SignalList result = api.v1SignalsListGet(symAuth.getSessionToken().getToken(), + symAuth.getKeyToken().getToken(), skip, limit); + return SymSignal.fromSignalList(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Lists all subscribers of a given signal + * + * @param id + * ID of the signal + * + * @param skip + * Offset - number of items to skip in the list + * + * @param limit + * Maximum number of results to return (Hard maximum according to + * REST API is 500) + * + * @return List of subscribers + * + */ + @Override + public SymChannelSubscriberResponse listSubscribers(String id, Integer skip, Integer limit) + throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + ChannelSubscriberResponse result = api.v1SignalsIdSubscribersGet(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), skip, limit); + return SymChannelSubscriberResponse.toSymChannelSubscriberResponse(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Subscribes the current session owner to a given signal + * + * @param id + * ID of the signal + * + * @return API response of subscription operation + * + */ + @Override + public ChannelSubscriptionResponse subscribe(String id) throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + return api.v1SignalsIdSubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), null, null); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Subscribes the set of specified users to a given symbol + * + * @param id + * ID of the signal + * + * @param pushed + * Force-push the signal (they cannot unsubscribe) + * + * @param userIds + * List of userIDs to subscribe (maximum 100 per operation per REST + * API Docs) + * + * @return API response of subscription operation + * + */ + @Override + public ChannelSubscriptionResponse bulkSubscribe(String id, boolean pushed, List userIds) + throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + return api.v1SignalsIdSubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), pushed, userIds); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Unsubscribes the session owner of specified users to a given symbol + * + * @param id + * ID of the signal + * + * @return API response of unsubscription operation + * + */ + @Override + public ChannelSubscriptionResponse unsubscribe(String id) throws SignalsException { + SignalsApi api = createSignalsApi(); + try { + return api.v1SignalsIdUnsubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), null); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + /** + * Unsubscribes the set of specified users to a given symbol + * + * @param id + * ID of the signal + * + * @param userIds + * List of userIDs to unsubscribe (maximum 100 per operation per REST + * API Docs) + * + * @return API response of unsubscription operation + * + */ + @Override + public ChannelSubscriptionResponse bulkUnsubscribe(String id, List userIds) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + return api.v1SignalsIdUnsubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), userIds); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + +} diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/StreamsClientImpl.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/StreamsClientImpl.java index 430a4bd0..c7ac42d7 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/StreamsClientImpl.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/StreamsClientImpl.java @@ -166,6 +166,7 @@ public SymStream getStream(UserIdList userIdList) throws StreamsException { } StreamsApi streamsApi = new StreamsApi(apiClient); + try { return SymStream.toSymStream(streamsApi.v1ImCreatePost(userIdList, symAuth.getSessionToken().getToken())); } catch (ApiException e) { diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SymphonyApisImpl.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SymphonyApisImpl.java index 86ceb22b..95dcdbee 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SymphonyApisImpl.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SymphonyApisImpl.java @@ -33,6 +33,7 @@ import org.symphonyoss.symphony.agent.api.DatafeedApi; import org.symphonyoss.symphony.agent.api.MessagesApi; import org.symphonyoss.symphony.agent.api.ShareApi; +import org.symphonyoss.symphony.agent.api.SignalsApi; import org.symphonyoss.symphony.clients.SymphonyApis; import org.symphonyoss.symphony.pod.api.*; @@ -49,7 +50,7 @@ public class SymphonyApisImpl implements SymphonyApis { private final SymAuth symAuth; private org.symphonyoss.symphony.pod.invoker.ApiClient podApiClient; - private org.symphonyoss.symphony.agent.invoker.ApiClient agentApiCient; + private org.symphonyoss.symphony.agent.invoker.ApiClient agentApiClient; private final Logger logger = LoggerFactory.getLogger(SymphonyApisImpl.class); @@ -87,10 +88,10 @@ public SymphonyApisImpl(SymAuth symAuth, SymphonyClientConfig config, Client pod //Get Service client to query for userID. - agentApiCient = org.symphonyoss.symphony.agent.invoker.Configuration.getDefaultApiClient(); + agentApiClient = org.symphonyoss.symphony.agent.invoker.Configuration.getDefaultApiClient(); if (agentHttpClient != null) - agentApiCient.setHttpClient(agentHttpClient); - agentApiCient.setBasePath(config.get(SymphonyClientConfigID.AGENT_URL)); + agentApiClient.setHttpClient(agentHttpClient); + agentApiClient.setBasePath(config.get(SymphonyClientConfigID.AGENT_URL)); } @@ -98,7 +99,7 @@ public SymphonyApisImpl(SymAuth symAuth, SymphonyClientConfig config, Client pod @Override public AttachmentsApi getAttachmentsApi() { - return new AttachmentsApi(agentApiCient); + return new AttachmentsApi(agentApiClient); } @Override @@ -109,12 +110,12 @@ public ConnectionApi getConnectionApi() { @Override public DatafeedApi getDatafeedApi() { - return new DatafeedApi(agentApiCient); + return new DatafeedApi(agentApiClient); } @Override public MessagesApi getMessagesApi() { - return new MessagesApi(agentApiCient); + return new MessagesApi(agentApiClient); } @Override @@ -144,7 +145,7 @@ public UserApi getUserApi() { @Override public ShareApi getShareApi() { - return new ShareApi(agentApiCient); + return new ShareApi(agentApiClient); } @@ -155,7 +156,7 @@ public org.symphonyoss.symphony.pod.api.SystemApi getPodSystemApi() { @Override public org.symphonyoss.symphony.agent.api.SystemApi getAgentSystemApi() { - return new org.symphonyoss.symphony.agent.api.SystemApi(agentApiCient); + return new org.symphonyoss.symphony.agent.api.SystemApi(agentApiClient); } @@ -194,6 +195,10 @@ public SessionApi getSessionApi() { return new SessionApi(podApiClient); } + @Override + public SignalsApi getSignalsApi() { + return new SignalsApi(agentApiClient); + } } diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/UsersClientImpl.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/UsersClientImpl.java index dbfd6dbf..22eec6ca 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/UsersClientImpl.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/UsersClientImpl.java @@ -23,6 +23,8 @@ package org.symphonyoss.symphony.clients.impl; import com.google.common.base.Strings; + +import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.symphonyoss.client.SymphonyClientConfig; @@ -58,6 +60,7 @@ public class UsersClientImpl implements org.symphonyoss.symphony.clients.UsersClient { private final SymAuth symAuth; private final ApiClient apiClient; + private final long getAllUsersTimeout; private final Logger logger = LoggerFactory.getLogger(UsersClientImpl.class); @@ -68,10 +71,7 @@ public class UsersClientImpl implements org.symphonyoss.symphony.clients.UsersCl * @param config Symphony Client config */ public UsersClientImpl(SymAuth symAuth, SymphonyClientConfig config) { - this(symAuth, config, null); - - } /** @@ -93,7 +93,7 @@ public UsersClientImpl(SymAuth symAuth, SymphonyClientConfig config, Client http apiClient.setBasePath(config.get(SymphonyClientConfigID.POD_URL)); - + getAllUsersTimeout = NumberUtils.toLong(config.get(SymphonyClientConfigID.GET_ALL_USERS_TIMEOUT), 5); } @@ -294,11 +294,12 @@ public Set getAllUsers() throws UsersClientException { executor.shutdown(); - executor.awaitTermination(5, TimeUnit.SECONDS); - - - logger.debug("Finished all threads. Total time retrieving users: {} sec", (System.currentTimeMillis() - startTime) / 1000); - + final boolean processCompleted = executor.awaitTermination(getAllUsersTimeout, TimeUnit.SECONDS); + if (processCompleted) { + logger.debug("Finished all threads. Total time retrieving users: {} sec", (System.currentTimeMillis() - startTime) / 1000); + } else { + logger.warn("Process timed-out waiting to getAllUsers(). Total time retrieving users: {} sec", (System.currentTimeMillis() - startTime) / 1000); + } } catch (ApiException e) { throw new UsersClientException("API Error communicating with POD, while retrieving all user details", @@ -334,11 +335,16 @@ public Set getAllUsersWithDetails() throws UsersClientException { symUser.setFeatures(featureList); userDetail = userApi.v1AdminUserUidGet(sessionToken, uid); symUser.setRoles(new HashSet<>(userDetail.getRoles())); - if (userDetail.getUserSystemInfo().getLastLoginDate() != null) - symUser.setLastLoginDate(new Date(userDetail.getUserSystemInfo().getLastLoginDate())); - if (userDetail.getUserSystemInfo().getCreatedDate() != null) - symUser.setCreatedDate(new Date(userDetail.getUserSystemInfo().getCreatedDate())); + if (userDetail.getUserSystemInfo() != null) { + symUser.setActive(UserSystemInfo.StatusEnum.ENABLED == userDetail.getUserSystemInfo().getStatus()); + if (userDetail.getUserSystemInfo().getLastLoginDate() != null) { + symUser.setLastLoginDate(new Date(userDetail.getUserSystemInfo().getLastLoginDate())); + } + if (userDetail.getUserSystemInfo().getCreatedDate() != null) { + symUser.setCreatedDate(new Date(userDetail.getUserSystemInfo().getCreatedDate())); + } + } } } catch (ApiException e) { diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAdminStreamInfo.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAdminStreamInfo.java index 60e9e018..9cd84d6a 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAdminStreamInfo.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAdminStreamInfo.java @@ -205,9 +205,9 @@ private static SymAdminStreamInfo toStreamInfo(AdminStreamInfo adminStreamInfo) SymAdminStreamInfo symAdminStreamInfo = new SymAdminStreamInfo(); symAdminStreamInfo.setId(adminStreamInfo.getId()); - symAdminStreamInfo.setIsActive(adminStreamInfo.getIsActive()); - symAdminStreamInfo.setIsExternal(adminStreamInfo.getIsExternal()); - symAdminStreamInfo.setIsPublic(adminStreamInfo.getIsPublic()); + symAdminStreamInfo.setIsActive(adminStreamInfo.isIsActive()); + symAdminStreamInfo.setIsExternal(adminStreamInfo.isIsExternal()); + symAdminStreamInfo.setIsPublic(adminStreamInfo.isIsPublic()); symAdminStreamInfo.setType(adminStreamInfo.getType()); symAdminStreamInfo.setAttributes(SymAdminStreamAttributes.toAdminStreamAttributes(adminStreamInfo.getAttributes())); return symAdminStreamInfo; diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAgentHealthCheck.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAgentHealthCheck.java index 9f4f13d2..504c0184 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAgentHealthCheck.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAgentHealthCheck.java @@ -151,10 +151,10 @@ public static SymAgentHealthCheck toSymAgentHealthCheck(V2HealthCheckResponse v2 symAgentHealthCheck.setAgentVersion(v2HealthCheckResponse.getAgentVersion()); symAgentHealthCheck.setEncryptDecryptError(v2HealthCheckResponse.getEncryptDecryptError()); - symAgentHealthCheck.setEncryptDecryptSuccess(v2HealthCheckResponse.getEncryptDecryptSuccess()); - symAgentHealthCheck.setKeyManagerConnectivity(v2HealthCheckResponse.getKeyManagerConnectivity()); + symAgentHealthCheck.setEncryptDecryptSuccess(v2HealthCheckResponse.isEncryptDecryptSuccess()); + symAgentHealthCheck.setKeyManagerConnectivity(v2HealthCheckResponse.isKeyManagerConnectivity()); symAgentHealthCheck.setKeyManagerConnectivityError(v2HealthCheckResponse.getKeyManagerConnectivityError()); - symAgentHealthCheck.setPodConnectivity(v2HealthCheckResponse.getPodConnectivity()); + symAgentHealthCheck.setPodConnectivity(v2HealthCheckResponse.isPodConnectivity()); symAgentHealthCheck.setPodConnectivityError(v2HealthCheckResponse.getPodConnectivityError()); symAgentHealthCheck.setPodVersion(v2HealthCheckResponse.getPodVersion()); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAttachmentInfo.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAttachmentInfo.java index 148a633e..872dc74a 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAttachmentInfo.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymAttachmentInfo.java @@ -113,11 +113,16 @@ public static SymAttachmentInfo toAttachmentInfo(V4AttachmentInfo attachmentInfo public static List toAttachmentsInfo(List attachmentInfos) { + if(attachmentInfos==null) + return null; + return attachmentInfos.stream().map(SymAttachmentInfo::toAttachmentInfo).collect(Collectors.toList()); } public static List toAttachmentsInfos(List attachmentInfos) { + if(attachmentInfos==null) + return null; return attachmentInfos.stream().map(SymAttachmentInfo::toAttachmentInfo).collect(Collectors.toList()); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriber.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriber.java new file mode 100644 index 00000000..bb001a58 --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriber.java @@ -0,0 +1,99 @@ +/* + * + * + * 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 org.symphonyoss.symphony.clients.model; + +import org.symphonyoss.symphony.agent.model.ChannelSubscriber; + +/** + * @author dovkatz on 03/13/2018 + */ +public class SymChannelSubscriber { + + private Boolean owner; + private Boolean pushed; + private String subscriberName; + private Long userId; + private Long timestamp; + + public Boolean getOwner() { + return owner; + } + + public void setOwner(Boolean owner) { + this.owner = owner; + } + + public Boolean getPushed() { + return pushed; + } + + public void setPushed(Boolean pushed) { + this.pushed = pushed; + } + + public String getSubscriberName() { + return subscriberName; + } + + public void setSubscriberName(String subscriberName) { + this.subscriberName = subscriberName; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public static ChannelSubscriber toChannelSubscriber(SymChannelSubscriber symSub) { + ChannelSubscriber sub=new ChannelSubscriber(); + sub.owner(symSub.getOwner()); + sub.pushed(symSub.getPushed()); + sub.subscriberName(symSub.getSubscriberName()); + sub.userId(symSub.getUserId()); + sub.timestamp(symSub.getTimestamp()); + return sub; + } + + public static SymChannelSubscriber toSymChannelSubscriber(ChannelSubscriber sub) { + SymChannelSubscriber symSub=new SymChannelSubscriber(); + symSub.setOwner(sub.isOwner()); + symSub.setPushed(sub.isPushed()); + symSub.setSubscriberName(sub.getSubscriberName()); + symSub.setUserId(sub.getUserId()); + symSub.setTimestamp(sub.getTimestamp()); + return symSub; + } +} diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriberResponse.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriberResponse.java new file mode 100644 index 00000000..9a3a22d8 --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriberResponse.java @@ -0,0 +1,83 @@ +/* + * + * + * 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 org.symphonyoss.symphony.clients.model; + +import java.util.ArrayList; +import java.util.List; + +import org.symphonyoss.symphony.agent.model.ChannelSubscriberResponse; + +/** + * @author dovkatz on 03/13/2018 + */ +public class SymChannelSubscriberResponse { + + private Integer total = null; + private Long offset = null; + private Boolean hasMore = null; + private List subscribers; + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public Long getOffset() { + return offset; + } + + public void setOffset(Long offset) { + this.offset = offset; + } + + public List getSubscribers() { + return subscribers; + } + + public void setSubscribers(List subs) { + this.subscribers = subs; + } + + public Boolean getHasMore() { + return hasMore; + } + + public void setHasMore(Boolean hasMore) { + this.hasMore = hasMore; + } + + public static SymChannelSubscriberResponse toSymChannelSubscriberResponse(ChannelSubscriberResponse response) { + SymChannelSubscriberResponse symResponse=new SymChannelSubscriberResponse(); + symResponse.setHasMore(response.isHasMore()); + symResponse.setTotal(response.getTotal()); + symResponse.setOffset(response.getOffset()); + List list=new ArrayList<>(); + response.getData().forEach((subscriber)->list.add(SymChannelSubscriber.toSymChannelSubscriber(subscriber)));; + symResponse.setSubscribers(list); + return symResponse; + } +} diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymFeature.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymFeature.java index 8cc80471..57ed46ca 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymFeature.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymFeature.java @@ -147,7 +147,7 @@ public static List toFeatures(SymFeatureList symFeatures) { private static SymFeature toSymFeature(Feature feature) { SymFeature symFeature = new SymFeature(); symFeature.setEntitlement(feature.getEntitlment()); - symFeature.setEnabled(feature.getEnabled()); + symFeature.setEnabled(feature.isEnabled()); return symFeature; } diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymMessage.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymMessage.java index c74adaed..25cd735e 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymMessage.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymMessage.java @@ -68,6 +68,11 @@ public class SymMessage { private ApiVersion apiVersion = null; + private String userAgent = null; + + private String originalFormat = null; + + public SymUser getSymUser() { return symUser; } @@ -177,6 +182,21 @@ public void setAttachementThumbnail(File attachementThumbnail) { this.attachementThumbnail = attachementThumbnail; } + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + + public String getOriginalFormat() { + return originalFormat; + } + + public void setOriginalFormat(String originalFormat) { + this.originalFormat = originalFormat; + } public ApiVersion getApiVersion() { @@ -221,6 +241,8 @@ public static SymMessage toSymMessage(V4Message v4Message) { symMessage.setSymUser(SymUser.toSymUser(v4Message.getUser())); symMessage.setMessage(v4Message.getMessage()); symMessage.setStream(SymStream.toSymStream(v4Message.getStream())); + symMessage.setUserAgent(v4Message.getUserAgent()); + symMessage.setOriginalFormat(v4Message.getOriginalFormat()); if (v4Message.getAttachments() != null) symMessage.setAttachments(SymAttachmentInfo.toAttachmentsInfos(v4Message.getAttachments())); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomAttributes.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomAttributes.java index efbf4249..80f462a2 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomAttributes.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomAttributes.java @@ -164,14 +164,14 @@ public void setMultiLateralRoom(Boolean multiLateralRoom) { public static SymRoomAttributes toSymRoomAttributes(V2RoomAttributes roomAttributes) { SymRoomAttributes symRoomAttributes = new SymRoomAttributes(); - symRoomAttributes.setPublic(roomAttributes.getPublic()); - symRoomAttributes.setCopyProtected(roomAttributes.getCopyProtected()); + symRoomAttributes.setPublic(roomAttributes.isPublic()); + symRoomAttributes.setCopyProtected(roomAttributes.isCopyProtected()); symRoomAttributes.setDescription(roomAttributes.getDescription()); - symRoomAttributes.setDiscoverable(roomAttributes.getDiscoverable()); + symRoomAttributes.setDiscoverable(roomAttributes.isDiscoverable()); symRoomAttributes.setKeywords(SymRoomTag.toSymRoomTagsV2(roomAttributes.getKeywords())); - symRoomAttributes.setMembersCanInvite(roomAttributes.getMembersCanInvite()); + symRoomAttributes.setMembersCanInvite(roomAttributes.isMembersCanInvite()); symRoomAttributes.setName(roomAttributes.getName()); - symRoomAttributes.setReadOnly(roomAttributes.getReadOnly()); + symRoomAttributes.setReadOnly(roomAttributes.isReadOnly()); symRoomAttributes.setKeywords(SymRoomTag.toSymRoomTagsV2(roomAttributes.getKeywords())); return symRoomAttributes; @@ -197,18 +197,18 @@ public static V2RoomAttributes toV2RoomAttributes(SymRoomAttributes roomAttribut public static SymRoomAttributes toSymRoomAttributes(V3RoomAttributes roomAttributes) { SymRoomAttributes symRoomAttributes = new SymRoomAttributes(); - symRoomAttributes.setPublic(roomAttributes.getPublic()); - symRoomAttributes.setCopyProtected(roomAttributes.getCopyProtected()); + symRoomAttributes.setPublic(roomAttributes.isPublic()); + symRoomAttributes.setCopyProtected(roomAttributes.isCopyProtected()); symRoomAttributes.setDescription(roomAttributes.getDescription()); - symRoomAttributes.setDiscoverable(roomAttributes.getDiscoverable()); + symRoomAttributes.setDiscoverable(roomAttributes.isDiscoverable()); symRoomAttributes.setKeywords(SymRoomTag.toSymRoomTagsV2(roomAttributes.getKeywords())); - symRoomAttributes.setMembersCanInvite(roomAttributes.getMembersCanInvite()); + symRoomAttributes.setMembersCanInvite(roomAttributes.isMembersCanInvite()); symRoomAttributes.setName(roomAttributes.getName()); - symRoomAttributes.setReadOnly(roomAttributes.getReadOnly()); - symRoomAttributes.setCrossPod(roomAttributes.getCrossPod()); - symRoomAttributes.setViewHistory(roomAttributes.getViewHistory()); - if (roomAttributes.getMultiLateralRoom() != null) - symRoomAttributes.setMultiLateralRoom(roomAttributes.getMultiLateralRoom()); + symRoomAttributes.setReadOnly(roomAttributes.isReadOnly()); + symRoomAttributes.setCrossPod(roomAttributes.isCrossPod()); + symRoomAttributes.setViewHistory(roomAttributes.isViewHistory()); + if (roomAttributes.isMultiLateralRoom() != null) + symRoomAttributes.setMultiLateralRoom(roomAttributes.isMultiLateralRoom()); return symRoomAttributes; } @@ -237,15 +237,15 @@ public static SymRoomAttributes toSymRoomAttributes(V4RoomProperties roomPropert SymRoomAttributes symRoomAttributes = new SymRoomAttributes(); - symRoomAttributes.setPublic(roomProperties.getPublic()); - symRoomAttributes.setCopyProtected(roomProperties.getCopyProtected()); + symRoomAttributes.setPublic(roomProperties.isPublic()); + symRoomAttributes.setCopyProtected(roomProperties.isCopyProtected()); symRoomAttributes.setDescription(roomProperties.getDescription()); - symRoomAttributes.setDiscoverable(roomProperties.getDiscoverable()); + symRoomAttributes.setDiscoverable(roomProperties.isDiscoverable()); //Seems like keywords is missing symRoomAttributes.setKeywords(SymRoomTag.toSymRoomTags(roomProperties.getKeywords())); - symRoomAttributes.setMembersCanInvite(roomProperties.getMembersCanInvite()); + symRoomAttributes.setMembersCanInvite(roomProperties.isMembersCanInvite()); symRoomAttributes.setName(roomProperties.getName()); - symRoomAttributes.setReadOnly(roomProperties.getReadOnly()); + symRoomAttributes.setReadOnly(roomProperties.isReadOnly()); symRoomAttributes.setCreatorUser(SymUser.toSymUser(roomProperties.getCreatorUser())); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomSystemInfo.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomSystemInfo.java index 1c85d5c5..7bdcb499 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomSystemInfo.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymRoomSystemInfo.java @@ -78,7 +78,7 @@ public void setActive(Boolean active) { public static SymRoomSystemInfo toSymRoomSystemInfo(RoomSystemInfo roomSystemInfo){ SymRoomSystemInfo symRoomSystemInfo = new SymRoomSystemInfo(); - symRoomSystemInfo.setActive(roomSystemInfo.getActive()); + symRoomSystemInfo.setActive(roomSystemInfo.isActive()); symRoomSystemInfo.setCreatedByUserId(roomSystemInfo.getCreatedByUserId()); symRoomSystemInfo.setCreationDate(roomSystemInfo.getCreationDate()); symRoomSystemInfo.setId(roomSystemInfo.getId()); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymSignal.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymSignal.java new file mode 100644 index 00000000..b942daa4 --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymSignal.java @@ -0,0 +1,132 @@ +/* + * + * + * 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 org.symphonyoss.symphony.clients.model; + +import java.util.ArrayList; +import java.util.List; + +import org.symphonyoss.symphony.agent.model.BaseSignal; +import org.symphonyoss.symphony.agent.model.Signal; +import org.symphonyoss.symphony.agent.model.SignalList; + +/** + * @author dovkatz on 03/13/2018 + */ +public class SymSignal { + + private Boolean companyWide = null; + private Boolean visibleOnProfile = null; + private Long timestamp = null; + private String id = null; + private String name = null; + private String query = null; + + + + public Boolean getCompanyWide() { + return companyWide; + } + + public void setCompanyWide(Boolean companyWide) { + this.companyWide = companyWide; + } + + public Boolean getVisibleOnProfile() { + return visibleOnProfile; + } + + public void setVisibleOnProfile(Boolean visibleOnProfile) { + this.visibleOnProfile = visibleOnProfile; + } + + public Long getTimestamp() { + return timestamp; + } + + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public static BaseSignal toBaseSignal(SymSignal symSignal) { + BaseSignal base=new BaseSignal(); + base.companyWide(symSignal.getCompanyWide()); + base.query(symSignal.getQuery()); + base.name(symSignal.getName()); + base.visibleOnProfile(symSignal.getVisibleOnProfile()); + return base; + } + + public static Signal toSignal(SymSignal symSignal) { + Signal signal=new Signal(); + signal.companyWide(symSignal.getCompanyWide()); + signal.id(symSignal.getId()); + signal.name(symSignal.getName()); + signal.query(symSignal.getQuery()); + signal.visibleOnProfile(symSignal.getVisibleOnProfile()); + signal.timestamp(symSignal.getTimestamp()); + return signal; + } + + public static SymSignal toSymSignal(Signal signal) { + SymSignal symSignal=new SymSignal(); + symSignal.setCompanyWide(signal.isCompanyWide()); + symSignal.setId(signal.getId()); + symSignal.setName(signal.getName()); + symSignal.setQuery(signal.getQuery()); + symSignal.setVisibleOnProfile(signal.isVisibleOnProfile()); + symSignal.setTimestamp(signal.getTimestamp()); + return symSignal; + } + + public static List fromSignalList(SignalList list){ + List result=new ArrayList<>(); + list.forEach((signal)->result.add(SymSignal.toSymSignal(signal))); + return result; + } +} diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStream.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStream.java index 8c7a0c97..6cd82b19 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStream.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStream.java @@ -56,6 +56,7 @@ public String getStreamId() { return streamId; } + public void setStreamId(String streamId) { this.streamId = streamId; } @@ -84,10 +85,17 @@ public void setMembers(List members) { this.members = members; } + /** + * @deprecated Replaced by {{@link #isExternal()}} + * @return boolean external + */ public Boolean getExternal() { return external; } + + public Boolean isExternal() { return external; } + public void setExternal(Boolean external) { this.external = external; } @@ -100,7 +108,8 @@ public static SymStream toSymStream(V4Stream stream) { SymStream symStream = new SymStream(); - symStream.setExternal(stream.getExternal()); + symStream.setExternal(stream.isExternal()); + if(stream.getMembers() != null) symStream.setMembers(stream.getMembers().stream().map(SymUser::toSymUser).collect(Collectors.toList())); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamAttributes.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamAttributes.java index 4dd43522..23081314 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamAttributes.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamAttributes.java @@ -101,8 +101,8 @@ public void setSymRoomSpecificStreamAttributes(SymRoomSpecificStreamAttributes s public static SymStreamAttributes toStreamAttributes(StreamAttributes streamAttributes) { SymStreamAttributes symStreamAttributes = new SymStreamAttributes(); - symStreamAttributes.setActive(streamAttributes.getActive()); - symStreamAttributes.setCrossPod(streamAttributes.getCrossPod()); + symStreamAttributes.setActive(streamAttributes.isActive()); + symStreamAttributes.setCrossPod(streamAttributes.isCrossPod()); symStreamAttributes.setId(streamAttributes.getId()); SymRoomSpecificStreamAttributes symRoomSpecificStreamAttributes = new SymRoomSpecificStreamAttributes(); diff --git a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamFilter.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamFilter.java index a30e721f..b1f4a7b4 100644 --- a/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamFilter.java +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymStreamFilter.java @@ -116,7 +116,7 @@ public static SymStreamFilter toSymStreamFilter(StreamFilter streamFilter) { SymStreamFilter symStreamFilter = new SymStreamFilter(); - symStreamFilter.setIncludeInactiveStreams(streamFilter.getIncludeInactiveStreams()); + symStreamFilter.setIncludeInactiveStreams(streamFilter.isIncludeInactiveStreams()); if (streamFilter.getStreamTypes() != null) { diff --git a/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java b/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java index 7b62b8b4..7b1b3371 100644 --- a/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java +++ b/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigBuilderTest.java @@ -19,11 +19,12 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class SymphonyClientConfigBuilderTest { @Test - public void configTest() + public void fullConfigBuildTest() { SymphonyClientConfig config = SymphonyClientConfigBuilder.newBuilder() .withSessionAuthUrl("dummyValue-SessionAuthUrl") @@ -37,17 +38,58 @@ public void configTest() .withJMXHealthcheck(true) .build(); - assertEquals(config.get(SymphonyClientConfigID.SESSIONAUTH_URL), "dummyValue-SessionAuthUrl"); - assertEquals(config.get(SymphonyClientConfigID.KEYAUTH_URL), "dummyValue-KeyAuthUrl"); - assertEquals(config.get(SymphonyClientConfigID.POD_URL), "dummyValue-PodUrl"); - assertEquals(config.get(SymphonyClientConfigID.AGENT_URL), "dummyValue-AgentUrl"); - assertEquals(config.get(SymphonyClientConfigID.TRUSTSTORE_FILE), "dummyValue-TrustStoreFile"); - assertEquals(config.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD), "dummyValue-TrustStorePassword"); - assertEquals(config.get(SymphonyClientConfigID.USER_EMAIL), "dummyValue-UserEmail"); - assertEquals(config.get(SymphonyClientConfigID.USER_CERT_FILE), "dummyValue-UserCertFile"); - assertEquals(config.get(SymphonyClientConfigID.USER_CERT_PASSWORD), "dummyValue-UserCertPassword"); - assertEquals(config.get(SymphonyClientConfigID.RECEIVER_EMAIL), "dummyValue-ReceiverEmail"); - assertEquals(config.get(SymphonyClientConfigID.DISABLE_SERVICES), String.valueOf(false)); - assertEquals(config.get(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED), String.valueOf(true)); + assertEquals("dummyValue-SessionAuthUrl", config.rawGet(SymphonyClientConfigID.SESSIONAUTH_URL)); + assertEquals("dummyValue-KeyAuthUrl", config.rawGet(SymphonyClientConfigID.KEYAUTH_URL)); + assertEquals("dummyValue-PodUrl", config.rawGet(SymphonyClientConfigID.POD_URL)); + assertEquals("dummyValue-AgentUrl", config.rawGet(SymphonyClientConfigID.AGENT_URL)); + assertEquals("dummyValue-TrustStoreFile", config.rawGet(SymphonyClientConfigID.TRUSTSTORE_FILE)); + assertEquals("dummyValue-TrustStorePassword", config.rawGet(SymphonyClientConfigID.TRUSTSTORE_PASSWORD)); + assertEquals("dummyValue-UserEmail", config.rawGet(SymphonyClientConfigID.USER_EMAIL)); + assertEquals("dummyValue-UserCertFile", config.rawGet(SymphonyClientConfigID.USER_CERT_FILE)); + assertEquals("dummyValue-UserCertPassword", config.rawGet(SymphonyClientConfigID.USER_CERT_PASSWORD)); + assertEquals("dummyValue-ReceiverEmail", config.rawGet(SymphonyClientConfigID.RECEIVER_EMAIL)); + assertEquals(String.valueOf(false), config.rawGet(SymphonyClientConfigID.DISABLE_SERVICES)); + assertEquals(String.valueOf(true), config.rawGet(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED)); + } + + @Test + public void nullConfigBuildTest() + { + SymphonyClientConfig config = SymphonyClientConfigBuilder.newBuilder() + .withSessionAuthUrl(null) + .withKeyAuthUrl(null) + .withPodUrl(null) + .withAgentUrl(null) + .withTrustStore(null, null) + .withUserCreds(null, null, null) + .withReceiverEmail(null) + .build(); + + assertNull(config.rawGet(SymphonyClientConfigID.SESSIONAUTH_URL)); + assertNull(config.rawGet(SymphonyClientConfigID.KEYAUTH_URL)); + assertNull(config.rawGet(SymphonyClientConfigID.POD_URL)); + assertNull(config.rawGet(SymphonyClientConfigID.AGENT_URL)); + assertNull(config.rawGet(SymphonyClientConfigID.TRUSTSTORE_FILE)); + assertNull(config.rawGet(SymphonyClientConfigID.TRUSTSTORE_PASSWORD)); + assertNull(config.rawGet(SymphonyClientConfigID.USER_EMAIL)); + assertNull(config.rawGet(SymphonyClientConfigID.USER_CERT_FILE)); + assertNull(config.rawGet(SymphonyClientConfigID.USER_CERT_PASSWORD)); + assertNull(config.rawGet(SymphonyClientConfigID.RECEIVER_EMAIL)); + } + + @Test + public void defaultConfigBuildTest() + { + SymphonyClientConfig config = SymphonyClientConfigBuilder.newBuilder() + .withSessionAuthUrl(null) + .withKeyAuthUrl(null) + .withPodUrl(null) + .withAgentUrl(null) + .withTrustStore(null, null) + .withUserCreds(null, null, null) + .build(); + + assertEquals(String.valueOf(false), config.rawGet(SymphonyClientConfigID.DISABLE_SERVICES)); + assertEquals(String.valueOf(true), config.rawGet(SymphonyClientConfigID.HEALTHCHECK_JMX_ENABLED)); } } diff --git a/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigTest.java b/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigTest.java index 4fff3bd7..319fc0dd 100644 --- a/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigTest.java +++ b/symphony-client/src/test/java/org/symphonyoss/client/SymphonyClientConfigTest.java @@ -21,8 +21,11 @@ import java.util.HashSet; import java.util.Map; +import java.util.Properties; import java.util.Set; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.symphonyoss.client.exceptions.ProgramFault; @@ -32,6 +35,20 @@ public class SymphonyClientConfigTest { private static final String SESSIONAUTH_URI = "https://corporate-api.symphony.com:8444/sessionauth"; private static final String OVERRIDE = "OVERRIDE"; + private Properties backup=null; + + @Before + public void backupProperties() { + backup=new Properties(); + backup.putAll(System.getProperties()); + } + + @After + public void restoreProperties() { + System.setProperties(backup); + backup=new Properties(); + } + @Test public void configTest() { try { diff --git a/symphony-client/src/test/java/org/symphonyoss/client/ai/utils/AiSpellParserTest.java b/symphony-client/src/test/java/org/symphonyoss/client/ai/utils/AiSpellParserTest.java new file mode 100644 index 00000000..1105aa1f --- /dev/null +++ b/symphony-client/src/test/java/org/symphonyoss/client/ai/utils/AiSpellParserTest.java @@ -0,0 +1,172 @@ +/* + * + * + * Copyright 2018 Diffblue Limited + * + * 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 SSF 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 org.symphonyoss.client.ai.utils; +import org.junit.Assert; +import org.junit.rules.ExpectedException; +import org.junit.Test; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import com.diffblue.deeptestutils.CompareWithFieldList; +import com.diffblue.deeptestutils.Reflector; +@org.junit.runner.RunWith(org.powermock.modules.junit4.PowerMockRunner.class) +public class AiSpellParserTest { + @org.junit.Rule + public ExpectedException thrown = ExpectedException.none(); + /* testedClasses: AiSpellParser */ + + /* + * Test generated by Diffblue Deeptest. + * This test case covers: + * conditional line 171 branch to line 172 + * org/symphonyoss/client/ai/utils/AiSpellParser.java:179: loop: 1 iterations + * iteration 1 + * conditional line 180 branch to line 180 + * conditional line 180 branch to line 179 + * conditional line 183 branch to line 183 + */ + + @org.junit.Test + public void org_symphonyoss_client_ai_utils_AiSpellParser_isCloseTo_000_a2a15613a4edd99f() throws Throwable { + + boolean retval; + { + /* Arrange */ + String input1 = "?"; + String input2 = ""; + double closenessFactor = 0.0; + + /* Act */ + Class c = Reflector.forName("org.symphonyoss.client.ai.utils.AiSpellParser"); + Method m = c.getDeclaredMethod("isCloseTo", Reflector.forName("java.lang.String"), Reflector.forName("java.lang.String"), Reflector.forName("double")); + m.setAccessible(true); + retval = (boolean) m.invoke(null, input1, input2, closenessFactor); + } + { + /* Assert result */ + Assert.assertEquals(false, retval); + } + } + + /* + * Test generated by Diffblue Deeptest. + * This test case covers: + * conditional line 171 branch to line 172 + * org/symphonyoss/client/ai/utils/AiSpellParser.java:179: loop: 1 iterations + * iteration 1 + * conditional line 180 branch to line 180 + * conditional line 180 branch to line 179 + * conditional line 183 branch to line 183 + */ + + @org.junit.Test + public void org_symphonyoss_client_ai_utils_AiSpellParser_isCloseTo_001_2e7b54f146d8f0cf() throws Throwable { + + boolean retval; + { + /* Arrange */ + String input1 = "?"; + String input2 = ""; + double closenessFactor = -0x1.0000000000001p+1 /* -2.0 */; + + /* Act */ + Class c = Reflector.forName("org.symphonyoss.client.ai.utils.AiSpellParser"); + Method m = c.getDeclaredMethod("isCloseTo", Reflector.forName("java.lang.String"), Reflector.forName("java.lang.String"), Reflector.forName("double")); + m.setAccessible(true); + retval = (boolean) m.invoke(null, input1, input2, closenessFactor); + } + { + /* Assert result */ + Assert.assertEquals(true, retval); + } + } + + /* + * Test generated by Diffblue Deeptest. + * This test case covers: + * conditional line 171 branch to line 175 + * org/symphonyoss/client/ai/utils/AiSpellParser.java:179: loop: 1 iterations + * iteration 1 + * conditional line 180 branch to line 180 + * conditional line 180 branch to line 179 + * conditional line 183 branch to line 183 + */ + + @org.junit.Test + public void org_symphonyoss_client_ai_utils_AiSpellParser_isCloseTo_002_71975b80a4f1f106() throws Throwable { + + boolean retval; + { + /* Arrange */ + String input1 = ""; + String input2 = "?"; + double closenessFactor = -0x1.0000000000001p+1 /* -2.0 */; + + /* Act */ + Class c = Reflector.forName("org.symphonyoss.client.ai.utils.AiSpellParser"); + Method m = c.getDeclaredMethod("isCloseTo", Reflector.forName("java.lang.String"), Reflector.forName("java.lang.String"), Reflector.forName("double")); + m.setAccessible(true); + retval = (boolean) m.invoke(null, input1, input2, closenessFactor); + } + { + /* Assert result */ + Assert.assertEquals(true, retval); + } + } + + /* + * Test generated by Diffblue Deeptest. + * This test case covers: + * conditional line 171 branch to line 175 + * org/symphonyoss/client/ai/utils/AiSpellParser.java:179: loop: 1 iterations + * iteration 1 + * conditional line 180 branch to line 180 + * conditional line 180 branch to line 181 + * conditional line 183 branch to line 183 + */ + + @org.junit.Test + public void org_symphonyoss_client_ai_utils_AiSpellParser_isCloseTo_003_5933843219c118fd() throws Throwable { + + boolean retval; + { + /* Arrange */ + String input1 = "?"; + String input2 = "?"; + double closenessFactor = -0x1.0000000000001p+8 /* -256.0 */; + + /* Act */ + Class c = Reflector.forName("org.symphonyoss.client.ai.utils.AiSpellParser"); + Method m = c.getDeclaredMethod("isCloseTo", Reflector.forName("java.lang.String"), Reflector.forName("java.lang.String"), Reflector.forName("double")); + m.setAccessible(true); + retval = (boolean) m.invoke(null, input1, input2, closenessFactor); + } + { + /* Assert result */ + Assert.assertEquals(true, retval); + } + } +} diff --git a/symphony-client/src/test/java/org/symphonyoss/symphony/clients/SignalsClientTest.java b/symphony-client/src/test/java/org/symphonyoss/symphony/clients/SignalsClientTest.java new file mode 100644 index 00000000..e9a365c1 --- /dev/null +++ b/symphony-client/src/test/java/org/symphonyoss/symphony/clients/SignalsClientTest.java @@ -0,0 +1,104 @@ +package org.symphonyoss.symphony.clients; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.math.BigDecimal; +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Spy; +import org.powermock.api.mockito.internal.mockcreation.RuntimeExceptionProxy; +import org.symphonyoss.client.SymphonyClient; +import org.symphonyoss.client.exceptions.SignalsException; +import org.symphonyoss.symphony.agent.api.SignalsApi; +import org.symphonyoss.symphony.agent.invoker.ApiException; +import org.symphonyoss.symphony.agent.model.BaseSignal; +import org.symphonyoss.symphony.agent.model.Signal; +import org.symphonyoss.symphony.agent.model.SuccessResponse; +import org.symphonyoss.symphony.clients.impl.SignalsClientImpl; +import org.symphonyoss.symphony.clients.model.SymSignal; +import org.symphonyoss.symphony.clients.model.SymSignalTest; +import org.symphonyoss.util.TestFactory; + +public class SignalsClientTest { + + SignalsClient signalsClient; + SymphonyClient testClient; + + @Spy + SignalsApi api; + @Spy + SignalsClientImpl spySignalsClient; + + @Before + public void setUp() { + testClient = TestFactory.getSymClient(); + signalsClient = testClient.getSignalsClient(); + spySignalsClient = spy(new SignalsClientImpl(testClient.getSymAuth(), testClient.getConfig())); + api = mock(SignalsApi.class); + when(spySignalsClient.createSignalsApi()).thenReturn(api); + } + + @Test + public void getClientTest() throws Exception { + assertTrue("get DEFAULT client", SignalsFactory.getClient(testClient) instanceof SignalsClientImpl); + } + + @Test + public void createSignalTest() throws Exception { + SymSignal signal = new SymSignal(); + signal.setName(SymSignalTest.DUMMY_NAME); + signal.setQuery(SymSignalTest.DUMMY_QUERY); + + Signal apiSignal = SymSignal.toSignal(signal); + when(api.v1SignalsCreatePost(anyString(), any(BaseSignal.class), anyString())).thenReturn(apiSignal); + SymSignal result = spySignalsClient.createSignal(signal); + assertEquals(SymSignalTest.DUMMY_NAME, result.getName()); + assertEquals(SymSignalTest.DUMMY_QUERY, result.getQuery()); + } + + @Test + public void createSignalWithError() throws Exception { + when(api.v1SignalsCreatePost(anyString(), any(BaseSignal.class), anyString())).thenThrow(new ApiException()); + try { + spySignalsClient.createSignal(new SymSignal()); + } catch (Throwable sig) { + // NOTE we will get a runtimeExceptionProxy due to how this is mocked + assertTrue(sig instanceof RuntimeExceptionProxy); + // This is the part we would expect in real life. + assertTrue(sig.getCause() instanceof SignalsException); + assertTrue(sig.getCause().getCause() instanceof ApiException); + } + } + + @Test + public void updateSignalTest() throws Exception { + SymSignal signal = new SymSignal(); + signal.setName(SymSignalTest.DUMMY_NAME); + signal.setQuery(SymSignalTest.DUMMY_QUERY); + signal.setId(SymSignalTest.DUMMY_ID); + when(api.v1SignalsIdUpdatePost(anyString(), anyString(), any(BaseSignal.class), anyString())).thenReturn(SymSignal.toSignal(signal)); + SymSignal result = spySignalsClient.updateSignal(signal.getId(), signal); + assertEquals(SymSignalTest.DUMMY_ID, result.getId()); + } + + @Test + public void deleteSignalTest() throws Exception { + SymSignal signal = new SymSignal(); + signal.setName(SymSignalTest.DUMMY_NAME); + signal.setQuery(SymSignalTest.DUMMY_QUERY); + signal.setId(SymSignalTest.DUMMY_ID); + SuccessResponse resp=new SuccessResponse(); + when(api.v1SignalsIdDeletePost(anyString(), anyString(), anyString())).thenReturn(resp); + spySignalsClient.deleteSignal(signal.getId()); + } + +} diff --git a/symphony-client/src/test/java/org/symphonyoss/symphony/clients/model/SymSignalTest.java b/symphony-client/src/test/java/org/symphonyoss/symphony/clients/model/SymSignalTest.java new file mode 100644 index 00000000..87b76dba --- /dev/null +++ b/symphony-client/src/test/java/org/symphonyoss/symphony/clients/model/SymSignalTest.java @@ -0,0 +1,83 @@ +package org.symphonyoss.symphony.clients.model; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.symphonyoss.symphony.agent.model.BaseSignal; +import org.symphonyoss.symphony.agent.model.Signal; +import org.symphonyoss.symphony.agent.model.SignalList; + +public class SymSignalTest { + public static final String DUMMY_ID = "dummy_id"; + public static final String DUMMY_QUERY = "HASHTAG:dummy AND CASHTAG:query"; + public static final String DUMMY_NAME = "Dummy Name for signal"; + public static final Boolean COMPANY_WIDE = false; + public static final Boolean VISIBLE_ON_PROFILE = true; + + public void compareSignalToSymSignal(Signal sig, SymSignal symSig) { + assertEquals(sig.getId(), symSig.getId()); + assertEquals(sig.getName(), symSig.getName()); + assertEquals(sig.getQuery(), symSig.getQuery()); + assertEquals(sig.isCompanyWide(), symSig.getCompanyWide()); + assertEquals(sig.isVisibleOnProfile(), symSig.getVisibleOnProfile()); + } + + public void compareBaseSignalToSymSignal(BaseSignal sig, SymSignal symSig) { + assertEquals(sig.getName(), symSig.getName()); + assertEquals(sig.getQuery(), symSig.getQuery()); + assertEquals(sig.isCompanyWide(), symSig.getCompanyWide()); + assertEquals(sig.isVisibleOnProfile(), symSig.getVisibleOnProfile()); + } + + @Test + public void testToSymSignal() { + Signal sig = new Signal(); + sig.id(DUMMY_ID); + sig.name(DUMMY_NAME); + sig.query(DUMMY_QUERY); + sig.companyWide(COMPANY_WIDE); + sig.visibleOnProfile(VISIBLE_ON_PROFILE); + SymSignal symSig = SymSignal.toSymSignal(sig); + compareSignalToSymSignal(sig, symSig); + } + + @Test + public void testFromSymSignal() { + SymSignal symSig = new SymSignal(); + symSig.setId(DUMMY_ID); + symSig.setName(DUMMY_NAME); + symSig.setQuery(DUMMY_QUERY); + symSig.setCompanyWide(COMPANY_WIDE); + symSig.setVisibleOnProfile(VISIBLE_ON_PROFILE); + Signal sig = SymSignal.toSignal(symSig); + compareSignalToSymSignal(sig, symSig); + } + + @Test + public void toBaseSignalTest() { + SymSignal symSig = new SymSignal(); + symSig.setName(DUMMY_NAME); + symSig.setQuery(DUMMY_QUERY); + symSig.setCompanyWide(COMPANY_WIDE); + symSig.setVisibleOnProfile(VISIBLE_ON_PROFILE); + BaseSignal sig = SymSignal.toBaseSignal(symSig); + compareBaseSignalToSymSignal(sig, symSig); + } + + @Test + public void toSignalListTest() { + SignalList sigList=new SignalList(); + Signal sig = new Signal(); + sig.id(DUMMY_ID); + sig.name(DUMMY_NAME); + sig.query(DUMMY_QUERY); + sig.companyWide(COMPANY_WIDE); + sig.visibleOnProfile(VISIBLE_ON_PROFILE); + sigList.add(sig); + List sigs=SymSignal.fromSignalList(sigList); + SymSignal symSig=sigs.get(0); + compareSignalToSymSignal(sig, symSig); + } +}