Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
11 changes: 5 additions & 6 deletions src/main/java/com/coveo/pushapiclient/CatalogSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.http.HttpResponse;

// TODO: LENS-851 - Make public when ready
class CatalogSource implements StreamEnabledSource {
Expand All @@ -11,19 +12,17 @@ class CatalogSource implements StreamEnabledSource {


/**
* Creates a Catalog Source in Coveo Org
* Creates a <a href='https://docs.coveo.com/en/3295/index-content/add-or-edit-a-catalog-source'>Catalog Source</a> in Coveo Org
*
* @param platformUrl
* @param organizationId
* @param apiKey
* @param platformClient
* @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);
public static HttpResponse<String> create(PlatformClient platformClient, String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
return platformClient.createSource(name, SourceType.CATALOG, sourceVisibility);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/coveo/pushapiclient/PlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,18 @@ public PlatformClient(String apiKey, String organizationId, Environment environm
*
* @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, final String sourceType, final boolean isPushEnabled, final boolean isStreamEnabled, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
public HttpResponse<String> createSource(String name, final SourceType sourceType, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());

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

/**
* Creates a push Source in Coveo Org
* Creates a <a href="https://docs.coveo.com/en/94/index-content/create-a-push-source">push Source </a> in Coveo Org
*
* @param platformUrl
* @param organizationId
* @param apiKey
* @param platformClient
* @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);
public static HttpResponse<String> create(PlatformClient platformClient, String name, SourceVisibility sourceVisibility) throws IOException, InterruptedException {
return platformClient.createSource(name, SourceType.PUSH, sourceVisibility);
}

/**
Expand Down
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, SourceType.PUSH.name(), true, false, sourceVisibility);
return this.platformClient.createSource(name, SourceType.PUSH, sourceVisibility);
}

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

public enum SourceType {
PUSH,
CATALOG,
public enum SourceType implements SourceTypeInterface{
PUSH{
public String toString() {
return "PUSH";
}
public boolean isPushEnabled(){ return true;}

@Override
public boolean isStreamEnabled() {
return false;
}

},
CATALOG{
public String toString() {
return "CATALOG";
}

@Override
public boolean isPushEnabled() {
return true;
}

@Override
public boolean isStreamEnabled() {
return true;
}
},
}

interface SourceTypeInterface {

String toString();
boolean isPushEnabled();
boolean isStreamEnabled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void setupClient() {

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

assertEquals("POST", argument.getValue().method());
Expand All @@ -126,7 +126,7 @@ public void testCreatePushSource() throws IOException, InterruptedException {

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

assertEquals("POST", argument.getValue().method());
Expand Down