-
Notifications
You must be signed in to change notification settings - Fork 5
feat: implement PushService class
#34
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
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e0296ef
create `PushSource` and `catalogSource` classes
y-lakhdar 419d177
add boilerplate for stream service
y-lakhdar 4e8528c
Merge branch 'main' of github.com:coveo/push-api-client.java into LEN…
y-lakhdar 1c5adec
revert master merge
y-lakhdar f5a2557
add required POST calls
y-lakhdar 673b76a
update streamService
y-lakhdar 5ef6772
apply ApiUrl corrections
y-lakhdar 93c9867
Merge branch 'LEN-839' of github.com:coveo/push-api-client.java into …
y-lakhdar 8e1e3e7
document StreamService
y-lakhdar de36933
Merge branch 'main' of github.com:coveo/push-api-client.java into LEN…
y-lakhdar 7f9ad5e
Update src/main/java/com/coveo/pushapiclient/StreamService.java
y-lakhdar 3499404
Update src/main/java/com/coveo/pushapiclient/StreamService.java
y-lakhdar f3ec845
Apply suggestions from code review
y-lakhdar 508564e
refactor unit tests
y-lakhdar 954ad44
Merge branch 'LEN-838' of github.com:coveo/push-api-client.java into …
y-lakhdar 0e9acac
Merge branch 'main' into LEN-838
y-lakhdar b121952
create batch update accumulator
y-lakhdar 476a09d
rework queue
y-lakhdar 141889d
complete unit tests
y-lakhdar aa68240
remove comments
y-lakhdar 369525a
update comment
y-lakhdar 7d5dc2c
draft PushService
y-lakhdar c90446c
apply corrections
y-lakhdar cd43eb9
Merge branch 'LEN-838' of github.com:coveo/push-api-client.java into …
y-lakhdar 9a7c88b
Merge branch 'LEN-838' of github.com:coveo/push-api-client.java into …
y-lakhdar cad5aac
add gitignore
y-lakhdar bd5ab59
Merge branch 'LENS-856' of github.com:coveo/push-api-client.java into…
y-lakhdar 0b5baa1
fix merge conflict
y-lakhdar ce594de
Merge branch 'LENS-856' of github.com:coveo/push-api-client.java into…
y-lakhdar 40a73dd
add unit tests
y-lakhdar b5bbee0
Apply suggestions from code review
y-lakhdar 4d6ff14
Merge branch 'main' of github.com:coveo/push-api-client.java into LEN…
y-lakhdar 018998b
Merge branch 'LENS-837' of github.com:coveo/push-api-client.java into…
y-lakhdar e429d3e
applying corrections
y-lakhdar d50d170
Merge branch 'main' into LENS-837
y-lakhdar cce0ca3
Merge branch 'main' into LENS-837
y-lakhdar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.http.HttpResponse; | ||
|
|
||
| import com.google.gson.Gson; | ||
|
|
||
| public class PushService { | ||
| private final PushEnabledSource source; | ||
| private final PlatformClient platformClient; | ||
| private PushServiceInternal service; | ||
|
|
||
| public PushService(PushEnabledSource source) { | ||
| String apiKey = source.getApiKey(); | ||
| String organizationId = source.getOrganizationId(); | ||
| PlatformUrl platformUrl = source.getPlatformUrl(); | ||
| UploadStrategy uploader = this.getUploadStrategy(); | ||
| DocumentUploadQueue queue = new DocumentUploadQueue(uploader); | ||
|
|
||
| this.platformClient = new PlatformClient(apiKey, organizationId, platformUrl); | ||
| this.service = new PushServiceInternal(queue); | ||
| this.source = source; | ||
| } | ||
|
|
||
| public void addOrUpdate(DocumentBuilder document) throws IOException, InterruptedException { | ||
| // TODO: LENS-843: include partial document updates | ||
| this.service.addOrUpdate(document); | ||
| } | ||
|
|
||
| public void delete(DeleteDocument document) throws IOException, InterruptedException { | ||
| this.service.delete(document); | ||
| } | ||
|
|
||
| public void close() throws IOException, InterruptedException { | ||
| this.service.close(); | ||
| } | ||
|
|
||
| private UploadStrategy getUploadStrategy() { | ||
| return (batchUpdate) -> { | ||
| String sourceId = this.getSourceId(); | ||
| HttpResponse<String> resFileContainer = this.platformClient.createFileContainer(); | ||
| FileContainer fileContainer = new Gson().fromJson(resFileContainer.body(), FileContainer.class); | ||
| this.platformClient.uploadContentToFileContainer(fileContainer, new Gson().toJson(batchUpdate.marshal())); | ||
| return this.platformClient.pushFileContainerContent(sourceId, fileContainer); | ||
| }; | ||
| } | ||
|
|
||
| private String getSourceId() { | ||
| return this.source.getId(); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/coveo/pushapiclient/PushServiceInternal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class PushServiceInternal { | ||
| private DocumentUploadQueue queue; | ||
|
|
||
| public PushServiceInternal(DocumentUploadQueue queue) { | ||
| this.queue = queue; | ||
| } | ||
|
|
||
| public void addOrUpdate(DocumentBuilder document) throws IOException, InterruptedException { | ||
| this.queue.add(document); | ||
| } | ||
|
|
||
| public void delete(DeleteDocument document) throws IOException, InterruptedException { | ||
| this.queue.add(document); | ||
| } | ||
|
|
||
| public void close() throws IOException, InterruptedException { | ||
| queue.flush(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/test/java/com/coveo/pushapiclient/PushServiceInternalTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.coveo.pushapiclient; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| import com.coveo.pushapiclient.exceptions.NoOpenStreamException; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.http.HttpResponse; | ||
|
|
||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| public class PushServiceInternalTest { | ||
| @Mock | ||
| private DocumentUploadQueue queue; | ||
|
|
||
| @InjectMocks | ||
| private PushServiceInternal service; | ||
|
|
||
| @Mock | ||
| private HttpResponse<String> httpResponse; | ||
|
|
||
| private AutoCloseable closeable; | ||
| private DocumentBuilder documentA; | ||
| private DocumentBuilder documentB; | ||
| private DeleteDocument documentC; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| documentA = new DocumentBuilder("https://my.document.uri?ref=1", "My first document title"); | ||
| documentB = new DocumentBuilder("https://my.document.uri?ref=2", "My second document title"); | ||
| documentC = new DeleteDocument("https://my.document.uri?ref=3"); | ||
|
|
||
| closeable = MockitoAnnotations.openMocks(this); | ||
|
|
||
| } | ||
|
|
||
| @After | ||
| public void closeService() throws Exception { | ||
| closeable.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testShouldAddNewDocumentToQueue() throws IOException, InterruptedException { | ||
| service.addOrUpdate(documentA); | ||
| service.addOrUpdate(documentB); | ||
|
|
||
| verify(this.queue, times(1)).add(documentA); | ||
| verify(this.queue, times(1)).add(documentB); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAddShouldAddDocumentToDeleteToQueue() throws IOException, InterruptedException { | ||
| service.delete(documentC); | ||
|
|
||
| verify(queue, times(1)).add(documentC); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCloseShouldFlushBufferedDocuments() | ||
| throws IOException, InterruptedException, NoOpenStreamException { | ||
| service.addOrUpdate(documentA); | ||
| service.addOrUpdate(documentB); | ||
| service.delete(documentC); | ||
| service.close(); | ||
|
|
||
| verify(queue, times(1)).flush(); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.