Skip to content

Commit

Permalink
update java client
Browse files Browse the repository at this point in the history
  • Loading branch information
scivey committed Oct 9, 2015
1 parent 21e2014 commit b41e402
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 185 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ thrift-node:
thrift-0.9 --gen js:node -o ./clients/nodejs/client/relevancedClient src/RelevancedProtocol.thrift

thrift-java:
mkdir -p clients/java/src
rm -rf clients/java/client/src/main/java/org/relevanced/client/gen_thrift_protocol
mkdir -p build/thrift
thrift-0.9 --gen java -o build/thrift src/RelevancedProtocol.thrift
mv ./build/thrift/gen-java/org/relevanced/client/gen_thrift_protocol ./clients/java/client/src/org/relevanced/client/
mv ./build/thrift/gen-java/org/relevanced/client/gen_thrift_protocol ./clients/java/client/src/main/java/org/relevanced/client/

build-docker-standalone:
cp build/deb/*.deb scripts/packaging/containers/standalone_server/data/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,172 +48,90 @@ public RelevancedBlockingClient(String host, int port) {
}
}

protected void handleResponseStatus(Status status) throws RelevancedException {
if (status.code == StatusCode.OK) {
return;
}
switch (status.code) {
case CENTROID_DOES_NOT_EXIST:
throw new CentroidDoesNotExist(status.message);
case CENTROID_ALREADY_EXISTS:
throw new CentroidAlreadyExists(status.message);
case DOCUMENT_DOES_NOT_EXIST:
throw new DocumentDoesNotExist(status.message);
case DOCUMENT_ALREADY_EXISTS:
throw new DocumentAlreadyExists(status.message);
default:
throw new UnknownException(status.message);
}
}

public Map<String, Double> multiGetTextSimilarity(List<String> centroidIds, String text) throws RelevancedException {
public Map<String, Double> multiGetTextSimilarity(List<String> centroidIds, String text) throws TException {
MultiSimilarityResponse response;
try {
response = thriftClient_.multiGetTextSimilarity(centroidIds, text);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.multiGetTextSimilarity(centroidIds, text);
return response.scores;
}

public Double getTextSimilarity(String centroidId, String text) throws RelevancedException {
public Double getTextSimilarity(String centroidId, String text) throws TException {
SimilarityResponse response;
try {
response = thriftClient_.getTextSimilarity(centroidId, text);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.getTextSimilarity(centroidId, text);
return response.similarity;
}

public Double getDocumentSimilarity(String centroidId, String documentId) throws RelevancedException {
public Double getDocumentSimilarity(String centroidId, String documentId) throws TException {
SimilarityResponse response;
try {
response = thriftClient_.getDocumentSimilarity(centroidId, documentId);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.getDocumentSimilarity(centroidId, documentId);
return response.similarity;
}

public Double getCentroidSimilarity(String centroidId1, String centroidId2) throws RelevancedException {
public Double getCentroidSimilarity(String centroidId1, String centroidId2) throws TException {
SimilarityResponse response;
try {
response = thriftClient_.getCentroidSimilarity(centroidId1, centroidId2);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.getCentroidSimilarity(centroidId1, centroidId2);
return response.similarity;
}

public String createDocument(String text) throws RelevancedException {
public String createDocument(String text) throws TException {
CrudResponse response;
try {
response = thriftClient_.createDocument(text);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
return response.created;
response = thriftClient_.createDocument(text);
return response.id;
}

public String createDocumentWithID(String id, String text) throws RelevancedException {
public String createDocumentWithID(String id, String text) throws TException {
CrudResponse response;
try {
response = thriftClient_.createDocumentWithID(id, text);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
return response.created;
response = thriftClient_.createDocumentWithID(id, text);
return response.id;
}

public Boolean deleteDocument(String documentId) throws RelevancedException {
public String deleteDocument(String documentId) throws TException {
CrudResponse response;
try {
response = thriftClient_.deleteDocument(documentId);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
return true;
response = thriftClient_.deleteDocument(documentId);
return response.id;
}

public String createCentroid(String name) throws RelevancedException {
public String createCentroid(String name) throws TException {
CrudResponse response;
try {
response = thriftClient_.createCentroid(name);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
return response.created;
response = thriftClient_.createCentroid(name);
return response.id;
}

public Boolean deleteCentroid(String name) throws RelevancedException {
public Boolean deleteCentroid(String name) throws TException {
CrudResponse response;
try {
response = thriftClient_.deleteCentroid(name);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
return true;
response = thriftClient_.deleteCentroid(name);
return response.id;
}

public Boolean addDocumentToCentroid(String centroidId, String documentId) throws RelevancedException {
public Boolean addDocumentToCentroid(String centroidId, String documentId) throws TException {
CrudResponse response;
try {
response = thriftClient_.addDocumentToCentroid(centroidId, documentId);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.addDocumentToCentroid(centroidId, documentId);
return true;
}

public Boolean removeDocumentFromCentroid(String centroidId, String documentId) throws RelevancedException {
public Boolean removeDocumentFromCentroid(String centroidId, String documentId) throws TException {
CrudResponse response;
try {
response = thriftClient_.removeDocumentFromCentroid(centroidId, documentId);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.removeDocumentFromCentroid(centroidId, documentId);
return true;
}

public List<String> listAllDocuments() throws RelevancedException {
try {
List<String> documents = thriftClient_.listAllDocuments();
return documents;
} catch (TException err) {
throw new ConnectionError(err);
}
public List<String> listAllDocuments() throws TException {
List<String> documents = thriftClient_.listAllDocuments();
return documents;
}

public List<String> listAllCentroids() throws RelevancedException {
try {
List<String> centroids = thriftClient_.listAllCentroids();
return centroids;
} catch (TException err) {
throw new ConnectionError(err);
}
public List<String> listAllCentroids() throws TException {
List<String> centroids = thriftClient_.listAllCentroids();
return centroids;
}

public List<String> listAllDocumentsForCentroid(String centroidId) throws RelevancedException {
public List<String> listAllDocumentsForCentroid(String centroidId) throws TException {
ListCentroidDocumentsResponse response;
try {
response = thriftClient_.listAllDocumentsForCentroid(centroidId);
} catch (TException err) {
throw new ConnectionError(err);
}
handleResponseStatus(response.status);
response = thriftClient_.listAllDocumentsForCentroid(centroidId);
return response.documents;
}

public Map<String, String> getServerMetadata() throws TException {
return thriftClient_.getServerMetadata();
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit b41e402

Please sign in to comment.