Skip to content
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

feat(conversations): add conversation and model management APIs #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ dependencies {
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
useJUnitPlatform {
if (System.getenv('CI')) {
excludeTags 'excludeFromCI'
}
}
}

swaggerSources {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/typesense/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Client {
private Stopwords stopwords;
private Map<String, StopwordsSet> individualStopwordsSets;

private Conversations conversations;
private Map<String, Conversation> individualConversations;

public Health health;
public Operations operations;
public Metrics metrics;
Expand All @@ -47,6 +50,8 @@ public Client(Configuration configuration){
this.analytics = new Analytics(this.apiCall);
this.stopwords = new Stopwords(this.apiCall);
this.individualStopwordsSets = new HashMap<>();
this.conversations = new Conversations(this.apiCall);
this.individualConversations = new HashMap<>();
}

public Collection collections(String name){
Expand Down Expand Up @@ -114,4 +119,19 @@ public StopwordsSet stopwords(String stopwordsSetId) {
retVal = this.individualStopwordsSets.get(stopwordsSetId);
return retVal;
}

public Conversation conversations(String id) {
Conversation retVal;

if (!this.individualConversations.containsKey(id)) {
this.individualConversations.put(id, new Conversation(id, this.apiCall));
}

retVal = this.individualConversations.get(id);
return retVal;
}

public Conversations conversations() {
return this.conversations;
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/typesense/api/Conversation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

package org.typesense.api;

import org.typesense.api.utils.URLEncoding;
import org.typesense.interfaces.ConversationDeleteSchema;
import org.typesense.interfaces.ConversationSchema;
import org.typesense.model.CollectionUpdateSchema;

public class Conversation {
private final ApiCall apiCall;
private final String conversationId;

public Conversation(String conversationId, ApiCall apiCall) {
this.apiCall = apiCall;
this.conversationId = conversationId;
}


public ConversationSchema retrieve() throws Exception {
return this.apiCall.get(this.getEndpoint(), null, ConversationSchema.class);
}

public ConversationDeleteSchema delete() throws Exception {
return this.apiCall.delete(this.getEndpoint(), null, ConversationDeleteSchema.class);
}

public CollectionUpdateSchema update(CollectionUpdateSchema schema) throws Exception {
return this.apiCall.put(this.getEndpoint(), schema, null, CollectionUpdateSchema.class);
}

private String getEndpoint() {
return Conversations.RESOURCE_PATH + "/" + URLEncoding.encodeURIComponent(conversationId);
}

}
34 changes: 34 additions & 0 deletions src/main/java/org/typesense/api/ConversationModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

package org.typesense.api;

import org.typesense.api.utils.URLEncoding;
import org.typesense.model.ConversationModelSchema;
import org.typesense.model.ConversationModelUpdateSchema;

public class ConversationModel {

private final ApiCall apiCall;
private final String id;

public ConversationModel(ApiCall apiCall, String id) {
this.apiCall = apiCall;
this.id = id;
}

public ConversationModelUpdateSchema update(ConversationModelUpdateSchema schema) throws Exception {
return this.apiCall.put(this.getEndpoint(), schema, null, ConversationModelUpdateSchema.class);
}

public ConversationModelSchema retrieve() throws Exception {
return this.apiCall.get(this.getEndpoint(), null, ConversationModelSchema.class);
}

public ConversationModelSchema delete() throws Exception {
return this.apiCall.delete(this.getEndpoint(), null, ConversationModelSchema.class);
}

private String getEndpoint() {
return ConversationModels.RESOURCE_PATH + "/" + URLEncoding.encodeURIComponent(this.id);
}

}
23 changes: 23 additions & 0 deletions src/main/java/org/typesense/api/ConversationModels.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.typesense.api;

import org.typesense.model.ConversationModelCreateSchema;
import org.typesense.model.ConversationModelSchema;

public class ConversationModels {

private final ApiCall apiCall;
public final static String RESOURCE_PATH = "/conversations/models";

public ConversationModels(ApiCall apiCall) {
this.apiCall = apiCall;
}

public ConversationModelCreateSchema create(ConversationModelCreateSchema schema) throws Exception {
return this.apiCall.post(RESOURCE_PATH, schema, null, ConversationModelCreateSchema.class);
}

public ConversationModelSchema[] retrieve() throws Exception {
return this.apiCall.get(RESOURCE_PATH, null, ConversationModelSchema[].class);
}

}
40 changes: 40 additions & 0 deletions src/main/java/org/typesense/api/Conversations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.typesense.api;

import java.util.HashMap;
import java.util.Map;

import org.typesense.interfaces.ConversationsRetrieveSchema;

public class Conversations {

private final ApiCall apiCall;
public final static String RESOURCE_PATH = "/conversations";

private final ConversationModels conversationModels;
private final Map<String, ConversationModel> individualConversations;

public Conversations(ApiCall apiCall) {
this.apiCall = apiCall;
this.conversationModels = new ConversationModels(this.apiCall);
this.individualConversations = new HashMap<>();
}

public ConversationsRetrieveSchema retrieve() throws Exception {
return this.apiCall.get(Conversations.RESOURCE_PATH, null, ConversationsRetrieveSchema.class);
}

public ConversationModels models() {
return this.conversationModels;
}

public ConversationModel models(String conversationId) {
ConversationModel retVal;

if (!this.individualConversations.containsKey(conversationId)) {
this.individualConversations.put(conversationId, new ConversationModel(apiCall, conversationId));
}

retVal = this.individualConversations.get(conversationId);
return retVal;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.typesense.interfaces;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.v3.oas.annotations.media.Schema;

public class ConversationDeleteSchema {
@JsonProperty("id")
private Long id = null;

public ConversationDeleteSchema id(Long id) {
this.id = id;
return this;
}

/**
* The ID of the conversation to delete
* @return id
**/
@Schema(required = true, description = "The ID of the conversation to delete")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Override
public boolean equals(java.lang.Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConversationDeleteSchema that = (ConversationDeleteSchema) o;
return Objects.equals(this.id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ConversationDeleteSchema {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append("}");
return sb.toString();
}

private String toIndentedString(java.lang.Object o) {
if (o == null) return "null";
return o.toString().replace("\n", "\n ");
}
}
128 changes: 128 additions & 0 deletions src/main/java/org/typesense/interfaces/ConversationSchema.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package org.typesense.interfaces;


import java.util.Arrays;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.v3.oas.annotations.media.Schema;

public class ConversationSchema {
@JsonProperty("id")
private Long id = null;

@JsonProperty("conversation")
private Object[] conversation = null;

@JsonProperty("last_updated")
private Long lastUpdated = null;

@JsonProperty("ttl")
private Long ttl = null;

public ConversationSchema id(Long id) {
this.id = id;
return this;
}

/**
* The unique identifier of the conversation
* @return id
**/
@Schema(required = true, description = "The unique identifier of the conversation")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public ConversationSchema conversation(Object[] conversation) {
this.conversation = conversation;
return this;
}

/**
* Array of conversation objects
* @return conversation
**/
@Schema(required = true, description = "Array of conversation objects")
public Object[] getConversation() {
return conversation;
}

public void setConversation(Object[] conversation) {
this.conversation = conversation;
}

public ConversationSchema lastUpdated(Long lastUpdated) {
this.lastUpdated = lastUpdated;
return this;
}

/**
* Timestamp of when the conversation was last updated
* @return lastUpdated
**/
@Schema(required = true, description = "Timestamp of when the conversation was last updated")
public Long getLastUpdated() {
return lastUpdated;
}

public void setLastUpdated(Long lastUpdated) {
this.lastUpdated = lastUpdated;
}

public ConversationSchema ttl(Long ttl) {
this.ttl = ttl;
return this;
}

/**
* Time to live for the conversation in seconds
* @return ttl
**/
@Schema(required = true, description = "Time to live for the conversation in seconds")
public Long getTtl() {
return ttl;
}

public void setTtl(Long ttl) {
this.ttl = ttl;
}

@Override
public boolean equals(java.lang.Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConversationSchema that = (ConversationSchema) o;
return Objects.equals(this.id, that.id) &&
Arrays.equals(this.conversation, that.conversation) &&
Objects.equals(this.lastUpdated, that.lastUpdated) &&
Objects.equals(this.ttl, that.ttl);
}

@Override
public int hashCode() {
return Objects.hash(id, Arrays.hashCode(conversation), lastUpdated, ttl);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ConversationSchema {\n");
sb.append(" id: ").append(toIndentedString(id)).append("\n");
sb.append(" conversation: ").append(toIndentedString(Arrays.toString(conversation))).append("\n");
sb.append(" lastUpdated: ").append(toIndentedString(lastUpdated)).append("\n");
sb.append(" ttl: ").append(toIndentedString(ttl)).append("\n");
sb.append("}");
return sb.toString();
}

private String toIndentedString(java.lang.Object o) {
if (o == null) return "null";
return o.toString().replace("\n", "\n ");
}
}
Loading