public class WWClient extends Object implements Serializable, IWWClient
IWWClient.ClientType
Constructor and Description |
---|
WWClient() |
Modifier and Type | Method and Description |
---|---|
ArrayList<String> |
addSpaceMembers(String id,
List<SpaceMembersAddDataSenderBuilder.SpaceMemberObject> members)
Easy helper method for adding Space members returning List of member IDs updated
|
void |
authenticate()
Attempt authentication of the WWClient
|
static WWClient |
buildClientApplicationAccess(String appId,
String appSecret,
AuthenticationEndpoint authenticationEndpoint)
Creates an application-level WWClient, not associated with a specific user.
|
static WWClient |
buildClientUserAccess(String userToken,
String appId,
String appSecret,
AuthenticationEndpoint authenticationEndpoint,
String redirectTo)
Creates and returns a WWClient for a specific user
|
static WWClient |
buildClientUserAccessFromToken(String appId,
String appSecret,
PeopleToken token)
Creates and returns a WWClient for a specific user.
|
Space |
createSpace(String title)
Easy helper method to create a Space with a title
|
Space |
createSpace(String title,
List<String> members)
Easy helper method to create a Space with a title and list of Members
|
Space |
createSpaceWithQuery(SpaceCreateGraphQLMutation mutationObject)
Easy helper method to create a Space with a SpaceCreateGraphQLMutation object
|
boolean |
deleteSpace(String id)
Easy helper method to delete a Space
|
String |
getAppCredentials()
Converts appId and appSecret into required content for Authorization header
|
IWWClient.ClientType |
getClientType()
Getter for ClientType, dependent upon the initialiser user
|
Conversation |
getConversationById(String conversationId)
Easy helper method to get a Conversation and its details by a conversation id
|
Conversation |
getConversationWithQuery(ConversationGraphQLQuery query)
Easy helper method to get a Conversation and its details with a query
|
ConversationWrapper |
getConversationWrapperWithQuery(ConversationGraphQLQuery query)
Easy helper method to get a ConversationWrapper and its details with a query, including access to PageInfo object
|
GraphResultContainer |
getCustomQuery(BaseGraphQLQuery query)
Perform a custom GraphQL query returning customised content for one or more fields.
|
Date |
getExpireDate()
Gets the time the token expires from the
AuthenticationResult |
Object |
getExpiresIn()
Gets the length of time until the token expires from the
AuthenticationResult |
String |
getJWTToken()
Gets JWT token for the user / application from the
AuthenticationResult . |
Person |
getMe()
Easy helper method to get My Person object.
|
List<Mentioned> |
getMentioned()
Easy helper method to get first 10 mentions for current user
|
MentionedContainer |
getMentionedContainerWithQuery(MentionedGraphQLQuery query)
Easy helper method to get mentions and PageInfo object for current user
|
List<Mentioned> |
getMentionedWithQuery(MentionedGraphQLQuery query)
Easy helper method to get mentions for current user
|
Message |
getMessageById(String messageId)
Easy helper method to get a Message and its details by id
|
Message |
getMessageWithQuery(MessageGraphQLQuery query)
Easy helper method to get a Message and its details with a query
|
List<Person> |
getPeople(List<String> ids)
Easy helper method to get Person objects with ids
|
List<Person> |
getPeopleByName(String name)
Easy helper method to get Person objects with part of a name
|
MembersContainer |
getPeopleContainerWithQuery(PeopleGraphQLQuery query)
Easy helper method to get Person objects with a query
|
List<Person> |
getPeopleWithQuery(PeopleGraphQLQuery query)
Easy helper method to get Person objects with a query
|
Person |
getPersonByEmail(String personEmail)
Easy helper method to get a Person with a person email.
|
Person |
getPersonById(String personId)
Easy helper method to get a Person with a person id.
|
Person |
getPersonWithQuery(PersonGraphQLQuery query)
Easy helper method to get a Person with a query
|
String |
getResultContent()
Getter for resultContent from relevant endpoint
|
Space |
getSpaceById(String spaceId)
Easy helper method to get a Space by a Space id
|
List<Person> |
getSpaceMembersById(String spaceId)
Easy helper method to get members for a space with the space id
|
List<Person> |
getSpaceMembersWithQuery(SpaceMembersGraphQLQuery query)
Easy helper method to get members of space with a query
|
List<? extends Space> |
getSpaces()
Easy helper method to get spaces from the WWClient
|
SpacesContainer |
getSpacesContainerWithQuery(SpacesGraphQLQuery query)
Easy helper method to get SpacesContainer with a query
|
List<? extends Space> |
getSpacesWithQuery(SpacesGraphQLQuery query)
Easy helper method to get Spaces with a query
|
Space |
getSpaceWithQuery(SpaceGraphQLQuery query)
Easy helper method to get a Space by using a SpaceGraphQLQuery
|
String |
getUserRefreshToken()
Gets the refreshtoken for a user authentication from the
AuthenticationResult |
boolean |
isAuthenticated()
Whether or not authentication has successfully occurred.
|
boolean |
isValid()
Tests whether the
AuthenticationResult is valid |
FileResponse |
postFileToSpace(File file,
String spaceId)
Post a file to Watson Workspace
|
FileResponse |
postFileToSpace(File file,
String spaceId,
String imageSize)
Post an image file to Watson Workspace
|
MessageResponse |
postMessageToSpace(AppMessage message,
String spaceId)
Easy helper method to post a Application Message to a Space
|
PhotoResponse |
postPhoto(File photo) |
List<Focus> |
postTextForFocusAnalysis(String text)
Post text for Watson Workspace to analyse for Focuses
|
ArrayList<String> |
removeSpaceMembers(String id,
List<String> members)
Easy helper method for removing Space members returning List of member IDs updated
|
void |
setResultContent(String resultContent)
Setter for resultContent from relevant endpoint
|
ArrayList<String> |
updateSpaceMembers(String id,
List<String> members,
SpaceUpdateGraphQLMutation.UpdateSpaceMemberOperation addOrRemove)
Easy helper method for updating a Space members returning List of member IDs updated
|
UpdateSpaceContainer |
updateSpaceMembersAndTitle(String id,
String title,
List<String> members,
SpaceUpdateGraphQLMutation.UpdateSpaceMemberOperation addOrRemove)
Easy helper method for updating a Space members and title, returning UpdateSpaceContainer with array of member
IDs updated and Space object with updated title
|
Space |
updateSpaceTitle(String id,
String newTitle)
Easy helper method for updating a Space Title returning Space object with updated Title
|
UpdateSpaceContainer |
updateSpaceWithMutation(SpaceUpdateGraphQLMutation mutationObject)
Easy helper method for updating a Space Title / members / both returning an UpdateSpaceContainer with updated
Space details / updated members / both
|
public static WWClient buildClientUserAccess(String userToken, String appId, String appSecret, AuthenticationEndpoint authenticationEndpoint, String redirectTo)
userToken
- String, the JWT user token to be passed, used to authenticate as the specific userappId
- String, the ID for the application the code is being run fromappSecret
- String, the secret for the application the code is being run fromauthenticationEndpoint
- AuthenticationEndpoint
or any sub-class thereof. Typically WWAuthenticationEndpoint
redirectTo
- String, URL to redirect to after authenticationpublic static WWClient buildClientApplicationAccess(String appId, String appSecret, AuthenticationEndpoint authenticationEndpoint)
appId
- String, the ID for the application the code is being run fromappSecret
- String, the secret for the application the code is being run fromauthenticationEndpoint
- AuthenticationEndpoint
or any sub-class thereof. Typically WWAuthenticationEndpoint
public static WWClient buildClientUserAccessFromToken(String appId, String appSecret, PeopleToken token)
appId
- String, the ID for the application the code is being run fromappSecret
- String, the secret for the application the code is being run fromtoken
- PeopleToken
containing access detailspublic IWWClient.ClientType getClientType()
IWWClient
getClientType
in interface IWWClient
IWWClient.ClientType.USER
or IWWClient.ClientType.APPLICATON
public String getAppCredentials() throws UnsupportedEncodingException
IWWClient
getAppCredentials
in interface IWWClient
UnsupportedEncodingException
- if the encoding option is not supportedpublic boolean isAuthenticated()
IWWClient
IWWClient.authenticate()
firstisAuthenticated
in interface IWWClient
public void authenticate() throws UnsupportedEncodingException, WWException
IWWClient
authenticate
in interface IWWClient
UnsupportedEncodingException
- Authorization header could not be constructedWWException
- Some other error occurred during authenticationpublic String getJWTToken()
IWWClient
AuthenticationResult
. The JWT token is an expiring token associated with the appId and appSecret. From the documentation: "This JWT
token is what you have to use in your App to pass to Watson Work Services on API calls so that you can use its services securely"getJWTToken
in interface IWWClient
public String getUserRefreshToken()
IWWClient
AuthenticationResult
getUserRefreshToken
in interface IWWClient
public Object getExpiresIn()
IWWClient
AuthenticationResult
getExpiresIn
in interface IWWClient
public Date getExpireDate()
IWWClient
AuthenticationResult
getExpireDate
in interface IWWClient
public boolean isValid()
IWWClient
AuthenticationResult
is validpublic List<? extends Space> getSpaces() throws WWException
WWException
- containing an error message, if the request was unsuccessfulpublic List<? extends Space> getSpacesWithQuery(SpacesGraphQLQuery query) throws WWException
query
- SpacesGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic SpacesContainer getSpacesContainerWithQuery(SpacesGraphQLQuery query) throws WWException
query
- SpacesGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic Space createSpace(String title, List<String> members) throws WWException
title
- String title for the Spacemembers
- List of member IDs to be granted access to the SpaceWWException
- containing an error message, if the request was unsuccessfulpublic Space createSpace(String title) throws WWException
title
- String title for the SpaceWWException
- containing an error message, if the request was unsuccessfulpublic Space createSpaceWithQuery(SpaceCreateGraphQLMutation mutationObject) throws WWException
mutationObject
- SpaceCreateGraphQLMutation containing the details to createWWException
- containing an error message, if the request was unsuccessfulpublic boolean deleteSpace(String id) throws WWException
id
- String id for the SpaceWWException
- containing an error message, if the request was unsuccessfulpublic Space updateSpaceTitle(String id, String newTitle) throws WWException
id
- String id of the Space to updatenewTitle
- String new title for the spaceWWException
- containing an error message, if the request was unsuccessfulpublic UpdateSpaceContainer updateSpaceWithMutation(SpaceUpdateGraphQLMutation mutationObject) throws WWException
mutationObject
- SpaceUpdateGraphQLMutation containing the details to updateWWException
- containing an error message, if the request was unsuccessfulpublic ArrayList<String> updateSpaceMembers(String id, List<String> members, SpaceUpdateGraphQLMutation.UpdateSpaceMemberOperation addOrRemove) throws WWException
id
- String id of the space to updatemembers
- List of member IDs to add / remove as membersaddOrRemove
- boolean whether members should be added to the Space or removedWWException
- containing an error message, if the request was unsuccessfulpublic UpdateSpaceContainer updateSpaceMembersAndTitle(String id, String title, List<String> members, SpaceUpdateGraphQLMutation.UpdateSpaceMemberOperation addOrRemove) throws WWException
id
- String id for the Space to updatetitle
- String title of the newly-created Spacemembers
- List of member IDs to add / remove as membersaddOrRemove
- UpdateSpaceMemberOperation enum whether members should be added to the Space or removedWWException
- containing an error message, if the request was unsuccessfulpublic ArrayList<String> addSpaceMembers(String id, List<SpaceMembersAddDataSenderBuilder.SpaceMemberObject> members) throws WWException
id
- String id of the space to updatemembers
- List of String member IDs to add as membersWWException
- containing an error message, if the request was unsuccessfulpublic ArrayList<String> removeSpaceMembers(String id, List<String> members) throws WWException
id
- String id of the space to updatemembers
- List of String member IDs to remove as membersWWException
- containing an error message, if the request was unsuccessfulpublic Space getSpaceById(String spaceId) throws WWException
spaceId
- id of the SpaceWWException
- containing an error message, if the request was unsuccessfulpublic Space getSpaceWithQuery(SpaceGraphQLQuery query) throws WWException
query
- SpaceGraphQLQuery for the callWWException
- containing an error message, if the request was unsuccessfulpublic Conversation getConversationById(String conversationId) throws WWException
conversationId
- String id of the conversationWWException
- containing an error message, if the request was unsuccessfulpublic Conversation getConversationWithQuery(ConversationGraphQLQuery query) throws WWException
query
- ConversationGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic ConversationWrapper getConversationWrapperWithQuery(ConversationGraphQLQuery query) throws WWException
query
- ConversationGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic Message getMessageById(String messageId) throws WWException
messageId
- String id of the MessageWWException
- containing an error message, if the request was unsuccessfulpublic Message getMessageWithQuery(MessageGraphQLQuery query) throws WWException
query
- MessageGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic Person getPersonById(String personId) throws WWException
personId
- String id of the personWWException
- containing an error message, if the request was unsuccessfulpublic Person getPersonByEmail(String personEmail) throws WWException
personEmail
- String email of the personWWException
- containing an error message, if the request was unsuccessfulpublic Person getPersonWithQuery(PersonGraphQLQuery query) throws WWException
query
- PersonGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic List<Person> getSpaceMembersById(String spaceId) throws WWException
spaceId
- String id of the spaceWWException
- containing an error message, if the request was unsuccessfulpublic List<Person> getSpaceMembersWithQuery(SpaceMembersGraphQLQuery query) throws WWException
query
- SpaceMembersGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic Person getMe() throws WWException
WWException
- containing an error message, if the request was unsuccessfulpublic List<Person> getPeople(List<String> ids) throws WWException
ids
- List of String person idsWWException
- containing an error message, if the request was unsuccessfulpublic List<Person> getPeopleByName(String name) throws WWException
name
- String part of a name. This needs to be a single wordWWException
- containing an error message, if the request was unsuccessfulpublic List<Person> getPeopleWithQuery(PeopleGraphQLQuery query) throws WWException
query
- PeopleGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic MembersContainer getPeopleContainerWithQuery(PeopleGraphQLQuery query) throws WWException
query
- PeopleGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic List<Mentioned> getMentioned() throws WWException
WWException
- containing an error message, if the request was unsuccessfulpublic List<Mentioned> getMentionedWithQuery(MentionedGraphQLQuery query) throws WWException
query
- MentionedGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic MentionedContainer getMentionedContainerWithQuery(MentionedGraphQLQuery query) throws WWException
query
- MentionedGraphQLQuery containing query parametersWWException
- containing an error message, if the request was unsuccessfulpublic MessageResponse postMessageToSpace(AppMessage message, String spaceId) throws WWException
message
- Application Message (use AppMessageBuilder) to postspaceId
- ID of the Space, where the message should be postedWWException
- contains an error message, if the post was unsuccessfulpublic FileResponse postFileToSpace(File file, String spaceId) throws WWException
file
- to post into the WorkspacespaceId
- String id of the space to post toWWException
- containing an error message, if the request was unsuccessfulpublic FileResponse postFileToSpace(File file, String spaceId, String imageSize) throws WWException
file
- to post into the WorkspacespaceId
- String id of the space to post toimageSize
- image size as height x width, e.g. 200x200. Only blank or null
values are current supportedWWException
- containing an error message, if the request was unsuccessfulpublic PhotoResponse postPhoto(File photo) throws WWException
photo
- File containing a jpeg to post. Should be less than 300KbWWException
- contains an error message, if the query was unsuccessfulpublic GraphResultContainer getCustomQuery(BaseGraphQLQuery query) throws WWException
query
- BaseGraphQLQuery custom query to runWWException
- contains an error message, if the query was unsuccessfulpublic List<Focus> postTextForFocusAnalysis(String text) throws WWException
text
- String text for Watson Work Services to analyseWWException
- containing an error message, if the request was unsuccessfulpublic String getResultContent()
IWWClient
getResultContent
in interface IWWClient
public void setResultContent(String resultContent)
IWWClient
setResultContent
in interface IWWClient
resultContent
- result content (data / errors) as JSON StringCopyright © 2018 OpenNTF. All rights reserved.