Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion src/main/java/com/coveo/pushapiclient/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Document {
* <p>
* See https://docs.coveo.com/en/107 for more information.
*/
public DocumentPermissions permissions;
public DocumentPermissions[] permissions;
Copy link
Contributor

Choose a reason for hiding this comment

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

final

Copy link
Member Author

Choose a reason for hiding this comment

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

Will be modified after creation in this case (when adding denied and allowed permissions with documentbuilder)

Copy link
Member Author

Choose a reason for hiding this comment

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

(this comment applies to the whole Document class, it it meant to be modified after creation with DocumentBuilder )

/**
* The file extension of the data you're pushing.
* <p>
Expand All @@ -101,5 +101,9 @@ public class Document {
* Example: `.html`
*/
public String fileExtension;

public Document() {
this.permissions = new DocumentPermissions[]{new DocumentPermissions()};
}
}

4 changes: 4 additions & 0 deletions src/main/java/com/coveo/pushapiclient/DocumentBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public DocumentBuilder(String uri, String title) {
this.document.title = title;
}

public Document getDocument() {
return this.document;
}

public DocumentBuilder withData(String data) {
this.document.data = data;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class DocumentPermissions {
/**
* Whether to allow anonymous users in this permission set.
*
* Default value is false.
*/
public boolean allowAnonymous;
Expand All @@ -15,4 +14,10 @@ public class DocumentPermissions {
* The list of denied permissions for this permission set.
*/
public SecurityIdentity[] deniedPermissions;
}

public DocumentPermissions() {
this.allowAnonymous = true;
this.allowedPermissions = new SecurityIdentity[]{};
this.deniedPermissions = new SecurityIdentity[]{};
}
}
13 changes: 11 additions & 2 deletions src/main/java/com/coveo/pushapiclient/PlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,17 @@ public HttpResponse<String> manageSecurityIdentities(String securityProviderId,
return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
}

public void pushDocument(String sourceId, Document doc) {
// TODO
public HttpResponse<String> pushDocument(String sourceId, String documentJSON, String documentId) throws IOException, InterruptedException {
String[] headers = this.getHeaders(this.getAuthorizationHeader(), this.getContentTypeApplicationJSONHeader());
URI uri = URI.create(this.getBasePushURL() + String.format("/sources/%s/documents?documentId=%s", sourceId, documentId));

HttpRequest request = HttpRequest.newBuilder()
.headers(headers)
.PUT(HttpRequest.BodyPublishers.ofString(documentJSON))
.uri(uri)
.build();

return this.httpClient.send(request, HttpResponse.BodyHandlers.ofString());
}

public void deleteDocument(String sourceId, String documentId, Boolean deleteChildren) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/coveo/pushapiclient/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public HttpResponse<String> deleteOldSecurityIdentities(String securityProviderI
public HttpResponse<String> manageSecurityIdentities(String securityProviderId, SecurityIdentityBatchConfig batchConfig) throws IOException, InterruptedException {
return this.platformClient.manageSecurityIdentities(securityProviderId, batchConfig);
}

public HttpResponse<String> addOrUpdateDocument(String sourceId, DocumentBuilder docBuilder) throws IOException, InterruptedException {
return this.platformClient.pushDocument(sourceId, docBuilder.marshal(), docBuilder.getDocument().uri);
}
}
18 changes: 16 additions & 2 deletions src/main/java/com/coveo/testlocally/TestingLocally.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TestingLocally {
public static void main(String[] args) {
Dotenv dotenv = Dotenv.load();

DocumentBuilder doc = new DocumentBuilder("https://perdu.com", "the title").withData("this is searchable").withDate(new Date());

Source source = new Source(dotenv.get("API_KEY"), dotenv.get("ORG_ID"));
try {
HttpResponse res = source.create("testlocaljava", SourceVisibility.SECURED);
Expand All @@ -22,7 +22,22 @@ public static void main(String[] args) {
e.printStackTrace();
}

testManageIdentities(source);
testPushDocument(dotenv.get("SOURCE_ID"), source);
}

public static void testPushDocument(String sourceId, Source source) {
DocumentBuilder doc = new DocumentBuilder("https://perdu.com", "the title").withData("this is searchable").withDate(new Date());
System.out.println(doc.marshal());
try {
source.addOrUpdateDocument(sourceId, doc);
} catch (IOException | InterruptedException e) {
System.out.println(e);
}

}

public static void testManageIdentities(Source source) {
IdentityModel identityModel = new IdentityModel("the_name", SecurityIdentityType.USER, new HashMap() {
});

Expand All @@ -31,7 +46,6 @@ public static void main(String[] args) {
};

AliasMapping[] aliasMapping = {new AliasMapping("the_provider_name", "the_name", SecurityIdentityType.USER, new HashMap<>())};

try {
SecurityIdentityModel securityIdentityModel = new SecurityIdentityModel(identityModels, identityModel, identityModels);
String jsonSecurityIdentityModel = new Gson().toJson(securityIdentityModel);
Expand Down