Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/com/coveo/pushapiclient/CatalogSource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coveo.pushapiclient;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

Expand All @@ -8,6 +9,23 @@ class CatalogSource implements StreamEnabledSource {
private final String apiKey;
private final ApiUrl urlExtractor;


/**
* Creates a Catalog Source in Coveo Org
*
* @param platformUrl
* @param organizationId
* @param apiKey
* @param name
* @param sourceVisibility
* @return
* @throws IOException
* @throws InterruptedException
*/
public static void create(PlatformUrl platformUrl, String organizationId, String apiKey, String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
new PlatformClient(apiKey,organizationId,platformUrl).createSource(name, SourceType.CATALOG.name(), true, true, sourceVisibility);
}

/**
* Create a Catalog source instance from its
* <a href="https://docs.coveo.com/en/3295#stream-api-url">Stream API URL</a>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/coveo/pushapiclient/PlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@ public PlatformClient(String apiKey, String organizationId, Environment environm
* Create a new push source
*
* @param name The name of the source to create
* @param sourceType
* @param isPushEnabled
* @param isStreamEnabled
* @param sourceVisibility The security option that should be applied to the content of the source. See [Content Security](https://docs.coveo.com/en/1779).
* @return
* @throws IOException
* @throws InterruptedException
*/
public HttpResponse<String> createSource(String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
public HttpResponse<String> createSource(String name, final String sourceType, final boolean isPushEnabled, final boolean isStreamEnabled, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());

String json = this.toJSON(new HashMap<>() {{
put("sourceType", "PUSH");
put("pushEnabled", true);
put("sourceType", sourceType);
put("pushEnabled", isPushEnabled);
put("streamEnabled", isStreamEnabled);
put("name", name);
put("sourceVisibility", sourceVisibility);
}});
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/coveo/pushapiclient/PushSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ public String getApiKey() {
return this.apiKey;
}

/**
* Creates a push Source in Coveo Org
*
* @param platformUrl
* @param organizationId
* @param apiKey
* @param name
* @param sourceVisibility
* @return
* @throws IOException
* @throws InterruptedException
*/
public static void create(PlatformUrl platformUrl, String organizationId, String apiKey, String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
new PlatformClient(apiKey,organizationId,platformUrl).createSource(name, SourceType.PUSH.name(), true, false, sourceVisibility);
}

/**
* Create a Push source instance from its
* <a href="https://docs.coveo.com/en/1546#push-api-url">Push API URL</a>
Expand Down Expand Up @@ -311,4 +327,5 @@ public HttpResponse<String> deleteDocument(String documentId, Boolean deleteChil
return this.platformClient.deleteDocument(this.getId(), documentId, deleteChildren);
}


}
2 changes: 1 addition & 1 deletion src/main/java/com/coveo/pushapiclient/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Source(String apiKey, String organizationId, Environment environment) {
* @throws InterruptedException
*/
public HttpResponse<String> create(String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
return this.platformClient.createSource(name, sourceVisibility);
return this.platformClient.createSource(name, SourceType.PUSH.name(), true, false, sourceVisibility);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/coveo/pushapiclient/SourceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.coveo.pushapiclient;

public enum SourceType {
PUSH,
CATALOG,
}
22 changes: 20 additions & 2 deletions src/test/java/com/coveo/pushapiclient/PlatformClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void setupClient() {
}

@Test
public void testCreateSource() throws IOException, InterruptedException {
client.createSource("the_name", SourceVisibility.SECURED);
public void testCreatePushSource() throws IOException, InterruptedException {
client.createSource("the_name", SourceType.PUSH.name(), true, false, SourceVisibility.SECURED);
verify(httpClient).send(argument.capture(), any(HttpResponse.BodyHandlers.ofString().getClass()));

assertEquals("POST", argument.getValue().method());
Expand All @@ -124,6 +124,24 @@ public void testCreateSource() throws IOException, InterruptedException {
assertEquals(true, requestBody.get("pushEnabled"));
}

@Test
public void testCreateCatalogSource() throws IOException, InterruptedException {
client.createSource("the_name", SourceType.CATALOG.name(), true, true, SourceVisibility.SECURED);
verify(httpClient).send(argument.capture(), any(HttpResponse.BodyHandlers.ofString().getClass()));

assertEquals("POST", argument.getValue().method());
assertTrue(argument.getValue().uri().getPath().contains("the_org_id/sources"));
assertAuthorizationHeader();
assertApplicationJsonHeader();

Map requestBody = StringSubscriber.toMap(argument.getValue().bodyPublisher());
assertEquals("the_name", requestBody.get("name"));
assertEquals(SourceVisibility.SECURED.toString(), requestBody.get("sourceVisibility"));
assertEquals("CATALOG", requestBody.get("sourceType"));
assertEquals(true, requestBody.get("pushEnabled"));
assertEquals(true, requestBody.get("streamEnabled"));
}

@Test
public void testCreateOrUpdateSecurityIdentity() throws IOException, InterruptedException {
client.createOrUpdateSecurityIdentity("my_provider", securityIdentityModel());
Expand Down