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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>org.example</groupId>
<artifactId>push-api-client.java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.10</version>
</dependency>
</dependencies>

<properties>
<maven.compiler.source>16</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/coveo/pushapiclient/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Document {
* <p>
* See https://docs.coveo.com/en/115 for more information.
*/
public Map<String, String> metadata;
public Map<String, Object> metadata;
/**
* The list of permission sets for this item.
* <p>
Expand Down
155 changes: 155 additions & 0 deletions src/main/java/com/coveo/pushapiclient/DocumentBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.coveo.pushapiclient;

import com.google.gson.Gson;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;

import java.util.Date;
import java.util.Map;

public class DocumentBuilder {
private Document document;

public DocumentBuilder(String uri, String title) {
this.document = new Document();
this.document.uri = uri;
this.document.title = title;
}

public DocumentBuilder withData(String data) {
this.document.data = data;
return this;
}

public DocumentBuilder withDate(String date) {
DateTime dt = DateTime.parse(date);
this.document.date = this.dateFormat(dt);
return this;
}

public DocumentBuilder withDate(Long date) {
DateTime dt = new DateTime(date);
this.document.date = this.dateFormat(dt);
return this;
}

public DocumentBuilder withDate(Date date) {
DateTime dt = new DateTime(date);
this.document.date = this.dateFormat(dt);
return this;
}

public DocumentBuilder withDate(DateTime date) {
this.document.date = this.dateFormat(date);
return this;
}

public DocumentBuilder withModifiedDate(String date) {
DateTime dt = DateTime.parse(date);
this.document.modifiedDate = this.dateFormat(dt);
return this;
}

public DocumentBuilder withModifiedDate(Long date) {
DateTime dt = new DateTime(date);
this.document.modifiedDate = this.dateFormat(dt);
return this;
}

public DocumentBuilder withModifiedDate(DateTime date) {
this.document.modifiedDate = this.dateFormat(date);
return this;
}

public DocumentBuilder withPermanentId(String permanentId) {
this.document.permanentId = permanentId;
return this;
}

public DocumentBuilder withCompressedBinaryData(CompressedBinaryData compressedBinaryData) {
this.validateCompressedBinaryData(compressedBinaryData.data);
this.document.compressedBinaryData = compressedBinaryData;
return this;
}

public DocumentBuilder withFileExtension(String fileExtension) {
this.validateFileExtension(fileExtension);
this.document.fileExtension = fileExtension;
return this;
}

public DocumentBuilder withParentID(String parentID) {
this.document.parentId = parentID;
return this;
}

public DocumentBuilder withClickableUri(String clickableUri) {
this.document.clickableUri = clickableUri;
return this;
}

public DocumentBuilder withAuthor(String author) {
this.document.author = author;
return this;
}

public DocumentBuilder withMetadataValue(String key, String metadataValue) {
this.setMetadataValue(key, metadataValue);
return this;
}

public DocumentBuilder withMetadataValue(String key, String[] metadataValue) {
this.setMetadataValue(key, metadataValue);
return this;
}

public DocumentBuilder withMetadataValue(String key, Integer metadataValue) {
this.setMetadataValue(key, metadataValue);
return this;
}

public DocumentBuilder withMetadataValue(String key, Integer[] metadataValue) {
this.setMetadataValue(key, metadataValue);
return this;
}

public DocumentBuilder withMetadata(Map<String, Object> metadata) {
metadata.forEach(this::setMetadataValue);
return this;
}

public DocumentBuilder withAllowedPermissions() {
// TODO
return this;
}

public DocumentBuilder withDeniedPermissions() {
// TODO
return this;
}

public String marshal() {
return new Gson().toJson(this.document);
}

private String dateFormat(DateTime dt) {
return dt.toString(ISODateTimeFormat.dateTime());
}

private void setMetadataValue(String key, Object metadataValue) {
this.validateReservedMetadataKeyNames(key);
this.document.metadata.put(key, metadataValue);
}

private void validateCompressedBinaryData(String data) {
// TODO
}

private void validateFileExtension(String fileExtension) {
// TODO
}

private void validateReservedMetadataKeyNames(String key) {
// TODO
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/coveo/testlocally/TestingLocally.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coveo.testlocally;

import com.coveo.pushapiclient.DocumentBuilder;

import java.util.Date;

public class TestingLocally {
public static void main(String[] args) {
DocumentBuilder doc = new DocumentBuilder("https://perdu.com", "the title").withData("this is searchable").withDate(new Date());
System.out.println(doc.marshal());
}
}