Skip to content

Commit

Permalink
update javadoc and serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
clun committed Jan 23, 2024
1 parent c454a0e commit a7667da
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 60 deletions.
2 changes: 1 addition & 1 deletion stargate-sdk-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>stargate-sdk-data</artifactId>
<name>+ stargate-sdk-data</name>
<name>Client for Stargate DataAPI</name>

<parent>
<groupId>com.datastax.stargate</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import io.stargate.sdk.data.domain.ApiData;
import io.stargate.sdk.data.domain.ApiError;
import io.stargate.sdk.data.domain.ApiResponse;
import io.stargate.sdk.data.domain.DocumentMutationResult;
import io.stargate.sdk.data.domain.DocumentMutationStatus;
import io.stargate.sdk.data.domain.JsonDocument;
import io.stargate.sdk.data.domain.JsonDocumentMutationResult;
import io.stargate.sdk.data.domain.JsonDocumentResult;
import io.stargate.sdk.data.domain.JsonResultUpdate;
import io.stargate.sdk.data.domain.UpdateStatus;
Expand Down Expand Up @@ -50,7 +53,7 @@
import static io.stargate.sdk.utils.AnsiUtils.green;

/**
* Wrapper for collection operations.
* Client for a collection (crud for documents).
*/
@Slf4j
public class CollectionClient {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.stargate.sdk.data;

import io.stargate.sdk.core.domain.Page;
import io.stargate.sdk.data.domain.DocumentMutationResult;
import io.stargate.sdk.data.domain.odm.Document;
import io.stargate.sdk.data.domain.odm.DocumentResult;
import io.stargate.sdk.data.domain.query.DeleteQuery;
Expand All @@ -16,10 +17,10 @@
import java.util.stream.Stream;

/**
* Crud repository with Json Api
* Client implementing repository pattern for a collection.
*
* @param <DOC>
* current bean
* java bean representing a document
*/
@Getter
public class CollectionRepository<DOC> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static io.stargate.sdk.utils.AnsiUtils.green;

/**
* Client for the JSON Document API.
* Client core for Data API (crud for namespaces).
*/
@Slf4j
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static io.stargate.sdk.utils.AnsiUtils.green;

/**
* Work with namespace and collections.
* Client for a namespace (crud for collections).
*/
@Getter @Slf4j
public class NamespaceClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;

/**
* Payload for json api response.
* Subpart of the payload for json api response holding returned data.
*/
@Data
public class ApiData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Data;

/**
* Payload for json Api error.
* Subpart of the payload for json api response holding error information.
*/
@Data
public class ApiError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Payload for json api response.
* Represents the Api response.
*/
@Data
public class ApiResponse {

/**
* Return by everything except find*()
* Return by all operations except find*()
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
private Map<String, Object> status;

/**
* If an error ocured
* List of errors, could be one per inserted items with reason.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
private List<ApiError> errors;

/**
* Data retrieved by find*()
* Data retrieve with operations find
*/
private ApiData data;

Expand All @@ -41,7 +40,7 @@ public ApiResponse() {
}

/**
* Syntax sugar.
* Read a value as a stream from the key/value 'status' map.
*
* @param key
* key to be retrieved
Expand All @@ -57,7 +56,7 @@ public Stream<String> getStatusKeyAsStringStream(@NonNull String key) {
}

/**
* Use when attribute in status is an object.
* Read a value as a List from the key/value 'status' map.
*
* @param key
* target get
Expand All @@ -68,15 +67,15 @@ public Stream<String> getStatusKeyAsStringStream(@NonNull String key) {
* @param <T>
* type in used
*/
public <T> T getStatusKeyAsObject(@NonNull String key, Class<T> targetClass) {
public <T> T getStatusKeyAsObject(@NonNull String key, @NonNull Class<T> targetClass) {
if (status.containsKey(key)) {
return JsonUtils.convertValue(status.get(key), targetClass);
}
return null;
}

/**
* Use when attribute in status is a list.
* Read a value as a Specialized class from the key/value 'status' map.
*
* @param key
* target get
Expand All @@ -97,19 +96,7 @@ public <T> List<T> getStatusKeyAsList(@NonNull String key, Class<T> targetClass)
}

/**
* Syntax sugar.
*
* @param key
* key to be retrieved
* @return
* list of values
*/
public List<String> getStatusKeyAsList(@NonNull String key) {
return getStatusKeyAsStringStream(key).collect(Collectors.toList());
}

/**
* Syntax sugar.
* Read a value as an Integer from the key/value 'status' map.
*
* @param key
* key to be retrieved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Data;

/**
* Request to create a collection.
* Represents the Collection definition with its name and metadata.
*/
@Data
public class CollectionDefinition {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.stargate.sdk.data;
package io.stargate.sdk.data.domain;

import io.stargate.sdk.data.domain.JsonDocument;
import io.stargate.sdk.data.domain.odm.Document;
import io.stargate.sdk.utils.JsonUtils;
import lombok.Getter;
Expand All @@ -9,7 +8,7 @@
import java.util.Map;

/**
* Wrapper to get result from API with schemaless document.
* Result per document mutation working a generic Document&lt;T&gt;
*
* @param <T>
* represents the pojo for returned document
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.stargate.sdk.data;
package io.stargate.sdk.data.domain;

/**
* Each document will have a STATUS.
* Status and document mutation like <code>CREATED</code>, <code>UPDATED</code> or <code>UNCHANGED</code>...
*/
public enum DocumentMutationStatus {
/** Document Created. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


/**
* Json Api Payload.
* Represents a document without schema contraints as a Map&lt;String, Object&gt;.(key/value)
*/
public class JsonDocument extends Document<Map<String, Object>> {

Expand Down Expand Up @@ -426,5 +426,4 @@ public boolean isAttributeExist(String key) {
return data.containsKey(key);
}


}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.stargate.sdk.data;

import io.stargate.sdk.data.domain.JsonDocument;
package io.stargate.sdk.data.domain;

import java.util.Map;

/**
* Wrapper to get result from API with schemaless document
* Result per document working with a schemaless document (JsonDocument or Json String).
*/
public class JsonDocumentMutationResult extends DocumentMutationResult<Map<String, Object>> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.UUID;

/**
* Json Results.
* Represents entity returns for find() queries working with shemaless documents.
*/
@Getter @Setter
public class JsonDocumentResult extends DocumentResult<Map<String, Object>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Data;

/**
* Payload for json Api update.
* Represents the payload returned for a specialized update function.
*/
@Data
public class JsonResultUpdate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Map;

/**
* Pogo to create a namspace.
* Represents the Namespace (keyspac) definition with its name and metadata.
*/
@Data
public class NamespaceDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import javax.print.Doc;

/**
* Working with entities.
* Unitary entity for a document. Adding `id` and `vector`.
*
* @param <T>
* type of bean in use
Expand Down Expand Up @@ -120,4 +120,15 @@ public Document<T> data(T data) {
public static <R> Document<R> of(String id, float[] vector, R data) {
return new Document<R>().id(id).vector(vector).data(data);
}

/**
* Print the document as a Json String.
*
* @return
* json string
*/
@Override
public String toString() {
return JsonUtils.marshallForDataApi(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


/**
* Result class with ODM.
* Unitary entity for a return document. It is a document amended with `similarity`.
*
* @param <DOC>
* pojo in use for ODM
Expand Down Expand Up @@ -83,5 +83,4 @@ public DocumentResult(JsonDocumentResult result, Class<DOC> clazz) {
public static <R> DocumentResult<R> of(JsonDocumentResult result, Class<R> clazz) {
return new DocumentResult<>(result, clazz);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Specialized entities for this Api
* Specialized domain objects for data operations.
*/
package io.stargate.sdk.data.domain;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Specialized exceptions for this API.
* Specialized runtime exceptions for Data API.
*/
package io.stargate.sdk.data.exception;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Main package for client to works with Stargate Data API (collection,vector)
* Core Data API Client Classes.
*/
package io.stargate.sdk.data;
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package io.stargate.sdk.data.utils;

import io.stargate.sdk.data.domain.ApiData;
import io.stargate.sdk.http.LoadBalancedHttpClient;
import io.stargate.sdk.http.ServiceHttp;
import io.stargate.sdk.http.domain.ApiResponseHttp;
import io.stargate.sdk.data.domain.ApiError;
import io.stargate.sdk.data.domain.ApiResponse;
import io.stargate.sdk.data.exception.DataApiDocumentAlreadyExistException;
import io.stargate.sdk.data.exception.DataApiErrorCode;
import io.stargate.sdk.data.exception.DataApiException;
import io.stargate.sdk.data.exception.DataApiDocumentAlreadyExistException;
import io.stargate.sdk.data.exception.DataApiInvalidArgumentException;
import io.stargate.sdk.http.LoadBalancedHttpClient;
import io.stargate.sdk.http.ServiceHttp;
import io.stargate.sdk.http.domain.ApiResponseHttp;
import io.stargate.sdk.utils.JsonUtils;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.function.Function;

import static io.stargate.sdk.utils.AnsiUtils.magenta;
Expand All @@ -32,12 +31,12 @@ public class DataApiUtils {
private DataApiUtils() {}

/**
* Accessing api.
* Wrapper to execute Http POST request.
*
* @param stargateHttpClient
* http client
* @param operation
* name of the operation
* operation name
* @param rootResource
* rest resource
* @param body
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Utilities to work with Json Structures
* Utilities to build and parse http requests
*/
package io.stargate.sdk.data.utils;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.stargate.sdk.data.DataApiClient;
import io.stargate.sdk.data.CollectionClient;
import io.stargate.sdk.data.CollectionRepository;
import io.stargate.sdk.data.DocumentMutationResult;
import io.stargate.sdk.data.domain.DocumentMutationResult;
import io.stargate.sdk.data.domain.CollectionDefinition;
import io.stargate.sdk.data.domain.query.Filter;
import io.stargate.sdk.data.domain.JsonDocument;
Expand Down

0 comments on commit a7667da

Please sign in to comment.