From cde9d054778c5ba62d4b53f52e524b74b38b1c55 Mon Sep 17 00:00:00 2001 From: Dov Katz Date: Tue, 13 Mar 2018 23:58:06 +0000 Subject: [PATCH 1/2] Added Symphony Signals API support --- .../symphonyoss/client/SymphonyClient.java | 7 + .../client/exceptions/SignalsException.java | 43 ++++ .../client/impl/SymphonyBasicClient.java | 6 + .../symphony/clients/SignalsClient.java | 61 +++++ .../symphony/clients/SignalsFactory.java | 47 ++++ .../symphony/clients/SymphonyApis.java | 3 + .../clients/impl/SignalsClientImpl.java | 211 ++++++++++++++++++ .../clients/impl/SymphonyApisImpl.java | 23 +- .../clients/model/SymChannelSubscriber.java | 99 ++++++++ .../model/SymChannelSubscriberResponse.java | 83 +++++++ .../symphony/clients/model/SymSignal.java | 132 +++++++++++ 11 files changed, 706 insertions(+), 9 deletions(-) create mode 100644 symphony-client/src/main/java/org/symphonyoss/client/exceptions/SignalsException.java create mode 100644 symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsClient.java create mode 100644 symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsFactory.java create mode 100644 symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SignalsClientImpl.java create mode 100644 symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriber.java create mode 100644 symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriberResponse.java create mode 100644 symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymSignal.java 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/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/SymphonyBasicClient.java b/symphony-client/src/main/java/org/symphonyoss/client/impl/SymphonyBasicClient.java index ca052c9b..10a29cf8 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 @@ -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/symphony/clients/SignalsClient.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/SignalsClient.java new file mode 100644 index 00000000..edd9e595 --- /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, BigDecimal skip, BigDecimal 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..9b360aa2 --- /dev/null +++ b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/impl/SignalsClientImpl.java @@ -0,0 +1,211 @@ +/* + * + * + * 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)); + } + + @Override + public SymSignal createSignal(SymSignal signal) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + 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); + } + } + + @Override + public SymSignal updateSignal(String id, SymSignal signal) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + 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); + } + } + + @Override + public void deleteSignal(String id) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + api.v1SignalsIdDeletePost(symAuth.getSessionToken().getToken(), id, symAuth.getKeyToken().getToken()); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + @Override + public SymSignal getSignal(String id) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + Signal result = api.v1SignalsIdGetGet(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken()); + return SymSignal.toSymSignal(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + @Override + public List listSignals(int skip, int limit) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + SignalList result = api.v1SignalsListGet(symAuth.getSessionToken().getToken(), + symAuth.getKeyToken().getToken(), skip, limit); + return SymSignal.fromSignalList(result); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + @Override + public SymChannelSubscriberResponse listSubscribers(String id, BigDecimal skip, BigDecimal limit) + throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + 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); + } + } + + @Override + public ChannelSubscriptionResponse subscribe(String id) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + return api.v1SignalsIdSubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), null, null); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + @Override + public ChannelSubscriptionResponse bulkSubscribe(String id, boolean pushed, List userIds) + throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + return api.v1SignalsIdSubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), pushed, userIds); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + @Override + public ChannelSubscriptionResponse unsubscribe(String id) throws SignalsException { + SignalsApi api = new SignalsApi(apiClient); + try { + return api.v1SignalsIdUnsubscribePost(symAuth.getSessionToken().getToken(), id, + symAuth.getKeyToken().getToken(), null); + } catch (ApiException ex) { + throw new SignalsException(ex); + } + } + + @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/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/model/SymChannelSubscriber.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymChannelSubscriber.java new file mode 100644 index 00000000..128768ce --- /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.getOwner()); + symSub.setPushed(sub.getPushed()); + 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..c2366172 --- /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.getHasMore()); + 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/SymSignal.java b/symphony-client/src/main/java/org/symphonyoss/symphony/clients/model/SymSignal.java new file mode 100644 index 00000000..c8a16f79 --- /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.getCompanyWide()); + symSignal.setId(signal.getId()); + symSignal.setName(signal.getName()); + symSignal.setQuery(signal.getQuery()); + symSignal.setVisibleOnProfile(signal.getVisibleOnProfile()); + 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; + } +} From 728bcf5e38f1642ba2c97f0057e1db6bbd2c4948 Mon Sep 17 00:00:00 2001 From: Dov Katz Date: Wed, 14 Mar 2018 00:23:49 +0000 Subject: [PATCH 2/2] Fix state-changing Unit tests which are modifying System properties. --- .../client/SymphonyClientConfigTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 {