Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-2908: Fluent API setup #205

Merged
merged 9 commits into from
Sep 11, 2020
Merged

Conversation

symphony-hong
Copy link
Contributor

@symphony-hong symphony-hong commented Sep 9, 2020

I will fully implement with all service after StreamService is reviewed. (unittest and doc as well)**

Create ServiceFactory class for providing services to SymphonyBdk entry point.

Simplify code in SymphonyBdk

Experimental: First implementing OBO call on StreamService.

User can do an OBO authentication by calling SymphonyBdk#obo(Obo.Handle). This method will return an AuthSession which is an obo session.

OboStreamService contains only OBO-enabled stream apis. User will do the OBO authentication out of scope of SymphonyBdk, then will pass the AuthSession which is returned by the previous step to the method to perform the call with oboSession.

Added unittest and documentation

Create ServiceFactory class for providing services to SymphonyBdk entry point.

Simplify code in SymphonyBdk

Experimental: First implementing OBO call on StreamService.

User can do an OBO authentication by calling SymphonyBdk#obo(Obo.Handle). This method will return an AuthSession which is an obo session.

OboStreamService contains only OBO-enabled stream apis. User will do the OBO authentication out of scope of SymphonyBdk, then will pass the AuthSession which is returned by the previous step to the method to perform the call with oboSession.

AuthSession oboSession = bdk.obo(Obo.username("hong.le"));
StreamFilter streamFilter = new StreamFilter().addStreamTypesItem(new StreamType().type(StreamType.TypeEnum.IM));
List<StreamAttributes> streamsList = bdk.streams().listStreams(streamFilter, oboSession);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would we handle session expiration here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the session expiration, the API call returns error 401, in this case, we will refresh the session by calling AuthSession#refresh


class ServiceFactory {

private final UserService userService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this class should contain single instance for each service? Is it really a factory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's not really a factory. I want to decouple the service stuff in SymphonyBdk to a dedicated class. The instance of each class is initialized at the constructor given an AuthSession. And I think for one AuthSession, we should only one instance of each service.
Maybe I should rename this class?

Copy link
Member

@thibauult thibauult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you removed Obo.java class? If not used anymore obviously

@symphony-hong
Copy link
Contributor Author

Have you removed Obo.java class? If not used anymore obviously

It will be removed 👍

Create OboUserService for calling user service methods using OBO Session

Remove methods wrapping the deprecated user service API

Remove redundant OBO class

AuthSession oboSession = bdk.obo("hong.le");
StreamFilter streamFilter = new StreamFilter().addStreamTypesItem(new StreamType().type(StreamType.TypeEnum.IM));
List<StreamAttributes> streamsList = bdk.streams().listStreams(oboSession, streamFilter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://perzoinc.atlassian.net/browse/APP-2908, we wanted to have something like :
bdk.messages(Obo.username("user.name")).send(STREAM, MESSAGE); or bdk.streams(Obo.username("user.name")).listStreams(streamFilter);
Why changing it to bdk.streams().listStreams(oboSession, streamFilter) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't want to initialize a new service instance each time we pass an Obo to bdk#messages, it will cause an memory issue if we call it a lot of times. (For ex: if we want to call an api OBO for 1000 thousands user, we have to instantiate 1000 message service instances)

* @return The information about the stream with the given id.
* @see <a href="https://developers.symphony.com/restapi/reference#stream-info-v2">Stream Info V2</a>
*/
public V2StreamAttributes getStreamInfo(AuthSession oboSession, String streamId) {
Copy link
Contributor

@symphony-elias symphony-elias Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this is misleading as oboSession can actually be a bot session. authSession could be a better option along with a comment in the javadoc saying it can be a bot or obo session.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will rename it.
(But IMHO, the bot session is actually the obo session that the bot do a call on behalf of itself 😄 )


import java.util.List;

class OboStreamService {
Copy link
Contributor

@symphony-elias symphony-elias Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO name is misleading as theses services are not limited to OBO.

Copy link
Contributor Author

@symphony-hong symphony-hong Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea behind this class is that me and @symphony-thibault want two layers for one service, the first one is at the Obo level which contains only OBO methods and the second one contains all the methods.

@symphony-hong symphony-hong marked this pull request as ready for review September 11, 2020 12:01
@symphony-hong symphony-hong requested a review from a team September 11, 2020 12:01
Copy link
Contributor

@symphony-elias symphony-elias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

docs/fluent.md Outdated
@@ -0,0 +1,70 @@
# Fluent API

The Fluent API is the most basic component of the BDK. This component provides the developers very quickly an entry point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the Fluent API is a "component"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I call it "feature"?

docs/fluent.md Outdated Show resolved Hide resolved
docs/fluent.md Outdated Show resolved Hide resolved
docs/fluent.md Outdated

public static void main(String[] args) {
//Init the BDK entry point
final SymphonyBdk bdk = new SymphonyBdk(loadFromSymphonyDir("config.yaml"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to haveloadFromClasspath("/config.yaml") in doc examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs/fluent.md Outdated Show resolved Hide resolved
docs/fluent.md Outdated Show resolved Hide resolved
Copy link
Member

@thibauult thibauult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@symphony-hong symphony-hong merged commit ff54008 into finos:master Sep 11, 2020
@symphony-hong symphony-hong deleted the APP-2908 branch October 12, 2020 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants